Mercurial > hgrepos > hgweb.cgi > yatex
annotate yatexadd.el @ 18:adc2f1472409
Make variables for temporary dictionary buffer-local.
Change the default value of YaTeX-nervous to t.
Create a temporary dictionary file when `T' is selected at the
dictionary selection menu.
author | yuuji |
---|---|
date | Mon, 16 May 1994 09:30:52 +0000 |
parents | cb9afa9c1213 |
children | b00c74813e56 |
rev | line source |
---|---|
6 | 1 ;;; -*- Emacs-Lisp -*- |
8 | 2 ;;; YaTeX add-in functions. |
16
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
3 ;;; yatexadd.el rev.8 |
14 | 4 ;;; (c )1991-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp] |
18 | 5 ;;; Last modified Sun May 15 18:00:12 1994 on 98fa |
8 | 6 ;;; $Id$ |
6 | 7 |
8 (provide 'yatexadd) | |
9 | |
10 ;;; | |
11 ;;Sample functions for LaTeX environment. | |
12 ;;; | |
13 (defvar YaTeX:tabular-default-rule | |
14 "@{\\vrule width 1pt\\ }c|c|c@{\\ \\vrule width 1pt}" | |
15 "*Your favorite default rule format." | |
16 ) | |
17 (defun YaTeX:tabular () | |
18 | 18 "YaTeX add-in function for tabular environment. |
19 Notice that this function refers the let-variable `env' in | |
20 YaTeX-make-begin-end." | |
21 (let ((width "") bars (rule "") (j 0) loc) | |
22 (if (string= env "tabular*") | |
23 (setq width (concat "{" (read-string "Width: ") "}"))) | |
24 (setq loc (YaTeX:read-position "tb") | |
25 bars (string-to-int (read-string "Number of `|': "))) | |
6 | 26 (if (> bars 0) |
27 (while (< j bars) (setq rule (concat rule "|")) (setq j (1+ j))) | |
28 (setq rule YaTeX:tabular-default-rule)) | |
29 (setq rule (read-string "rule format: " rule)) | |
30 | |
8 | 31 (message "") |
18 | 32 (format "%s%s{%s}" width loc rule)) |
33 ) | |
34 (fset 'YaTeX:tabular* 'YaTeX:tabular) | |
35 (defun YaTeX:array () | |
36 (concat (YaTeX:read-position "tb") | |
37 "{" (read-string "Column format: ") "}") | |
6 | 38 ) |
39 | |
8 | 40 (defun YaTeX:read-position (oneof) |
41 (let ((pos "") loc) | |
6 | 42 (while (not (string-match |
8 | 43 (setq loc (read-key-sequence |
44 (format "Position (`%s') [%s]: " oneof pos))) | |
6 | 45 "\r\^g\n")) |
46 (cond | |
8 | 47 ((string-match loc oneof) |
6 | 48 (if (not (string-match loc pos)) |
49 (setq pos (concat pos loc)))) | |
50 ((and (string-match loc "\C-h\C-?") (> (length pos) 0)) | |
51 (setq pos (substring pos 0 (1- (length pos))))) | |
52 (t | |
53 (ding) | |
8 | 54 (message "Please input one of `%s'." oneof) |
6 | 55 (sit-for 3)))) |
8 | 56 (message "") |
57 (if (string= pos "") "" | |
58 (concat "[" pos "]"))) | |
59 ) | |
60 | |
61 (defun YaTeX:table () | |
62 "YaTeX add-in function for table environment." | |
63 (YaTeX:read-position "htbp") | |
6 | 64 ) |
65 | |
66 (defun YaTeX:description () | |
67 "Truly poor service:-)" | |
68 (setq single-command "item[]") | |
8 | 69 "" |
6 | 70 ) |
71 | |
72 (defun YaTeX:itemize () | |
73 "It's also poor service." | |
74 (setq single-command "item") | |
8 | 75 "" |
6 | 76 ) |
77 | |
78 (fset 'YaTeX:enumerate 'YaTeX:itemize) | |
8 | 79 |
11 | 80 (defun YaTeX:picture () |
81 "Ask the size of coordinates of picture environment." | |
82 (concat (YaTeX:read-coordinates "Picture size") | |
83 (YaTeX:read-coordinates "Initial position")) | |
84 ) | |
85 | |
12 | 86 (defun YaTeX:equation () |
87 (if (fboundp 'YaTeX-toggle-math-mode) | |
88 (YaTeX-toggle-math-mode t)) ;force math-mode ON. | |
89 ) | |
90 (fset 'YaTeX:eqnarray 'YaTeX:equation) | |
91 (fset 'YaTeX:displaymath 'YaTeX:equation) | |
92 | |
16
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
93 (defun YaTeX:list () |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
94 "%\n{} %default label\n{} %formatting parameter" |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
95 ) |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
96 |
18 | 97 (defun YaTeX:minipage () |
98 (concat (YaTeX:read-position "cbt") | |
99 "{" (read-string "Width: ") "}") | |
100 ) | |
101 | |
8 | 102 ;;; |
103 ;;Sample functions for section-type command. | |
104 ;;; | |
105 (defun YaTeX:multiput () | |
106 (concat (YaTeX:read-coordinates "Pos") | |
107 (YaTeX:read-coordinates "Step") | |
108 "{" (read-string "How many times: ") "}") | |
109 ) | |
110 | |
111 (defun YaTeX:put () | |
112 (YaTeX:read-coordinates "Pos") | |
113 ) | |
114 | |
115 (defun YaTeX:makebox () | |
116 (concat (YaTeX:read-coordinates "Dimension") | |
117 (YaTeX:read-position "lrtb")) | |
118 ) | |
119 | |
120 (defun YaTeX:framebox () | |
121 (if (YaTeX-quick-in-environment-p "picture") | |
122 (YaTeX:makebox)) | |
123 ) | |
124 | |
125 (defun YaTeX:dashbox () | |
126 (concat "{" (read-string "Dash dimension: ") "}" | |
127 (YaTeX:read-coordinates "Dimension")) | |
128 ) | |
129 | |
130 (defun YaTeX:read-coordinates (&optional mes varX varY) | |
131 (concat | |
132 "(" | |
133 (read-string (format "%s %s: " (or mes "Dimension") (or varX "X"))) | |
134 "," | |
135 (read-string (format "%s %s: " (or mes "Dimension") (or varY "Y"))) | |
136 ")") | |
137 ) | |
138 | |
139 ;;; | |
140 ;;Sample functions for maketitle-type command. | |
141 ;;; | |
142 (defun YaTeX:sum () | |
143 "Read range of summation." | |
144 (YaTeX:check-completion-type 'maketitle) | |
145 (concat (YaTeX:read-boundary "_") (YaTeX:read-boundary "^")) | |
146 ) | |
147 | |
148 (fset 'YaTeX:int 'YaTeX:sum) | |
149 | |
150 (defun YaTeX:lim () | |
151 "Insert limit notation of \\lim." | |
152 (YaTeX:check-completion-type 'maketitle) | |
153 (let ((var (read-string "Variable: ")) limit) | |
154 (if (string= "" var) "" | |
155 (setq limit (read-string "Limit ($ means infinity): ")) | |
156 (if (string= "$" limit) (setq limit "\\infty")) | |
157 (concat "_{" var " \\rightarrow " limit "}"))) | |
158 ) | |
159 | |
160 (defun YaTeX:gcd () | |
161 "Add-in function for \\gcd(m,n)." | |
162 (YaTeX:check-completion-type 'maketitle) | |
163 (YaTeX:read-coordinates "\\gcd" "(?,)" "(,?)") | |
164 ) | |
165 | |
166 (defun YaTeX:read-boundary (ULchar) | |
167 "Read boundary usage by _ or ^. _ or ^ is indicated by argument ULchar." | |
11 | 168 (let ((bndry (read-string (concat ULchar "{???} ($ for infinity): ")))) |
8 | 169 (if (string= bndry "") "" |
11 | 170 (if (string= bndry "$") (setq bndry "\\infty")) |
8 | 171 (concat ULchar "{" bndry "}"))) |
172 ) | |
173 | |
14 | 174 (defun YaTeX:verb () |
175 "Enclose \\verb's contents with the same characters." | |
176 (let ((quote-char (read-string "Quoting char: " "|")) | |
177 (contents (read-string "Quoted contents: "))) | |
178 (concat quote-char contents quote-char)) | |
179 ) | |
180 | |
181 ;;; | |
182 ;;Subroutine | |
183 ;;; | |
184 | |
8 | 185 (defun YaTeX:check-completion-type (type) |
186 "Check valid completion type." | |
187 (if (not (eq type YaTeX-current-completion-type)) | |
188 (error "This should be completed with %s-type completion." type)) | |
189 ) | |
11 | 190 |
191 | |
192 ;;; | |
193 ;;; [[Add-in functions for reading section arguments]] | |
194 ;;; | |
195 ;; All of add-in functions for reading sections arguments should | |
196 ;; take an argument ARGP that specify the argument position. | |
197 ;; If argument position is out of range, nil should be returned, | |
198 ;; else nil should NOT be returned. | |
13 | 199 |
200 ;; | |
201 ; Label selection | |
202 ;; | |
11 | 203 (defvar YaTeX-label-menu-other |
204 (if YaTeX-japan "':‘¼‚̃oƒbƒtƒ@‚̃‰ƒxƒ‹\n" "':LABEL IN OTHER BUFFER.\n")) | |
205 (defvar YaTeX-label-menu-any | |
206 (if YaTeX-japan "*:”CˆÓ‚Ì•¶Žš—ñ\n" "*:ANY STRING.\n")) | |
207 (defvar YaTeX-label-buffer "*Label completions*") | |
208 (defvar YaTeX-label-guide-msg "Select label and hit RETURN.") | |
209 (defvar YaTeX-label-select-map nil | |
210 "Key map used in label selection buffer.") | |
211 (defun YaTeX::label-setup-key-map () | |
212 (if YaTeX-label-select-map nil | |
213 (message "Setting up label selection mode map...") | |
214 (setq YaTeX-label-select-map (copy-keymap global-map)) | |
215 (suppress-keymap YaTeX-label-select-map) | |
216 (substitute-all-key-definition | |
217 'previous-line 'YaTeX::label-previous YaTeX-label-select-map) | |
218 (substitute-all-key-definition | |
219 'next-line 'YaTeX::label-next YaTeX-label-select-map) | |
220 (define-key YaTeX-label-select-map "\C-n" 'YaTeX::label-next) | |
221 (define-key YaTeX-label-select-map "\C-p" 'YaTeX::label-previous) | |
222 (define-key YaTeX-label-select-map "<" 'beginning-of-buffer) | |
223 (define-key YaTeX-label-select-map ">" 'end-of-buffer) | |
224 (define-key YaTeX-label-select-map "\C-m" 'exit-recursive-edit) | |
225 (define-key YaTeX-label-select-map "\C-j" 'exit-recursive-edit) | |
226 (define-key YaTeX-label-select-map " " 'exit-recursive-edit) | |
227 (define-key YaTeX-label-select-map "\C-g" 'abort-recursive-edit) | |
228 (define-key YaTeX-label-select-map "/" 'isearch-forward) | |
229 (define-key YaTeX-label-select-map "?" 'isearch-backward) | |
230 (define-key YaTeX-label-select-map "'" 'YaTeX::label-search-tag) | |
231 (define-key YaTeX-label-select-map "*" 'YaTeX::label-search-tag) | |
232 (message "Setting up label selection mode map...Done") | |
233 (let ((key ?A)) | |
234 (while (<= key ?Z) | |
235 (define-key YaTeX-label-select-map (char-to-string key) | |
236 'YaTeX::label-search-tag) | |
237 (define-key YaTeX-label-select-map (char-to-string (+ key (- ?a ?A))) | |
238 'YaTeX::label-search-tag) | |
239 (setq key (1+ key))))) | |
240 ) | |
241 (defun YaTeX::label-next () | |
242 (interactive) (forward-line 1) (message YaTeX-label-guide-msg)) | |
243 (defun YaTeX::label-previous () | |
244 (interactive) (forward-line -1) (message YaTeX-label-guide-msg)) | |
245 (defun YaTeX::label-search-tag () | |
246 (interactive) | |
247 (let ((case-fold-search t)) | |
248 (cond | |
249 ((save-excursion | |
250 (forward-char 1) | |
251 (re-search-forward (concat "^" (this-command-keys)) nil t)) | |
252 (goto-char (match-beginning 0))) | |
253 ((save-excursion | |
254 (goto-char (point-min)) | |
255 (re-search-forward (concat "^" (this-command-keys)) nil t)) | |
256 (goto-char (match-beginning 0)))) | |
257 (message YaTeX-label-guide-msg)) | |
258 ) | |
259 (defun YaTeX::ref (argp) | |
260 (cond | |
261 ((= argp 1) | |
262 (save-excursion | |
263 (let ((lnum 0) e0 m1 e1 label label-list (buf (current-buffer)) | |
264 (p (point)) initl line) | |
265 (goto-char (point-min)) | |
266 (message "Collecting labels...") | |
267 (save-window-excursion | |
12 | 268 (YaTeX-showup-buffer |
269 YaTeX-label-buffer (function (lambda (x) (window-width x)))) | |
11 | 270 (with-output-to-temp-buffer YaTeX-label-buffer |
271 (while (re-search-forward "\\label{\\([^}]+\\)}" nil t) | |
272 (setq e0 (match-end 0) m1 (match-beginning 1) e1 (match-end 1)) | |
273 (if (search-backward | |
274 YaTeX-comment-prefix (point-beginning-of-line) t) nil | |
275 (setq label (buffer-substring m1 e1) | |
276 label-list (cons label label-list)) | |
277 (or initl | |
278 (if (< p (point)) (setq initl lnum))) | |
279 (beginning-of-line) | |
280 (skip-chars-forward " \t\n" nil) | |
281 (princ (format "%c:{%s}\t<<%s>>\n" (+ (% lnum 26) ?A) label | |
282 (buffer-substring (point) (point-end-of-line)))) | |
283 (setq lnum (1+ lnum)) | |
284 (message "Collecting \\label{}... %d" lnum)) | |
285 (goto-char e0)) | |
286 (princ YaTeX-label-menu-other) | |
287 (princ YaTeX-label-menu-any) | |
288 );with | |
289 (goto-char p) | |
290 (message "Collecting labels...Done") | |
291 (pop-to-buffer YaTeX-label-buffer) | |
292 (YaTeX::label-setup-key-map) | |
293 (setq truncate-lines t) | |
294 (setq buffer-read-only t) | |
295 (use-local-map YaTeX-label-select-map) | |
296 (message YaTeX-label-guide-msg) | |
297 (goto-line (or initl lnum)) ;goto recently defined label line | |
298 (unwind-protect | |
299 (progn | |
300 (recursive-edit) | |
301 (set-buffer (get-buffer YaTeX-label-buffer)) ;assertion | |
302 (beginning-of-line) | |
303 (setq line (count-lines (point-min)(point))) | |
304 (cond | |
305 ((= line lnum) (setq label (YaTeX-label-other))) | |
306 ((>= line (1+ lnum )) | |
307 (setq label (read-string "\\ref{???}: "))) | |
308 (t (setq label (nth (- lnum line 1) label-list))))) | |
309 (bury-buffer YaTeX-label-buffer))) | |
310 label | |
311 )) | |
312 )) | |
313 ) | |
16
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
314 (fset 'YaTeX::pageref 'YaTeX::ref) |
11 | 315 |
316 (defun YaTeX-label-other () | |
317 (let ((lbuf "*YaTeX mode buffers*") (blist (buffer-list)) (lnum -1) buf rv | |
318 (ff "**find-file**")) | |
12 | 319 (YaTeX-showup-buffer |
320 lbuf (function (lambda (x) 1))) ;;Select next window surely. | |
11 | 321 (with-output-to-temp-buffer lbuf |
322 (while blist | |
323 (if (and (buffer-file-name (setq buf (car blist))) | |
324 (progn (set-buffer buf) (eq major-mode 'yatex-mode))) | |
325 (princ | |
326 (format "%c:{%s}\n" (+ (% (setq lnum (1+ lnum)) 26) ?A) | |
327 (buffer-name buf)))) | |
328 (setq blist (cdr blist))) | |
329 (princ (format "':{%s}" ff))) | |
330 (pop-to-buffer lbuf) | |
331 (YaTeX::label-setup-key-map) | |
332 (setq buffer-read-only t) | |
333 (use-local-map YaTeX-label-select-map) | |
334 (message YaTeX-label-guide-msg) | |
335 (unwind-protect | |
336 (progn | |
337 (recursive-edit) | |
338 (set-buffer lbuf) | |
339 (beginning-of-line) | |
340 (setq rv | |
341 (if (re-search-forward "{\\([^\\}]+\\)}" (point-end-of-line) t) | |
342 (buffer-substring (match-beginning 1) (match-end 1)) nil))) | |
343 (kill-buffer lbuf)) | |
344 (cond | |
345 ((null rv) "") | |
346 ((string= rv ff) | |
347 (call-interactively 'find-file) | |
348 (YaTeX::ref argp)) | |
349 (t | |
350 (set-buffer rv) | |
351 (YaTeX::ref argp))) | |
352 ) | |
353 ) | |
354 | |
13 | 355 ;; |
356 ; completion for the arguments of \newcommand | |
357 ;; | |
358 (defun YaTeX::newcommand (&optional argp) | |
359 (cond | |
360 ((= argp 1) | |
361 (let ((command (read-string "Define newcommand: " "\\"))) | |
362 (put 'YaTeX::newcommand 'command (substring command 1)) | |
363 command)) | |
364 ((= argp 2) | |
365 (let ((argc | |
366 (string-to-int (read-string "Number of arguments(Default 0): "))) | |
367 (def (read-string "Definition: ")) | |
368 (command (get 'YaTeX::newcommand 'command))) | |
369 ;;!!! It's illegal to insert string in the add-in function !!! | |
370 (if (> argc 0) (insert (format "[%d]" argc))) | |
371 (if (and (stringp command) | |
372 (string< "" command) | |
373 (y-or-n-p "Update user completion table?")) | |
18 | 374 (cond |
375 ((= argc 0) | |
376 (YaTeX-update-table | |
377 (list command) | |
378 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table)) | |
379 ((= argc 1) | |
380 (YaTeX-update-table | |
381 (list command) | |
382 'section-table 'user-section-table 'tmp-section-table)) | |
383 (t (YaTeX-update-table | |
384 (list command argc) | |
385 'section-table 'user-section-table 'tmp-section-table)))) | |
13 | 386 (message "") |
387 def ;return command name | |
388 )) | |
389 (t "")) | |
390 ) | |
391 | |
16
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
392 ;; |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
393 ; completion for the arguments of \pagestyle |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
394 ;; |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
395 (defun YaTeX::pagestyle (&optional argp) |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
396 "Read the pagestyle with completion." |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
397 (completing-read |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
398 "Page style: " |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
399 '(("plain") ("empty") ("headings") ("myheadings") ("normal") nil)) |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
400 ) |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
401 ;; |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
402 ; completion for the arguments of \pagenumbering |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
403 ;; |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
404 (defun YaTeX::pagenumbering (&optional argp) |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
405 "Read the numbering style." |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
406 (completing-read |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
407 "Page numbering style: " |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
408 '(("arabic") ("Alpha") ("alpha") ("Roman") ("roman"))) |
cb9afa9c1213
Auto-indentation at begin-type completion works correctly.
yuuji
parents:
14
diff
changeset
|
409 ) |
13 | 410 |
11 | 411 ;;; |
412 ;; global subroutines | |
413 ;;; | |
414 (defun substitute-all-key-definition (olddef newdef keymap) | |
415 "Replace recursively OLDDEF with NEWDEF for any keys in KEYMAP now | |
416 defined as OLDDEF. In other words, OLDDEF is replaced with NEWDEF | |
417 where ever it appears." | |
418 (if (arrayp keymap) | |
419 (let ((len (length keymap)) | |
420 (i 0)) | |
421 (while (< i len) | |
422 (let ((map (aref keymap i))) | |
423 (cond | |
424 ((arrayp map) (substitute-key-definition olddef newdef map)) | |
425 ((equal map olddef) | |
426 (aset keymap i newdef))) | |
427 (setq i (1+ i))))) | |
428 (while keymap | |
429 (if (equal (cdr-safe (car-safe keymap)) olddef) | |
430 (setcdr (car keymap) newdef)) | |
431 (setq keymap (cdr keymap))))) |