yatex

annotate yatex19.el @ 47:d7e7b4654058

Support special popup frame. Refine highlightening method. On Emacs-19, couldn't save user completion table correctly, fixed.
author yuuji
date Mon, 24 Oct 1994 17:26:47 +0000
parents cd1b63102eed
children eb0512bfcb7f
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@47 4 ;;; Last modified Fri Sep 23 04:30:27 1994 on figaro
yuuji@46 5 ;;; $Id$
yuuji@46 6
yuuji@46 7 ;;; $B$H$j$"$($:(B hilit19 $B$r;H$C$F$$$k;~$K?'$,IU$/$h$&$K$7$F(B
yuuji@46 8 ;;; $B%a%K%e!<%P!<$G$4$K$g$4$K$g$G$-$k$h$&$K$7$?$@$1!#(B
yuuji@46 9 ;;; $B$$$C$?$$C/$,%a%K%e!<%P!<;H$C$F(BLaTeX$B%=!<%9=q$/$s$@$m$&$+(B?
yuuji@46 10 ;;; $B$^$"$$$$$dN}=,N}=,!#8e$m$NJ}$K$A$g$C$H%3%a%s%H$"$j!#(B
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@46 206 ;; $B%m!<%+%k$J%^%/%m$rFI$_9~$s$@8e(B redraw $B$9$k$H(B
yuuji@46 207 ;; $B%m!<%+%k%^%/%m$r(B keyword $B$H$7$F8w$i$;$k(B(keyword$B$8$c$^$:$$$+$J!D(B)$B!#(B
yuuji@46 208 (defvar YaTeX-hilit-pattern-adjustment
yuuji@46 209 (list
yuuji@46 210 ;;\def $B$,(B define $B$J$s$@$+$i(B new* $B$b(B define $B$G$7$g$&!#(B
yuuji@46 211 '("\\\\\\(re\\)?new\\(environment\\|command\\){" "}" define)
yuuji@46 212 '("\\\\new\\(length\\|theorem\\|counter\\){" "}" define)
yuuji@46 213 ;;$B%;%/%7%g%s%3%^%s%I$,C1$J$k%-!<%o!<%I$C$F$3$H$O$J$$$G$7$g$&!#(B
yuuji@46 214 (list
yuuji@46 215 (concat "\\\\\\(" YaTeX-sectioning-regexp "\\){") "}"
yuuji@46 216 'sectioning))
yuuji@46 217 "Adjustment for hilit19's LaTeX hilit pattern.")
yuuji@46 218 (defvar YaTeX-hilit-sectioning-face
yuuji@47 219 '(yellow/dodgerblue yellow/cornflowerblue))
yuuji@47 220 (defvar YaTeX-hilit-singlecmd-face
yuuji@47 221 '(slateblue2 aquamarine))
yuuji@46 222 (defun YaTeX-19-collect-macro ()
yuuji@46 223 (cond
yuuji@46 224 ((and (featurep 'hilit19) (fboundp 'hilit-translate))
yuuji@47 225 (let ((get-face
yuuji@47 226 (function
yuuji@47 227 (lambda (table)
yuuji@47 228 (cond
yuuji@47 229 ((eq hilit-background-mode 'light) (car table))
yuuji@47 230 ((eq hilit-background-mode 'dark) (car (cdr table)))
yuuji@47 231 (t nil))))))
yuuji@47 232 (hilit-translate
yuuji@47 233 sectioning (funcall get-face YaTeX-hilit-sectioning-face)
yuuji@47 234 macro (funcall get-face YaTeX-hilit-singlecmd-face)))
yuuji@47 235 (setq hilit-patterns-alist ;Remove at first.
yuuji@46 236 (delq 'yatex-mode hilit-patterns-alist)
yuuji@46 237 hilit-patterns-alist
yuuji@46 238 (cons
yuuji@46 239 (cons 'yatex-mode
yuuji@46 240 (append
yuuji@46 241 YaTeX-hilit-pattern-adjustment
yuuji@46 242 (cdr (assq 'latex-mode hilit-patterns-alist))
yuuji@46 243 (list
yuuji@46 244 (list
yuuji@46 245 (concat "\\\\\\("
yuuji@46 246 (mapconcat
yuuji@46 247 (function (lambda (s) (regexp-quote (car s))))
yuuji@46 248 (append user-section-table tmp-section-table)
yuuji@46 249 "\\|")
yuuji@46 250 "\\){")
yuuji@47 251 "}" 'keyword)
yuuji@47 252 (list
yuuji@47 253 (concat "\\\\\\("
yuuji@47 254 (mapconcat
yuuji@47 255 (function (lambda (s) (regexp-quote (car s))))
yuuji@47 256 (append user-singlecmd-table tmp-singlecmd-table)
yuuji@47 257 "\\|")
yuuji@47 258 "\\)")
yuuji@47 259 0 'macro))))
yuuji@46 260 hilit-patterns-alist)))))
yuuji@46 261 (YaTeX-19-collect-macro)
yuuji@46 262 (defun YaTeX-hilit-recenter (arg)
yuuji@46 263 "Collect current local macro and hilit-recenter."
yuuji@46 264 (interactive "P")
yuuji@46 265 (YaTeX-19-collect-macro)
yuuji@46 266 (hilit-recenter arg))
yuuji@46 267 (if (fboundp 'hilit-recenter) ;Replace hilit-recenter with
yuuji@46 268 (mapcar (function (lambda (key) ;YaTeX-hilit-recenter in yatex-mode
yuuji@46 269 (define-key YaTeX-mode-map key 'YaTeX-hilit-recenter)))
yuuji@46 270 (where-is-internal 'hilit-recenter)))
yuuji@46 271
yuuji@46 272 ;;; reverseVideo $B$K$7$F(B hilit-background-mode $B$r(B 'dark
yuuji@46 273 ;;; $B$K$7$F$$$k?M$O?t<0$J$I$,0E$/$J$j$9$.$F8+$E$i$$$+$b$7$l$J$$!#(B
yuuji@46 274 ;;; $B<!$N%3!<%I$r(B hilit19 $B$r%m!<%I$7$F$$$k>l=j$ND>8e$KCV$/$H$A$g$C(B
yuuji@46 275 ;;; $B$H$O$^$7!#(B
yuuji@46 276 ;;; (if (eq hilit-background-mode 'dark)
yuuji@46 277 ;;; (hilit-translate
yuuji@46 278 ;;; string 'mediumspringgreen
yuuji@46 279 ;;; formula 'khaki
yuuji@46 280 ;;; label 'yellow-underlined))
yuuji@46 281
yuuji@46 282 (provide 'yatex19)