Skip to content

Commit c907bb0

Browse files
committed
Fix compile
1 parent f8a7be4 commit c907bb0

File tree

1 file changed

+74
-131
lines changed

1 file changed

+74
-131
lines changed

jcs-template.el

Lines changed: 74 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,63 @@
4040
:group 'faces
4141
:link '(url-link :tag "Github" "https://github.com/jcs-emacs/jcs-etemplate"))
4242

43+
(defcustom jcs-template-headers
44+
'("d-colon"
45+
"d-dash"
46+
"d-double-quote"
47+
"d-semicolon"
48+
"d-slash"
49+
"d-percent"
50+
"t-slash"
51+
"c-style"
52+
"sharp"
53+
"semicolon"
54+
"d-single-quote"
55+
"tag"
56+
"percent")
57+
"List of template headers."
58+
:type 'list
59+
:group 'jcs-template)
60+
61+
;;
62+
;; (@* "Util" )
63+
;;
64+
65+
(defun jcs-current-file-empty-p (&optional fn)
66+
"Check if the FN an empty file."
67+
(if fn (with-current-buffer fn (and (bobp) (eobp)))
68+
(and (bobp) (eobp))))
69+
70+
(defun jcs-string-compare-p (regexp str type &optional ignore-case)
71+
"Compare STR with REGEXP by TYPE.
72+
73+
Argument TYPE can be on of the following symbol.
74+
75+
* regex - uses function `string-match-p'. (default)
76+
* strict - uses function `string='.
77+
* prefix - uses function `string-prefix-p'.
78+
* suffix - uses function `string-suffix-p'.
79+
80+
Optional argument IGNORE-CASE is only uses when TYPE is either symbol `prefix'
81+
or `suffix'."
82+
(cl-case type
83+
(`strict (string= regexp str))
84+
(`prefix (string-prefix-p regexp str ignore-case))
85+
(`suffix (string-suffix-p regexp str ignore-case))
86+
(t (ignore-errors (string-match-p regexp str)))))
87+
88+
(defun jcs-contain-list-type-str (elt list type &optional reverse)
89+
"Return non-nil if ELT is listed in LIST.
90+
91+
Argument TYPE see function `jcs-string-compare-p' for more information.
92+
93+
If optional argument REVERSE is non-nil, LIST item and ELT argument."
94+
(cl-some
95+
(lambda (elm)
96+
(if reverse (jcs-string-compare-p elt elm type)
97+
(jcs-string-compare-p elm elt type)))
98+
list))
99+
43100
;;
44101
;; (@* "Insertion" )
45102
;;
@@ -72,48 +129,9 @@ FAILED is callback if does NOT successfully inserted header content."
72129
result))
73130

74131
;;
75-
;; (@* "Buffer String" )
132+
;; (@* "Core" )
76133
;;
77134

78-
(defvar jcs-template--header-double-colon nil
79-
"Preload the double colon file info template.")
80-
81-
(defvar jcs-template--header-double-dash nil
82-
"Preload the double dash file info template.")
83-
84-
(defvar jcs-template--header-double-quote nil
85-
"Preload the double quote file info template.")
86-
87-
(defvar jcs-template--header-double-semicolon nil
88-
"Preload the double semicolon file info template.")
89-
90-
(defvar jcs-template--header-double-slash nil
91-
"Preload the double slash file info template.")
92-
93-
(defvar jcs-template--header-double-percent nil
94-
"Preload the double percent file info template.")
95-
96-
(defvar jcs-template--header-triple-slash nil
97-
"Preload the triple slash file info template.")
98-
99-
(defvar jcs-template--header-c-style nil
100-
"Preload the global file info template.")
101-
102-
(defvar jcs-template--header-sharp nil
103-
"Preload the sharp file info template.")
104-
105-
(defvar jcs-template--header-semicolon nil
106-
"Preload the semicolon file info template.")
107-
108-
(defvar jcs-template--header-single-quote nil
109-
"Preload the single quote file info template.")
110-
111-
(defvar jcs-template--header-tag nil
112-
"Preload the tag file info template.")
113-
114-
(defvar jcs-template--header-percent nil
115-
"Preload the percent file info template.")
116-
117135
(defvar jcs-template--headers-loaded-p nil
118136
"Return non-nil, if headers are loaded as cache.")
119137

@@ -124,104 +142,29 @@ FAILED is callback if does NOT successfully inserted header content."
124142
If optional argument FORCE is non-nil, refresh cache once."
125143
(interactive)
126144
(when (or force (null jcs-template--headers-loaded-p))
127-
(setq jcs-template--header-double-colon (file-header-template-string "__header/d_colon.txt")
128-
jcs-template--header-double-dash (file-header-template-string "__header/d_dash.txt")
129-
jcs-template--header-double-quote (file-header-template-string "__header/d_quote.txt")
130-
jcs-template--header-double-semicolon (file-header-template-string "__header/d_semicolon.txt")
131-
jcs-template--header-double-slash (file-header-template-string "__header/d_slash.txt")
132-
jcs-template--header-double-percent (file-header-template-string "__header/d_percent.txt")
133-
jcs-template--header-triple-slash (file-header-template-string "__header/t_slash.txt")
134-
jcs-template--header-c-style (file-header-template-string "__header/c_style.txt")
135-
jcs-template--header-semicolon (file-header-template-string "__header/semicolon.txt")
136-
jcs-template--header-sharp (file-header-template-string "__header/sharp.txt")
137-
jcs-template--header-single-quote (file-header-template-string "__header/singlequote.txt")
138-
jcs-template--header-tag (file-header-template-string "__header/tag.txt")
139-
jcs-template--header-percent (file-header-template-string "__header/percent.txt")
140-
jcs-template--headers-loaded-p t)))
145+
(dolist (header jcs-template-headers)
146+
(set (intern (concat "jcs-template--header-" header))
147+
(file-header-template-string (format "__header/%s.txt" header))))
148+
(setq jcs-template--headers-loaded-p t)))
141149

142150
;;
143151
;; (@* "Header" )
144152
;;
145153

146154
;;;###autoload
147-
(defun jcs-template-header-double-colon ()
148-
"Return the preloaded double colon file info template."
149-
(file-header-swap-keyword-template jcs-template--header-double-colon))
150-
151-
;;;###autoload
152-
(defun jcs-template-header-double-dash ()
153-
"Return the preloaded double dash file info template."
154-
(file-header-swap-keyword-template jcs-template--header-double-dash))
155-
156-
;;;###autoload
157-
(defun jcs-template-header-double-quote ()
158-
"Return the preloaded double quote file info template."
159-
(file-header-swap-keyword-template jcs-template--header-double-quote))
160-
161-
;;;###autoload
162-
(defun jcs-template-header-double-semicolon ()
163-
"Return the preloaded double semicolon file info template."
164-
(file-header-swap-keyword-template jcs-template--header-double-semicolon))
165-
166-
;;;###autoload
167-
(defun jcs-template-header-double-slash ()
168-
"Return the preloaded double slash file info template."
169-
(file-header-swap-keyword-template jcs-template--header-double-slash))
170-
171-
;;;###autoload
172-
(defun jcs-template-header-triple-slash ()
173-
"Return the preloaded triple slash file info template."
174-
(file-header-swap-keyword-template jcs-template--header-triple-slash))
175-
176-
;;;###autoload
177-
(defun jcs-template-header-c-style ()
178-
"Return the preloaded c-style file info template."
179-
(file-header-swap-keyword-template jcs-template--header-c-style))
180-
181-
;;
182-
;;; ;
183-
184-
;;;###autoload
185-
(defun jcs-template-header-semicolon ()
186-
"Return the preloaded semicolon file info template."
187-
(file-header-swap-keyword-template jcs-template--header-semicolon))
155+
(defmacro jcs-template-define-header (name)
156+
"Define template header by NAME."
157+
(let ((var (intern (concat "jcs-template--header-" name)))
158+
(func (intern (concat "jcs-template-header-" name))))
159+
`(progn
160+
(defvar ,var nil
161+
,(format "Preload the %s header template." name))
162+
(defun ,func nil
163+
,(format "Return the preload %s header template." name)
164+
(file-header-swap-keyword-template ,var)))))
188165

189-
;;
190-
;;; #
191-
192-
;;;###autoload
193-
(defun jcs-template-header-sharp ()
194-
"Return the preloaded sharp file info template."
195-
(file-header-swap-keyword-template jcs-template--header-sharp))
196-
197-
;;
198-
;;; '
199-
200-
;;;###autoload
201-
(defun jcs-template-header-single-quote ()
202-
"Return the preloaded single quote file info template."
203-
(file-header-swap-keyword-template jcs-template--header-single-quote))
204-
205-
;;
206-
;;; <!-- -->
207-
208-
;;;###autoload
209-
(defun jcs-template-header-tag ()
210-
"Return the preloaded tag file info template."
211-
(file-header-swap-keyword-template jcs-template--header-tag))
212-
213-
;;
214-
;;; %
215-
216-
;;;###autoload
217-
(defun jcs-template-header-double-percent ()
218-
"Return the preloaded double percent file info template."
219-
(file-header-swap-keyword-template jcs-template--header-double-percent))
220-
221-
;;;###autoload
222-
(defun jcs-template-header-percent ()
223-
"Return the preloaded percent file info template."
224-
(file-header-swap-keyword-template jcs-template--header-percent))
166+
(dolist (header jcs-template-headers)
167+
(eval `(jcs-template-define-header ,header)))
225168

226169
(provide 'jcs-template)
227170
;;; jcs-template.el ends here

0 commit comments

Comments
 (0)