yatex

annotate yatex19.el @ 72:0aaebd07dad0

Support font-lock on XEmacs-21, Emacs-20, Emacs-21. Support Emacs-21.
author yuuji
date Mon, 25 Dec 2000 10:19:28 +0000
parents 44e3a5e1e883
children f41b01fef5d6
rev   line source
yuuji@46 1 ;;; -*- Emacs-Lisp -*-
yuuji@46 2 ;;; YaTeX facilities for Emacs 19
yuuji@72 3 ;;; (c )1994-2000 by HIROSE Yuuji.[yuuji@yatex.org]
yuuji@72 4 ;;; Last modified Mon Dec 25 19:16:04 2000 on firestorm
yuuji@46 5 ;;; $Id$
yuuji@46 6
yuuji@64 7 ;(require 'yatex)
yuuji@47 8
yuuji@72 9 (cond
yuuji@72 10 (YaTeX-use-hilit19 (require 'hilit19))
yuuji@72 11 (YaTeX-use-font-lock (require 'font-lock)))
yuuji@72 12
yuuji@72 13 (defvar YaTeX-use-highlighting (or YaTeX-use-font-lock YaTeX-use-hilit19)
yuuji@72 14 "*Use highlighting buffer or not.")
yuuji@72 15 (defvar YaTeX-background-mode
yuuji@72 16 (cond
yuuji@72 17 ((boundp 'hilit-background-mode) hilit-background-mode)
yuuji@72 18 ((boundp 'frame-background-mode) frame-background-mode)
yuuji@72 19 ((fboundp 'get-frame-background-mode)
yuuji@72 20 (get-frame-background-mode (selected-frame)))
yuuji@72 21 (t nil)))
yuuji@70 22
yuuji@64 23 (defvar YaTeX-mode-menu-map (make-sparse-keymap "YaTeX"))
yuuji@64 24 (defvar YaTeX-mode-menu-map-process (make-sparse-keymap "Process"))
yuuji@64 25 (define-key YaTeX-mode-map [menu-bar yatex]
yuuji@64 26 (cons "YaTeX" YaTeX-mode-menu-map))
yuuji@64 27 (YaTeX-define-menu
yuuji@64 28 'YaTeX-mode-menu-map-process
yuuji@64 29 (nreverse
yuuji@64 30 '((buffer "LaTeX" . (lambda () (interactive) (YaTeX-typeset-menu nil ?j)))
yuuji@64 31 (kill "Kill LaTeX" . (lambda () (interactive) (YaTeX-typeset-menu nil ?k)))
yuuji@64 32 (bibtex "BibTeX" . (lambda () (interactive) (YaTeX-typeset-menu nil ?b)))
yuuji@64 33 (mindex "makeindex" . (lambda () (interactive) (YaTeX-typeset-menu nil ?i)))
yuuji@64 34 (preview "Preview" . (lambda () (interactive) (YaTeX-typeset-menu nil ?p)))
yuuji@64 35 (lpr "lpr" . (lambda () (interactive) (YaTeX-typeset-menu nil ?l)))
yuuji@64 36 (lpq "lpq" . (lambda () (interactive) (YaTeX-typeset-menu nil ?q))))))
yuuji@64 37 (defvar YaTeX-mode-menu-map-modes (make-sparse-keymap "Modes"))
yuuji@64 38 (YaTeX-define-menu
yuuji@64 39 'YaTeX-mode-menu-map-modes
yuuji@64 40 (delq nil
yuuji@64 41 (nreverse
yuuji@64 42 (list
yuuji@64 43 (if YaTeX-auto-math-mode nil
yuuji@64 44 (cons 'math (cons "Toggle math-mode"
yuuji@64 45 '(lambda () (interactive)
yuuji@64 46 (YaTeX-switch-mode-menu nil ?t)))))
yuuji@64 47 (cons 'mod (cons "Toggle Modify Mode"
yuuji@64 48 '(lambda () (interactive)
yuuji@64 49 (YaTeX-switch-mode-menu nil ?m))))))))
yuuji@64 50 (defvar YaTeX-mode-menu-map-percent (make-sparse-keymap "percent"))
yuuji@64 51 (YaTeX-define-menu
yuuji@64 52 'YaTeX-mode-menu-map-percent
yuuji@64 53 (nreverse
yuuji@64 54 '((! "Change LaTeX typesetter(%#!)"
yuuji@64 55 . (lambda () (interactive) (YaTeX-%-menu nil nil ?!)))
yuuji@64 56 (begend "Set %#BEGIN-%#END on region"
yuuji@64 57 . (lambda () (interactive) (YaTeX-%-menu nil nil ?b)))
yuuji@64 58 (lpr "Change LPR format"
yuuji@64 59 . (lambda () (interactive) (YaTeX-%-menu nil nil ?l))))))
yuuji@46 60
yuuji@64 61 (defvar YaTeX-mode-menu-map-jump (make-sparse-keymap "jump"))
yuuji@64 62 (YaTeX-define-menu
yuuji@64 63 'YaTeX-mode-menu-map-jump
yuuji@64 64 (nreverse
yuuji@64 65 '((corres "Goto corersponding position" . YaTeX-goto-corresponding-*)
yuuji@64 66 (main "Visit main source"
yuuji@64 67 . (lambda () (interactive) (YaTeX-visit-main)))
yuuji@64 68 (main-other "Visit main source other window"
yuuji@64 69 . YaTeX-visit-main-other-window))))
yuuji@46 70
yuuji@64 71 (defvar YaTeX-mode-menu-map-comment (make-sparse-keymap "comment"))
yuuji@64 72 (YaTeX-define-menu
yuuji@64 73 'YaTeX-mode-menu-map-comment
yuuji@64 74 (nreverse
yuuji@64 75 '((comment "Comment region or environment" . YaTeX-comment-region)
yuuji@64 76 (uncomment "Unomment region or environment" . YaTeX-uncomment-region)
yuuji@64 77 (commentp "Comment paragraph" . YaTeX-comment-paragraph)
yuuji@64 78 (uncommentp "Uncomment paragraph" . YaTeX-uncomment-paragraph))))
yuuji@46 79
yuuji@64 80 (YaTeX-define-menu
yuuji@64 81 'YaTeX-mode-menu-map
yuuji@64 82 (nreverse
yuuji@64 83 (list
yuuji@64 84 ;; Change/Kill/Fill -------------------------------------------------------
yuuji@64 85 (cons (list 'chg "Change") (cons "Change macros" 'YaTeX-change-*))
yuuji@64 86 (cons (list 'kill "Kill") (cons "Kill macros" 'YaTeX-kill-*))
yuuji@64 87 (cons (list 'fill "Fill") (cons "Fill \\item" 'YaTeX-fill-item))
yuuji@64 88 (cons (list 'nl "Newline") (cons "Newline" 'YaTeX-intelligent-newline))
yuuji@64 89 ;; ========================================================================
yuuji@64 90 (cons (list 'sep1 "---") (cons "---" nil))
yuuji@64 91 ;; Comment/Uncomment ------------------------------------------------------
yuuji@64 92 (cons (list 'comment "comment") (cons "Comment region or environment"
yuuji@64 93 'YaTeX-comment-region))
yuuji@64 94 (cons (list 'uncomment "uncomment") (cons "Uncomment region or environment"
yuuji@64 95 'YaTeX-uncomment-region))
yuuji@64 96 (cons (list 'commentp "commentp") (cons "Comment paragraph"
yuuji@64 97 'YaTeX-comment-paragraph))
yuuji@64 98 (cons (list 'uncommentp "uncommentp") (cons "Uncomment paragraph"
yuuji@64 99 'YaTeX-uncomment-paragraph))
yuuji@64 100 ;; ========================================================================
yuuji@64 101 (cons (list 'sep2 "---") (cons "---" nil))
yuuji@64 102 ;; Jump cursor ------------------------------------------------------------
yuuji@64 103 (cons (list 'jump "jump") (cons "Jump Cursor" YaTeX-mode-menu-map-jump))
yuuji@64 104 ;; Document hierarchy ---------------------------------------------------
yuuji@64 105 (cons (list 'hier "hier") (cons "Display Document hierarchy"
yuuji@64 106 'YaTeX-display-hierarchy))
yuuji@64 107 ;; What position ----------------------------------------------------------
yuuji@64 108 (cons (list 'col "column") (cons "What column in tabular"
yuuji@64 109 'YaTeX-what-column))
yuuji@64 110 ;; % menu -----------------------------------------------------------------
yuuji@64 111 (cons (list 'percent "percent") (cons "Edit %# notation"
yuuji@64 112 YaTeX-mode-menu-map-percent))
yuuji@64 113 ;; Switch modes -----------------------------------------------------------
yuuji@64 114 (cons (list 'mode "mode") (cons "Switching YaTeX's modes"
yuuji@64 115 YaTeX-mode-menu-map-modes))
yuuji@64 116 ;; ========================================================================
yuuji@64 117 (cons (list 'sep "---") (cons "---" nil))
yuuji@64 118 ;; Help for LaTeX ---------------------------------------------------------
yuuji@64 119 (cons (list 'ap "apr") (cons "Apropos on LaTeX commands" 'YaTeX-apropos))
yuuji@64 120 (cons (list 'help "help") (cons "Help on LaTeX commands" 'YaTeX-help))
yuuji@64 121 ;; Menu for Typeset relating processes ------------------------------------
yuuji@64 122 (cons (list 'process "Process menu")
yuuji@64 123 (cons "Process" YaTeX-mode-menu-map-process)))
yuuji@64 124 ))
yuuji@46 125
yuuji@64 126 ;; Make section-type commands menu -------------------------------------------
yuuji@64 127 (defvar YaTeX-mode-menu-map-sectionr
yuuji@64 128 (make-sparse-keymap "Enclose region with section-type macro"))
yuuji@64 129 (defvar YaTeX-mode-menu-map-section (make-sparse-keymap "Section-type macro"))
yuuji@46 130 (let ((sorted-section
yuuji@46 131 (sort
yuuji@46 132 (delq nil
yuuji@46 133 (mapcar (function (lambda (s)
yuuji@46 134 (if (> (length (car s)) 5)
yuuji@46 135 (car s))))
yuuji@46 136 (append section-table user-section-table)))
yuuji@46 137 'string<)))
yuuji@64 138 (YaTeX-define-menu
yuuji@64 139 'YaTeX-mode-menu-map-section
yuuji@64 140 (mapcar
yuuji@64 141 (function (lambda (secname)
yuuji@64 142 (cons (intern secname)
yuuji@64 143 (cons secname
yuuji@64 144 (list 'lambda ()
yuuji@64 145 (list 'interactive)
yuuji@64 146 (list 'YaTeX-make-section
yuuji@64 147 nil nil nil
yuuji@64 148 secname))))))
yuuji@64 149 sorted-section))
yuuji@64 150 (YaTeX-define-menu
yuuji@64 151 'YaTeX-mode-menu-map-sectionr
yuuji@64 152 (mapcar
yuuji@64 153 (function (lambda (secname)
yuuji@64 154 (cons (intern secname)
yuuji@64 155 (cons secname
yuuji@64 156 (list 'lambda ()
yuuji@64 157 (list 'interactive)
yuuji@64 158 (list 'YaTeX-make-section
yuuji@64 159 nil
yuuji@64 160 (list 'region-beginning)
yuuji@64 161 (list 'region-end)
yuuji@64 162 secname))))))
yuuji@64 163 sorted-section)))
yuuji@46 164
yuuji@64 165 (YaTeX-define-menu
yuuji@64 166 'YaTeX-mode-menu-map
yuuji@64 167 (nreverse
yuuji@64 168 (list
yuuji@64 169 (cons '(sectionr "Section-type (long name)")
yuuji@64 170 (cons "Section type" YaTeX-mode-menu-map-section))
yuuji@64 171 (cons '(section "Section-type region (long name)")
yuuji@64 172 (cons "Section type region (long name)"
yuuji@64 173 YaTeX-mode-menu-map-sectionr)))))
yuuji@64 174
yuuji@64 175 ;; Make large-type commands menu ---------------------------------------------
yuuji@64 176 (defvar YaTeX-mode-menu-map-envr (make-sparse-keymap "Environment region"))
yuuji@64 177 (defvar YaTeX-mode-menu-map-env (make-sparse-keymap "Environment"))
yuuji@64 178
yuuji@64 179 (let ((sorted-env
yuuji@64 180 (sort
yuuji@64 181 (mapcar (function (lambda (s) (car s)))
yuuji@64 182 (append env-table user-env-table))
yuuji@64 183 'string<)))
yuuji@64 184 (YaTeX-define-menu
yuuji@64 185 'YaTeX-mode-menu-map-env
yuuji@64 186 (mapcar
yuuji@64 187 (function (lambda (envname)
yuuji@64 188 (cons (intern envname)
yuuji@64 189 (cons envname
yuuji@64 190 (list 'lambda ()
yuuji@64 191 (list 'interactive)
yuuji@64 192 (list 'YaTeX-insert-begin-end
yuuji@64 193 envname nil))))))
yuuji@64 194 sorted-env))
yuuji@64 195 (YaTeX-define-menu
yuuji@64 196 'YaTeX-mode-menu-map-envr
yuuji@64 197 (mapcar
yuuji@64 198 (function (lambda (envname)
yuuji@64 199 (cons (intern envname)
yuuji@64 200 (cons envname
yuuji@64 201 (list 'lambda ()
yuuji@64 202 (list 'interactive)
yuuji@64 203 (list 'YaTeX-insert-begin-end
yuuji@64 204 envname t))))))
yuuji@64 205 sorted-env)))
yuuji@64 206 (YaTeX-define-menu
yuuji@64 207 'YaTeX-mode-menu-map
yuuji@64 208 (nreverse
yuuji@64 209 (list
yuuji@64 210 (cons '(envr "Environment")
yuuji@64 211 (cons "Environment" YaTeX-mode-menu-map-env))
yuuji@64 212 (cons '(env "Environment region")
yuuji@64 213 (cons "Environment region"
yuuji@64 214 YaTeX-mode-menu-map-envr)))))
yuuji@64 215
yuuji@64 216 (and (featurep 'xemacs)
yuuji@64 217 (add-hook 'yatex-mode-hook
yuuji@64 218 '(lambda ()
yuuji@64 219 (or (assoc "YaTeX" current-menubar)
yuuji@64 220 (progn
yuuji@64 221 (set-buffer-menubar (copy-sequence current-menubar))
yuuji@64 222 (add-submenu nil YaTeX-mode-menu-map))))))
yuuji@46 223
yuuji@53 224 ;; Other key bindings for window-system
yuuji@53 225 ;(YaTeX-define-key [?\C- ] 'YaTeX-do-completion)
yuuji@53 226 (define-key YaTeX-mode-map [?\M-\C- ] 'YaTeX-mark-environment)
yuuji@53 227
yuuji@46 228 ;; Highlightening
yuuji@53 229 ;; メニューに比べてこっちは結構本気でやってます。
yuuji@53 230 ;; だって文書構造がとっても分かり易いんだもん。
yuuji@53 231 ;; みんなも hilit19.el を使おう!
yuuji@72 232 ;; とかいってるうちに hilit19 って obsolete になってしまった…
yuuji@72 233 ;; …ということで、hilit19 用のパターンを font-lock に変換する関数を
yuuji@72 234 ;; 作成してなんとか font-lock にも対応(2000年12月)。
yuuji@72 235 ;; しかし、font-lock は仕様が変わりやすい雰囲気でずっと動き続けるか
yuuji@72 236 ;; どうかは不明。むしろ進化の止まったhilit19を使い続ける方が安心と
yuuji@72 237 ;; 言えないこともないが世の流れは読めず……。
yuuji@53 238 ;;
yuuji@53 239 ;; さて、まずは対応する {} をピカピカ範囲とするような関数を作る。
yuuji@53 240 ;; これは hilit-LaTeX.el を参考にした。でも、ちゃんと section 型コマンドの
yuuji@53 241 ;; 引数を数えて正しい位置までピカピカさせるよ〜ん!
yuuji@53 242
yuuji@53 243 (defun YaTeX-19-region-section-type (pattern)
yuuji@53 244 "Return list of starting and end point of section-type commands of PATTERN."
yuuji@53 245 (if (re-search-forward pattern nil t)
yuuji@69 246 (let ((m0 (match-beginning 0)) (e0 (match-end 0)) cmd (argc 1))
yuuji@64 247 (setq cmd (substring (YaTeX-match-string 0) 1)
yuuji@53 248 argc (or (car (cdr (YaTeX-lookup-table cmd 'section))) argc))
yuuji@69 249 (if (= argc 0) (cons m0 (point)) ;引数個数0ならマッチした領域
yuuji@69 250 (skip-chars-forward " \n\t*")
yuuji@69 251 (while (looking-at "\\[") (forward-list 1)) ;optionならスキップ
yuuji@69 252 (skip-chars-forward " \n\t")
yuuji@72 253 (prog1
yuuji@72 254 (if (looking-at "{") ;{}が始まるならちゃんとしたsection型
yuuji@72 255 (cons m0
yuuji@72 256 (condition-case err
yuuji@72 257 (progn
yuuji@72 258 ;;(skip-chars-backward "^{") (forward-char -2)
yuuji@72 259 (while (> argc 0)
yuuji@72 260 (skip-chars-forward "^{")
yuuji@72 261 (forward-list 1)
yuuji@72 262 (setq argc (1- argc)))
yuuji@72 263 (point))
yuuji@72 264 (error m0)))
yuuji@72 265 ;{}でないならたぶん \verb 環境などにあるダミー
yuuji@72 266 (cons m0 e0))
yuuji@72 267 ;;move to re-search end not to make font-lock confused
yuuji@72 268 (goto-char e0))))))
yuuji@53 269
yuuji@53 270 (defun YaTeX-19-region-large-type (pattern)
yuuji@53 271 "Return list of large-type contents.
yuuji@53 272 Assumes PATTERN begins with `{'."
yuuji@53 273 (if (re-search-forward pattern nil t)
yuuji@72 274 (let ((m0 (match-beginning 0)) (e0 (match-end 0))p)
yuuji@53 275 (goto-char m0)
yuuji@53 276 (skip-chars-forward "^ \t\n")
yuuji@53 277 (skip-chars-forward " \t\n")
yuuji@72 278 (prog1
yuuji@72 279 (cons (setq p (point))
yuuji@72 280 (condition-case err
yuuji@72 281 (progn (goto-char m0) (forward-list 1) (1- (point)))
yuuji@72 282 (error (1+ p))))
yuuji@72 283 ;;move to re-search end not to make font-lock confused
yuuji@72 284 (goto-char e0)))))
yuuji@53 285
yuuji@53 286 ;; 些細なことだが % の前の文字もピカリとさせてしまうようで… >hilit19
yuuji@53 287 ;; ↓この関数は下の hilit-set-mode-patterns の "[^\\]\\(%\\).*$" に
yuuji@53 288 ;; 依存している
yuuji@53 289 (defun YaTeX-19-region-comment (pattern)
yuuji@53 290 "Return list of comment start and end point."
yuuji@53 291 (if (re-search-forward pattern nil t)
yuuji@56 292 (cons (match-beginning 2) (match-end 0))))
yuuji@56 293
yuuji@56 294 ;;(make-face 'tt)
yuuji@56 295 ;;(set-face-font 'tt "-schumacher-clean-medium-r-normal--*-*-*-*-*-*-*-*")
yuuji@56 296 ;;(hilit-translate 'tt "white")
yuuji@53 297
yuuji@53 298 (defvar YaTeX-hilit-patterns-alist
yuuji@53 299 '(
yuuji@53 300 ;; comments
yuuji@56 301 (YaTeX-19-region-comment "\\([^\\]\\|^\\)\\(%\\).*$" comment)
yuuji@58 302
yuuji@64 303 (YaTeX-19-region-section-type "\\\\footnote\\(mark\\|text\\)?\\>" keyword)
yuuji@53 304 ("\\\\[a-z]+box" 0 keyword)
yuuji@64 305 (YaTeX-19-region-section-type "\\\\\\(v\\|h\\)space\\>" keyword)
yuuji@58 306
yuuji@53 307 ;; (re-)define new commands/environments/counters
yuuji@53 308 (YaTeX-19-region-section-type
yuuji@64 309 "\\\\\\(re\\)?new\\(environment\\|command\\|theorem\\|length\\|counter\\)\\>"
yuuji@60 310 defun)
yuuji@53 311 (YaTeX-19-region-section-type
yuuji@64 312 "\\\\textbf\\>" bold)
yuuji@53 313
yuuji@53 314 ;; various declarations/definitions
yuuji@53 315 (YaTeX-19-region-section-type
yuuji@64 316 "\\\\\\(set\\|setto\\|addto\\)\\(length\\|width\\|counter\\)\\>"
yuuji@53 317 define)
yuuji@53 318 (YaTeX-19-region-section-type
yuuji@64 319 "\\\\\\(title\\|author\\|date\\|thanks\\)\\>" define)
yuuji@53 320
yuuji@59 321 ("\\\\document\\(style\\|class\\)\\(\\[.*\\]\\)?{" "}" decl)
yuuji@53 322 ("\\\\\\(begin\\|end\\|nofiles\\|includeonly\\){" "}" decl)
yuuji@53 323 ("\\\\\\(raggedright\\|makeindex\\|makeglossary\\|maketitle\\)\\b" 0 decl)
yuuji@53 324 ("\\\\\\(pagestyle\\|thispagestyle\\|pagenumbering\\){" "}" decl)
yuuji@53 325 ("\\\\\\(normalsize\\|small\\|footnotesize\\|scriptsize\\|tiny\\|large\\|Large\\|LARGE\\|huge\\|Huge\\)\\b" 0 decl)
yuuji@53 326 ("\\\\\\(appendix\\|tableofcontents\\|listoffigures\\|listoftables\\)\\b"
yuuji@53 327 0 decl)
yuuji@53 328 ("\\\\\\(bf\\|em\\|it\\|rm\\|sf\\|sl\\|ss\\|tt\\)\\b" 0 decl)
yuuji@53 329
yuuji@53 330 ;; label-like things
yuuji@53 331 ;;this should be customized by YaTeX-item-regexp
yuuji@53 332 ("\\\\\\(sub\\)*item\\b\\(\\[[^]]*\\]\\)?" 0 label)
yuuji@53 333 (YaTeX-19-region-section-type
yuuji@64 334 "\\\\caption\\(\\[[^]]*\\]\\)?\\>" label)
yuuji@53 335
yuuji@61 336 ;; things that do some sort of cross-reference
yuuji@61 337 (YaTeX-19-region-section-type
yuuji@64 338 "\\\\\\(\\(no\\)?cite\\|\\(page\\)?ref\\|label\\|index\\|glossary\\)\\>"
yuuji@61 339 crossref)
yuuji@61 340
yuuji@61 341 ;; things that bring in external files
yuuji@61 342 ("\\\\\\(include\\|input\\|bibliography\\){" "}" include)
yuuji@61 343
yuuji@53 344 ;; formulas
yuuji@53 345 ("[^\\]\\\\(" "\\\\)" formula) ; \( \)
yuuji@53 346 ("[^\\]\\\\\\[" "\\\\\\]" formula) ; \[ \]
yuuji@68 347 ("\\\\begin{\\(eqn\\|equation\\|x?x?align\\|split\\|multline\\|gather\\)"
yuuji@68 348 "\\\\end{\\(eqn\\|equation\\|x?x?align\\|split\\|multline\\|gather\\).*}"
yuuji@58 349 formula)
yuuji@72 350 ("\\([^\\$]\\|^\\)\\($\\($[^$]*\\$\\|[^$]*\\)\\$\\)" 2 formula); '$...$' or '$$...$$'
yuuji@53 351
yuuji@61 352 ;; "wysiwyg" emphasis -- these don't work on nested expressions
yuuji@56 353 (YaTeX-19-region-large-type "{\\\\\\(em\\|it\\|sl\\)" italic)
yuuji@53 354 (YaTeX-19-region-large-type "{\\\\bf" bold)
yuuji@56 355 ;;;(YaTeX-19-region-large-type "{\\\\tt" tt)
yuuji@56 356 ;;;("\\\\begin{verbatim" "\\\\end{verbatim" tt)
yuuji@53 357
yuuji@61 358 ("``" "''" string))
yuuji@72 359 "*Hiliting pattern alist for LaTeX text.")
yuuji@53 360
yuuji@53 361 ;;(defvar YaTeX-hilit-pattern-adjustment-default nil)
yuuji@53 362 ;; ↑いらなくなった。
yuuji@51 363 (defvar YaTeX-hilit-pattern-adjustment-private nil
yuuji@53 364 "*Adjustment hilit-pattern-alist for default yatex-mode's pattern.")
yuuji@46 365 (defvar YaTeX-hilit-sectioning-face
yuuji@57 366 '(yellow/dodgerblue yellow/slateblue)
yuuji@51 367 "*Hilightening face for sectioning unit. '(FaceForLight FaceForDark)")
yuuji@57 368 (defvar YaTeX-hilit-sectioning-attenuation-rate
yuuji@57 369 '(15 40)
yuuji@57 370 "*Maximum attenuation rate of sectioning face. '(ForeRate BackRate)
yuuji@57 371 Each rate specifies how much portion of RGB value should be attenuated
yuuji@57 372 towards to lowest sectioning unit. Numbers should be written in percentage.")
yuuji@52 373 (defvar YaTeX-sectioning-patterns-alist nil
yuuji@52 374 "Hilightening patterns for sectioning units.")
yuuji@47 375 (defvar YaTeX-hilit-singlecmd-face
yuuji@72 376 '("slateblue2" . "aquamarine")
yuuji@51 377 "*Hilightening face for maketitle type. '(FaceForLight FaceForDark)")
yuuji@52 378
yuuji@52 379 ;;; セクションコマンドを、構造レベルの高さに応じて色の濃度を変える
yuuji@52 380 ;;; 背景が黒でないと何が嬉しいのか分からないに違いない.
yuuji@53 381 ;;; もしかして白地の時は構造レベルに応じて色を明るくしたほうが良いのか?
yuuji@72 382 ;;; ...どうやらそうでもないらしい。これでいいみたい(2000/12)。
yuuji@60 383 ;(if (fboundp 'win32-color-values)
yuuji@60 384 ; (fset 'x-color-values 'win32-color-values))
yuuji@60 385
yuuji@72 386 (defun YaTeX-19-create-face (sym fgcolor &optional bgcolor)
yuuji@72 387 "Create face named SYM with face of FGCOLOR/BGCOLOR."
yuuji@72 388 (cond
yuuji@72 389 ((and YaTeX-use-font-lock (fboundp 'defface))
yuuji@72 390 (custom-declare-face
yuuji@72 391 sym
yuuji@72 392 (list
yuuji@72 393 (list (list
yuuji@72 394 '(class color)
yuuji@72 395 ;(list 'background YaTeX-background-mode)
yuuji@72 396 )
yuuji@72 397 (delq nil
yuuji@72 398 (append
yuuji@72 399 (list ':foreground fgcolor)
yuuji@72 400 (if bgcolor
yuuji@72 401 (list ':background bgcolor))
yuuji@72 402 ))
yuuji@72 403 )
yuuji@72 404 (list t (list ':bold t ':underline t))
yuuji@72 405 )
yuuji@72 406 (format "Font lock face for %s" sym)
yuuji@72 407 ':group 'font-lock-faces)
yuuji@72 408 (set sym sym)
yuuji@72 409 sym)
yuuji@72 410 ((and YaTeX-use-hilit19 (and (fboundp 'hilit-translate)))
yuuji@72 411 (let ((face (intern (concat fgcolor "/" bgcolor))))
yuuji@72 412 (hilit-translate sym face)
yuuji@72 413 face))))
yuuji@72 414
yuuji@53 415 (cond
yuuji@72 416 (YaTeX-use-highlighting
yuuji@72 417 (cond
yuuji@72 418 (window-system
yuuji@72 419 (let*((sectface
yuuji@72 420 (car (if (eq YaTeX-background-mode 'dark)
yuuji@72 421 (cdr YaTeX-hilit-sectioning-face)
yuuji@72 422 YaTeX-hilit-sectioning-face)))
yuuji@72 423 (sectcol (symbol-name sectface))
yuuji@72 424 (fl YaTeX-use-font-lock)
yuuji@72 425 (form (if fl "#%02x%02x%02x" "hex-%02x%02x%02x"))
yuuji@72 426 sect-pat-alist)
yuuji@72 427 (if (string-match "/" sectcol)
yuuji@72 428 (let ((fmin (nth 0 YaTeX-hilit-sectioning-attenuation-rate))
yuuji@72 429 (bmin (nth 1 YaTeX-hilit-sectioning-attenuation-rate))
yuuji@72 430 colorvalue fR fG fB bR bG bB pat fg bg level from face list lm)
yuuji@72 431 (require 'yatexsec)
yuuji@72 432 (setq fg (substring sectcol 0 (string-match "/" sectcol))
yuuji@72 433 bg (substring sectcol (1+ (string-match "/" sectcol)))
yuuji@72 434 colorvalue (x-color-values fg)
yuuji@72 435 fR (/ (nth 0 colorvalue) 256)
yuuji@72 436 fG (/ (nth 1 colorvalue) 256)
yuuji@72 437 fB (/ (nth 2 colorvalue) 256)
yuuji@72 438 colorvalue (x-color-values bg)
yuuji@72 439 bR (/ (nth 0 colorvalue) 256)
yuuji@72 440 bG (/ (nth 1 colorvalue) 256)
yuuji@72 441 bB (/ (nth 2 colorvalue) 256)
yuuji@72 442 lm YaTeX-sectioning-max-level
yuuji@72 443 list YaTeX-sectioning-level)
yuuji@72 444 (while list
yuuji@72 445 (setq pat (concat YaTeX-ec-regexp (car (car list))
yuuji@72 446 ;;"\\*?\\(\\[[^]]*\\]\\)?\\>" ;改行はさむと駄目
yuuji@72 447 "\\>"
yuuji@72 448 )
yuuji@72 449 level (cdr (car list))
yuuji@72 450 fg (format form
yuuji@72 451 (- fR (/ (* level fR fmin) lm 100))
yuuji@72 452 (- fG (/ (* level fG fmin) lm 100))
yuuji@72 453 (- fB (/ (* level fB fmin) lm 100)))
yuuji@72 454 bg (format form
yuuji@72 455 (- bR (/ (* level bR bmin) lm 100))
yuuji@72 456 (- bG (/ (* level bG bmin) lm 100))
yuuji@72 457 (- bB (/ (* level bB bmin) lm 100)))
yuuji@72 458 from (intern (format "YaTeX-sectioning-%d" level))
yuuji@72 459 ;;face (intern (concat fg "/" bg))
yuuji@72 460 )
yuuji@72 461 (setq face (YaTeX-19-create-face from fg bg))
yuuji@72 462 (setq sect-pat-alist
yuuji@72 463 (cons;;(list pat "}" face)
yuuji@72 464 (list 'YaTeX-19-region-section-type pat face)
yuuji@72 465 sect-pat-alist))
yuuji@72 466 (setq list (cdr list)))
yuuji@72 467 (setq YaTeX-sectioning-patterns-alist sect-pat-alist)))))
yuuji@72 468 (t ;not window-system
yuuji@72 469 (setq YaTeX-sectioning-patterns-alist
yuuji@72 470 (list
yuuji@72 471 (list
yuuji@72 472 (concat YaTeX-ec-regexp
yuuji@72 473 "\\(\\(sub\\)*\\(section\\|paragraph\\)\\|chapter"
yuuji@72 474 "\\|part\\){[^}]*}")
yuuji@72 475 0
yuuji@72 476 'define)))))))
yuuji@52 477
yuuji@53 478 ;; ローカルなマクロを読み込んだ後 redraw すると
yuuji@53 479 ;; ローカルマクロを keyword として光らせる(keywordじゃまずいかな…)。
yuuji@72 480 (defvar hilit-patterns-alist nil) ;for absence of hilit19
yuuji@72 481
yuuji@53 482 (defun YaTeX-19-collect-macros ()
yuuji@46 483 (cond
yuuji@72 484 (YaTeX-use-highlighting
yuuji@47 485 (let ((get-face
yuuji@47 486 (function
yuuji@47 487 (lambda (table)
yuuji@47 488 (cond
yuuji@72 489 ((eq YaTeX-background-mode 'light) (car table))
yuuji@72 490 ((eq YaTeX-background-mode 'dark) (cdr table))
yuuji@57 491 (t nil)))))
yuuji@57 492 sect single)
yuuji@72 493 (YaTeX-19-create-face ;;hilit-translate
yuuji@52 494 ;;sectioning (funcall get-face YaTeX-hilit-sectioning-face)
yuuji@72 495 'macro (funcall get-face YaTeX-hilit-singlecmd-face))
yuuji@57 496 (if (setq sect (append user-section-table tmp-section-table))
yuuji@57 497 (setq sect (concat "\\\\\\("
yuuji@57 498 (mapconcat
yuuji@57 499 (function
yuuji@57 500 (lambda (s) (regexp-quote (car s))))
yuuji@57 501 sect
yuuji@57 502 "\\|")
yuuji@64 503 "\\)\\>")))
yuuji@57 504 (if (setq single (append user-singlecmd-table tmp-singlecmd-table))
yuuji@57 505 (setq single (concat "\\\\\\("
yuuji@57 506 (mapconcat
yuuji@57 507 (function (lambda (s) (regexp-quote (car s))))
yuuji@57 508 single
yuuji@57 509 "\\|")
yuuji@57 510 "\\)\\b")))
yuuji@57 511 (setq hilit-patterns-alist ;Remove at first.
yuuji@57 512 (delq (assq 'yatex-mode hilit-patterns-alist) hilit-patterns-alist)
yuuji@57 513 hilit-patterns-alist
yuuji@57 514 (cons
yuuji@57 515 (cons 'yatex-mode
yuuji@57 516 (append
yuuji@57 517 (list nil)
yuuji@57 518 YaTeX-sectioning-patterns-alist
yuuji@57 519 YaTeX-hilit-pattern-adjustment-private
yuuji@57 520 ;;YaTeX-hilit-pattern-adjustment-default
yuuji@57 521 YaTeX-hilit-patterns-alist
yuuji@57 522 (delq nil
yuuji@57 523 (list
yuuji@57 524 (if sect (list
yuuji@57 525 'YaTeX-19-region-section-type
yuuji@57 526 sect
yuuji@57 527 'keyword))
yuuji@57 528 (if single (list single 0 'macro))))))
yuuji@57 529 hilit-patterns-alist))))))
yuuji@53 530 ;;(YaTeX-19-collect-macros) ;causes an error
yuuji@46 531 (defun YaTeX-hilit-recenter (arg)
yuuji@46 532 "Collect current local macro and hilit-recenter."
yuuji@46 533 (interactive "P")
yuuji@53 534 (YaTeX-19-collect-macros)
yuuji@46 535 (hilit-recenter arg))
yuuji@72 536 (defvar YaTeX-19-recenter-function
yuuji@72 537 (cond
yuuji@72 538 (YaTeX-use-hilit19 (cons 'YaTeX-hilit-recenter 'hilit-recenter))
yuuji@72 539 (YaTeX-use-font-lock (cons 'YaTeX-font-lock-recenter 'recenter))
yuuji@72 540 (t nil)))
yuuji@72 541
yuuji@72 542 (if YaTeX-19-recenter-function
yuuji@72 543 (let ((k (where-is-internal (cdr YaTeX-19-recenter-function))))
yuuji@72 544 (while k
yuuji@72 545 (define-key YaTeX-mode-map (car k) (car YaTeX-19-recenter-function))
yuuji@72 546 (setq k (cdr k)))))
yuuji@72 547
yuuji@72 548 (defun YaTeX-font-lock-recenter (&optional arg)
yuuji@72 549 (interactive "P")
yuuji@72 550 (setq YaTeX-font-lock-keywords
yuuji@72 551 (YaTeX-convert-pattern-hilit2fontlock
yuuji@72 552 (cdr (assq 'yatex-mode (YaTeX-19-collect-macros))))
yuuji@72 553 font-lock-keywords nil)
yuuji@72 554 ;(save-excursion
yuuji@72 555 ; (font-lock-fontify-region (window-start) (window-end)))
yuuji@72 556 (font-lock-mode -1) ;is stupid, but sure.
yuuji@72 557 (font-lock-mode 1))
yuuji@72 558
yuuji@72 559 (defvar YaTeX-font-lock-keywords nil
yuuji@72 560 "Pattern-face alist of yahtml-mode for font-lock")
yuuji@72 561
yuuji@72 562 (defun YaTeX-font-lock-set-default-keywords ()
yuuji@72 563 (put 'yatex-mode 'font-lock-defaults
yuuji@72 564 (list 'YaTeX-font-lock-keywords nil nil))
yuuji@72 565 (setq YaTeX-font-lock-keywords
yuuji@72 566 (YaTeX-convert-pattern-hilit2fontlock
yuuji@72 567 (cons nil
yuuji@72 568 (append YaTeX-sectioning-patterns-alist
yuuji@72 569 YaTeX-hilit-pattern-adjustment-private
yuuji@72 570 YaTeX-hilit-patterns-alist)))))
yuuji@72 571
yuuji@72 572 (if YaTeX-use-font-lock
yuuji@72 573 (progn
yuuji@72 574 (if (and (boundp 'hilit-mode-enable-list) hilit-mode-enable-list)
yuuji@72 575 ;;for those who use both hilit19 and font-lock
yuuji@72 576 (if (eq (car hilit-mode-enable-list) 'not)
yuuji@72 577 (or (member 'yatex-mode hilit-mode-enable-list)
yuuji@72 578 (nconc hilit-mode-enable-list (list 'yatex-mode)))
yuuji@72 579 (setq hilit-mode-enable-list
yuuji@72 580 (delq 'yatex-mode hilit-mode-enable-list))))
yuuji@72 581 (YaTeX-font-lock-set-default-keywords)))
yuuji@46 582
yuuji@53 583 (defun YaTeX-switch-to-new-window ()
yuuji@53 584 (let ((c 0) (i 1) (free (make-string win:max-configs ? )))
yuuji@53 585 (while (< i win:max-configs)
yuuji@53 586 (or (aref win:configs i) (aset free i (+ i win:base-key)))
yuuji@53 587 (setq i (1+ i)))
yuuji@53 588 (while (not (string-match (char-to-string c) free))
yuuji@53 589 (message "Which window to create? [%s]: " free)
yuuji@53 590 (setq c (read-char)))
yuuji@53 591 (message "Creating window [%c]" c)
yuuji@53 592 (set-buffer (get-buffer-create "*scratch*"))
yuuji@53 593 (win:switch-window (- c win:base-key))))
yuuji@53 594
yuuji@53 595 (defun YaTeX-visit-main-other-frame ()
yuuji@53 596 "Visit main file in other frame.
yuuji@53 597 WARNING, This code is not perfect."
yuuji@53 598 (interactive)
yuuji@53 599 (if (YaTeX-main-file-p) (message "I think this is main LaTeX source.")
yuuji@53 600 (let (parent)
yuuji@53 601 (save-excursion (YaTeX-visit-main t) (setq parent (current-buffer)))
yuuji@53 602 (cond
yuuji@53 603 ((get-buffer-window parent t)
yuuji@53 604 (goto-buffer-window parent))
yuuji@53 605 ((and (featurep 'windows) win:use-frame)
yuuji@53 606 (YaTeX-switch-to-new-window)
yuuji@53 607 (switch-to-buffer parent))
yuuji@53 608 (t (switch-to-buffer-other-frame (buffer-name parent)))))))
yuuji@53 609
yuuji@53 610 (defun YaTeX-goto-corresponding-*-other-frame (arg)
yuuji@53 611 "Go to corresponding object in other frame."
yuuji@53 612 (interactive "P")
yuuji@53 613 (let (b p)
yuuji@53 614 (save-window-excursion
yuuji@53 615 (save-excursion
yuuji@53 616 (YaTeX-goto-corresponding-* arg)
yuuji@53 617 (setq b (current-buffer) p (point))))
yuuji@53 618 (cond
yuuji@53 619 ((get-buffer-window b t)
yuuji@53 620 (goto-buffer-window b)
yuuji@53 621 (goto-char p))
yuuji@53 622 ((and (featurep 'windows) win:use-frame)
yuuji@53 623 (YaTeX-switch-to-new-window)
yuuji@53 624 (switch-to-buffer b)
yuuji@53 625 (goto-char p))
yuuji@53 626 (t (switch-to-buffer-other-frame (buffer-name b))
yuuji@72 627 (goto-char p)))))
yuuji@53 628
yuuji@49 629 ;;; reverseVideo にして hilit-background-mode を 'dark
yuuji@49 630 ;;; にしている人は数式などが暗くなりすぎて見づらいかもしれない。
yuuji@49 631 ;;; 次のコードを hilit19 をロードしている場所の直後に置くとちょっ
yuuji@49 632 ;;; とはまし。
yuuji@46 633 ;;; (if (eq hilit-background-mode 'dark)
yuuji@46 634 ;;; (hilit-translate
yuuji@46 635 ;;; string 'mediumspringgreen
yuuji@46 636 ;;; formula 'khaki
yuuji@46 637 ;;; label 'yellow-underlined))
yuuji@57 638 (and YaTeX-emacs-19
yuuji@64 639 (not (featurep 'xemacs))
yuuji@58 640 (boundp 'byte-compile-current-file)
yuuji@72 641 byte-compile-current-file
yuuji@72 642 (progn
yuuji@72 643 (if YaTeX-emacs-20 (require 'font-lock))
yuuji@72 644 (if (and (boundp 'window-system) window-system)
yuuji@72 645 (require 'hilit19)
yuuji@72 646 (error "Byte compile this file on window system! Not `-nw'!"))))
yuuji@46 647
yuuji@46 648 (provide 'yatex19)
yuuji@72 649
yuuji@72 650
yuuji@72 651 ; Local variables:
yuuji@72 652 ; fill-prefix: ";;; "
yuuji@72 653 ; paragraph-start: "^$\\| \\|;;;$"
yuuji@72 654 ; paragraph-separate: "^$\\| \\|;;;$"
yuuji@72 655 ; buffer-file-coding-system: sjis
yuuji@72 656 ; End: