yatex
diff 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 |
line diff
1.1 --- a/yatex19.el Sun Jan 22 14:20:46 1995 +0000 1.2 +++ b/yatex19.el Thu Feb 02 17:18:29 1995 +0000 1.3 @@ -1,13 +1,14 @@ 1.4 ;;; -*- Emacs-Lisp -*- 1.5 ;;; YaTeX facilities for Emacs 19 1.6 ;;; (c )1994-1995 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp] 1.7 -;;; Last modified Sun Jan 22 23:15:56 1995 on landcruiser 1.8 +;;; Last modified Thu Feb 2 23:44:30 1995 on figaro 1.9 ;;; $Id$ 1.10 1.11 ;;; とりあえず hilit19 を使っている時に色が付くようにして 1.12 ;;; メニューバーでごにょごにょできるようにしただけ。 1.13 ;;; いったい誰がメニューバー使ってLaTeXソース書くんだろうか? 1.14 ;;; まあいいや練習練習。後ろの方にちょっとコメントあり。 1.15 +;;; 真中辺にあるけど、hilit19.el 対応の方は結構本気。 1.16 1.17 (require 'yatex) 1.18 1.19 @@ -207,28 +208,116 @@ 1.20 (sort (append env-table user-env-table) 1.21 '(lambda (x y) (string< (car x) (car y)))))) 1.22 1.23 +;; Other key bindings for window-system 1.24 +;(YaTeX-define-key [?\C- ] 'YaTeX-do-completion) 1.25 +(define-key YaTeX-mode-map [?\M-\C- ] 'YaTeX-mark-environment) 1.26 + 1.27 ;; Highlightening 1.28 -;; ローカルなマクロを読み込んだ後 redraw すると 1.29 -;; ローカルマクロを keyword として光らせる(keywordじゃまずいかな…)。 1.30 -(defvar YaTeX-hilit-patterns-alist nil 1.31 - "*Hiliting pattern alist for LaTeX text. 1.32 -Default value is equal to latex-mode's one.") 1.33 -(defvar YaTeX-hilit-pattern-adjustment-default 1.34 - (list 1.35 - ;;\def が define なんだから new* も define でしょう。 1.36 - '("\\\\\\(re\\)?new\\(environment\\|command\\){" "}" define) 1.37 - '("\\\\new\\(length\\|theorem\\|counter\\){" "}" define) 1.38 - ;;セクションコマンドが単なるキーワードってことはないでしょう。 1.39 - ;;(list 1.40 - ;;(concat "\\\\\\(" YaTeX-sectioning-regexp "\\){") "}" 1.41 - ;;'sectioning) 1.42 - ;;eqnarray などの数式環境が入ってないみたい… 1.43 - '("\\\\begin{\\(eqnarray\\*?\\|equation\\*?\\)}" 1.44 - "\\\\end{\\(eqnarray\\*?\\|equation\\*?\\)}" 1.45 - formula)) 1.46 - "Adjustment for hilit19's LaTeX hilit pattern.") 1.47 +;; メニューに比べてこっちは結構本気でやってます。 1.48 +;; だって文書構造がとっても分かり易いんだもん。 1.49 +;; みんなも hilit19.el を使おう! 1.50 +;; 1.51 +;; さて、まずは対応する {} をピカピカ範囲とするような関数を作る。 1.52 +;; これは hilit-LaTeX.el を参考にした。でも、ちゃんと section 型コマンドの 1.53 +;; 引数を数えて正しい位置までピカピカさせるよ〜ん! 1.54 + 1.55 +(defun YaTeX-19-region-section-type (pattern) 1.56 + "Return list of starting and end point of section-type commands of PATTERN." 1.57 + (if (re-search-forward pattern nil t) 1.58 + (let ((m0 (match-beginning 0)) cmd (argc 1)) 1.59 + (setq cmd (substring (YaTeX-match-string 0) 1 -1) 1.60 + argc (or (car (cdr (YaTeX-lookup-table cmd 'section))) argc)) 1.61 + (cons m0 1.62 + (progn (skip-chars-backward "^{") (forward-char -2) 1.63 + (while (> argc 0) 1.64 + (skip-chars-forward "^{") 1.65 + (forward-list 1) 1.66 + (setq argc (1- argc))) 1.67 + (point)))))) 1.68 + 1.69 +(defun YaTeX-19-region-large-type (pattern) 1.70 + "Return list of large-type contents. 1.71 +Assumes PATTERN begins with `{'." 1.72 + (if (re-search-forward pattern nil t) 1.73 + (let ((m0 (match-beginning 0))) 1.74 + (goto-char m0) 1.75 + (skip-chars-forward "^ \t\n") 1.76 + (skip-chars-forward " \t\n") 1.77 + (cons (point) 1.78 + (progn (goto-char m0) (forward-list 1) 1.79 + (1- (point))))))) 1.80 + 1.81 +;; 些細なことだが % の前の文字もピカリとさせてしまうようで… >hilit19 1.82 +;; ↓この関数は下の hilit-set-mode-patterns の "[^\\]\\(%\\).*$" に 1.83 +;; 依存している 1.84 +(defun YaTeX-19-region-comment (pattern) 1.85 + "Return list of comment start and end point." 1.86 + (if (re-search-forward pattern nil t) 1.87 + (cons (match-beginning 1) (match-end 0)))) 1.88 + 1.89 +(defvar YaTeX-hilit-patterns-alist 1.90 + '( 1.91 + ;; comments 1.92 + (YaTeX-19-region-comment "[^\\]\\(%\\).*$" comment) 1.93 + 1.94 + (YaTeX-19-region-section-type "\\\\footnote\\(mark\\|text\\)?{" keyword) 1.95 + ("\\\\[a-z]+box" 0 keyword) 1.96 + (YaTeX-19-region-section-type "\\\\\\(v\\|h\\)space\\(\*\\)?{" keyword) 1.97 + 1.98 + ;; (re-)define new commands/environments/counters 1.99 + (YaTeX-19-region-section-type 1.100 + "\\\\\\(re\\)?new\\(environment\\|command\\|theorem\\){" defun) 1.101 + (YaTeX-19-region-section-type 1.102 + "\\\\\\(re\\)?new\\(length\\|counter\\){" define) 1.103 + 1.104 + ;; various declarations/definitions 1.105 + (YaTeX-19-region-section-type 1.106 + "\\\\\\(set\\|setto\\|addto\\)\\(length\\|width\\|counter\\){" 1.107 + define) 1.108 + (YaTeX-19-region-section-type 1.109 + "\\\\\\(title\\|author\\|date\\|thanks\\){" define) 1.110 + 1.111 + ("\\\\documentstyle\\(\\[.*\\]\\)?{" "}" decl) 1.112 + ("\\\\\\(begin\\|end\\|nofiles\\|includeonly\\){" "}" decl) 1.113 + ("\\\\\\(raggedright\\|makeindex\\|makeglossary\\|maketitle\\)\\b" 0 decl) 1.114 + ("\\\\\\(pagestyle\\|thispagestyle\\|pagenumbering\\){" "}" decl) 1.115 + ("\\\\\\(normalsize\\|small\\|footnotesize\\|scriptsize\\|tiny\\|large\\|Large\\|LARGE\\|huge\\|Huge\\)\\b" 0 decl) 1.116 + ("\\\\\\(appendix\\|tableofcontents\\|listoffigures\\|listoftables\\)\\b" 1.117 + 0 decl) 1.118 + ("\\\\\\(bf\\|em\\|it\\|rm\\|sf\\|sl\\|ss\\|tt\\)\\b" 0 decl) 1.119 + 1.120 + ;; label-like things 1.121 + ;;this should be customized by YaTeX-item-regexp 1.122 + ("\\\\\\(sub\\)*item\\b\\(\\[[^]]*\\]\\)?" 0 label) 1.123 + (YaTeX-19-region-section-type 1.124 + "\\\\caption\\(\\[[^]]*\\]\\)?{" label) 1.125 + 1.126 + ;; formulas 1.127 + ("[^\\]\\\\(" "\\\\)" formula) ; \( \) 1.128 + ("[^\\]\\\\\\[" "\\\\\\]" formula) ; \[ \] 1.129 + ("\\\\begin{\\(eqn\\|equation\\)" "\\\\end{\\(eqn\\|equation\\)" formula) 1.130 + ("[^\\$]\\($\\($[^$]*\\$\\|[^$]*\\)\\$\\)" 1 formula) ; '$...$' or '$$...$$' 1.131 + 1.132 + ;; things that bring in external files 1.133 + ("\\\\\\(include\\|input\\|bibliography\\){" "}" include) 1.134 + 1.135 + ;; "wysiwyg" emphasis -- these don't work with nested expressions 1.136 + ;; ("{\\\\\\(em\\|it\\|sl\\)" "}" italic) 1.137 + (YaTeX-19-region-large-type "{\\\\bf" bold) 1.138 + 1.139 + ("``" "''" string) 1.140 + 1.141 + ;; things that do some sort of cross-reference 1.142 + (YaTeX-19-region-section-type 1.143 + "\\\\\\(\\(no\\)?cite\\|\\(page\\)?ref\\|label\\|index\\|glossary\\){" 1.144 + crossref) 1.145 + ) 1.146 + "*Hiliting pattern alist for LaTeX text.") 1.147 + 1.148 +;;(defvar YaTeX-hilit-pattern-adjustment-default nil) 1.149 +;; ↑いらなくなった。 1.150 (defvar YaTeX-hilit-pattern-adjustment-private nil 1.151 - "*Private variable, same purpose as YaTeX-hilit-pattern-adjustment-default.") 1.152 + "*Adjustment hilit-pattern-alist for default yatex-mode's pattern.") 1.153 (defvar YaTeX-hilit-sectioning-face 1.154 '(yellow/dodgerblue yellow/cornflowerblue) 1.155 "*Hilightening face for sectioning unit. '(FaceForLight FaceForDark)") 1.156 @@ -240,54 +329,55 @@ 1.157 1.158 ;;; セクションコマンドを、構造レベルの高さに応じて色の濃度を変える 1.159 ;;; 背景が黒でないと何が嬉しいのか分からないに違いない. 1.160 -(let*((sectface 1.161 - (car (if (eq hilit-background-mode 'dark) 1.162 - (cdr YaTeX-hilit-sectioning-face) 1.163 - YaTeX-hilit-sectioning-face))) 1.164 - (sectcol (symbol-name sectface)) 1.165 - sect-pat-alist) 1.166 - (if (string-match "/" sectcol) 1.167 - (let (colorvalue fR fG fB bR bG bB list pat fg bg level from face) 1.168 - (require 'yatexsec) 1.169 - (setq fg (substring sectcol 0 (string-match "/" sectcol)) 1.170 - bg (substring sectcol (1+ (string-match "/" sectcol))) 1.171 - colorvalue (x-color-values fg) 1.172 - fR (/ (nth 0 colorvalue) 256) 1.173 - fG (/ (nth 1 colorvalue) 256) 1.174 - fB (/ (nth 2 colorvalue) 256) 1.175 - colorvalue (x-color-values bg) 1.176 - bR (/ (nth 0 colorvalue) 256) 1.177 - bG (/ (nth 1 colorvalue) 256) 1.178 - bB (/ (nth 2 colorvalue) 256) 1.179 - list YaTeX-sectioning-level) 1.180 - (while list 1.181 - (setq pat (concat YaTeX-ec-regexp (car (car list)) "\\*?{") 1.182 - level (cdr (car list)) 1.183 - fg (format "hex-%02x%02x%02x" 1.184 - (- fR (/ (* level fR) 40)) ;40 musn't be constant 1.185 - (- fG (/ (* level fG) 40)) 1.186 - (- fB (/ (* level fB) 40))) 1.187 - bg (format "hex-%02x%02x%02x" 1.188 - (- bR (/ (* level bR) 15)) ;20 musn't be constant 1.189 - (- bG (/ (* level bG) 15)) 1.190 - (- bB (/ (* level bB) 15))) 1.191 - from (intern (format "sectioning-%d" level)) 1.192 - face (intern (concat fg "/" bg))) 1.193 - (hilit-translate from face) 1.194 - (setq sect-pat-alist 1.195 - (cons (list pat "}" face) 1.196 - sect-pat-alist)) 1.197 - (setq list (cdr list))) 1.198 - (setq YaTeX-sectioning-patterns-alist sect-pat-alist)))) 1.199 +;;; もしかして白地の時は構造レベルに応じて色を明るくしたほうが良いのか? 1.200 +(cond 1.201 + ((and (featurep 'hilit19) (fboundp 'x-color-values)) 1.202 + (let*((sectface 1.203 + (car (if (eq hilit-background-mode 'dark) 1.204 + (cdr YaTeX-hilit-sectioning-face) 1.205 + YaTeX-hilit-sectioning-face))) 1.206 + (sectcol (symbol-name sectface)) 1.207 + sect-pat-alist) 1.208 + (if (string-match "/" sectcol) 1.209 + (let (colorvalue fR fG fB bR bG bB list pat fg bg level from face) 1.210 + (require 'yatexsec) 1.211 + (setq fg (substring sectcol 0 (string-match "/" sectcol)) 1.212 + bg (substring sectcol (1+ (string-match "/" sectcol))) 1.213 + colorvalue (x-color-values fg) 1.214 + fR (/ (nth 0 colorvalue) 256) 1.215 + fG (/ (nth 1 colorvalue) 256) 1.216 + fB (/ (nth 2 colorvalue) 256) 1.217 + colorvalue (x-color-values bg) 1.218 + bR (/ (nth 0 colorvalue) 256) 1.219 + bG (/ (nth 1 colorvalue) 256) 1.220 + bB (/ (nth 2 colorvalue) 256) 1.221 + list YaTeX-sectioning-level) 1.222 + (while list 1.223 + (setq pat (concat YaTeX-ec-regexp (car (car list)) "\\*?{") 1.224 + level (cdr (car list)) 1.225 + fg (format "hex-%02x%02x%02x" 1.226 + (- fR (/ (* level fR) 40)) ;40 musn't be constant 1.227 + (- fG (/ (* level fG) 40)) 1.228 + (- fB (/ (* level fB) 40))) 1.229 + bg (format "hex-%02x%02x%02x" 1.230 + (- bR (/ (* level bR) 15)) ;20 musn't be constant 1.231 + (- bG (/ (* level bG) 15)) 1.232 + (- bB (/ (* level bB) 15))) 1.233 + from (intern (format "sectioning-%d" level)) 1.234 + face (intern (concat fg "/" bg))) 1.235 + (hilit-translate from face) 1.236 + (setq sect-pat-alist 1.237 + (cons;;(list pat "}" face) 1.238 + (list 'YaTeX-19-region-section-type pat face) 1.239 + sect-pat-alist)) 1.240 + (setq list (cdr list))) 1.241 + (setq YaTeX-sectioning-patterns-alist sect-pat-alist)))))) 1.242 1.243 -(defun YaTeX-19-collect-macro () 1.244 +;; ローカルなマクロを読み込んだ後 redraw すると 1.245 +;; ローカルマクロを keyword として光らせる(keywordじゃまずいかな…)。 1.246 +(defun YaTeX-19-collect-macros () 1.247 (cond 1.248 ((and (featurep 'hilit19) (fboundp 'hilit-translate)) 1.249 - (or YaTeX-hilit-patterns-alist 1.250 - (let ((alist (cdr (assq 'latex-mode hilit-patterns-alist)))) 1.251 - (setcar (assoc "\\\\item\\(\\[[^]]*\\]\\)?" alist) 1.252 - (concat YaTeX-item-regexp "\\b\\(\\[[^]]*\\]\\)?")) 1.253 - (setq YaTeX-hilit-patterns-alist alist))) 1.254 (let ((get-face 1.255 (function 1.256 (lambda (table) 1.257 @@ -306,17 +396,18 @@ 1.258 (append 1.259 YaTeX-sectioning-patterns-alist 1.260 YaTeX-hilit-pattern-adjustment-private 1.261 - YaTeX-hilit-pattern-adjustment-default 1.262 + ;;YaTeX-hilit-pattern-adjustment-default 1.263 YaTeX-hilit-patterns-alist 1.264 (list 1.265 (list 1.266 + 'YaTeX-19-region-section-type 1.267 (concat "\\\\\\(" 1.268 (mapconcat 1.269 (function (lambda (s) (regexp-quote (car s)))) 1.270 (append user-section-table tmp-section-table) 1.271 "\\|") 1.272 "\\){") 1.273 - "}" 'keyword) 1.274 + 'keyword) 1.275 (list 1.276 (concat "\\\\\\(" 1.277 (mapconcat 1.278 @@ -326,17 +417,64 @@ 1.279 "\\)\\b") 1.280 0 'macro)))) 1.281 hilit-patterns-alist))))) 1.282 -(YaTeX-19-collect-macro) 1.283 +;;(YaTeX-19-collect-macros) ;causes an error 1.284 (defun YaTeX-hilit-recenter (arg) 1.285 "Collect current local macro and hilit-recenter." 1.286 (interactive "P") 1.287 - (YaTeX-19-collect-macro) 1.288 + (YaTeX-19-collect-macros) 1.289 (hilit-recenter arg)) 1.290 (if (fboundp 'hilit-recenter) ;Replace hilit-recenter with 1.291 (mapcar (function (lambda (key) ;YaTeX-hilit-recenter in yatex-mode 1.292 (define-key YaTeX-mode-map key 'YaTeX-hilit-recenter))) 1.293 (where-is-internal 'hilit-recenter))) 1.294 1.295 +(defun YaTeX-switch-to-new-window () 1.296 + (let ((c 0) (i 1) (free (make-string win:max-configs ? ))) 1.297 + (while (< i win:max-configs) 1.298 + (or (aref win:configs i) (aset free i (+ i win:base-key))) 1.299 + (setq i (1+ i))) 1.300 + (while (not (string-match (char-to-string c) free)) 1.301 + (message "Which window to create? [%s]: " free) 1.302 + (setq c (read-char))) 1.303 + (message "Creating window [%c]" c) 1.304 + (set-buffer (get-buffer-create "*scratch*")) 1.305 + (win:switch-window (- c win:base-key)))) 1.306 + 1.307 +(defun YaTeX-visit-main-other-frame () 1.308 + "Visit main file in other frame. 1.309 +WARNING, This code is not perfect." 1.310 + (interactive) 1.311 + (if (YaTeX-main-file-p) (message "I think this is main LaTeX source.") 1.312 + (let (parent) 1.313 + (save-excursion (YaTeX-visit-main t) (setq parent (current-buffer))) 1.314 + (cond 1.315 + ((get-buffer-window parent t) 1.316 + (goto-buffer-window parent)) 1.317 + ((and (featurep 'windows) win:use-frame) 1.318 + (YaTeX-switch-to-new-window) 1.319 + (switch-to-buffer parent)) 1.320 + (t (switch-to-buffer-other-frame (buffer-name parent))))))) 1.321 + 1.322 +(defun YaTeX-goto-corresponding-*-other-frame (arg) 1.323 + "Go to corresponding object in other frame." 1.324 + (interactive "P") 1.325 + (let (b p) 1.326 + (save-window-excursion 1.327 + (save-excursion 1.328 + (YaTeX-goto-corresponding-* arg) 1.329 + (setq b (current-buffer) p (point)))) 1.330 + (cond 1.331 + ((get-buffer-window b t) 1.332 + (goto-buffer-window b) 1.333 + (goto-char p)) 1.334 + ((and (featurep 'windows) win:use-frame) 1.335 + (YaTeX-switch-to-new-window) 1.336 + (switch-to-buffer b) 1.337 + (goto-char p)) 1.338 + (t (switch-to-buffer-other-frame (buffer-name b)) 1.339 + (goto-char p)))) 1.340 +) 1.341 + 1.342 ;;; reverseVideo にして hilit-background-mode を 'dark 1.343 ;;; にしている人は数式などが暗くなりすぎて見づらいかもしれない。 1.344 ;;; 次のコードを hilit19 をロードしている場所の直後に置くとちょっ