yatex

annotate yatex19.el @ 53:5f4b18da14b3

Fix functions relating YaTeX-beginning-of-environment or YaTeX-end-of-environment. Line indentation by TAB much improved. Functions that work at enclosing environments, YaTeX-enclose-<ENVNAME>, introduced. Functions for enclosing verbatim and equations are supplied. SPC, DEL, +, - in YaTeX-hierarchy buffer. Compensate odd highlighting of hilit19.
author yuuji
date Thu, 02 Feb 1995 17:18:29 +0000
parents 5d94deabb9f9
children a9653fbd1c1c
rev   line source
yuuji@46 1 ;;; -*- Emacs-Lisp -*-
yuuji@46 2 ;;; YaTeX facilities for Emacs 19
yuuji@52 3 ;;; (c )1994-1995 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
yuuji@53 4 ;;; Last modified Thu Feb 2 23:44:30 1995 on figaro
yuuji@46 5 ;;; $Id$
yuuji@46 6
yuuji@49 7 ;;; とりあえず hilit19 を使っている時に色が付くようにして
yuuji@49 8 ;;; メニューバーでごにょごにょできるようにしただけ。
yuuji@49 9 ;;; いったい誰がメニューバー使ってLaTeXソース書くんだろうか?
yuuji@49 10 ;;; まあいいや練習練習。後ろの方にちょっとコメントあり。
yuuji@53 11 ;;; 真中辺にあるけど、hilit19.el 対応の方は結構本気。
yuuji@46 12
yuuji@47 13 (require 'yatex)
yuuji@47 14
yuuji@46 15 (defun YaTeX-19-define-sub-menu (map vec &rest bindings)
yuuji@46 16 "Define sub-menu-item in MAP at vector VEC as BINDINGS.
yuuji@46 17 BINDINGS is a form with optional length: (symbol title binding).
yuuji@46 18 When you defined menu-bar keymap such like:
yuuji@46 19 (define-key foo-map [menu-bar foo] (make-sparse-keymap \"foo menu\"))
yuuji@46 20 and you want to define sub menu for `foo menu' as followings.
yuuji@46 21 foo -> menu1 (calling function `func1')
yuuji@46 22 menu2 (doing interactive call `(func2 ...)'
yuuji@46 23 Call this function like this:
yuuji@46 24 (YaTeX-19-define-sub-menu foo-map [menu-bar foo]
yuuji@46 25 '(m1 \"Function 1\" func1)
yuuji@46 26 '(m2 \"Function 2\" (lambda () (interactive) (func2 ...))))
yuuji@46 27 where
yuuji@46 28 `m1' and `m2' are the keymap symbol for sub-menu of `[menu-bar foo].
yuuji@46 29 `Funtion 1' and `Function 2' are the title strings for sub-menu.
yuuji@46 30 "
yuuji@46 31 (let ((i 0) (vec2 (make-vector (1+ (length vec)) nil)))
yuuji@46 32 (while (< i (length vec))
yuuji@46 33 (aset vec2 i (aref vec i))
yuuji@46 34 (setq i (1+ i)))
yuuji@46 35 (setq bindings (reverse bindings))
yuuji@46 36 (mapcar
yuuji@46 37 (function
yuuji@46 38 (lambda (bind)
yuuji@46 39 (aset vec2 (1- (length vec2)) (car bind)) ;set menu-symbol
yuuji@46 40 (define-key map vec2
yuuji@46 41 (cons (car (cdr bind))
yuuji@46 42 (car (cdr (cdr bind)))))))
yuuji@46 43 bindings)))
yuuji@46 44
yuuji@46 45 ;; Menu for Typeset relating processes ----------------------------------------
yuuji@46 46 (define-key YaTeX-mode-map [menu-bar yatex]
yuuji@46 47 (cons "YaTeX" (make-sparse-keymap "YaTeX")))
yuuji@46 48 (define-key YaTeX-mode-map [menu-bar yatex process]
yuuji@46 49 (cons "Process" (make-sparse-keymap "Process")))
yuuji@46 50 (YaTeX-19-define-sub-menu
yuuji@46 51 YaTeX-mode-map [menu-bar yatex process]
yuuji@46 52 '(buffer "LaTeX" (lambda () (interactive) (YaTeX-typeset-menu nil ?j)))
yuuji@46 53 '(kill "Kill LaTeX" (lambda () (interactive) (YaTeX-typeset-menu nil ?k)))
yuuji@46 54 '(bibtex "BibTeX" (lambda () (interactive) (YaTeX-typeset-menu nil ?b)))
yuuji@46 55 '(makeindex "makeindex" (lambda () (interactive) (YaTeX-typeset-menu nil ?i)))
yuuji@46 56 '(preview "Preview" (lambda () (interactive) (YaTeX-typeset-menu nil ?p)))
yuuji@46 57 '(lpr "lpr" (lambda () (interactive) (YaTeX-typeset-menu nil ?l)))
yuuji@46 58 '(lpq "lpq" (lambda () (interactive) (YaTeX-typeset-menu nil ?q)))
yuuji@46 59 )
yuuji@46 60
yuuji@46 61 ;; Help for LaTeX ------------------------------------------------------------
yuuji@46 62 (YaTeX-19-define-sub-menu
yuuji@46 63 YaTeX-mode-map [menu-bar yatex]
yuuji@46 64 '(sephelp "--")
yuuji@46 65 '(help "Help on LaTeX commands" YaTeX-help)
yuuji@46 66 '(apropos "Apropos on LaTeX commands" YaTeX-apropos))
yuuji@46 67
yuuji@46 68 ;; Switch modes --------------------------------------------------------------
yuuji@46 69 (define-key YaTeX-mode-map [menu-bar yatex switch]
yuuji@46 70 (cons "Switching YaTeX's modes" (make-sparse-keymap "modes")))
yuuji@46 71 (or YaTeX-auto-math-mode
yuuji@46 72 (define-key YaTeX-mode-map [menu-bar yatex switch math]
yuuji@46 73 '("Toggle math mode" . (lambda () (interactive)
yuuji@46 74 (YaTeX-switch-mode-menu nil ?t)))))
yuuji@46 75 (define-key YaTeX-mode-map [menu-bar yatex switch mod]
yuuji@46 76 '("Toggle modify mode" . (lambda () (interactive)
yuuji@46 77 (YaTeX-switch-mode-menu nil ?m))))
yuuji@46 78
yuuji@46 79 ;; % menu --------------------------------------------------------------------
yuuji@46 80 (define-key YaTeX-mode-map [menu-bar yatex percent]
yuuji@46 81 (cons "Edit %# notation" (make-sparse-keymap "Edit %# notation")))
yuuji@46 82 (YaTeX-19-define-sub-menu
yuuji@46 83 YaTeX-mode-map [menu-bar yatex percent]
yuuji@46 84 '(! "Change LaTeX typesetter(%#!)"
yuuji@46 85 (lambda () (interactive) (YaTeX-%-menu nil nil ?!)))
yuuji@46 86 '(begend "Set %#BEGIN-%#END on region"
yuuji@46 87 (lambda () (interactive) (YaTeX-%-menu nil nil ?b)))
yuuji@46 88 '(lpr "Change LPR format"
yuuji@46 89 (lambda () (interactive) (YaTeX-%-menu nil nil ?l))))
yuuji@46 90
yuuji@46 91 ;; What position -------------------------------------------------------------
yuuji@46 92 (YaTeX-19-define-sub-menu
yuuji@46 93 YaTeX-mode-map [menu-bar yatex]
yuuji@46 94 '(what "What column in tabular" YaTeX-what-column))
yuuji@46 95
yuuji@52 96 ;; Document hierarchy ------------------------------------------------------
yuuji@52 97 (YaTeX-19-define-sub-menu
yuuji@52 98 YaTeX-mode-map [menu-bar yatex]
yuuji@52 99 '(hier "Display document hierarchy" YaTeX-display-hierarchy-directly))
yuuji@52 100
yuuji@46 101 ;; Jump cursor ---------------------------------------------------------------
yuuji@46 102 (define-key YaTeX-mode-map [menu-bar yatex jump]
yuuji@46 103 (cons "Jump cursor"
yuuji@46 104 (make-sparse-keymap "Jump cursor")))
yuuji@46 105 (YaTeX-19-define-sub-menu
yuuji@46 106 YaTeX-mode-map [menu-bar yatex jump]
yuuji@46 107 '(corres "Goto corersponding position" YaTeX-goto-corresponding-*)
yuuji@46 108 '(main "Visit main source" (lambda () (interactive) (YaTeX-visit-main)))
yuuji@46 109 '(main-other "Visit main source other window" YaTeX-visit-main-other-window)
yuuji@46 110 )
yuuji@46 111
yuuji@46 112 ;; ===========================================================================
yuuji@46 113 (define-key YaTeX-mode-map [menu-bar yatex sepcom]
yuuji@46 114 '("---" . nil))
yuuji@46 115
yuuji@46 116 ;; Comment/Uncomment ---------------------------------------------------------
yuuji@46 117 (YaTeX-19-define-sub-menu
yuuji@46 118 YaTeX-mode-map [menu-bar yatex]
yuuji@46 119 '(comment "Comment region or environment" YaTeX-comment-region)
yuuji@46 120 '(uncomment "Unomment region or environment" YaTeX-uncomment-region)
yuuji@46 121 '(commentp "Comment paragraph" YaTeX-comment-paragraph)
yuuji@47 122 '(uncommentp "Uncomment paragraph" YaTeX-uncomment-paragraph)
yuuji@46 123 '(sepcom "--" nil)
yuuji@46 124 )
yuuji@46 125
yuuji@46 126
yuuji@46 127 ;; ===========================================================================
yuuji@46 128 ;; Change/Kill/Fill
yuuji@46 129 (YaTeX-19-define-sub-menu
yuuji@46 130 YaTeX-mode-map [menu-bar yatex]
yuuji@46 131 '(change "Change macros" YaTeX-change-*)
yuuji@46 132 '(kill "Kill macros" YaTeX-kill-*)
yuuji@46 133 '(fillitem "Fill \\item" YaTeX-fill-item)
yuuji@46 134 '(newline "Newline" YaTeX-intelligent-newline)
yuuji@46 135 '(sepchg "--" nil)
yuuji@46 136 )
yuuji@46 137
yuuji@46 138 ;; Menu for completions ------------------------------------------------------
yuuji@46 139
yuuji@46 140
yuuji@46 141 ;;;(YaTeX-19-define-sub-menu
yuuji@46 142 ;;; YaTeX-mode-map [menu-bar yatex]
yuuji@46 143 ;;; '(secr "Section-type command on region" YaTeX-make-section-region)
yuuji@46 144 ;;; '(sec "Section-type command" YaTeX-make-section))
yuuji@46 145
yuuji@46 146 (define-key YaTeX-mode-map [menu-bar yatex sectionr]
yuuji@46 147 (cons "Section-type region(long name)"
yuuji@46 148 (make-sparse-keymap "Enclose region with section-type macro")))
yuuji@46 149 (define-key YaTeX-mode-map [menu-bar yatex section]
yuuji@47 150 (cons "Section-type(long name)"
yuuji@46 151 (make-sparse-keymap "Section-type macro")))
yuuji@46 152 (let ((sorted-section
yuuji@46 153 (sort
yuuji@46 154 (delq nil
yuuji@46 155 (mapcar (function (lambda (s)
yuuji@46 156 (if (> (length (car s)) 5)
yuuji@46 157 (car s))))
yuuji@46 158 (append section-table user-section-table)))
yuuji@46 159 'string<)))
yuuji@46 160 (apply 'YaTeX-19-define-sub-menu
yuuji@46 161 YaTeX-mode-map [menu-bar yatex section]
yuuji@46 162 (mapcar (function (lambda (secname)
yuuji@46 163 (list (intern secname) secname
yuuji@46 164 (list 'lambda ()
yuuji@46 165 (list 'interactive)
yuuji@46 166 (list 'YaTeX-make-section
yuuji@46 167 nil nil nil secname)))))
yuuji@46 168 sorted-section))
yuuji@46 169 (apply 'YaTeX-19-define-sub-menu
yuuji@46 170 YaTeX-mode-map [menu-bar yatex sectionr]
yuuji@46 171 (mapcar (function (lambda (secname)
yuuji@46 172 (list (intern secname) secname
yuuji@46 173 (list 'lambda ()
yuuji@46 174 (list 'interactive)
yuuji@46 175 (list 'YaTeX-make-section
yuuji@46 176 nil
yuuji@46 177 (list 'region-beginning)
yuuji@46 178 (list 'region-end)
yuuji@46 179 secname)))))
yuuji@46 180 sorted-section)))
yuuji@46 181
yuuji@46 182 (define-key YaTeX-mode-map [menu-bar yatex envr]
yuuji@46 183 (cons "Environment region" (make-sparse-keymap "Environment region")))
yuuji@46 184 (define-key YaTeX-mode-map [menu-bar yatex env]
yuuji@46 185 (cons "Environment" (make-sparse-keymap "Environment")))
yuuji@46 186 (let (prev envname)
yuuji@46 187 (mapcar
yuuji@46 188 (function
yuuji@46 189 (lambda (envalist)
yuuji@46 190 (setq envname (car envalist))
yuuji@46 191 (define-key-after
yuuji@46 192 (lookup-key YaTeX-mode-map [menu-bar yatex env])
yuuji@46 193 (vector (intern envname))
yuuji@46 194 (cons envname
yuuji@46 195 (list 'lambda () (list 'interactive)
yuuji@46 196 (list 'YaTeX-insert-begin-end
yuuji@46 197 envname nil)))
yuuji@46 198 prev)
yuuji@46 199 (define-key-after
yuuji@46 200 (lookup-key YaTeX-mode-map [menu-bar yatex envr])
yuuji@46 201 (vector (intern envname))
yuuji@46 202 (cons envname
yuuji@46 203 (list 'lambda () (list 'interactive)
yuuji@46 204 (list 'YaTeX-insert-begin-end
yuuji@46 205 envname t)))
yuuji@46 206 prev)
yuuji@46 207 (setq prev (intern envname))))
yuuji@46 208 (sort (append env-table user-env-table)
yuuji@46 209 '(lambda (x y) (string< (car x) (car y))))))
yuuji@46 210
yuuji@53 211 ;; Other key bindings for window-system
yuuji@53 212 ;(YaTeX-define-key [?\C- ] 'YaTeX-do-completion)
yuuji@53 213 (define-key YaTeX-mode-map [?\M-\C- ] 'YaTeX-mark-environment)
yuuji@53 214
yuuji@46 215 ;; Highlightening
yuuji@53 216 ;; メニューに比べてこっちは結構本気でやってます。
yuuji@53 217 ;; だって文書構造がとっても分かり易いんだもん。
yuuji@53 218 ;; みんなも hilit19.el を使おう!
yuuji@53 219 ;;
yuuji@53 220 ;; さて、まずは対応する {} をピカピカ範囲とするような関数を作る。
yuuji@53 221 ;; これは hilit-LaTeX.el を参考にした。でも、ちゃんと section 型コマンドの
yuuji@53 222 ;; 引数を数えて正しい位置までピカピカさせるよ〜ん!
yuuji@53 223
yuuji@53 224 (defun YaTeX-19-region-section-type (pattern)
yuuji@53 225 "Return list of starting and end point of section-type commands of PATTERN."
yuuji@53 226 (if (re-search-forward pattern nil t)
yuuji@53 227 (let ((m0 (match-beginning 0)) cmd (argc 1))
yuuji@53 228 (setq cmd (substring (YaTeX-match-string 0) 1 -1)
yuuji@53 229 argc (or (car (cdr (YaTeX-lookup-table cmd 'section))) argc))
yuuji@53 230 (cons m0
yuuji@53 231 (progn (skip-chars-backward "^{") (forward-char -2)
yuuji@53 232 (while (> argc 0)
yuuji@53 233 (skip-chars-forward "^{")
yuuji@53 234 (forward-list 1)
yuuji@53 235 (setq argc (1- argc)))
yuuji@53 236 (point))))))
yuuji@53 237
yuuji@53 238 (defun YaTeX-19-region-large-type (pattern)
yuuji@53 239 "Return list of large-type contents.
yuuji@53 240 Assumes PATTERN begins with `{'."
yuuji@53 241 (if (re-search-forward pattern nil t)
yuuji@53 242 (let ((m0 (match-beginning 0)))
yuuji@53 243 (goto-char m0)
yuuji@53 244 (skip-chars-forward "^ \t\n")
yuuji@53 245 (skip-chars-forward " \t\n")
yuuji@53 246 (cons (point)
yuuji@53 247 (progn (goto-char m0) (forward-list 1)
yuuji@53 248 (1- (point)))))))
yuuji@53 249
yuuji@53 250 ;; 些細なことだが % の前の文字もピカリとさせてしまうようで… >hilit19
yuuji@53 251 ;; ↓この関数は下の hilit-set-mode-patterns の "[^\\]\\(%\\).*$" に
yuuji@53 252 ;; 依存している
yuuji@53 253 (defun YaTeX-19-region-comment (pattern)
yuuji@53 254 "Return list of comment start and end point."
yuuji@53 255 (if (re-search-forward pattern nil t)
yuuji@53 256 (cons (match-beginning 1) (match-end 0))))
yuuji@53 257
yuuji@53 258 (defvar YaTeX-hilit-patterns-alist
yuuji@53 259 '(
yuuji@53 260 ;; comments
yuuji@53 261 (YaTeX-19-region-comment "[^\\]\\(%\\).*$" comment)
yuuji@53 262
yuuji@53 263 (YaTeX-19-region-section-type "\\\\footnote\\(mark\\|text\\)?{" keyword)
yuuji@53 264 ("\\\\[a-z]+box" 0 keyword)
yuuji@53 265 (YaTeX-19-region-section-type "\\\\\\(v\\|h\\)space\\(\*\\)?{" keyword)
yuuji@53 266
yuuji@53 267 ;; (re-)define new commands/environments/counters
yuuji@53 268 (YaTeX-19-region-section-type
yuuji@53 269 "\\\\\\(re\\)?new\\(environment\\|command\\|theorem\\){" defun)
yuuji@53 270 (YaTeX-19-region-section-type
yuuji@53 271 "\\\\\\(re\\)?new\\(length\\|counter\\){" define)
yuuji@53 272
yuuji@53 273 ;; various declarations/definitions
yuuji@53 274 (YaTeX-19-region-section-type
yuuji@53 275 "\\\\\\(set\\|setto\\|addto\\)\\(length\\|width\\|counter\\){"
yuuji@53 276 define)
yuuji@53 277 (YaTeX-19-region-section-type
yuuji@53 278 "\\\\\\(title\\|author\\|date\\|thanks\\){" define)
yuuji@53 279
yuuji@53 280 ("\\\\documentstyle\\(\\[.*\\]\\)?{" "}" decl)
yuuji@53 281 ("\\\\\\(begin\\|end\\|nofiles\\|includeonly\\){" "}" decl)
yuuji@53 282 ("\\\\\\(raggedright\\|makeindex\\|makeglossary\\|maketitle\\)\\b" 0 decl)
yuuji@53 283 ("\\\\\\(pagestyle\\|thispagestyle\\|pagenumbering\\){" "}" decl)
yuuji@53 284 ("\\\\\\(normalsize\\|small\\|footnotesize\\|scriptsize\\|tiny\\|large\\|Large\\|LARGE\\|huge\\|Huge\\)\\b" 0 decl)
yuuji@53 285 ("\\\\\\(appendix\\|tableofcontents\\|listoffigures\\|listoftables\\)\\b"
yuuji@53 286 0 decl)
yuuji@53 287 ("\\\\\\(bf\\|em\\|it\\|rm\\|sf\\|sl\\|ss\\|tt\\)\\b" 0 decl)
yuuji@53 288
yuuji@53 289 ;; label-like things
yuuji@53 290 ;;this should be customized by YaTeX-item-regexp
yuuji@53 291 ("\\\\\\(sub\\)*item\\b\\(\\[[^]]*\\]\\)?" 0 label)
yuuji@53 292 (YaTeX-19-region-section-type
yuuji@53 293 "\\\\caption\\(\\[[^]]*\\]\\)?{" label)
yuuji@53 294
yuuji@53 295 ;; formulas
yuuji@53 296 ("[^\\]\\\\(" "\\\\)" formula) ; \( \)
yuuji@53 297 ("[^\\]\\\\\\[" "\\\\\\]" formula) ; \[ \]
yuuji@53 298 ("\\\\begin{\\(eqn\\|equation\\)" "\\\\end{\\(eqn\\|equation\\)" formula)
yuuji@53 299 ("[^\\$]\\($\\($[^$]*\\$\\|[^$]*\\)\\$\\)" 1 formula) ; '$...$' or '$$...$$'
yuuji@53 300
yuuji@53 301 ;; things that bring in external files
yuuji@53 302 ("\\\\\\(include\\|input\\|bibliography\\){" "}" include)
yuuji@53 303
yuuji@53 304 ;; "wysiwyg" emphasis -- these don't work with nested expressions
yuuji@53 305 ;; ("{\\\\\\(em\\|it\\|sl\\)" "}" italic)
yuuji@53 306 (YaTeX-19-region-large-type "{\\\\bf" bold)
yuuji@53 307
yuuji@53 308 ("``" "''" string)
yuuji@53 309
yuuji@53 310 ;; things that do some sort of cross-reference
yuuji@53 311 (YaTeX-19-region-section-type
yuuji@53 312 "\\\\\\(\\(no\\)?cite\\|\\(page\\)?ref\\|label\\|index\\|glossary\\){"
yuuji@53 313 crossref)
yuuji@53 314 )
yuuji@53 315 "*Hiliting pattern alist for LaTeX text.")
yuuji@53 316
yuuji@53 317 ;;(defvar YaTeX-hilit-pattern-adjustment-default nil)
yuuji@53 318 ;; ↑いらなくなった。
yuuji@51 319 (defvar YaTeX-hilit-pattern-adjustment-private nil
yuuji@53 320 "*Adjustment hilit-pattern-alist for default yatex-mode's pattern.")
yuuji@46 321 (defvar YaTeX-hilit-sectioning-face
yuuji@51 322 '(yellow/dodgerblue yellow/cornflowerblue)
yuuji@51 323 "*Hilightening face for sectioning unit. '(FaceForLight FaceForDark)")
yuuji@52 324 (defvar YaTeX-sectioning-patterns-alist nil
yuuji@52 325 "Hilightening patterns for sectioning units.")
yuuji@47 326 (defvar YaTeX-hilit-singlecmd-face
yuuji@51 327 '(slateblue2 aquamarine)
yuuji@51 328 "*Hilightening face for maketitle type. '(FaceForLight FaceForDark)")
yuuji@52 329
yuuji@52 330 ;;; セクションコマンドを、構造レベルの高さに応じて色の濃度を変える
yuuji@52 331 ;;; 背景が黒でないと何が嬉しいのか分からないに違いない.
yuuji@53 332 ;;; もしかして白地の時は構造レベルに応じて色を明るくしたほうが良いのか?
yuuji@53 333 (cond
yuuji@53 334 ((and (featurep 'hilit19) (fboundp 'x-color-values))
yuuji@53 335 (let*((sectface
yuuji@53 336 (car (if (eq hilit-background-mode 'dark)
yuuji@53 337 (cdr YaTeX-hilit-sectioning-face)
yuuji@53 338 YaTeX-hilit-sectioning-face)))
yuuji@53 339 (sectcol (symbol-name sectface))
yuuji@53 340 sect-pat-alist)
yuuji@53 341 (if (string-match "/" sectcol)
yuuji@53 342 (let (colorvalue fR fG fB bR bG bB list pat fg bg level from face)
yuuji@53 343 (require 'yatexsec)
yuuji@53 344 (setq fg (substring sectcol 0 (string-match "/" sectcol))
yuuji@53 345 bg (substring sectcol (1+ (string-match "/" sectcol)))
yuuji@53 346 colorvalue (x-color-values fg)
yuuji@53 347 fR (/ (nth 0 colorvalue) 256)
yuuji@53 348 fG (/ (nth 1 colorvalue) 256)
yuuji@53 349 fB (/ (nth 2 colorvalue) 256)
yuuji@53 350 colorvalue (x-color-values bg)
yuuji@53 351 bR (/ (nth 0 colorvalue) 256)
yuuji@53 352 bG (/ (nth 1 colorvalue) 256)
yuuji@53 353 bB (/ (nth 2 colorvalue) 256)
yuuji@53 354 list YaTeX-sectioning-level)
yuuji@53 355 (while list
yuuji@53 356 (setq pat (concat YaTeX-ec-regexp (car (car list)) "\\*?{")
yuuji@53 357 level (cdr (car list))
yuuji@53 358 fg (format "hex-%02x%02x%02x"
yuuji@53 359 (- fR (/ (* level fR) 40)) ;40 musn't be constant
yuuji@53 360 (- fG (/ (* level fG) 40))
yuuji@53 361 (- fB (/ (* level fB) 40)))
yuuji@53 362 bg (format "hex-%02x%02x%02x"
yuuji@53 363 (- bR (/ (* level bR) 15)) ;20 musn't be constant
yuuji@53 364 (- bG (/ (* level bG) 15))
yuuji@53 365 (- bB (/ (* level bB) 15)))
yuuji@53 366 from (intern (format "sectioning-%d" level))
yuuji@53 367 face (intern (concat fg "/" bg)))
yuuji@53 368 (hilit-translate from face)
yuuji@53 369 (setq sect-pat-alist
yuuji@53 370 (cons;;(list pat "}" face)
yuuji@53 371 (list 'YaTeX-19-region-section-type pat face)
yuuji@53 372 sect-pat-alist))
yuuji@53 373 (setq list (cdr list)))
yuuji@53 374 (setq YaTeX-sectioning-patterns-alist sect-pat-alist))))))
yuuji@52 375
yuuji@53 376 ;; ローカルなマクロを読み込んだ後 redraw すると
yuuji@53 377 ;; ローカルマクロを keyword として光らせる(keywordじゃまずいかな…)。
yuuji@53 378 (defun YaTeX-19-collect-macros ()
yuuji@46 379 (cond
yuuji@46 380 ((and (featurep 'hilit19) (fboundp 'hilit-translate))
yuuji@47 381 (let ((get-face
yuuji@47 382 (function
yuuji@47 383 (lambda (table)
yuuji@47 384 (cond
yuuji@47 385 ((eq hilit-background-mode 'light) (car table))
yuuji@47 386 ((eq hilit-background-mode 'dark) (car (cdr table)))
yuuji@47 387 (t nil))))))
yuuji@47 388 (hilit-translate
yuuji@52 389 ;;sectioning (funcall get-face YaTeX-hilit-sectioning-face)
yuuji@47 390 macro (funcall get-face YaTeX-hilit-singlecmd-face)))
yuuji@47 391 (setq hilit-patterns-alist ;Remove at first.
yuuji@46 392 (delq 'yatex-mode hilit-patterns-alist)
yuuji@46 393 hilit-patterns-alist
yuuji@46 394 (cons
yuuji@46 395 (cons 'yatex-mode
yuuji@46 396 (append
yuuji@52 397 YaTeX-sectioning-patterns-alist
yuuji@51 398 YaTeX-hilit-pattern-adjustment-private
yuuji@53 399 ;;YaTeX-hilit-pattern-adjustment-default
yuuji@51 400 YaTeX-hilit-patterns-alist
yuuji@46 401 (list
yuuji@46 402 (list
yuuji@53 403 'YaTeX-19-region-section-type
yuuji@46 404 (concat "\\\\\\("
yuuji@46 405 (mapconcat
yuuji@46 406 (function (lambda (s) (regexp-quote (car s))))
yuuji@46 407 (append user-section-table tmp-section-table)
yuuji@46 408 "\\|")
yuuji@46 409 "\\){")
yuuji@53 410 'keyword)
yuuji@47 411 (list
yuuji@47 412 (concat "\\\\\\("
yuuji@47 413 (mapconcat
yuuji@47 414 (function (lambda (s) (regexp-quote (car s))))
yuuji@47 415 (append user-singlecmd-table tmp-singlecmd-table)
yuuji@47 416 "\\|")
yuuji@51 417 "\\)\\b")
yuuji@47 418 0 'macro))))
yuuji@46 419 hilit-patterns-alist)))))
yuuji@53 420 ;;(YaTeX-19-collect-macros) ;causes an error
yuuji@46 421 (defun YaTeX-hilit-recenter (arg)
yuuji@46 422 "Collect current local macro and hilit-recenter."
yuuji@46 423 (interactive "P")
yuuji@53 424 (YaTeX-19-collect-macros)
yuuji@46 425 (hilit-recenter arg))
yuuji@46 426 (if (fboundp 'hilit-recenter) ;Replace hilit-recenter with
yuuji@46 427 (mapcar (function (lambda (key) ;YaTeX-hilit-recenter in yatex-mode
yuuji@46 428 (define-key YaTeX-mode-map key 'YaTeX-hilit-recenter)))
yuuji@46 429 (where-is-internal 'hilit-recenter)))
yuuji@46 430
yuuji@53 431 (defun YaTeX-switch-to-new-window ()
yuuji@53 432 (let ((c 0) (i 1) (free (make-string win:max-configs ? )))
yuuji@53 433 (while (< i win:max-configs)
yuuji@53 434 (or (aref win:configs i) (aset free i (+ i win:base-key)))
yuuji@53 435 (setq i (1+ i)))
yuuji@53 436 (while (not (string-match (char-to-string c) free))
yuuji@53 437 (message "Which window to create? [%s]: " free)
yuuji@53 438 (setq c (read-char)))
yuuji@53 439 (message "Creating window [%c]" c)
yuuji@53 440 (set-buffer (get-buffer-create "*scratch*"))
yuuji@53 441 (win:switch-window (- c win:base-key))))
yuuji@53 442
yuuji@53 443 (defun YaTeX-visit-main-other-frame ()
yuuji@53 444 "Visit main file in other frame.
yuuji@53 445 WARNING, This code is not perfect."
yuuji@53 446 (interactive)
yuuji@53 447 (if (YaTeX-main-file-p) (message "I think this is main LaTeX source.")
yuuji@53 448 (let (parent)
yuuji@53 449 (save-excursion (YaTeX-visit-main t) (setq parent (current-buffer)))
yuuji@53 450 (cond
yuuji@53 451 ((get-buffer-window parent t)
yuuji@53 452 (goto-buffer-window parent))
yuuji@53 453 ((and (featurep 'windows) win:use-frame)
yuuji@53 454 (YaTeX-switch-to-new-window)
yuuji@53 455 (switch-to-buffer parent))
yuuji@53 456 (t (switch-to-buffer-other-frame (buffer-name parent)))))))
yuuji@53 457
yuuji@53 458 (defun YaTeX-goto-corresponding-*-other-frame (arg)
yuuji@53 459 "Go to corresponding object in other frame."
yuuji@53 460 (interactive "P")
yuuji@53 461 (let (b p)
yuuji@53 462 (save-window-excursion
yuuji@53 463 (save-excursion
yuuji@53 464 (YaTeX-goto-corresponding-* arg)
yuuji@53 465 (setq b (current-buffer) p (point))))
yuuji@53 466 (cond
yuuji@53 467 ((get-buffer-window b t)
yuuji@53 468 (goto-buffer-window b)
yuuji@53 469 (goto-char p))
yuuji@53 470 ((and (featurep 'windows) win:use-frame)
yuuji@53 471 (YaTeX-switch-to-new-window)
yuuji@53 472 (switch-to-buffer b)
yuuji@53 473 (goto-char p))
yuuji@53 474 (t (switch-to-buffer-other-frame (buffer-name b))
yuuji@53 475 (goto-char p))))
yuuji@53 476 )
yuuji@53 477
yuuji@49 478 ;;; reverseVideo にして hilit-background-mode を 'dark
yuuji@49 479 ;;; にしている人は数式などが暗くなりすぎて見づらいかもしれない。
yuuji@49 480 ;;; 次のコードを hilit19 をロードしている場所の直後に置くとちょっ
yuuji@49 481 ;;; とはまし。
yuuji@46 482 ;;; (if (eq hilit-background-mode 'dark)
yuuji@46 483 ;;; (hilit-translate
yuuji@46 484 ;;; string 'mediumspringgreen
yuuji@46 485 ;;; formula 'khaki
yuuji@46 486 ;;; label 'yellow-underlined))
yuuji@46 487
yuuji@46 488 (provide 'yatex19)