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