comparison yatex.el @ 64:36a48185b95a

Changes are listed in yatex.new. Major one is supporing GNU Emacs20 and XEmacs.
author yuuji
date Tue, 16 Dec 1997 13:28:38 +0000
parents b9f753846b6b
children 0eb6997bee16
comparison
equal deleted inserted replaced
63:6ad4a2399731 64:36a48185b95a
1 ;;; -*- Emacs-Lisp -*- 1 ;;; -*- Emacs-Lisp -*-
2 ;;; Yet Another tex-mode for emacs. 2 ;;; Yet Another tex-mode for emacs.
3 ;;; yatex.el rev. 1.64 3 ;;; yatex.el rev. 1.65
4 ;;; (c )1991-1997 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp] 4 ;;; (c )1991-1997 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
5 ;;; Last modified Tue Apr 8 05:07:31 1997 on crx 5 ;;; Last modified Tue Dec 16 22:15:26 1997 on crx
6 ;;; $Id$ 6 ;;; $Id$
7 7
8 ;; This program is free software; you can redistribute it and/or modify 8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by 9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option) 10 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; You should have received a copy of the GNU General Public License 18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program; see the file COPYING. If not, write to 19 ;; along with this program; see the file COPYING. If not, write to
20 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 20 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 21
22 (require 'comment) 22 (require 'comment)
23 (defconst YaTeX-revision-number "1.64" 23 (require 'yatexlib)
24 (defconst YaTeX-revision-number "1.65"
24 "Revision number of running yatex.el" 25 "Revision number of running yatex.el"
25 ) 26 )
26
27 ;---------- Local variables ---------- 27 ;---------- Local variables ----------
28 ;;; 28 ;;;
29 ;; Initialize local variable for yatex-mode. 29 ;; Initialize local variable for yatex-mode.
30 ;; Preserving user preferred definitions. 30 ;; Preserving user preferred definitions.
31 ;; ** Check all of these defvar-ed values ** 31 ;; ** Check all of these defvar-ed values **
37 You can select favorite prefix key by setq in your ~/.emacs." 37 You can select favorite prefix key by setq in your ~/.emacs."
38 ) 38 )
39 (defvar YaTeX-environment-indent 1 39 (defvar YaTeX-environment-indent 1
40 "*Indentation depth at column width in LaTeX environments." 40 "*Indentation depth at column width in LaTeX environments."
41 ) 41 )
42 (defvar YaTeX-fill-prefix "" 42 (defvar YaTeX-fill-prefix nil
43 "*fill-prefix used for auto-fill-mode. 43 "*fill-prefix used for auto-fill-mode.
44 The default value is null string." 44 The default value is nil."
45 ) 45 )
46 (defvar YaTeX-fill-column 72 46 (defvar YaTeX-fill-column 72
47 "*fill-column used for auto-fill-mode." 47 "*fill-column used for auto-fill-mode."
48 ) 48 )
49 (defvar YaTeX-comment-prefix "%" 49 (defvar YaTeX-comment-prefix "%"
55 the register YaTeX-current-position-register. So every time you 55 the register YaTeX-current-position-register. So every time you
56 make a trip to any other part of text other than you are writing, you can 56 make a trip to any other part of text other than you are writing, you can
57 return to the editing paragraph by calling register-to-point with argument 57 return to the editing paragraph by calling register-to-point with argument
58 YaTeX-current-position-register." 58 YaTeX-current-position-register."
59 ) 59 )
60 (defvar YaTeX-dos (eq system-type 'ms-dos))
61 (defvar YaTeX-emacs-19 (string= "19" (substring emacs-version 0 2)))
62 (defvar YaTeX-user-completion-table
63 (if YaTeX-dos "~/_yatexrc" "~/.yatexrc")
64 "*Default filename in which user completion table is saved."
65 )
66 ;;(defvar YaTeX-tmp-dic-unit 'main-file 60 ;;(defvar YaTeX-tmp-dic-unit 'main-file
67 ;; "*Default switching unit of temporary dictionary. 61 ;; "*Default switching unit of temporary dictionary.
68 ;;There are two switching unit: 62 ;;There are two switching unit:
69 ;;'main-file : switch tmp-dic according to main-file directory. 63 ;;'main-file : switch tmp-dic according to main-file directory.
70 ;;'directory : switch tmp-dic dir by dir." 64 ;;'directory : switch tmp-dic dir by dir."
71 ;;) 65 ;;)
72 (defvar YaTeX-japan (or (boundp 'NEMACS) (boundp 'MULE))
73 "Whether yatex mode is running on Japanese environment or not."
74 )
75 (defvar tex-command (if YaTeX-japan "jlatex" "latex") 66 (defvar tex-command (if YaTeX-japan "jlatex" "latex")
76 "*Default command for typesetting LaTeX text." 67 "*Default command for typesetting LaTeX text."
77 ) 68 )
78 (defvar bibtex-command (if YaTeX-japan "jbibtex" "bibtex") 69 (defvar bibtex-command (if YaTeX-japan "jbibtex" "bibtex")
79 "*Default command of BibTeX." 70 "*Default command of BibTeX."
132 ) 123 )
133 (defvar latex-message-kanji-code 2 124 (defvar latex-message-kanji-code 2
134 "*Kanji coding system latex command types out. 125 "*Kanji coding system latex command types out.
135 1 = Shift JIS, 2 = JIS, 3 = EUC." 126 1 = Shift JIS, 2 = JIS, 3 = EUC."
136 ) 127 )
137 (defvar YaTeX-inhibit-prefix-letter nil
138 "*T for changing key definitions from [prefix] Letter to [prefix] C-Letter."
139 )
140 (defvar NTT-jTeX nil 128 (defvar NTT-jTeX nil
141 "*Use NTT-jTeX for latex command." 129 "*T for using NTT-jTeX for latex command.
142 ) 130 More precisely, setting t to this variables inhibits inter-word break on
143 (defvar YaTeX-item-regexp (concat (regexp-quote "\\") "\\(sub\\)*item") 131 typeset document by line-break of source text. That is, YaTeX automatically
132 put % after each line at filling.
133 改行+インデントによって、タイプセット後の字間が空いてしまうのを抑制する場合に
134 tにする(古いNTT-jTeXで顕著に現れる)。具体的には、fillするときに各行の終わりに
135 %を付加する。"
136 )
137 (defvar YaTeX-item-regexp
138 (concat (regexp-quote "\\") "\\(sub\\|bib\\)*item")
144 "*Regular expression of item command." 139 "*Regular expression of item command."
145 )
146 (defvar YaTeX-nervous t
147 "*If you are nervous about maintenance of yatexrc, set this value to T.
148 And you will have the local dictionary."
149 ) 140 )
150 (defvar YaTeX-sectioning-regexp 141 (defvar YaTeX-sectioning-regexp
151 "\\(part\\|chapter\\*?\\|\\(sub\\)*\\(section\\|paragraph\\)\\*?\\)\\b" 142 "\\(part\\|chapter\\*?\\|\\(sub\\)*\\(section\\|paragraph\\)\\*?\\)\\b"
152 "*LaTeX sectioning commands regexp." 143 "*LaTeX sectioning commands regexp."
153 ) 144 )
180 YaTeX-verbatim-environments) 171 YaTeX-verbatim-environments)
181 "*In these environments, YaTeX inhibits fill-paragraph from formatting. 172 "*In these environments, YaTeX inhibits fill-paragraph from formatting.
182 Define those environments as a form of list." 173 Define those environments as a form of list."
183 ) 174 )
184 (defvar YaTeX-itemizing-env-regexp 175 (defvar YaTeX-itemizing-env-regexp
185 "itemize\\|enumerate\\|description\\|list" 176 "itemize\\|enumerate\\|description\\|list\\|thebibliography"
186 "*Regexp of itemizing environments") 177 "*Regexp of itemizing environments")
187 (defvar YaTeX-equation-env-regexp 178 (defvar YaTeX-equation-env-regexp
188 "array\\*?\\|equation\\*?" 179 "array\\*?\\|equation\\*?"
189 "*Regexp of environments for equations") 180 "*Regexp of environments for equations")
190 (defvar YaTeX-array-env-regexp 181 (defvar YaTeX-array-env-regexp
195 "*Regexp of environments where `&' becomes field delimiter.") 186 "*Regexp of environments where `&' becomes field delimiter.")
196 (defvar YaTeX-uncomment-once t 187 (defvar YaTeX-uncomment-once t
197 "*T for removing all continuous commenting character(%). 188 "*T for removing all continuous commenting character(%).
198 Nil for removing only one commenting character at the beginning-of-line." 189 Nil for removing only one commenting character at the beginning-of-line."
199 ) 190 )
200 (defvar YaTeX-default-pop-window-height 10
201 "Default typesetting buffer height.
202 If integer, sets the window-height of typesetting buffer.
203 If string, sets the percentage of it.
204 If nil, use default pop-to-buffer."
205 )
206 (defvar YaTeX-close-paren-always t 191 (defvar YaTeX-close-paren-always t
207 "Close parenthesis always when YaTeX-modify-mode is nil." 192 "Close parenthesis always when YaTeX-modify-mode is nil."
208 )
209 (defvar YaTeX-no-begend-shortcut nil
210 "*T for disabling shortcut of begin-type completion, [prefix] b d, etc."
211 ) 193 )
212 (defvar YaTeX-greek-by-maketitle-completion nil 194 (defvar YaTeX-greek-by-maketitle-completion nil
213 "*T for greek letters completion by maketitle-type completion." 195 "*T for greek letters completion by maketitle-type completion."
214 ) 196 )
215 (defvar YaTeX-auto-math-mode t 197 (defvar YaTeX-auto-math-mode t
232 ) 214 )
233 (defvar YaTeX-math-key-list 215 (defvar YaTeX-math-key-list
234 (append YaTeX-math-key-list-private YaTeX-math-key-list-default) 216 (append YaTeX-math-key-list-private YaTeX-math-key-list-default)
235 "Key sequence to invoke math-mode's image completion." 217 "Key sequence to invoke math-mode's image completion."
236 ) 218 )
237 (defvar YaTeX-create-file-prefix-g nil
238 "*Non-nil creates new file when [prefix] g on \\include{foo}."
239 )
240 (defvar YaTeX-skip-default-reader nil 219 (defvar YaTeX-skip-default-reader nil
241 "Non-nil skips default argument reader of section-type completion." 220 "Non-nil skips default argument reader of section-type completion."
242 ) 221 )
243 (defvar YaTeX-simple-messages nil 222 (defvar YaTeX-simple-messages nil
244 "Non-nil makes minibuffer messages simpler." 223 "Non-nil makes minibuffer messages simpler."
224 )
225 (defvar YaTeX-template-file "~/work/template.tex"
226 "*Template TeX source file. This will be inserted to empty file."
245 ) 227 )
246 (defvar YaTeX-addin-prefix "YaTeX:") 228 (defvar YaTeX-addin-prefix "YaTeX:")
247 ;------------ Completion table ------------ 229 ;------------ Completion table ------------
248 ; Set tex-section-like command possible completion 230 ; Set tex-section-like command possible completion
249 (defvar section-table 231 (defvar section-table
250 '(("part") ("chapter") ("section") ("subsection") 232 '(("part") ("chapter") ("section") ("subsection")
251 ("subsubsection") ("paragraph") ("subparagraph") 233 ("subsubsection") ("paragraph") ("subparagraph")
252 ("author") ("thanks") ("documentstyle") ("pagestyle") 234 ("author") ("thanks") ("documentstyle") ("documentclass") ("pagestyle")
253 ("title") ("underline") ("label") ("makebox") 235 ("title") ("underline") ("label") ("makebox")
254 ("footnote") ("footnotetext") 236 ("footnote") ("footnotetext")
255 ("hspace*") ("vspace*") ("bibliography") ("bibitem") ("cite") 237 ("hspace*") ("vspace*") ("bibliography") ("bibitem") ("cite")
256 ("input") ("include") ("includeonly") ("mbox") ("hbox") ("caption") 238 ("input") ("include") ("includeonly") ("mbox") ("hbox") ("caption")
257 ("newlength") ("setlength" 2) ("addtolength" 2) ("settowidth" 2) 239 ("newlength") ("setlength" 2) ("addtolength" 2) ("settowidth" 2)
258 ("setcounter" 2) ("addtocounter" 2) ("stepcounter" 2) 240 ("setcounter" 2) ("addtocounter" 2) ("stepcounter" 2)
259 ("newcommand" 2) ("renewcommand" 2) 241 ("newcommand" 2) ("renewcommand" 2)
260 ("setcounter" 2) ("newenvironment" 3) ("newtheorem" 2) 242 ("setcounter" 2) ("newenvironment" 3) ("newtheorem" 2)
261 ("cline") ("framebox") ("savebox" 2) ("date") ("put") ("ref") 243 ("cline") ("framebox") ("savebox" 2) ("sbox" 2) ("newsavebox") ("usebox")
244 ("date") ("put") ("ref")
262 ("frac" 2) ("multicolumn" 3) ("shortstack") 245 ("frac" 2) ("multicolumn" 3) ("shortstack")
263 ) 246 )
264 "Default completion table for section-type completion." 247 "Default completion table for section-type completion."
265 ) 248 )
266 (defvar user-section-table nil) 249 (defvar user-section-table nil)
322 ;; Do not change this section. 305 ;; Do not change this section.
323 ;;; 306 ;;;
324 (defvar YaTeX-mode-map nil 307 (defvar YaTeX-mode-map nil
325 "Keymap used in YaTeX mode" 308 "Keymap used in YaTeX mode"
326 ) 309 )
327 (defvar YaTeX-typesetting-mode-map nil
328 "Keymap used in YaTeX typesetting buffer"
329 )
330 (defvar YaTeX-prefix-map nil 310 (defvar YaTeX-prefix-map nil
331 "Keymap used when YaTeX-prefix key pushed" 311 "Keymap used when YaTeX-prefix key pushed"
332 ) 312 )
333 (defvar YaTeX-user-extensional-map (make-sparse-keymap) 313 (defvar YaTeX-user-extensional-map (make-sparse-keymap)
334 "*Keymap used for the user's customization") 314 "*Keymap used for the user's customization")
340 When non-nil, each opening parentheses only opens, 320 When non-nil, each opening parentheses only opens,
341 nil enters both open/close parentheses when opening parentheses key pressed." 321 nil enters both open/close parentheses when opening parentheses key pressed."
342 ) 322 )
343 (defvar YaTeX-math-mode nil 323 (defvar YaTeX-math-mode nil
344 "Holds whether current mode is math-mode." 324 "Holds whether current mode is math-mode."
345 )
346 ;---------- Define default key bindings on YaTeX mode map ----------
347 (defun YaTeX-define-key (key binding &optional map)
348 "Define key on YaTeX-prefix-map."
349 (if YaTeX-inhibit-prefix-letter
350 (let ((c (aref key 0)))
351 (cond
352 ((and (>= c ?a) (<= c ?z)) (aset key 0 (1+ (- c ?a))))
353 ((and (>= c ?A) (<= c ?Z) (numberp YaTeX-inhibit-prefix-letter))
354 (aset key 0 (1+ (- c ?A))))
355 (t nil))))
356 (define-key (or map YaTeX-prefix-map) key binding)
357 )
358 (defun YaTeX-define-begend-key-normal (key env &optional map)
359 "Define short cut YaTeX-make-begin-end key."
360 (YaTeX-define-key
361 key
362 (list 'lambda '(arg) '(interactive "P")
363 (list 'YaTeX-insert-begin-end env 'arg))
364 map)
365 )
366 (defun YaTeX-define-begend-region-key (key env &optional map)
367 "Define short cut YaTeX-make-begin-end-region key."
368 (YaTeX-define-key key (list 'lambda nil '(interactive)
369 (list 'YaTeX-insert-begin-end env t)) map)
370 )
371 (defun YaTeX-define-begend-key (key env &optional map)
372 "Define short cut key for begin type completion both for normal
373 and region mode. To customize YaTeX, user should use this function."
374 (YaTeX-define-begend-key-normal key env map)
375 (if YaTeX-inhibit-prefix-letter nil
376 (YaTeX-define-begend-region-key
377 (concat (upcase (substring key 0 1)) (substring key 1)) env))
378 ) 325 )
379 ;;; 326 ;;;
380 ;; Define key table 327 ;; Define key table
381 ;;; 328 ;;;
382 (if YaTeX-mode-map 329 (if YaTeX-mode-map
471 (lambda (key) 418 (lambda (key)
472 (define-key YaTeX-mode-map (car key) 'YaTeX-math-insert-sequence))) 419 (define-key YaTeX-mode-map (car key) 'YaTeX-math-insert-sequence)))
473 YaTeX-math-key-list) 420 YaTeX-math-key-list)
474 ) 421 )
475 422
476 (if YaTeX-typesetting-mode-map nil
477 (setq YaTeX-typesetting-mode-map (make-keymap))
478 ;(suppress-keymap YaTeX-typesetting-mode-map t)
479 (define-key YaTeX-typesetting-mode-map " " 'YaTeX-jump-error-line)
480 (define-key YaTeX-typesetting-mode-map "\C-m" 'YaTeX-send-string)
481 (define-key YaTeX-typesetting-mode-map "1" 'delete-other-windows)
482 (define-key YaTeX-typesetting-mode-map "0" 'delete-window)
483 (define-key YaTeX-typesetting-mode-map "q" 'delete-window)
484 )
485
486 (defvar YaTeX-section-completion-map nil 423 (defvar YaTeX-section-completion-map nil
487 "*Key map used at YaTeX completion in the minibuffer.") 424 "*Key map used at YaTeX completion in the minibuffer.")
488 (if YaTeX-section-completion-map nil 425 (if YaTeX-section-completion-map nil
489 (setq YaTeX-section-completion-map 426 (setq YaTeX-section-completion-map
490 (copy-keymap (or (and (boundp 'gmhist-completion-map) 427 (copy-keymap (or (and (boundp 'gmhist-completion-map)
501 "*Key map used at YaTeX reading arguments in the minibuffer.") 438 "*Key map used at YaTeX reading arguments in the minibuffer.")
502 (if YaTeX-recursive-map nil 439 (if YaTeX-recursive-map nil
503 (setq YaTeX-recursive-map (copy-keymap global-map)) 440 (setq YaTeX-recursive-map (copy-keymap global-map))
504 (define-key YaTeX-recursive-map YaTeX-prefix YaTeX-prefix-map)) 441 (define-key YaTeX-recursive-map YaTeX-prefix YaTeX-prefix-map))
505 442
506 ;; (define-key YaTeX-recursive-map
507 ;; (concat YaTeX-prefix (if YaTeX-inhibit-prefix-letter "\C-s" "s"))
508 ;; 'YaTeX-make-section)
509 ;; (define-key map
510 ;; (concat YaTeX-prefix (if YaTeX-inhibit-prefix-letter "\C-m" "m"))
511 ;; 'YaTeX-make-singlecmd)
512 ;; (define-key map
513 ;; (concat YaTeX-prefix (if YaTeX-inhibit-prefix-letter "\C-l" "l"))
514 ;; 'YaTeX-make-fontsize)
515
516
517 ;---------- Define other variable ---------- 443 ;---------- Define other variable ----------
518 (defvar env-name "document" "*Initial tex-environment completion") 444 (defvar env-name "document" "*Initial tex-environment completion")
519 (defvar section-name "documentstyle" "*Initial tex-section completion") 445 (defvar section-name "documentstyle" "*Initial tex-section completion")
520 (defvar fontsize-name "large" "*Initial fontsize completion") 446 (defvar fontsize-name "large" "*Initial fontsize completion")
521 (defvar single-command "maketitle" "*Initial LaTeX single command") 447 (defvar single-command "maketitle" "*Initial LaTeX single command")
522 (defvar YaTeX-user-table-is-read nil
523 "Flag that means whether user completion table has been read or not."
524 )
525 (defvar YaTeX-kanji-code-alist nil
526 "Kanji-code expression translation table."
527 )
528 (if (boundp 'MULE)
529 (setq YaTeX-kanji-code-alist
530 (list (cons
531 1
532 (if YaTeX-dos (if (boundp '*sjis-dos*) *sjis-dos* *sjis*dos)
533 *sjis*))
534 '(2 . *junet*) '(3 . *euc-japan*))
535 ))
536 (defvar YaTeX-kanji-code (if YaTeX-dos 1 2) 448 (defvar YaTeX-kanji-code (if YaTeX-dos 1 2)
537 "*File kanji code used by Japanese TeX." 449 "*File kanji code used by Japanese TeX."
538 ) 450 )
539 (defvar YaTeX-coding-system nil "File coding system used by Japanese TeX.") 451 (defvar YaTeX-coding-system nil "File coding system used by Japanese TeX.")
540 (defvar YaTeX-latex-message-code "Process coding system for LaTeX.")
541 (cond 452 (cond
453 (YaTeX-emacs-20
454 (setq YaTeX-coding-system
455 (cdr (assoc YaTeX-kanji-code YaTeX-kanji-code-alist))))
542 ((boundp 'MULE) 456 ((boundp 'MULE)
543 (setq YaTeX-coding-system 457 (setq YaTeX-coding-system
544 (symbol-value (cdr (assoc YaTeX-kanji-code YaTeX-kanji-code-alist)))) 458 (symbol-value (cdr (assoc YaTeX-kanji-code YaTeX-kanji-code-alist)))))
545 (if (not YaTeX-dos)
546 (setq YaTeX-latex-message-code *autoconv*)))
547 ((boundp 'NEMACS) 459 ((boundp 'NEMACS)
548 (setq YaTeX-latex-message-code latex-message-kanji-code)) 460 (setq YaTeX-latex-message-code latex-message-kanji-code)))
549 ) 461
550 (defvar YaTeX-parent-file nil 462 (defvar YaTeX-mode-syntax-table nil
551 "*Main LaTeX source file name used when %#! expression doesn't exist.") 463 "*Syntax table for yatex-mode")
552 (make-variable-buffer-local 'YaTeX-parent-file) 464
465 (if YaTeX-mode-syntax-table nil
466 (setq YaTeX-mode-syntax-table (make-syntax-table (standard-syntax-table)))
467 (modify-syntax-entry ?\< "(>" YaTeX-mode-syntax-table)
468 (modify-syntax-entry ?\> ")<" YaTeX-mode-syntax-table)
469 (modify-syntax-entry ?\n " " YaTeX-mode-syntax-table)
470 )
553 471
554 ;---------- Provide YaTeX-mode ---------- 472 ;---------- Provide YaTeX-mode ----------
555 ;;; 473 ;;;
556 ;; Major mode definition 474 ;; Major mode definition
557 ;;; 475 ;;;
626 YaTeX-math-mode indent-line-function 544 YaTeX-math-mode indent-line-function
627 comment-start comment-start-skip 545 comment-start comment-start-skip
628 )) 546 ))
629 (cond ((boundp 'MULE) 547 (cond ((boundp 'MULE)
630 (set-file-coding-system YaTeX-coding-system)) 548 (set-file-coding-system YaTeX-coding-system))
549 ((and YaTeX-emacs-20 (fboundp 'coding-system-equal))
550 (or (coding-system-equal
551 YaTeX-coding-system buffer-file-coding-system)
552 (set-buffer-file-coding-system YaTeX-coding-system)))
553 ((featurep 'mule)
554 (set-file-coding-system YaTeX-coding-system))
631 ((boundp 'NEMACS) 555 ((boundp 'NEMACS)
632 (make-local-variable 'kanji-fileio-code) 556 (make-local-variable 'kanji-fileio-code)
633 (setq kanji-fileio-code YaTeX-kanji-code))) 557 (setq kanji-fileio-code YaTeX-kanji-code)))
634 (setq fill-column YaTeX-fill-column 558 (setq fill-column YaTeX-fill-column
635 fill-prefix YaTeX-fill-prefix 559 fill-prefix YaTeX-fill-prefix
639 comment-start YaTeX-comment-prefix 563 comment-start YaTeX-comment-prefix
640 comment-end "" 564 comment-end ""
641 ;;comment-start-skip "[^\\\\]%+[ \t]*" 565 ;;comment-start-skip "[^\\\\]%+[ \t]*"
642 ) 566 )
643 (use-local-map YaTeX-mode-map) 567 (use-local-map YaTeX-mode-map)
568 (set-syntax-table YaTeX-mode-syntax-table)
644 (if YaTeX-dos (setq YaTeX-saved-screen-height (screen-height))) 569 (if YaTeX-dos (setq YaTeX-saved-screen-height (screen-height)))
645 (YaTeX-read-user-completion-table) 570 (YaTeX-read-user-completion-table)
646 (and (fboundp 'YaTeX-19-collect-macros) (YaTeX-19-collect-macros)) 571 (and (fboundp 'YaTeX-19-collect-macros) (YaTeX-19-collect-macros))
647 (turn-on-auto-fill) ;1.63 572 (turn-on-auto-fill) ;1.63
573 (and (= 0 (buffer-size)) (file-exists-p YaTeX-template-file)
574 (y-or-n-p (format "Insert %s?" YaTeX-template-file))
575 (insert-file-contents (expand-file-name YaTeX-template-file)))
648 (run-hooks 'text-mode-hook 'yatex-mode-hook) 576 (run-hooks 'text-mode-hook 'yatex-mode-hook)
649 ) 577 )
650 578
651 ;---------- Define YaTeX-mode functions ---------- 579 ;---------- Define YaTeX-mode functions ----------
652 (defvar YaTeX-ec "\\" "Escape character of current mark-up language.") 580 (defvar YaTeX-ec "\\" "Escape character of current mark-up language.")
653 (defvar YaTeX-ec-regexp (regexp-quote YaTeX-ec)) 581 (defvar YaTeX-ec-regexp (regexp-quote YaTeX-ec))
654 (defvar YaTeX-struct-begin 582 (defvar YaTeX-struct-begin
655 (concat YaTeX-ec "begin{%1}%2") 583 (concat YaTeX-ec "begin{%1}%2")
656 "Keyword to begin environment.") 584 "Keyword format of begin-environment.")
657 (defvar YaTeX-struct-end (concat YaTeX-ec "end{%1}") 585 (defvar YaTeX-struct-end
658 "Keyword to end environment.") 586 (concat YaTeX-ec "end{%1}")
587 "Keyword format of end-environment.")
659 (defvar YaTeX-struct-name-regexp "[^}]+" 588 (defvar YaTeX-struct-name-regexp "[^}]+"
660 "Environment name regexp.") 589 "Environment name regexp.")
661 (defvar YaTeX-TeX-token-regexp 590 (defvar YaTeX-TeX-token-regexp
662 (cond (YaTeX-japan "[A-Za-z*あ-ん亜-龠]+") 591 (cond (YaTeX-japan "[A-Za-z*あ-ん亜-龠]+")
663 (t "[A-Za-z*]+")) 592 (t "[A-Za-z*]+"))
670 ;; "Keyword to make section.") 599 ;; "Keyword to make section.")
671 600
672 ;;; 601 ;;;
673 ;; autoload section 602 ;; autoload section
674 ;;; 603 ;;;
675 ;;autoload from yatexlib(general functions).
676 (autoload 'YaTeX-showup-buffer "yatexlib" "YaTeX library" t)
677 (autoload 'YaTeX-window-list "yatexlib" "YaTeX library" t)
678 (autoload 'YaTeX-search-active-forward "yatexlib" "YaTeX library" t)
679 (autoload 'YaTeX-search-active-backward "yatexlib" "YaTeX library" t)
680 (autoload 'substitute-all-key-definition "yatexlib" "YaTeX library" t)
681 (autoload 'YaTeX-switch-to-buffer "yatexlib" "YaTeX library" t)
682 (autoload 'YaTeX-switch-to-buffer-other-window "yatexlib" "YaTeX library" t)
683 (autoload 'YaTeX-replace-format "yatexlib" "YaTeX library" t)
684 (autoload 'YaTeX-replace-format-args "yatexlib" "YaTeX library" t)
685 (autoload 'rindex "yatexlib" "YaTeX library" t)
686 (autoload 'YaTeX-match-string "yatexlib" "YaTeX library" t)
687 (autoload 'YaTeX-minibuffer-complete "yatexlib" "YaTeX library" t)
688 (autoload 'goto-buffer-window "yatexlib" "YaTeX library" t)
689 (autoload 'split-window-calculate-height "yatexlib" "YaTeX library" t)
690 (autoload 'read-string-with-history "yatexlib" "YaTeX library" t)
691 (autoload 'read-from-minibuffer-with-history "yatexlib" "YaTeX library" t)
692 (autoload 'completing-read-with-history "yatexlib" "YaTeX library" t)
693 (autoload 'YaTeX-switch-to-window "yatexlib" "For windows.el" t)
694 604
695 ;;autoload from yatexprc.el 605 ;;autoload from yatexprc.el
696 (autoload 'YaTeX-visit-main "yatexprc" "Visit main LaTeX file." t) 606 (autoload 'YaTeX-visit-main "yatexprc" "Visit main LaTeX file." t)
697 (autoload 'YaTeX-visit-main-other-window "yatexprc" 607 (autoload 'YaTeX-visit-main-other-window "yatexprc"
698 "Visit main other window." t) 608 "Visit main other window." t)
780 (if region-mode 690 (if region-mode
781 (progn 691 (progn
782 (insert "\n") 692 (insert "\n")
783 (or exchange (exchange-point-and-mark))) 693 (or exchange (exchange-point-and-mark)))
784 (goto-char beg2) 694 (goto-char beg2)
785 (YaTeX-intelligent-newline nil)) 695 (YaTeX-intelligent-newline nil)
696 (YaTeX-indent-line))
786 (if YaTeX-current-position-register 697 (if YaTeX-current-position-register
787 (point-to-register YaTeX-current-position-register))) 698 (point-to-register YaTeX-current-position-register)))
788 ) 699 )
789 700
790 (defun YaTeX-make-begin-end (arg) 701 (defun YaTeX-make-begin-end (arg)
809 720
810 (defun YaTeX-make-begin-end-region () 721 (defun YaTeX-make-begin-end-region ()
811 "Call YaTeX-make-begin-end with ARG to specify region mode." 722 "Call YaTeX-make-begin-end with ARG to specify region mode."
812 (interactive) 723 (interactive)
813 (YaTeX-make-begin-end t) 724 (YaTeX-make-begin-end t)
814 )
815
816 (defun YaTeX-inner-environment (&optional quick)
817 "Return current inner-most environment.
818 Non-nil for optional argument QUICK restricts search bound to most
819 recent sectioning command. Matching point is stored to property 'point
820 of 'YaTeX-inner-environment, which can be referred by
821 (get 'YaTeX-inner-environment 'point)."
822 (let*((nest 0)
823 (beg (YaTeX-replace-format-args
824 (regexp-quote YaTeX-struct-begin)
825 YaTeX-struct-name-regexp
826 (if (eq major-mode 'yahtml-mode) "\\s *.*" "")
827 ""))
828 (end (YaTeX-replace-format-args
829 (regexp-quote YaTeX-struct-end)
830 YaTeX-struct-name-regexp "" ""))
831 (begend (concat "\\(" beg "\\)\\|\\(" end "\\)"))
832 bound m0
833 (open
834 (concat "^" (or (cdr (assq major-mode '((yahtml-mode . "<")))) "{")))
835 (close
836 (concat "^"
837 (or (cdr(assq major-mode '((yahtml-mode . "\n\t >")))) "}"))))
838 (save-excursion
839 (if quick
840 (setq bound
841 (save-excursion
842 (YaTeX-re-search-active-backward
843 (concat YaTeX-ec-regexp
844 "\\(" YaTeX-sectioning-regexp "\\)\\*?\\{")
845 YaTeX-comment-prefix nil 1)
846 (or (bobp) (end-of-line))
847 (point))))
848 (if (catch 'begin
849 (if (and (numberp bound) (< (point) bound)) (throw 'begin nil))
850 (while (YaTeX-re-search-active-backward
851 begend YaTeX-comment-prefix bound t)
852 (setq m0 (match-beginning 0))
853 (if (looking-at end) ;;(match-beginning 2)
854 (setq nest (1+ nest))
855 (setq nest (1- nest)))
856 (if (< nest 0)
857 (progn
858 (put 'YaTeX-inner-environment 'point m0)
859 (goto-char m0)
860 (put 'YaTeX-inner-environment 'indent (current-column))
861 (throw 'begin t)))))
862 (buffer-substring
863 (progn (skip-chars-forward open) (1+ (point)))
864 (progn (skip-chars-forward close) (point))))))
865 )
866
867 (defun YaTeX-end-environment ()
868 "Close opening environment"
869 (interactive)
870 (let ((env (YaTeX-inner-environment)))
871 (if (not env) (error "No premature environment")
872 (save-excursion
873 (if (YaTeX-search-active-forward
874 (YaTeX-replace-format-args YaTeX-struct-end env "" "")
875 YaTeX-comment-prefix nil t)
876 (if (y-or-n-p
877 (concat "Environment `" env
878 "' may be already closed. Force close?"))
879 nil
880 (error "end environment aborted."))))
881 (message "") ;Erase (y or n) message.
882 (YaTeX-insert-struc 'end env)
883 (save-excursion
884 (goto-char (or (get 'YaTeX-inner-environment 'point) (match-end 0)))
885 (if (pos-visible-in-window-p)
886 (sit-for (if YaTeX-dos 2 1))
887 (message "Matches with %s at line %d"
888 (YaTeX-replace-format-args YaTeX-struct-begin env "" "")
889 (count-lines (point-min) (point)))))))
890 )
891
892 ;;;VER2
893 (defun YaTeX-insert-struc (what env)
894 (cond
895 ((eq what 'begin)
896 (insert (YaTeX-replace-format-args
897 YaTeX-struct-begin env (YaTeX-addin env))))
898 ((eq what 'end)
899 (insert (YaTeX-replace-format-args YaTeX-struct-end env)))
900 (t nil))
901 ) 725 )
902 726
903 (defun YaTeX-make-section (arg &optional beg end cmd) 727 (defun YaTeX-make-section (arg &optional beg end cmd)
904 "Make LaTeX \\section{} type command with completing read. 728 "Make LaTeX \\section{} type command with completing read.
905 With numeric ARG, you can specify the number of arguments of 729 With numeric ARG, you can specify the number of arguments of
953 (goto-char beg) 777 (goto-char beg)
954 (insert YaTeX-ec section-name "{") 778 (insert YaTeX-ec section-name "{")
955 (goto-char (marker-position e))) 779 (goto-char (marker-position e)))
956 (use-global-map YaTeX-recursive-map) 780 (use-global-map YaTeX-recursive-map)
957 (if (= numarg 0) (YaTeX-make-singlecmd section-name) 781 (if (= numarg 0) (YaTeX-make-singlecmd section-name)
958 (insert YaTeX-ec section-name (YaTeX-addin section-name))) 782 (progn (insert YaTeX-ec section-name)
783 (insert (YaTeX-addin section-name))))
959 (while (<= j numarg) 784 (while (<= j numarg)
960 (insert 785 (insert
961 "{" 786 "{"
962 (setq title 787 (setq title
963 (cond 788 (cond
1627 ん〜やっぱりむずかしいね。分からない時は隣の Lisper に聞くか、 1452 ん〜やっぱりむずかしいね。分からない時は隣の Lisper に聞くか、
1628 fj野鳥の会で聞こう! 1453 fj野鳥の会で聞こう!
1629 ") 1454 ")
1630 1455
1631 (defvar YaTeX-processed-file-regexp-alist-default 1456 (defvar YaTeX-processed-file-regexp-alist-default
1632 '(("\\\\epsfile{[^},]*file=\\(\\([^,} ]*/\\)?[^,}. ]+\\)\\(\\.e?ps\\)?[^}]*}" 1) 1457 '(("\\\\epsfile\\(\\[[^]]+\\]\\)?{[^},]*file=\\(\\([^,} ]*/\\)?[^,}. ]+\\)\\(\\.e?ps\\)?[^}]*}" 2)
1633 ("\\\\epsfig{[^},]*fi\\(le\\|gure\\)=\\(\\([^,} ]*/\\)?[^,}. ]+\\)\\(\\.e?ps\\)?[^}]*}" 2) 1458 ("\\\\epsfig{[^},]*fi\\(le\\|gure\\)=\\(\\([^,} ]*/\\)?[^,}. ]+\\)\\(\\.e?ps\\)?[^}]*}" 2)
1634 ("\\\\postscriptbox{[^}]*}{[^}]*}{\\(\\([^,} ]*/\\)?[^}. ]+\\)\\(\\.e?ps\\)?}" 1) 1459 ("\\\\postscriptbox{[^}]*}{[^}]*}{\\(\\([^,} ]*/\\)?[^}. ]+\\)\\(\\.e?ps\\)?}" 1)
1635 ("\\\\\\(epsfbox\\|includegraphics\\){\\(\\([^,} ]*/\\)?[^}. ]+\\)\\(\\.e?ps\\)?}" 2) 1460 ("\\\\\\(epsfbox\\|includegraphics\\|epsfig\\)\\*?{\\(\\([^,} ]*/\\)?[^}. ]+\\)\\(\\.e?ps\\)?}" 2) ;\epsfbox{hoge.ps} or \includegraphics{hoge.eps}
1636 ("\\\\\\(psbox\\)\\(\\[[^]]+\\]\\)?{\\(\\([^,} ]*/\\)?[^} ]+\\)\\(\\.e?ps\\)}" 3) ;\psbox[options...]{hoge.eps} (97/1/11) 1461 ("\\\\\\(psbox\\)\\(\\[[^]]+\\]\\)?{\\(\\([^,} ]*/\\)?[^} ]+\\)\\(\\.e?ps\\)}" 3) ;\psbox[options...]{hoge.eps} (97/1/11)
1637 ) 1462 )
1638 "See the documentation of YaTeX-processed-file-regexp-alist." 1463 "See the documentation of YaTeX-processed-file-regexp-alist."
1639 ) 1464 )
1640 1465
1983 (while (re-search-forward (concat "^" prefix) (point-end-of-line) t) 1808 (while (re-search-forward (concat "^" prefix) (point-end-of-line) t)
1984 (replace-match "") 1809 (replace-match "")
1985 (if once (end-of-line))) 1810 (if once (end-of-line)))
1986 ) 1811 )
1987 1812
1988 (defun YaTeX-kill-option-string ()
1989 (if (and (eq predicate 'YaTeX-on-begin-end-p)
1990 (looking-at "\\(\\[.*\\]\\)*\\({.*}\\)*"))
1991 (delete-region (match-beginning 0) (match-end 0)))
1992 )
1993
1994 (defun YaTeX-kill-some-pairs (predicate gofunc kill-contents) 1813 (defun YaTeX-kill-some-pairs (predicate gofunc kill-contents)
1995 "Kill some matching pair. 1814 "Kill some matching pair.
1996 This function assumes that pairs occupy each line where they resid." 1815 This function assumes that pairs occupy whole of each line where they resid."
1997 ;;(interactive)
1998 (if (not (funcall predicate)) nil 1816 (if (not (funcall predicate)) nil
1999 (let ((beg (make-marker)) (end (make-marker)) (p (make-marker))) 1817 (let ((b1 (match-beginning 0)) (e1 (match-end 0))
2000 (set-marker end (match-end 0)) 1818 b2 e2)
2001 (if (match-beginning 2)
2002 (set-marker beg (match-beginning 2))
2003 (set-marker beg (match-beginning 1))
2004 (goto-char (match-end 0))
2005 (YaTeX-kill-option-string))
2006 (save-excursion 1819 (save-excursion
2007 (funcall gofunc) 1820 (funcall gofunc)
2008 (delete-region (point-beginning-of-line) (match-end 0)) 1821 (funcall predicate) ;get match data
2009 (YaTeX-kill-option-string) 1822 (if (< (point) e1) ;if currently on begin-line
2010 (if (and (eolp) (not (eobp))) (delete-char 1)) 1823 (progn
2011 (set-marker p (point)) 1824 (setq b2 b1 e2 e1
2012 (goto-char beg) 1825 b1 (match-beginning 0) e1 (match-end 0))
2013 (delete-region (point-beginning-of-line) end) 1826 (goto-char e2)) ;goto end-line's end
2014 (if (and (eolp) (not (eobp))) (delete-char 1)) 1827 (setq b2 (match-beginning 0)
2015 (if kill-contents (delete-region p (point)))) 1828 e2 (match-end 0))
1829 (goto-char e2)) ;now e2 has surely end-line's end
1830 (skip-chars-forward " \t")
1831 (and (eolp)
1832 (not (eobp))
1833 (setq e2 (1+ (point))))
1834 (if (not kill-contents)
1835 (kill-region
1836 (progn
1837 (goto-char b2)
1838 (skip-chars-backward " \t")
1839 (if (bolp) (point) b2))
1840 e2))
1841 (goto-char b1)
1842 (skip-chars-backward " \t")
1843 (if (not kill-contents)
1844 (progn
1845 (kill-append
1846 (buffer-substring
1847 (setq b1 (if (bolp) (point) b1))
1848 (setq e1
1849 (progn
1850 (goto-char e1)
1851 (while (looking-at "{\\| \t")
1852 (forward-list 1))
1853 (skip-chars-forward " \t")
1854 (if (and (eolp) (not (eobp)))
1855 (1+ (point))
1856 (point)))))
1857 t)
1858 (delete-region b1 e1))
1859 (kill-region
1860 (if (bolp) (point) b1)
1861 e2)))
2016 t)) 1862 t))
2017 ) 1863 )
2018 1864
2019 (defun YaTeX-kill-section-command (point kill-all) 1865 (defun YaTeX-kill-section-command (point kill-all)
2020 "Kill section-type command at POINT leaving its argument. 1866 "Kill section-type command at POINT leaving its argument.
2092 This function refers a local variable `source-window' in YaTeX-make-section" 1938 This function refers a local variable `source-window' in YaTeX-make-section"
2093 (interactive) 1939 (interactive)
2094 (require 'yatexsec) ;some case needs this 1940 (require 'yatexsec) ;some case needs this
2095 (if (> (minibuffer-depth) 1) 1941 (if (> (minibuffer-depth) 1)
2096 (error "Too many minibuffer levels for overview.")) 1942 (error "Too many minibuffer levels for overview."))
2097 (let ((sw (selected-window))(enable-recursive-minibuffers t) sect) 1943 (let ((sw (selected-window))
1944 (minibuffer-max-depth nil) ; for XEmacs20
1945 (enable-recursive-minibuffers t) sect)
2098 (unwind-protect 1946 (unwind-protect
2099 (progn 1947 (progn
2100 (select-window source-window) 1948 (select-window source-window)
2101 (setq sect (YaTeX-read-section-in-minibuffer 1949 (setq sect (YaTeX-read-section-in-minibuffer
2102 "Sectioning(Up=C-p, Down=C-n, Help=?): " 1950 "Sectioning(Up=C-p, Down=C-n, Help=?): "
2619 (defun YaTeX-previous-line-indentation () 2467 (defun YaTeX-previous-line-indentation ()
2620 (save-excursion 2468 (save-excursion
2621 (forward-line -1) 2469 (forward-line -1)
2622 (skip-chars-forward " \t") 2470 (skip-chars-forward " \t")
2623 (current-column))) 2471 (current-column)))
2624
2625 (defun YaTeX-reindent (col)
2626 "Remove current indentation and reindento to COL column."
2627 (save-excursion
2628 (beginning-of-line)
2629 (skip-chars-forward " \t")
2630 (if (/= col (current-column))
2631 (progn
2632 (delete-region (point) (progn (beginning-of-line) (point)))
2633 (indent-to col))))
2634 (skip-chars-forward " \t" (point-end-of-line)))
2635 2472
2636 (defun YaTeX-indent-line () 2473 (defun YaTeX-indent-line ()
2637 "Indent corrent line referrin current environment." 2474 "Indent corrent line referrin current environment."
2638 (interactive) 2475 (interactive)
2639 (let ((indent-relative 2476 (let ((indent-relative
2704 YaTeX-environment-indent))) 2541 YaTeX-environment-indent)))
2705 ;;Default movement 2542 ;;Default movement
2706 ((and (bolp) fill-prefix) (insert fill-prefix)) 2543 ((and (bolp) fill-prefix) (insert fill-prefix))
2707 (t (save-excursion 2544 (t (save-excursion
2708 (beginning-of-line) 2545 (beginning-of-line)
2709 (skip-chars-forward " \t") 2546 (if fill-prefix
2710 (indent-relative-maybe)) 2547 (progn
2548 (delete-region (point)
2549 (progn (skip-chars-forward " \t")
2550 (point)))
2551 (insert fill-prefix))
2552 (skip-chars-forward " \t")
2553 (indent-relative-maybe)))
2711 (skip-chars-forward " \t"))) 2554 (skip-chars-forward " \t")))
2712 ;;if current line is \begin, re-indent \end too 2555 ;;if current line is \begin, re-indent \end too
2713 (if (and (YaTeX-on-begin-end-p) (match-beginning 1)) 2556 (if (and (YaTeX-on-begin-end-p) (match-beginning 1))
2714 (save-excursion 2557 (save-excursion
2715 ;;(beginning-of-line) 2558 ;;(beginning-of-line)
2745 (backward-word 1) 2588 (backward-word 1)
2746 (looking-at "\\sw+")) ;is not japanese string 2589 (looking-at "\\sw+")) ;is not japanese string
2747 (insert YaTeX-comment-prefix)))))) 2590 (insert YaTeX-comment-prefix))))))
2748 ) 2591 )
2749 2592
2750 (defun YaTeX-local-table-symbol (symbol)
2751 "Return the lisp symbol which keeps local completion table of SYMBOL."
2752 (intern (concat "YaTeX$"
2753 default-directory
2754 (symbol-name symbol)))
2755 )
2756
2757 (defun YaTeX-sync-local-table (symbol)
2758 "Synchronize local variable SYMBOL.
2759 Copy its corresponding directory dependent completion table to SYMBOL."
2760 (if (boundp (YaTeX-local-table-symbol symbol))
2761 (set symbol (symbol-value (YaTeX-local-table-symbol symbol))))
2762 )
2763
2764 (defun YaTeX-read-user-completion-table (&optional forcetoread)
2765 "Append user completion table of LaTeX macros"
2766 (let*((user-table (expand-file-name YaTeX-user-completion-table))
2767 (local-table (expand-file-name (file-name-nondirectory user-table)))
2768 var localvar localbuf (curbuf (current-buffer)) sexp)
2769 (if YaTeX-user-table-is-read nil
2770 (message "Loading user completion table")
2771 (if (file-exists-p user-table) (load-file user-table)
2772 (message "Welcome to the field of YaTeX. I'm glad to see you!")))
2773 (setq YaTeX-user-table-is-read t)
2774 (cond
2775 ((file-exists-p local-table)
2776 (set-buffer (setq localbuf (find-file-noselect local-table)))
2777 (widen)
2778 (goto-char (point-min))
2779 (while (re-search-forward "(setq \\([^ ]+\\)" nil t)
2780 (setq var (intern (buffer-substring
2781 (match-beginning 1) (match-end 1)))
2782 localvar (YaTeX-local-table-symbol var))
2783 (goto-char (match-beginning 0))
2784 (setq sexp (buffer-substring (point)
2785 (progn (forward-sexp) (point))))
2786 (set-buffer curbuf)
2787 (or (assq var (buffer-local-variables)) (make-local-variable var))
2788 (eval (read sexp))
2789 (or (and (boundp localvar)
2790 (symbol-value localvar)
2791 (not forcetoread))
2792 (set localvar (symbol-value var)))
2793 (set-buffer localbuf))
2794 (kill-buffer localbuf)))
2795 (set-buffer curbuf))
2796 )
2797
2798 (defun YaTeX-reload-dictionary ()
2799 "Reload local dictionary.
2800 Use this function after editing ./.yatexrc."
2801 (interactive)
2802 (let ((YaTeX-user-table-is-read nil))
2803 (YaTeX-read-user-completion-table t))
2804 )
2805
2806 (defun YaTeX-lookup-table (word type)
2807 "Lookup WORD in completion table whose type is TYPE.
2808 This function refers the symbol tmp-TYPE-table, user-TYPE-table, TYPE-table.
2809 Typically, TYPE is one of 'env, 'section, 'fontsize, 'singlecmd."
2810 (if (symbolp type) (setq type (symbol-name type)))
2811 (or (assoc word (symbol-value (intern (concat "tmp-" type "-table"))))
2812 (assoc word (symbol-value (intern (concat "user-" type "-table"))))
2813 (assoc word (symbol-value (intern (concat type "-table"))))))
2814
2815 (defun YaTeX-update-table (vallist default-table user-table local-table)
2816 "Update completion table if the car of VALLIST is not in current tables.
2817 Second argument DEFAULT-TABLE is the quoted symbol of default completion
2818 table, third argument USER-TABLE is user table which will be saved in
2819 YaTeX-user-completion-table, fourth argument LOCAL-TABLE should have the
2820 completion which is valid during current Emacs's session. If you
2821 want to make LOCAL-TABLE valid longer span (but restrict in this directory)
2822 create the file in current directory which has the same name with
2823 YaTeX-user-completion-table."
2824 (let ((car-v (car vallist)) key answer
2825 (file (file-name-nondirectory YaTeX-user-completion-table)))
2826 (cond
2827 ((assoc car-v (symbol-value default-table))
2828 nil) ;Nothing to do
2829 ((setq key (assoc car-v (symbol-value user-table)))
2830 (if (equal (cdr vallist) (cdr key)) nil
2831 ;; if association hits, but contents differ.
2832 (message
2833 "%s's attributes turned into %s" (car vallist) (cdr vallist))
2834 (set user-table (delq key (symbol-value user-table)))
2835 (set user-table (cons vallist (symbol-value user-table)))
2836 (YaTeX-update-dictionary
2837 YaTeX-user-completion-table user-table "user")))
2838 ((setq key (assoc car-v (symbol-value local-table)))
2839 (if (equal (cdr vallist) (cdr key)) nil
2840 (message
2841 "%s's attributes turned into %s" (car vallist) (cdr vallist))
2842 (set local-table (delq key (symbol-value local-table)))
2843 (set local-table (cons vallist (symbol-value local-table)))
2844 (set (YaTeX-local-table-symbol local-table) (symbol-value local-table))
2845 (YaTeX-update-dictionary file local-table)))
2846 ;; All of above cases, there are some completion in tables.
2847 ;; Then update tables.
2848 (t
2849 (if (not YaTeX-nervous)
2850 (setq answer "u")
2851 (message
2852 "`%s' is not in table. Register into: U)serDic L)ocalDic N)one D)iscard"
2853 (car vallist))
2854 (setq answer (char-to-string (read-char))))
2855 (cond
2856 ((string-match answer "uy")
2857 (set user-table (cons vallist (symbol-value user-table)))
2858 (YaTeX-update-dictionary YaTeX-user-completion-table user-table "user")
2859 )
2860 ((string-match answer "tl")
2861 (set local-table (cons vallist (symbol-value local-table)))
2862 (set (YaTeX-local-table-symbol local-table) (symbol-value local-table))
2863 (YaTeX-update-dictionary file local-table))
2864 ((string-match answer "d") nil) ;discard it
2865 (t (set default-table
2866 (cons vallist (symbol-value default-table))))))))
2867 )
2868
2869 (defun YaTeX-cplread-with-learning
2870 (prom default-table user-table local-table
2871 &optional pred reqmatch init hsym)
2872 "Completing read with learning.
2873 Do a completing read with prompt PROM. Completion table is what
2874 DEFAULT-TABLE, USER-TABLE, LOCAL table are appended in reverse order.
2875 Note that these tables are passed by the symbol.
2876 Optional arguments PRED, REQMATH and INIT are passed to completing-read
2877 as its arguments PREDICATE, REQUIRE-MATCH and INITIAL-INPUT respectively.
2878 If optional 8th argument HSYM, history symbol, is passed, use it as
2879 history list variable."
2880 (YaTeX-sync-local-table local-table)
2881 (let*((table (append (symbol-value local-table)
2882 (symbol-value user-table)
2883 (symbol-value default-table)))
2884 (word (completing-read-with-history
2885 prom table pred reqmatch init hsym)))
2886 (if (and (string< "" word) (not (assoc word table)))
2887 (YaTeX-update-table (list word) default-table user-table local-table))
2888 word)
2889 )
2890
2891 (defun YaTeX-update-dictionary (file symbol &optional type)
2892 (let ((local-table-buf (find-file-noselect file))
2893 (name (symbol-name symbol))
2894 (value (symbol-value symbol)))
2895 (save-excursion
2896 (message "Updating %s dictionary..." (or type "local"))
2897 (set-buffer local-table-buf)
2898 (goto-char (point-max))
2899 (search-backward (concat "(setq " name) nil t)
2900 (delete-region (point) (progn (forward-sexp) (point)))
2901 (delete-blank-lines)
2902 (insert "(setq " name " '(\n")
2903 (mapcar '(lambda (s)
2904 (insert (format "%s\n" (prin1-to-string s))))
2905 value)
2906 (insert "))\n\n")
2907 (delete-blank-lines)
2908 (basic-save-buffer)
2909 (kill-buffer local-table-buf)
2910 (message "Updating %s dictionary...Done" (or type "local"))))
2911 )
2912
2913 ;; --------------- General sub functions ---------------
2914 (defun point-beginning-of-line ()
2915 (save-excursion (beginning-of-line)(point))
2916 )
2917
2918 (defun point-end-of-line ()
2919 (save-excursion (end-of-line)(point))
2920 )
2921
2922
2923 (provide 'yatex) 2593 (provide 'yatex)
2924 (defvar yatex-mode-load-hook nil 2594 (defvar yatex-mode-load-hook nil
2925 "*List of functions to be called when yatex.el is loaded.") 2595 "*List of functions to be called when yatex.el is loaded.")
2926 (if (and YaTeX-emacs-19 window-system (not (featurep 'yatex19))) 2596 (if (and YaTeX-emacs-19 window-system (not (featurep 'yatex19)))
2927 (load "yatex19")) 2597 (load "yatex19"))

yatex.org