yatex

annotate yatex19.el @ 49:eb0512bfcb7f

Abolish user-article table. Use normal read-string instead. Supply smart add-in function for documentstyle. Update user dictionary whenever new words entered. Enhance [prefix] c. Allow user defined sectioning commands in yatexsec.
author yuuji
date Fri, 25 Nov 1994 08:26:13 +0000
parents d7e7b4654058
children b0371b6ed799
rev   line source
yuuji@46 1 ;;; -*- Emacs-Lisp -*-
yuuji@46 2 ;;; YaTeX facilities for Emacs 19
yuuji@46 3 ;;; (c )1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
yuuji@49 4 ;;; Last modified Mon Nov 21 21:52:16 1994 on figaro
yuuji@46 5 ;;; $Id$
yuuji@46 6
yuuji@49 7 ;;; とりあえず hilit19 を使っている時に色が付くようにして
yuuji@49 8 ;;; メニューバーでごにょごにょできるようにしただけ。
yuuji@49 9 ;;; いったい誰がメニューバー使ってLaTeXソース書くんだろうか?
yuuji@49 10 ;;; まあいいや練習練習。後ろの方にちょっとコメントあり。
yuuji@46 11
yuuji@47 12 (require 'yatex)
yuuji@47 13
yuuji@46 14 (defun YaTeX-19-define-sub-menu (map vec &rest bindings)
yuuji@46 15 "Define sub-menu-item in MAP at vector VEC as BINDINGS.
yuuji@46 16 BINDINGS is a form with optional length: (symbol title binding).
yuuji@46 17 When you defined menu-bar keymap such like:
yuuji@46 18 (define-key foo-map [menu-bar foo] (make-sparse-keymap \"foo menu\"))
yuuji@46 19 and you want to define sub menu for `foo menu' as followings.
yuuji@46 20 foo -> menu1 (calling function `func1')
yuuji@46 21 menu2 (doing interactive call `(func2 ...)'
yuuji@46 22 Call this function like this:
yuuji@46 23 (YaTeX-19-define-sub-menu foo-map [menu-bar foo]
yuuji@46 24 '(m1 \"Function 1\" func1)
yuuji@46 25 '(m2 \"Function 2\" (lambda () (interactive) (func2 ...))))
yuuji@46 26 where
yuuji@46 27 `m1' and `m2' are the keymap symbol for sub-menu of `[menu-bar foo].
yuuji@46 28 `Funtion 1' and `Function 2' are the title strings for sub-menu.
yuuji@46 29 "
yuuji@46 30 (let ((i 0) (vec2 (make-vector (1+ (length vec)) nil)))
yuuji@46 31 (while (< i (length vec))
yuuji@46 32 (aset vec2 i (aref vec i))
yuuji@46 33 (setq i (1+ i)))
yuuji@46 34 (setq bindings (reverse bindings))
yuuji@46 35 (mapcar
yuuji@46 36 (function
yuuji@46 37 (lambda (bind)
yuuji@46 38 (aset vec2 (1- (length vec2)) (car bind)) ;set menu-symbol
yuuji@46 39 (define-key map vec2
yuuji@46 40 (cons (car (cdr bind))
yuuji@46 41 (car (cdr (cdr bind)))))))
yuuji@46 42 bindings)))
yuuji@46 43
yuuji@46 44 ;; Menu for Typeset relating processes ----------------------------------------
yuuji@46 45 (define-key YaTeX-mode-map [menu-bar yatex]
yuuji@46 46 (cons "YaTeX" (make-sparse-keymap "YaTeX")))
yuuji@46 47 (define-key YaTeX-mode-map [menu-bar yatex process]
yuuji@46 48 (cons "Process" (make-sparse-keymap "Process")))
yuuji@46 49 (YaTeX-19-define-sub-menu
yuuji@46 50 YaTeX-mode-map [menu-bar yatex process]
yuuji@46 51 '(buffer "LaTeX" (lambda () (interactive) (YaTeX-typeset-menu nil ?j)))
yuuji@46 52 '(kill "Kill LaTeX" (lambda () (interactive) (YaTeX-typeset-menu nil ?k)))
yuuji@46 53 '(bibtex "BibTeX" (lambda () (interactive) (YaTeX-typeset-menu nil ?b)))
yuuji@46 54 '(makeindex "makeindex" (lambda () (interactive) (YaTeX-typeset-menu nil ?i)))
yuuji@46 55 '(preview "Preview" (lambda () (interactive) (YaTeX-typeset-menu nil ?p)))
yuuji@46 56 '(lpr "lpr" (lambda () (interactive) (YaTeX-typeset-menu nil ?l)))
yuuji@46 57 '(lpq "lpq" (lambda () (interactive) (YaTeX-typeset-menu nil ?q)))
yuuji@46 58 )
yuuji@46 59
yuuji@46 60 ;; Help for LaTeX ------------------------------------------------------------
yuuji@46 61 (YaTeX-19-define-sub-menu
yuuji@46 62 YaTeX-mode-map [menu-bar yatex]
yuuji@46 63 '(sephelp "--")
yuuji@46 64 '(help "Help on LaTeX commands" YaTeX-help)
yuuji@46 65 '(apropos "Apropos on LaTeX commands" YaTeX-apropos))
yuuji@46 66
yuuji@46 67 ;; Switch modes --------------------------------------------------------------
yuuji@46 68 (define-key YaTeX-mode-map [menu-bar yatex switch]
yuuji@46 69 (cons "Switching YaTeX's modes" (make-sparse-keymap "modes")))
yuuji@46 70 (or YaTeX-auto-math-mode
yuuji@46 71 (define-key YaTeX-mode-map [menu-bar yatex switch math]
yuuji@46 72 '("Toggle math mode" . (lambda () (interactive)
yuuji@46 73 (YaTeX-switch-mode-menu nil ?t)))))
yuuji@46 74 (define-key YaTeX-mode-map [menu-bar yatex switch mod]
yuuji@46 75 '("Toggle modify mode" . (lambda () (interactive)
yuuji@46 76 (YaTeX-switch-mode-menu nil ?m))))
yuuji@46 77
yuuji@46 78 ;; % menu --------------------------------------------------------------------
yuuji@46 79 (define-key YaTeX-mode-map [menu-bar yatex percent]
yuuji@46 80 (cons "Edit %# notation" (make-sparse-keymap "Edit %# notation")))
yuuji@46 81 (YaTeX-19-define-sub-menu
yuuji@46 82 YaTeX-mode-map [menu-bar yatex percent]
yuuji@46 83 '(! "Change LaTeX typesetter(%#!)"
yuuji@46 84 (lambda () (interactive) (YaTeX-%-menu nil nil ?!)))
yuuji@46 85 '(begend "Set %#BEGIN-%#END on region"
yuuji@46 86 (lambda () (interactive) (YaTeX-%-menu nil nil ?b)))
yuuji@46 87 '(lpr "Change LPR format"
yuuji@46 88 (lambda () (interactive) (YaTeX-%-menu nil nil ?l))))
yuuji@46 89
yuuji@46 90 ;; What position -------------------------------------------------------------
yuuji@46 91 (YaTeX-19-define-sub-menu
yuuji@46 92 YaTeX-mode-map [menu-bar yatex]
yuuji@46 93 '(what "What column in tabular" YaTeX-what-column))
yuuji@46 94
yuuji@46 95 ;; Jump cursor ---------------------------------------------------------------
yuuji@46 96 (define-key YaTeX-mode-map [menu-bar yatex jump]
yuuji@46 97 (cons "Jump cursor"
yuuji@46 98 (make-sparse-keymap "Jump cursor")))
yuuji@46 99 (YaTeX-19-define-sub-menu
yuuji@46 100 YaTeX-mode-map [menu-bar yatex jump]
yuuji@46 101 '(corres "Goto corersponding position" YaTeX-goto-corresponding-*)
yuuji@46 102 '(main "Visit main source" (lambda () (interactive) (YaTeX-visit-main)))
yuuji@46 103 '(main-other "Visit main source other window" YaTeX-visit-main-other-window)
yuuji@46 104 )
yuuji@46 105
yuuji@46 106 ;; ===========================================================================
yuuji@46 107 (define-key YaTeX-mode-map [menu-bar yatex sepcom]
yuuji@46 108 '("---" . nil))
yuuji@46 109
yuuji@46 110 ;; Comment/Uncomment ---------------------------------------------------------
yuuji@46 111 (YaTeX-19-define-sub-menu
yuuji@46 112 YaTeX-mode-map [menu-bar yatex]
yuuji@46 113 '(comment "Comment region or environment" YaTeX-comment-region)
yuuji@46 114 '(uncomment "Unomment region or environment" YaTeX-uncomment-region)
yuuji@46 115 '(commentp "Comment paragraph" YaTeX-comment-paragraph)
yuuji@47 116 '(uncommentp "Uncomment paragraph" YaTeX-uncomment-paragraph)
yuuji@46 117 '(sepcom "--" nil)
yuuji@46 118 )
yuuji@46 119
yuuji@46 120
yuuji@46 121 ;; ===========================================================================
yuuji@46 122 ;; Change/Kill/Fill
yuuji@46 123 (YaTeX-19-define-sub-menu
yuuji@46 124 YaTeX-mode-map [menu-bar yatex]
yuuji@46 125 '(change "Change macros" YaTeX-change-*)
yuuji@46 126 '(kill "Kill macros" YaTeX-kill-*)
yuuji@46 127 '(fillitem "Fill \\item" YaTeX-fill-item)
yuuji@46 128 '(newline "Newline" YaTeX-intelligent-newline)
yuuji@46 129 '(sepchg "--" nil)
yuuji@46 130 )
yuuji@46 131
yuuji@46 132 ;; Menu for completions ------------------------------------------------------
yuuji@46 133
yuuji@46 134
yuuji@46 135 ;;;(YaTeX-19-define-sub-menu
yuuji@46 136 ;;; YaTeX-mode-map [menu-bar yatex]
yuuji@46 137 ;;; '(secr "Section-type command on region" YaTeX-make-section-region)
yuuji@46 138 ;;; '(sec "Section-type command" YaTeX-make-section))
yuuji@46 139
yuuji@46 140 (define-key YaTeX-mode-map [menu-bar yatex sectionr]
yuuji@46 141 (cons "Section-type region(long name)"
yuuji@46 142 (make-sparse-keymap "Enclose region with section-type macro")))
yuuji@46 143 (define-key YaTeX-mode-map [menu-bar yatex section]
yuuji@47 144 (cons "Section-type(long name)"
yuuji@46 145 (make-sparse-keymap "Section-type macro")))
yuuji@46 146 (let ((sorted-section
yuuji@46 147 (sort
yuuji@46 148 (delq nil
yuuji@46 149 (mapcar (function (lambda (s)
yuuji@46 150 (if (> (length (car s)) 5)
yuuji@46 151 (car s))))
yuuji@46 152 (append section-table user-section-table)))
yuuji@46 153 'string<)))
yuuji@46 154 (apply 'YaTeX-19-define-sub-menu
yuuji@46 155 YaTeX-mode-map [menu-bar yatex section]
yuuji@46 156 (mapcar (function (lambda (secname)
yuuji@46 157 (list (intern secname) secname
yuuji@46 158 (list 'lambda ()
yuuji@46 159 (list 'interactive)
yuuji@46 160 (list 'YaTeX-make-section
yuuji@46 161 nil nil nil secname)))))
yuuji@46 162 sorted-section))
yuuji@46 163 (apply 'YaTeX-19-define-sub-menu
yuuji@46 164 YaTeX-mode-map [menu-bar yatex sectionr]
yuuji@46 165 (mapcar (function (lambda (secname)
yuuji@46 166 (list (intern secname) secname
yuuji@46 167 (list 'lambda ()
yuuji@46 168 (list 'interactive)
yuuji@46 169 (list 'YaTeX-make-section
yuuji@46 170 nil
yuuji@46 171 (list 'region-beginning)
yuuji@46 172 (list 'region-end)
yuuji@46 173 secname)))))
yuuji@46 174 sorted-section)))
yuuji@46 175
yuuji@46 176 (define-key YaTeX-mode-map [menu-bar yatex envr]
yuuji@46 177 (cons "Environment region" (make-sparse-keymap "Environment region")))
yuuji@46 178 (define-key YaTeX-mode-map [menu-bar yatex env]
yuuji@46 179 (cons "Environment" (make-sparse-keymap "Environment")))
yuuji@46 180 (let (prev envname)
yuuji@46 181 (mapcar
yuuji@46 182 (function
yuuji@46 183 (lambda (envalist)
yuuji@46 184 (setq envname (car envalist))
yuuji@46 185 (define-key-after
yuuji@46 186 (lookup-key YaTeX-mode-map [menu-bar yatex env])
yuuji@46 187 (vector (intern envname))
yuuji@46 188 (cons envname
yuuji@46 189 (list 'lambda () (list 'interactive)
yuuji@46 190 (list 'YaTeX-insert-begin-end
yuuji@46 191 envname nil)))
yuuji@46 192 prev)
yuuji@46 193 (define-key-after
yuuji@46 194 (lookup-key YaTeX-mode-map [menu-bar yatex envr])
yuuji@46 195 (vector (intern envname))
yuuji@46 196 (cons envname
yuuji@46 197 (list 'lambda () (list 'interactive)
yuuji@46 198 (list 'YaTeX-insert-begin-end
yuuji@46 199 envname t)))
yuuji@46 200 prev)
yuuji@46 201 (setq prev (intern envname))))
yuuji@46 202 (sort (append env-table user-env-table)
yuuji@46 203 '(lambda (x y) (string< (car x) (car y))))))
yuuji@46 204
yuuji@46 205 ;; Highlightening
yuuji@49 206 ;; ローカルなマクロを読み込んだ後 redraw すると
yuuji@49 207 ;; ローカルマクロを keyword として光らせる(keywordじゃまずいかな…)。
yuuji@46 208 (defvar YaTeX-hilit-pattern-adjustment
yuuji@46 209 (list
yuuji@49 210 ;;\def が define なんだから new* も define でしょう。
yuuji@46 211 '("\\\\\\(re\\)?new\\(environment\\|command\\){" "}" define)
yuuji@46 212 '("\\\\new\\(length\\|theorem\\|counter\\){" "}" define)
yuuji@49 213 ;;セクションコマンドが単なるキーワードってことはないでしょう。
yuuji@46 214 (list
yuuji@46 215 (concat "\\\\\\(" YaTeX-sectioning-regexp "\\){") "}"
yuuji@49 216 'sectioning)
yuuji@49 217 ;;eqnarray などの数式環境が入ってないみたい…
yuuji@49 218 '("\\\\begin{\\(eqnarray\\*?\\)\\|\\(equation\\*?\\)}"
yuuji@49 219 "\\\\end{\\(eqnarray\\*?\\)\\|\\(equation\\*?\\)}"
yuuji@49 220 formula))
yuuji@46 221 "Adjustment for hilit19's LaTeX hilit pattern.")
yuuji@46 222 (defvar YaTeX-hilit-sectioning-face
yuuji@47 223 '(yellow/dodgerblue yellow/cornflowerblue))
yuuji@47 224 (defvar YaTeX-hilit-singlecmd-face
yuuji@47 225 '(slateblue2 aquamarine))
yuuji@46 226 (defun YaTeX-19-collect-macro ()
yuuji@46 227 (cond
yuuji@46 228 ((and (featurep 'hilit19) (fboundp 'hilit-translate))
yuuji@47 229 (let ((get-face
yuuji@47 230 (function
yuuji@47 231 (lambda (table)
yuuji@47 232 (cond
yuuji@47 233 ((eq hilit-background-mode 'light) (car table))
yuuji@47 234 ((eq hilit-background-mode 'dark) (car (cdr table)))
yuuji@47 235 (t nil))))))
yuuji@47 236 (hilit-translate
yuuji@47 237 sectioning (funcall get-face YaTeX-hilit-sectioning-face)
yuuji@47 238 macro (funcall get-face YaTeX-hilit-singlecmd-face)))
yuuji@47 239 (setq hilit-patterns-alist ;Remove at first.
yuuji@46 240 (delq 'yatex-mode hilit-patterns-alist)
yuuji@46 241 hilit-patterns-alist
yuuji@46 242 (cons
yuuji@46 243 (cons 'yatex-mode
yuuji@46 244 (append
yuuji@46 245 YaTeX-hilit-pattern-adjustment
yuuji@46 246 (cdr (assq 'latex-mode hilit-patterns-alist))
yuuji@46 247 (list
yuuji@46 248 (list
yuuji@46 249 (concat "\\\\\\("
yuuji@46 250 (mapconcat
yuuji@46 251 (function (lambda (s) (regexp-quote (car s))))
yuuji@46 252 (append user-section-table tmp-section-table)
yuuji@46 253 "\\|")
yuuji@46 254 "\\){")
yuuji@47 255 "}" 'keyword)
yuuji@47 256 (list
yuuji@47 257 (concat "\\\\\\("
yuuji@47 258 (mapconcat
yuuji@47 259 (function (lambda (s) (regexp-quote (car s))))
yuuji@47 260 (append user-singlecmd-table tmp-singlecmd-table)
yuuji@47 261 "\\|")
yuuji@47 262 "\\)")
yuuji@47 263 0 'macro))))
yuuji@46 264 hilit-patterns-alist)))))
yuuji@46 265 (YaTeX-19-collect-macro)
yuuji@46 266 (defun YaTeX-hilit-recenter (arg)
yuuji@46 267 "Collect current local macro and hilit-recenter."
yuuji@46 268 (interactive "P")
yuuji@46 269 (YaTeX-19-collect-macro)
yuuji@46 270 (hilit-recenter arg))
yuuji@46 271 (if (fboundp 'hilit-recenter) ;Replace hilit-recenter with
yuuji@46 272 (mapcar (function (lambda (key) ;YaTeX-hilit-recenter in yatex-mode
yuuji@46 273 (define-key YaTeX-mode-map key 'YaTeX-hilit-recenter)))
yuuji@46 274 (where-is-internal 'hilit-recenter)))
yuuji@46 275
yuuji@49 276 ;;; reverseVideo にして hilit-background-mode を 'dark
yuuji@49 277 ;;; にしている人は数式などが暗くなりすぎて見づらいかもしれない。
yuuji@49 278 ;;; 次のコードを hilit19 をロードしている場所の直後に置くとちょっ
yuuji@49 279 ;;; とはまし。
yuuji@46 280 ;;; (if (eq hilit-background-mode 'dark)
yuuji@46 281 ;;; (hilit-translate
yuuji@46 282 ;;; string 'mediumspringgreen
yuuji@46 283 ;;; formula 'khaki
yuuji@46 284 ;;; label 'yellow-underlined))
yuuji@46 285
yuuji@46 286 (provide 'yatex19)