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