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