-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathlentic-asciidoc.el
180 lines (149 loc) · 5.15 KB
/
lentic-asciidoc.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
;;; lentic-asciidoc.el --- asciidoc support for lentic -*- lexical-binding: t -*-
;;; Header:
;; This file is not part of Emacs
;; Author: Phillip Lord <[email protected]>
;; Maintainer: Phillip Lord <[email protected]>
;; The contents of this file are subject to the GPL License, Version 3.0.
;;
;; Copyright (C) 2014-2022 Free Software Foundation, Inc.
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Lentic buffers with asciidoc [source] blocks.
;;; Code:
;; #+begin_src emacs-lisp
(require 'lentic)
(require 'lentic-chunk)
(require 'm-buffer)
(defun lentic-asciidoc-oset (conf)
(lentic-m-oset
conf
'this-buffer (current-buffer)
'comment ";; "))
(defun lentic-asciidoc-commented-new ()
(lentic-asciidoc-oset
(lentic-commented-asciidoc-configuration
"lb-commented-clojure asciidoc"
:lentic-file
(concat
(file-name-sans-extension
(buffer-file-name)) ".adoc"))))
;;;###autoload
(defun lentic-clojure-asciidoc-init ()
(lentic-asciidoc-commented-new))
(add-to-list 'lentic-init-functions #'lentic-clojure-asciidoc-init)
(defun lentic-asciidoc-uncommented-new ()
(lentic-asciidoc-oset
(lentic-uncommented-asciidoc-configuration
"lb-uncommented-clojure-asciidoc"
:lentic-file
(concat
(file-name-sans-extension
(buffer-file-name)) ".clj"))))
;;;###autoload
(defun lentic-asciidoc-clojure-init ()
(lentic-asciidoc-uncommented-new))
;;;###autoload
(add-to-list 'lentic-init-functions #'lentic-asciidoc-clojure-init)
;; ** Support Emacs-Lisp
;;;###autoload
(defun lentic-asciidoc-el-init ()
(lentic-asciidoc-oset
(lentic-uncommented-asciidoc-configuration
"temp"
:lentic-file
(concat
(file-name-sans-extension
buffer-file-name)
".el"))))
;;;###autoload
(add-to-list 'lentic-init-functions #'lentic-asciidoc-el-init)
(defclass lentic-commented-asciidoc-configuration
(lentic-commented-chunk-configuration)
((srctags :initarg :srctags
:documentation "Language tags in source chunk"
:initform '("clojure" "lisp")))
"Lentic buffer config for asciidoc and other code.")
(defclass lentic-uncommented-asciidoc-configuration
(lentic-uncommented-chunk-configuration)
((srctags :initarg :srctags
:documentation "Language tags in source chunk"
:initform '("clojure" "lisp")))
"Lentic buffer config for asciidoc and other code")
(defun lentic-splitter (l)
"Returns a function which for use as a partition predicate.
The returned function returns the first element of L until it is
passed a value higher than the first element, then it returns the
second element and so on."
#'(lambda (x)
(when
(and l
(< (car l) x))
(setq l (-drop 1 l)))
(car l)))
(defun lentic-partition-after-source (l-source l-dots)
"Given a set of markers l-source, partition the markers in
l-dots.
The source markers represent [source] markers, so we take the
next matches to \"....\" immediately after a [source] marker.
This should remove other \"....\" matches.
"
(-partition-by
(lentic-splitter l-source)
(-drop-while
(lambda (x)
(and l-source
(< x (car l-source))))
l-dots)))
(defun lentic-chunk-match-asciidoc
(conf buffer)
(let* ((source
(m-buffer-match-begin
buffer
(format ";* *\\[source,%s\\]"
(regexp-opt
(oref conf srctags)))))
;; this could also be a start of title
(dots
(m-buffer-match buffer
"^;* *----"))
(source-start
(lentic-partition-after-source
source
(m-buffer-match-begin
dots)))
(source-end
(lentic-partition-after-source
source (m-buffer-match-end dots))))
(when source
(list
(-map 'cadr source-start)
(-map 'car source-end)))))
(cl-defmethod lentic-chunk-match
((conf lentic-commented-asciidoc-configuration) buffer)
(lentic-chunk-match-asciidoc conf buffer))
(cl-defmethod lentic-chunk-match
((conf lentic-uncommented-asciidoc-configuration) buffer)
(lentic-chunk-match-asciidoc conf buffer))
(cl-defmethod lentic-invert
((conf lentic-commented-asciidoc-configuration))
(lentic-m-oset (lentic-asciidoc-uncommented-new)
'that-buffer (lentic-this conf)))
(cl-defmethod lentic-invert
((conf lentic-uncommented-asciidoc-configuration))
(lentic-m-oset (lentic-asciidoc-commented-new)
'that-buffer (lentic-this conf)))
(provide 'lentic-asciidoc)
;;; lentic-asciidoc.el ends here
;; #+end_src