Mercurial > hgrepos > hgweb.cgi > yatex
annotate yatexgen.el @ 287:5921f28ef77c dev
Change the first lines.
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Sat, 01 Sep 2012 08:14:41 +0900 |
parents | 0734be649cb8 |
children | 2a72779d9c50 |
rev | line source |
---|---|
287 | 1 ;;; yatexgen.el --- YaTeX add-in function generator(rev.5) |
2 | |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
72
diff
changeset
|
3 ;;; (c)1991-1995,1999,2000 by HIROSE Yuuji.[yuuji@yatex.org] |
287 | 4 ;;; Last modified Sat Sep 1 08:10:36 2012 on firestorm |
9 | 5 ;;; $Id$ |
6 | |
287 | 7 ;;; Code: |
9 | 8 (require 'yatex) |
9 | |
10 (defmacro YaTeX-setq (var japanese english) | |
11 (list 'setq var | |
287 | 12 (if YaTeX-japan japanese english))) |
9 | 13 |
14 (put 'YaTeX-setq 'lisp-indent-hook 1) | |
15 | |
16 (YaTeX-setq YaTeX-generate-initial-message | |
17 " 自動生成モードへようこそ!! | |
18 | |
19 初めてやる人はこのバッファの例にしたがって指示通りにやって練習してね。 | |
20 本番の時もこのバッファに出るメッセージを *よく読んで* 操作しないとう | |
21 まく関数が作れないよ!! | |
22 | |
23 ではリターンキーを押して下さい。" | |
24 " Welcome to auto-generation mode!! | |
25 | |
26 If this is your first trial, exercise this according to example and | |
27 following my messages. Then, at making actual function, operate | |
28 reading my messages *carefully*, or you'll fail to generate appropriate | |
29 function. | |
30 | |
287 | 31 Hit return key!") |
9 | 32 |
33 (YaTeX-setq YaTeX-generate-start-message | |
34 "さぁはじめるよ.\n1.登録したい補完をやってみて. | |
35 たとえば section 型補完の \\documentstyle だったら \\documentstyle{} | |
36 だけをいれてみてね. ちゃんと『〜型補完』を使わないとダメよ!。 | |
37 で、おわったらりたーん!!" | |
38 "Let's begin completion for which you want to make add-in function. | |
39 If you want to make add-in function for \\documentstyle input only | |
40 `\\documentstyle{}' *with* completion of yatex-mode. | |
287 | 41 If you finish this, please press RET.") |
9 | 42 |
43 (YaTeX-setq YaTeX-generate-abort-message | |
44 "やめた、やめた〜いめんどくせ〜" | |
287 | 45 "Aborted.") |
9 | 46 |
47 (YaTeX-setq YaTeX-generate-same-message | |
48 "それじゃ、なにも変わってねぇだろーが! やめた。" | |
287 | 49 "I found no difference between them. So I'm quitting.") |
9 | 50 |
51 (YaTeX-setq YaTeX-generate-invalid-message | |
52 "それは、ちと無理というものじゃ." | |
287 | 53 "It's impossible.") |
9 | 54 |
55 (YaTeX-setq YaTeX-generate-idontknow-message | |
56 "う〜ん、難しくてよくわからないなぁ。ばかでごめんねェ〜" | |
287 | 57 "Sorry I can't tell your adding method.") |
9 | 58 |
59 (YaTeX-setq YaTeX-generate-confirm-message | |
60 "ということは、付け足したい部分はこれでいいのね" | |
287 | 61 "Is it additional string of add-in function?") |
9 | 62 |
63 (YaTeX-setq YaTeX-generate-output-message | |
64 "2.じゃ、それにくっつけたいものを *カーソルの位置に* 足してみて. | |
65 さっきの \\documentstyle{} の例だと \\documentstyle[12pt]{} とかにするの。 | |
66 しつこいようだけど、今の位置からカーソル動かしちゃダメよ!! | |
67 で、またおわったらりたーん!!" | |
68 "2.Then input additional string *at CURSOR POSITION* | |
69 According to last example \\documentstyle{}, | |
287 | 70 modify it \\documentstyle[12pt]{}. RET to finish.") |
9 | 71 |
72 (YaTeX-setq YaTeX-generate-put-arg-message | |
73 "3.このうち、キーボードから読み込んで欲しい文字列を順に入れて。 | |
74 さっきの \\documentstyle[12pt]{} だったら、付加する文字は[12pt]だけど | |
75 手で入れたいのは 12pt の部分だけですね。 | |
76 で、全部入れ終ったら、りたーんだけうってね!!" | |
77 "3.In this string, extract string which you want to input from key | |
78 board with quiry afterwards. For example, though additional string is | |
79 \\documentstyle[12pt]{}, but you want enter only `12pt' by hand. | |
287 | 80 RET to finish!") |
9 | 81 |
82 (YaTeX-setq YaTeX-generate-read-prompt-message | |
83 "4.では、あとでこれらの文字列を読み込む時に、どういうプロンプトを | |
84 出したいですか? 順に入れて下さい。面倒なら単にリターンを打ってね。 | |
85 さっきの 12pt の部分だったら、『サイズは』とかがおすすめ。" | |
86 "4.When you use this add-in function afterwards, what message | |
87 do you like to be prompted with to enter these values. In last | |
287 | 88 example `12pt', typical prompt string may be `Size?: '.") |
9 | 89 |
90 (YaTeX-setq YaTeX-generate-done-message | |
91 "よし! これが、君の作りたかった関数だ。~/.emacs にでも入れてせいぜい | |
92 楽してくれ。このバッファ(*ご案内*)を yatex-mode にしておくから | |
93 できた関数が本当にお望みの動作をするか確かめてみるといいかもね。 | |
94 ところで、この関数こんなに簡単だろう? そろそろ自分で書いたらどう? | |
95 " | |
96 "OK! This is the definition of function you want to make! Add | |
97 this description to your ~/.emacs or so. Use this buffer(*Guide*) | |
98 for testing of this function please. | |
99 But you can see this function quite easy, can't you? You had better | |
100 write your most favorite add-in function yourself! | |
287 | 101 ") |
9 | 102 |
103 (YaTeX-setq YaTeX-generate-nomatch-message | |
104 "こらこら、そんな文字列どこにもねーぞ!!" | |
287 | 105 "No such string in additional string.") |
106 | |
9 | 107 (YaTeX-setq YaTeX-generate-buffer |
108 "*付加関数生成バッファ*" | |
287 | 109 "*Generate-add-in-function*") |
9 | 110 |
111 (YaTeX-setq YaTeX-generate-message-buffer | |
112 "*ご案内*" | |
287 | 113 "*Guide*") |
9 | 114 |
115 (YaTeX-setq YaTeX-generate-bug-message | |
116 "ごめ〜ん!! ちょっと、このアドイン関数つくるの失敗しちゃったみたい!! | |
117 作者まで連絡してくださ〜〜〜い!" | |
118 "Sorry I failed to make add-in function for you... | |
287 | 119 Send bug report to me.") |
9 | 120 |
121 (YaTeX-setq YaTeX-generate-narrow-message | |
122 "画面がせますぎるような気がします。" | |
287 | 123 "Too narrow screen height.") |
9 | 124 |
125 (defvar YaTeX-generate-message-height | |
126 10 "Window height of YaTeX-generate-message-buffer") | |
127 | |
52 | 128 ;; Do you need learning for generated function? |
70 | 129 ;; If you need, please tell me (yuuji@yatex.org) |
52 | 130 ;;(defvar YaTeX-generate-variables-for-learning nil) |
131 ;;(defvar YaTeX-generate-current-completion-table nil) | |
132 | |
9 | 133 ;;; |
134 ;Generate mode. | |
135 ;;; | |
136 (defun YaTeX-generate () | |
137 "Genarate YaTeX add-in function with enquiry." | |
138 (interactive) | |
70 | 139 (if (< (YaTeX-screen-height) (+ YaTeX-generate-message-height 10)) |
9 | 140 (error YaTeX-generate-narrow-message)) |
141 (put 'YaTeX-generate 'disabled t) | |
142 (save-window-excursion | |
143 (unwind-protect | |
144 (let (input output (i 0) (beg 0) end add-in map map1 si str slist | |
145 (from (make-marker)) (to (make-marker))) | |
146 (delete-other-windows) | |
147 (switch-to-buffer YaTeX-generate-message-buffer) | |
148 (yatex-mode) | |
149 (erase-buffer) | |
150 (insert YaTeX-generate-initial-message) | |
151 (read-string | |
152 (if YaTeX-japan "リターンキーを押して下さい." "Press RETURN.")) | |
153 (erase-buffer) | |
154 (insert YaTeX-generate-start-message) | |
155 (pop-to-buffer (get-buffer-create YaTeX-generate-buffer)) | |
156 (enlarge-window (- (window-height) YaTeX-generate-message-height 1)) | |
157 (erase-buffer) | |
158 (yatex-mode) | |
159 (use-local-map (setq map (copy-keymap YaTeX-mode-map))) | |
160 (define-key (current-local-map) "\n" 'exit-recursive-edit) | |
161 (define-key (current-local-map) "\r" 'exit-recursive-edit) | |
162 (define-key (current-local-map) "\C-g" 'abort-recursive-edit) | |
163 (setq map1 (copy-keymap map)) | |
164 (YaTeX-suppress-sparse-keymap map) | |
165 ;;First get input form. | |
166 (recursive-edit) | |
72 | 167 (setq input (YaTeX-minibuffer-string) |
9 | 168 end (1- (length input))) |
169 (if (string= "" input) (error YaTeX-generate-abort-message)) | |
170 (YaTeX-generate-move-to-add-in-position) | |
171 (set-marker from (1- (point))) ;;Can't write before `from' | |
172 (set-marker to (1+ (point))) ;;Can't write after `to' | |
173 ;;Second get output form. | |
174 (setq beg (1- (point)));;Cheat begin point! | |
175 (YaTeX-generate-display-message YaTeX-generate-output-message) | |
176 (use-local-map map1) | |
177 (fset 'si (symbol-function 'self-insert-command)) | |
178 (defun self-insert-command (arg) | |
179 (interactive "p") | |
180 (if (or (not (equal (buffer-name) YaTeX-generate-buffer)) | |
181 (and (> (point) (marker-position from)) | |
182 (< (point) (marker-position to)))) | |
183 (insert (this-command-keys)) (ding))) | |
184 (unwind-protect | |
185 (recursive-edit) | |
186 (fset 'self-insert-command (symbol-function 'si))) | |
72 | 187 (setq output (YaTeX-minibuffer-string)) |
9 | 188 (cond ((string= "" output) (error YaTeX-generate-abort-message)) |
189 ((string= input output) (error YaTeX-generate-same-message)) | |
190 ((< (length output) (length input)) | |
191 (error YaTeX-generate-invalid-message))) | |
192 ;;(while (and (< beg end) (= (aref input beg) (aref output i))) | |
193 ;; (setq beg (1+ beg) i (1+ i))) ;;for universal use. | |
194 (setq i (1- (length output))) | |
195 (while (and (>= end beg) (= (aref output i) (aref input end))) | |
196 (setq end (1- end) i (1- i))) | |
197 (setq add-in (substring output beg | |
198 (if (= i (1- (length output))) nil (1+ i)))) | |
199 (erase-buffer) | |
200 (insert add-in) | |
201 (if (not (y-or-n-p YaTeX-generate-confirm-message)) | |
202 (error YaTeX-generate-idontknow-message)) | |
203 ;;Extract arguments. | |
204 (YaTeX-generate-display-message YaTeX-generate-put-arg-message) | |
205 (setq i 1) | |
206 (while (not (string= | |
207 "" (setq str (read-string (format "Arg %d: " i))))) | |
208 (if (not (string-match (regexp-quote str) add-in)) | |
209 (progn | |
210 (ding) | |
211 (YaTeX-generate-display-message | |
212 YaTeX-generate-nomatch-message -1)) | |
213 (setq slist (append slist (list (list str))) i (1+ i))) | |
214 );input all of arguments. | |
215 ;;Compare with output string. | |
216 (set-buffer YaTeX-generate-buffer) ;;for safety | |
217 (emacs-lisp-mode) | |
218 (if (> i 1) | |
219 (YaTeX-generate-parse-add-in slist add-in) | |
220 (erase-buffer) | |
221 (insert "(defun " (YaTeX-generate-function-name) " ()\n") | |
222 (insert "\"" (YaTeX-generate-lisp-quote add-in) "\")\n") | |
223 (indent-region (point-min) (point-max) nil) | |
224 (message (if YaTeX-japan | |
225 "このくらいの関数手で書け!!" | |
226 "You don't need me to make such easy function."))) | |
227 );let | |
228 (put 'YaTeX-generate 'disabled nil) | |
229 (put 'YaTeX-addin 'disabled nil) | |
230 )) | |
231 (YaTeX-generate-display-message YaTeX-generate-done-message) | |
232 (switch-to-buffer YaTeX-generate-buffer) | |
233 (condition-case error | |
234 (eval-current-buffer) | |
235 (error (insert YaTeX-generate-bug-message))) | |
287 | 236 (pop-to-buffer YaTeX-generate-message-buffer)) |
9 | 237 |
238 (defun YaTeX-generate-parse-add-in (args add-in) | |
239 "Parse add-in string and extract argument for it. | |
240 Variable add-in is referred in parent function." | |
241 (let ((i 1) j (case-fold-search nil) ;i holds argument number | |
242 (prompt (make-vector (length args) "")) | |
243 (used (make-vector (length add-in) nil)) | |
244 func-name (string "")) | |
245 ;;Phase 1. extract argument from add-in string. | |
246 (mapcar | |
247 '(lambda (arg) | |
248 (let ((index 0) (match 0) beg end (carg (car arg))) | |
249 (YaTeX-generate-display-message | |
250 YaTeX-generate-read-prompt-message) | |
251 (aset prompt (1- i) | |
252 (read-string | |
253 (format | |
254 (if YaTeX-japan "%d番目(%s)を読む時?: " | |
255 "When reading argument #%d(%s)?: ") i (car arg)))) | |
256 (while (string-match (regexp-quote carg) (substring add-in index)) | |
257 (setq beg (+ index (match-beginning 0)) | |
258 end (+ index (match-end 0))) | |
259 (if (aref used beg) nil | |
260 (setq match (1+ match)) | |
261 (cond | |
262 ((= match 1) | |
263 ;;(setq arg (append arg (list (list beg end)))) | |
264 (YaTeX-generate-register-match)) | |
265 ((YaTeX-generate-ask-match-position) | |
266 (YaTeX-generate-register-match)))) | |
267 (setq index end)) | |
268 (setq i (1+ i)))) | |
269 args) | |
270 ;;Phase 2. Generate function!! | |
271 (setq i 0) | |
272 (setq func-name (YaTeX-generate-function-name)) | |
273 (while (< i (length add-in)) | |
274 (setq beg i j (aref used i)) | |
275 (while (and (< i (length add-in)) (equal j (aref used i))) | |
276 (setq i (1+ i))) | |
277 (if j ;If it is argument. | |
278 (setq string (concat string (format " arg%d" j))) | |
279 (setq string | |
280 (concat string " \"" | |
281 (YaTeX-generate-quote-quote (substring add-in beg i)) | |
282 "\"")) | |
283 )) | |
284 (erase-buffer) | |
285 (setq i 1) | |
286 (insert | |
287 "(defun " func-name " ()\n" | |
288 " (let (") | |
289 (mapcar | |
290 '(lambda (arg) | |
291 (insert (format "(arg%d (read-string \"%s: \"))\n" | |
292 i (aref prompt (1- i)))) | |
293 (setq i (1+ i))) | |
294 args) | |
295 (delete-region (point) (progn (forward-line -1) (end-of-line) (point))) | |
296 (insert ")\n(concat " (YaTeX-generate-lisp-quote string) | |
297 ")))\n") | |
298 (indent-region (point-min) (point) nil) | |
287 | 299 used)) |
9 | 300 |
301 (defun YaTeX-generate-ask-match-position () | |
302 "Ask user whether match-position is in his expectation, | |
303 Referencing variables in parent function YaTeX-generate-parse-add-in." | |
304 (pop-to-buffer YaTeX-generate-message-buffer) | |
305 (goto-char (point-max)) | |
306 (insert "\n\n" | |
307 (format (if YaTeX-japan "%d 番目の引数 %s って" | |
308 "Is argument #%d's value `%s' also corresponding to") | |
309 i carg) "\n" add-in "\n") | |
310 (indent-to-column beg) | |
311 (let ((c beg)) | |
312 (while (< c end) (insert "^") (setq c (1+ c)))) | |
313 (insert "\n" (if YaTeX-japan "ここにも対応してるの?" | |
314 "this underlined part too?")) | |
315 (other-window -1) | |
287 | 316 (y-or-n-p (if YaTeX-japan "下線部はあってますか" "Is underline right"))) |
9 | 317 |
318 (defun YaTeX-generate-register-match () | |
319 (nconc arg (list (list beg end))) | |
320 (let ((x beg)) | |
287 | 321 (while (< x end) (aset used x i)(setq x (1+ x))))) |
9 | 322 |
323 (defun YaTeX-generate-display-message (mes &optional bottom) | |
324 "Display message to generation buffer." | |
325 (pop-to-buffer YaTeX-generate-message-buffer) | |
326 (goto-char (point-max)) | |
327 (insert "\n\n") | |
328 (if bottom (recenter (1- bottom)) (recenter 0)) | |
329 (insert mes) | |
287 | 330 (other-window -1)) |
9 | 331 |
332 (defun YaTeX-generate-move-to-add-in-position () | |
333 "Move cursor where add-in function should insert string." | |
334 (cond | |
335 ((eq YaTeX-current-completion-type 'begin) | |
336 (goto-char (point-min)) | |
337 (skip-chars-forward "^{") | |
72 | 338 (setq YaTeX-env-name |
9 | 339 (buffer-substring (1+ (point)) |
340 (progn (skip-chars-forward "^}") (point)))) | |
341 (forward-char 1)) | |
342 ((eq YaTeX-current-completion-type 'section) | |
343 (goto-char (point-min)) | |
344 (skip-chars-forward "^{")) | |
345 ((eq YaTeX-current-completion-type 'maketitle) | |
346 (goto-char (point-max)) | |
347 (if (= (preceding-char) ? ) | |
287 | 348 (forward-char -1))))) |
9 | 349 |
350 (defun YaTeX-generate-function-name () | |
351 (concat | |
352 "YaTeX:" | |
353 (cond | |
72 | 354 ((eq YaTeX-current-completion-type 'begin) YaTeX-env-name) |
355 ((eq YaTeX-current-completion-type 'section) YaTeX-section-name) | |
287 | 356 ((eq YaTeX-current-completion-type 'maketitle) YaTeX-single-command)))) |
9 | 357 |
358 (defun YaTeX-generate-lisp-quote (str) | |
359 (let ((len (length str))(i 0) (quote "")) | |
360 (while (< i len) | |
361 (if (= (aref str i) ?\\) | |
362 (setq quote (concat quote "\\"))) | |
363 (if (= (aref str i) 127) | |
364 (setq quote (concat quote "\"")) | |
365 (setq quote (concat quote (substring str i (1+ i))))) | |
366 (setq i (1+ i))) | |
287 | 367 quote)) |
9 | 368 |
369 (defun YaTeX-generate-quote-quote (str) | |
370 (let ((len (length str))(i 0) (quote "")) | |
371 (while (< i len) | |
372 (if (= (aref str i) ?\") | |
373 (setq quote (concat quote (char-to-string 127)))) | |
374 (setq quote (concat quote (substring str i (1+ i)))) | |
375 (setq i (1+ i))) | |
287 | 376 quote)) |
9 | 377 |
378 (defun YaTeX-suppress-sparse-keymap (map) | |
379 (let ((i ? )) | |
380 (while (< i 127) | |
381 (define-key map (char-to-string i) 'undefined) | |
287 | 382 (setq i (1+ i))))) |
23 | 383 |
384 ;;; | |
385 ;; Auto-generate Function for Lispers. | |
386 ;;; | |
387 (defun YaTeX-generate-read-completion-type (nth) | |
388 (message | |
389 "Read type(%d): (S)tring (C)omplete (F)ile ([)option (P)osition co(O)rd. (q)uit" nth) | |
390 (let ((c (read-char))) | |
391 (cond | |
392 ((= c ?s) 'string) | |
393 ((= c ?c) 'completion) | |
394 ((= c ?f) 'file) | |
395 ((= c ?\[) 'option) | |
396 ((= c ?p) 'oneof) | |
397 ((= c ?o) 'coord) | |
398 ;;((= c ?m) 'macro) | |
287 | 399 (t 'quit)))) |
400 | |
23 | 401 (defun YaTeX-generate-read-completion-table () |
402 (let ((i 1) cand (cands "(") (cb (current-buffer)) | |
403 (buf (get-buffer-create " *Candidates*"))) | |
404 (save-window-excursion | |
405 (save-excursion | |
406 (YaTeX-showup-buffer buf nil) | |
407 (set-buffer buf) | |
408 (erase-buffer) | |
409 (while (string< | |
410 "" | |
411 (setq cand (read-string (format "Item[%d](RET to exit): " i)))) | |
46 | 412 (setq cands (concat cands (format "(\"%s\")\n" cand)) |
23 | 413 i (1+ i)) |
414 (insert cand "\n")) | |
415 (kill-buffer buf))) | |
416 ;;(set-buffer cb) | |
287 | 417 (setq YaTeX-generate-current-completion-table (concat cands ")")))) |
418 | |
23 | 419 (defun YaTeX-generate-corresponding-paren (left) |
420 (cond | |
421 ((equal left "{") "}") | |
422 ((equal left "[") "]") | |
423 ((equal left "(") ")") | |
424 ((equal left "<") ">") | |
59 | 425 ((equal left "\\begin{") "}") |
287 | 426 (t left))) |
427 | |
23 | 428 (defun YaTeX-generate-create-read-string (&optional nth) |
429 (concat | |
46 | 430 "(read-string \"" |
23 | 431 (read-string (if nth (format "Prompt for argument#%d: " nth) "Prompt: ")) |
46 | 432 ": \"\n" |
433 "\"" (read-string "Default: ") "\"" | |
287 | 434 ")\n")) |
435 | |
23 | 436 (defun YaTeX-generate-create-completing-read (&optional nth) |
52 | 437 (prog1 |
438 (concat | |
439 "(completing-read \"" | |
440 (read-string | |
441 (if nth (format "Prompt for argument#%d: " nth) "Prompt: ")) | |
442 ": \"\n" | |
443 (format "'%s\n" (YaTeX-generate-read-completion-table)) | |
444 "nil " | |
445 (format "%s)" (y-or-n-p "Require match? "))) | |
446 (if nil ;;;(y-or-n-p "Do you need learning for this completion?") | |
447 (setq YaTeX-generate-variables-for-learning | |
448 (cons | |
449 (cons (format "YaTeX-%s-%d" command (or nth 0)) | |
450 YaTeX-generate-current-completion-table) | |
287 | 451 YaTeX-generate-variables-for-learning))))) |
452 | |
23 | 453 (defun YaTeX-generate-create-read-file-name (&optional nth) |
454 (concat | |
46 | 455 "(read-file-name \"" |
23 | 456 (read-string (if nth (format "Prompt for argument#%d: " nth) "Prompt: ")) |
287 | 457 ": \" "" \"\" t \"\")\n")) |
458 | |
23 | 459 (defun YaTeX-generate-create-read-oneof (&optional nth readpos) |
460 (concat | |
461 (if readpos | |
46 | 462 "(YaTeX:read-position \"" |
463 "(YaTeX:read-oneof \"") | |
287 | 464 (read-string "Acceptable characters: " "lcr") "\")\n")) |
465 | |
23 | 466 (defun YaTeX-generate-option-type (command) |
467 (let ((func (format "YaTeX:%s" command)) leftp | |
468 (buf (get-buffer-create YaTeX-generate-buffer)) type (n 1)) | |
469 (set-buffer buf) | |
470 (erase-buffer) | |
471 (insert "(defun " func " ()\n (concat\n") | |
472 (catch 'done | |
473 (while t | |
474 (setq type (YaTeX-generate-read-completion-type n)) | |
475 (insert | |
476 (cond | |
477 ;;Read string | |
478 ((eq type 'string) | |
52 | 479 (concat "\"" (setq leftp (read-string "Left parenthesis: " "(")) |
480 "\"\n" | |
23 | 481 (YaTeX-generate-create-read-string) |
52 | 482 "\"" (YaTeX-generate-corresponding-paren leftp) "\"") |
483 ) | |
23 | 484 ;;Completing-read |
485 ((eq type 'completion) | |
52 | 486 (concat "\"" (setq leftp (read-string "Left parenthesis: " "{")) |
487 "\"\n" | |
23 | 488 (YaTeX-generate-create-completing-read) |
52 | 489 "\"" (YaTeX-generate-corresponding-paren leftp) "\"") |
23 | 490 ) |
491 ((eq type 'file) | |
52 | 492 (concat "\"" (setq leftp (read-string "Left parenthesis: " "(")) |
493 "\"\n" | |
23 | 494 (YaTeX-generate-create-read-file-name) |
52 | 495 "\"" (YaTeX-generate-corresponding-paren leftp) "\"") |
23 | 496 ) |
497 ((eq type 'oneof) | |
498 (YaTeX-generate-create-read-oneof nil t) | |
499 ) | |
500 ((eq type 'option) | |
46 | 501 (concat "(let ((op (read-string \"" |
23 | 502 (read-string "Prompt: ") |
46 | 503 ": \")))\n" |
504 "(if (string< \"\" op)\n" | |
505 " (concat \"[\" op \"]\")\n" | |
506 " \"\"))\n") | |
23 | 507 ) |
508 ((eq type 'coord) | |
46 | 509 (concat "(YaTeX:read-coordinates \"" |
23 | 510 (read-string "Prompt for coordinates: ") |
46 | 511 ": \")\n") |
23 | 512 ) |
513 ((eq type 'macro) | |
514 (error "not yet supported") | |
515 ) | |
516 (t (throw 'done t)))) | |
517 (setq n (1+ n)))) | |
518 (insert "))\n") ;close defun | |
519 (goto-char (point-min)) | |
520 (while (not (eobp)) (lisp-indent-line) (forward-line 1)) | |
521 (eval-current-buffer) | |
287 | 522 buf)) |
523 | |
23 | 524 (defun YaTeX-generate-argument-type (command argc) |
525 "Create an argument-type add-in function." | |
526 (interactive) | |
527 (let ((func (format "YaTeX::%s" command)) (argp 1) | |
528 (cb (current-buffer)) | |
529 (buf (get-buffer-create YaTeX-generate-buffer))) | |
530 (set-buffer buf) | |
531 (erase-buffer) | |
532 (insert "(defun " func " (&optional argp)\n(cond\n") | |
533 (while (<= argp argc) | |
534 (insert (format "((equal argp %d)\n" argp)) | |
535 (setq type (YaTeX-generate-read-completion-type argp)) | |
536 (insert | |
537 (cond | |
538 ((eq type 'string) | |
539 (concat (YaTeX-generate-create-read-string argp))) | |
540 ((eq type 'completion) | |
541 (concat (YaTeX-generate-create-completing-read argp))) | |
542 ((eq type 'oneof) | |
543 (YaTeX-generate-create-read-oneof)) | |
544 ((eq type 'file) | |
545 (concat (YaTeX-generate-create-read-file-name argp))) | |
546 (t "")) | |
547 ")\n") | |
548 (setq argp (1+ argp))) | |
549 (insert "))\n") | |
550 (goto-char (point-min)) | |
551 (while (not (eobp)) (lisp-indent-line) (forward-line 1)) | |
552 (eval-current-buffer) | |
553 (set-buffer cb) | |
554 (YaTeX-update-table | |
555 (if (> argc 1) (list command argc) (list command)) | |
556 'section-table 'user-section-table 'tmp-section-table) | |
287 | 557 buf)) |
558 | |
23 | 559 (defun YaTeX-generate-simple (&optional command) |
560 "Simple but requiring some elisp knowledge add-in generator." | |
561 (interactive) | |
52 | 562 (setq YaTeX-generate-variables-for-learning nil) |
23 | 563 (or command |
564 (setq command | |
565 (completing-read | |
72 | 566 (format |
567 "Making add-in function for (default %s): " YaTeX-section-name) | |
23 | 568 (append |
569 section-table user-section-table tmp-section-table | |
570 env-table user-env-table tmp-env-table | |
571 singlecmd-table user-singlecmd-table tmp-singlecmd-table) | |
572 nil nil) | |
72 | 573 command (if (string= "" command) YaTeX-section-name command))) |
49 | 574 (message |
575 (cond | |
576 (YaTeX-japan "(o)追加型? (a)引数型? (yatexadd.docを参照のこと) :") | |
577 (t "(O)ption? (A)rgument?"))) | |
23 | 578 (YaTeX-showup-buffer |
579 (if (= (read-char) ?o) | |
580 (YaTeX-generate-option-type command) | |
581 (YaTeX-generate-argument-type | |
582 command | |
287 | 583 (string-to-int (read-string "How many arguments?: ")))) nil)) |
584 | |
70 | 585 (provide 'yatexgen) |