Mercurial > hgrepos > hgweb.cgi > yatex
annotate yatexlib.el @ 168:191cffccc912 dev
Replace all \ref{LABEL} when changing \label{LABEL}.
Move YaTeX-yatex-buffer-list to yatexlib.el
author | yuuji@gentei.org |
---|---|
date | Wed, 16 Feb 2011 20:08:05 +0900 |
parents | b65b3dc543d1 |
children | ab02213f5683 |
rev | line source |
---|---|
23 | 1 ;;; -*- Emacs-Lisp -*- |
64 | 2 ;;; YaTeX and yahtml common libraries, general functions and definitions |
23 | 3 ;;; yatexlib.el |
88 | 4 ;;; (c)1994-2009 by HIROSE Yuuji.[yuuji@yatex.org] |
168
191cffccc912
Replace all \ref{LABEL} when changing \label{LABEL}.
yuuji@gentei.org
parents:
142
diff
changeset
|
5 ;;; Last modified Wed Feb 16 19:58:33 2011 on firestorm |
23 | 6 ;;; $Id$ |
7 | |
64 | 8 ;; General variables |
9 (defvar YaTeX-dos (memq system-type '(ms-dos windows-nt OS/2))) | |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
10 (defvar YaTeX-macos (memq system-type '(darwin))) |
64 | 11 (defvar YaTeX-emacs-19 (>= (string-to-int emacs-version) 19)) |
12 (defvar YaTeX-emacs-20 (>= (string-to-int emacs-version) 20)) | |
72 | 13 (defvar YaTeX-emacs-21 (>= (string-to-int emacs-version) 21)) |
64 | 14 (defvar YaTeX-user-completion-table |
15 (if YaTeX-dos "~/_yatexrc" "~/.yatexrc") | |
16 "*Default filename in which user completion table is saved.") | |
17 | |
72 | 18 (defvar YaTeX-display-color-p |
19 (or (and (fboundp 'display-color-p) (display-color-p)) | |
20 (and (fboundp 'device-class) | |
21 (eq 'color (device-class (selected-device)))) | |
22 window-system) ; falls down lazy check.. | |
23 "Current display's capability of expressing colors.") | |
24 | |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
25 (defvar YaTeX-japan |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
26 (or (boundp 'NEMACS) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
27 (boundp 'MULE) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
28 (and (boundp 'current-language-environment) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
29 (string-match "[Jj]apanese" current-language-environment))) |
64 | 30 "Whether yatex mode is running on Japanese environment or not.") |
31 | |
70 | 32 ;; autoload from yahtml.el |
33 (autoload 'yahtml-inner-environment-but "yahtml" "yahtml internal func." t) | |
34 | |
80 | 35 (defvar latex-message-kanji-code 2 |
36 "*Kanji coding system latex command types out. | |
37 1 = Shift JIS, 2 = JIS, 3 = EUC. 4 = UTF-8") | |
38 | |
64 | 39 (defvar YaTeX-kanji-code-alist |
40 (cond | |
41 ((boundp '*junet*) | |
77 | 42 (list '(0 . *noconv*) |
43 (cons | |
64 | 44 1 |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
45 (cond |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
46 (YaTeX-dos (if (boundp '*sjis-dos*) *sjis-dos* *sjis*dos)) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
47 (YaTeX-macos (if (boundp '*sjis-mac*) *sjis-mac* *sjis*mac)) |
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
48 (t *sjis*))) |
64 | 49 '(2 . *junet*) '(3 . *euc-japan*))) |
80 | 50 ((and YaTeX-emacs-20 (featurep 'mule)) |
64 | 51 ;;(cdr-safe(assq 'coding-system (assoc "Japanese" language-info-alist))) |
77 | 52 (list '(0 . no-conversion) |
53 (cons | |
64 | 54 1 (cond (YaTeX-dos 'shift_jis-dos) |
79
0734be649cb8
Do not care file-coding-system when YaTeX-kanji-code is nil.
yuuji
parents:
77
diff
changeset
|
55 (YaTeX-macos 'shift_jis-mac) |
64 | 56 ((member 'shift_jis (coding-system-list)) 'shift_jis-unix) |
57 (t 'sjis))) | |
68 | 58 '(2 . iso-2022-jp-unix) |
80 | 59 '(3 . euc-jp-unix) |
60 '(4 . utf-8)))) | |
64 | 61 "Kanji-code expression translation table.") |
62 (defvar YaTeX-inhibit-prefix-letter nil | |
63 "*T for changing key definitions from [prefix] Letter to [prefix] C-Letter.") | |
64 | |
65 (defvar YaTeX-no-begend-shortcut nil | |
66 "*T for disabling shortcut of begin-type completion, [prefix] b d, etc.") | |
67 | |
68 (defvar YaTeX-default-pop-window-height 10 | |
69 "Default typesetting buffer height. | |
70 If integer, sets the window-height of typesetting buffer. | |
71 If string, sets the percentage of it. | |
72 If nil, use default pop-to-buffer.") | |
73 | |
74 (defvar YaTeX-create-file-prefix-g nil | |
75 "*Non-nil creates new file when [prefix] g on \\include{foo}.") | |
76 | |
77 (defvar YaTeX-nervous t | |
78 "*If you are nervous about maintenance of yatexrc, set this value to T. | |
79 And you will have the local dictionary.") | |
80 | |
72 | 81 (defvar YaTeX-use-italic-bold (string< "20" emacs-version) |
82 "*Non-nil tries to find italic/bold fontset. | |
83 This variable is effective when font-lock is used. | |
84 \it, \bf 内部での日本語が□になってしまう場合はこれをnilにして下さい。") | |
85 | |
64 | 86 ;----------- work variables ---------------------------------------- |
80 | 87 (defvar YaTeX-minibuffer-completion-map nil |
88 "Minibuffer completion key map that allows comma completion.") | |
89 (if YaTeX-minibuffer-completion-map nil | |
90 (setq YaTeX-minibuffer-completion-map | |
91 (copy-keymap minibuffer-local-completion-map)) | |
92 (define-key YaTeX-minibuffer-completion-map " " | |
93 'YaTeX-minibuffer-complete) | |
94 (define-key YaTeX-minibuffer-completion-map "\t" | |
95 'YaTeX-minibuffer-complete)) | |
96 | |
64 | 97 (defvar YaTeX-typesetting-mode-map nil |
69 | 98 "Keymap used in YaTeX typesetting buffer") |
99 | |
64 | 100 (if YaTeX-typesetting-mode-map nil |
101 (setq YaTeX-typesetting-mode-map (make-keymap)) | |
102 ;(suppress-keymap YaTeX-typesetting-mode-map t) | |
103 (define-key YaTeX-typesetting-mode-map " " 'YaTeX-jump-error-line) | |
104 (define-key YaTeX-typesetting-mode-map "\C-m" 'YaTeX-send-string) | |
105 (define-key YaTeX-typesetting-mode-map "1" 'delete-other-windows) | |
106 (define-key YaTeX-typesetting-mode-map "0" 'delete-window) | |
107 (define-key YaTeX-typesetting-mode-map "q" 'delete-window)) | |
108 | |
109 (defvar YaTeX-parent-file nil | |
110 "*Main LaTeX source file name used when %#! expression doesn't exist.") | |
111 (make-variable-buffer-local 'YaTeX-parent-file) | |
112 | |
113 ;---------- Define default key bindings on YaTeX mode map ---------- | |
114 ;;;###autoload | |
115 (defun YaTeX-define-key (key binding &optional map) | |
116 "Define key on YaTeX-prefix-map." | |
117 (if YaTeX-inhibit-prefix-letter | |
118 (let ((c (aref key 0))) | |
119 (cond | |
120 ((and (>= c ?a) (<= c ?z)) (aset key 0 (1+ (- c ?a)))) | |
121 ((and (>= c ?A) (<= c ?Z) (numberp YaTeX-inhibit-prefix-letter)) | |
122 (aset key 0 (1+ (- c ?A)))) | |
123 (t nil)))) | |
124 (define-key (or map YaTeX-prefix-map) key binding)) | |
125 | |
126 ;;;###autoload | |
127 (defun YaTeX-local-table-symbol (symbol) | |
128 "Return the lisp symbol which keeps local completion table of SYMBOL." | |
129 (intern (concat "YaTeX$" | |
130 default-directory | |
131 (symbol-name symbol)))) | |
132 | |
133 ;;;###autoload | |
134 (defun YaTeX-sync-local-table (symbol) | |
135 "Synchronize local variable SYMBOL. | |
136 Copy its corresponding directory dependent completion table to SYMBOL." | |
137 (if (boundp (YaTeX-local-table-symbol symbol)) | |
138 (set symbol (symbol-value (YaTeX-local-table-symbol symbol))))) | |
139 | |
140 (defvar YaTeX-user-table-is-read nil | |
141 "Flag that means whether user completion table has been read or not.") | |
142 ;;;###autoload | |
143 (defun YaTeX-read-user-completion-table (&optional forcetoread) | |
144 "Append user completion table of LaTeX macros" | |
80 | 145 (interactive) |
64 | 146 (let*((user-table (expand-file-name YaTeX-user-completion-table)) |
147 (local-table (expand-file-name (file-name-nondirectory user-table))) | |
148 var localvar localbuf (curbuf (current-buffer)) sexp) | |
149 (if YaTeX-user-table-is-read nil | |
150 (message "Loading user completion table") | |
151 (if (file-exists-p user-table) (load-file user-table) | |
152 (message "Welcome to the field of YaTeX. I'm glad to see you!"))) | |
153 (setq YaTeX-user-table-is-read t) | |
154 (cond | |
155 ((file-exists-p local-table) | |
156 (set-buffer (setq localbuf (find-file-noselect local-table))) | |
157 (widen) | |
158 (goto-char (point-min)) | |
80 | 159 (while (re-search-forward "(setq \\([^ \t\n]+\\)" nil t) |
64 | 160 (setq var (intern (buffer-substring |
161 (match-beginning 1) (match-end 1))) | |
162 localvar (YaTeX-local-table-symbol var)) | |
163 (goto-char (match-beginning 0)) | |
164 (setq sexp (buffer-substring (point) | |
165 (progn (forward-sexp) (point)))) | |
166 (set-buffer curbuf) | |
167 (or (assq var (buffer-local-variables)) (make-local-variable var)) | |
168 (eval (read sexp)) | |
169 (or (and (boundp localvar) | |
170 (symbol-value localvar) | |
171 (not forcetoread)) | |
172 (set localvar (symbol-value var))) | |
173 (set-buffer localbuf)) | |
174 (kill-buffer localbuf))) | |
175 (set-buffer curbuf))) | |
176 | |
177 ;;;###autoload | |
178 (defun YaTeX-reload-dictionary () | |
179 "Reload local dictionary. | |
180 Use this function after editing ./.yatexrc." | |
181 (interactive) | |
182 (let ((YaTeX-user-table-is-read nil)) | |
183 (YaTeX-read-user-completion-table t))) | |
184 | |
185 ;;;###autoload | |
186 (defun YaTeX-lookup-table (word type) | |
187 "Lookup WORD in completion table whose type is TYPE. | |
188 This function refers the symbol tmp-TYPE-table, user-TYPE-table, TYPE-table. | |
189 Typically, TYPE is one of 'env, 'section, 'fontsize, 'singlecmd." | |
190 (if (symbolp type) (setq type (symbol-name type))) | |
191 (or (assoc word (symbol-value (intern (concat "tmp-" type "-table")))) | |
192 (assoc word (symbol-value (intern (concat "user-" type "-table")))) | |
193 (assoc word (symbol-value (intern (concat type "-table")))))) | |
194 | |
195 ;;;###autoload | |
196 (defun YaTeX-update-table (vallist default-table user-table local-table) | |
197 "Update completion table if the car of VALLIST is not in current tables. | |
198 Second argument DEFAULT-TABLE is the quoted symbol of default completion | |
199 table, third argument USER-TABLE is user table which will be saved in | |
200 YaTeX-user-completion-table, fourth argument LOCAL-TABLE should have the | |
201 completion which is valid during current Emacs's session. If you | |
202 want to make LOCAL-TABLE valid longer span (but restrict in this directory) | |
203 create the file in current directory which has the same name with | |
204 YaTeX-user-completion-table." | |
205 (let ((car-v (car vallist)) key answer | |
206 (file (file-name-nondirectory YaTeX-user-completion-table))) | |
207 (cond | |
208 ((assoc car-v (symbol-value default-table)) | |
209 nil) ;Nothing to do | |
210 ((setq key (assoc car-v (symbol-value user-table))) | |
211 (if (equal (cdr vallist) (cdr key)) nil | |
212 ;; if association hits, but contents differ. | |
213 (message | |
214 "%s's attributes turned into %s" (car vallist) (cdr vallist)) | |
215 (set user-table (delq key (symbol-value user-table))) | |
216 (set user-table (cons vallist (symbol-value user-table))) | |
217 (YaTeX-update-dictionary | |
218 YaTeX-user-completion-table user-table "user"))) | |
219 ((setq key (assoc car-v (symbol-value local-table))) | |
220 (if (equal (cdr vallist) (cdr key)) nil | |
221 (message | |
222 "%s's attributes turned into %s" (car vallist) (cdr vallist)) | |
223 (set local-table (delq key (symbol-value local-table))) | |
224 (set local-table (cons vallist (symbol-value local-table))) | |
225 (set (YaTeX-local-table-symbol local-table) (symbol-value local-table)) | |
226 (YaTeX-update-dictionary file local-table))) | |
227 ;; All of above cases, there are some completion in tables. | |
228 ;; Then update tables. | |
229 (t | |
230 (if (not YaTeX-nervous) | |
231 (setq answer "u") | |
232 (message | |
233 (cond | |
234 (YaTeX-japan | |
68 | 235 "`%s'の登録先: U)ユーザ辞書 L)ローカル辞書 N)メモリ D)しない") |
64 | 236 (t |
237 "Register `%s' into: U)serDic L)ocalDic N)one D)iscard")) | |
238 (if (> (length car-v) 23) | |
68 | 239 (concat (substring car-v 0 10) "..." (substring car-v -9)) |
64 | 240 car-v)) |
241 (setq answer (char-to-string (read-char)))) | |
242 (cond | |
243 ((string-match answer "uy") | |
244 (set user-table (cons vallist (symbol-value user-table))) | |
245 (YaTeX-update-dictionary YaTeX-user-completion-table user-table "user") | |
246 ) | |
247 ((string-match answer "tl") | |
248 (set local-table (cons vallist (symbol-value local-table))) | |
249 (set (YaTeX-local-table-symbol local-table) (symbol-value local-table)) | |
250 (YaTeX-update-dictionary file local-table)) | |
251 ((string-match answer "d") nil) ;discard it | |
252 (t (set default-table | |
253 (cons vallist (symbol-value default-table))))))))) | |
254 | |
255 ;;;###autoload | |
256 (defun YaTeX-cplread-with-learning | |
257 (prom default-table user-table local-table | |
258 &optional pred reqmatch init hsym) | |
259 "Completing read with learning. | |
260 Do a completing read with prompt PROM. Completion table is what | |
261 DEFAULT-TABLE, USER-TABLE, LOCAL table are appended in reverse order. | |
262 Note that these tables are passed by the symbol. | |
263 Optional arguments PRED, REQMATH and INIT are passed to completing-read | |
264 as its arguments PREDICATE, REQUIRE-MATCH and INITIAL-INPUT respectively. | |
265 If optional 8th argument HSYM, history symbol, is passed, use it as | |
266 history list variable." | |
267 (YaTeX-sync-local-table local-table) | |
268 (let*((table (append (symbol-value local-table) | |
269 (symbol-value user-table) | |
270 (symbol-value default-table))) | |
271 (word (completing-read-with-history | |
272 prom table pred reqmatch init hsym))) | |
273 (if (and (string< "" word) (not (assoc word table))) | |
274 (YaTeX-update-table (list word) default-table user-table local-table)) | |
275 word)) | |
276 | |
277 ;;;###autoload | |
278 (defun YaTeX-update-dictionary (file symbol &optional type) | |
279 (let ((local-table-buf (find-file-noselect file)) | |
280 (name (symbol-name symbol)) | |
281 (value (symbol-value symbol))) | |
282 (save-excursion | |
283 (message "Updating %s dictionary..." (or type "local")) | |
284 (set-buffer local-table-buf) | |
285 (goto-char (point-max)) | |
286 (search-backward (concat "(setq " name) nil t) | |
287 (delete-region (point) (progn (forward-sexp) (point))) | |
288 (delete-blank-lines) | |
289 (insert "(setq " name " '(\n") | |
290 (mapcar '(lambda (s) | |
291 (insert (format "%s\n" (prin1-to-string s)))) | |
292 value) | |
293 (insert "))\n\n") | |
294 (delete-blank-lines) | |
295 (basic-save-buffer) | |
296 (kill-buffer local-table-buf) | |
297 (message "Updating %s dictionary...Done" (or type "local"))))) | |
298 | |
299 ;;;###autoload | |
300 (defun YaTeX-define-begend-key-normal (key env &optional map) | |
301 "Define short cut YaTeX-make-begin-end key." | |
302 (YaTeX-define-key | |
303 key | |
304 (list 'lambda '(arg) '(interactive "P") | |
305 (list 'YaTeX-insert-begin-end env 'arg)) | |
306 map)) | |
307 | |
308 ;;;###autoload | |
309 (defun YaTeX-define-begend-region-key (key env &optional map) | |
310 "Define short cut YaTeX-make-begin-end-region key." | |
311 (YaTeX-define-key key (list 'lambda nil '(interactive) | |
312 (list 'YaTeX-insert-begin-end env t)) map)) | |
313 | |
314 ;;;###autoload | |
315 (defun YaTeX-define-begend-key (key env &optional map) | |
86 | 316 "Define short cut key for begin type completion. |
317 Define both strokes for normal and region mode. | |
318 To customize YaTeX, user should use this function." | |
64 | 319 (YaTeX-define-begend-key-normal key env map) |
320 (if YaTeX-inhibit-prefix-letter nil | |
321 (YaTeX-define-begend-region-key | |
322 (concat (upcase (substring key 0 1)) (substring key 1)) env))) | |
323 | |
23 | 324 ;;;###autoload |
325 (defun YaTeX-search-active-forward (string cmntrx &optional bound err cnt func) | |
326 "Search STRING which is not commented out by CMNTRX. | |
327 Optional arguments after BOUND, ERR, CNT are passed literally to search-forward | |
328 or search-backward. | |
329 Optional sixth argument FUNC changes search-function." | |
49 | 330 (let ((sfunc (or func 'search-forward)) found md) |
23 | 331 (while (and (prog1 |
332 (setq found (funcall sfunc string bound err cnt)) | |
333 (setq md (match-data))) | |
334 (or | |
64 | 335 (and (eq major-mode 'yatex-mode) |
336 (YaTeX-in-verb-p (match-beginning 0))) | |
23 | 337 (save-excursion |
72 | 338 (goto-char (match-beginning 0)) |
23 | 339 (beginning-of-line) |
340 (re-search-forward cmntrx (match-beginning 0) t))))) | |
341 (store-match-data md) | |
69 | 342 found)) |
23 | 343 |
344 (defun YaTeX-re-search-active-forward (regexp cmntrx &optional bound err cnt) | |
345 "Search REGEXP backward which is not commented out by regexp CMNTRX. | |
346 See also YaTeX-search-active-forward." | |
69 | 347 (YaTeX-search-active-forward regexp cmntrx bound err cnt 're-search-forward)) |
348 | |
23 | 349 (defun YaTeX-search-active-backward (string cmntrx &optional bound err cnt) |
350 "Search STRING backward which is not commented out by regexp CMNTRX. | |
351 See also YaTeX-search-active-forward." | |
69 | 352 (YaTeX-search-active-forward string cmntrx bound err cnt 'search-backward)) |
353 | |
23 | 354 (defun YaTeX-re-search-active-backward (regexp cmntrx &optional bound err cnt) |
355 "Search REGEXP backward which is not commented out by regexp CMNTRX. | |
356 See also YaTeX-search-active-forward." | |
69 | 357 (YaTeX-search-active-forward |
358 regexp cmntrx bound err cnt 're-search-backward)) | |
23 | 359 |
80 | 360 (defun YaTeX-relative-path-p (path) |
361 "Return non-nil if PATH is not absolute one." | |
362 (let ((md (match-data))) | |
363 (unwind-protect | |
364 (not (string-match "^\\(/\\|[a-z]:\\|\\\\\\).*/" file)) | |
365 (store-match-data md)))) | |
366 | |
23 | 367 ;;;###autoload |
368 (defun YaTeX-switch-to-buffer (file &optional setbuf) | |
369 "Switch to buffer if buffer exists, find file if not. | |
370 Optional second arg SETBUF t make use set-buffer instead of switch-to-buffer." | |
371 (interactive "Fswitch to file: ") | |
70 | 372 (if (bufferp file) |
373 (setq file (buffer-file-name file)) | |
80 | 374 (and (YaTeX-relative-path-p file) |
70 | 375 (eq major-mode 'yatex-mode) |
376 YaTeX-search-file-from-top-directory | |
377 (save-excursion | |
378 (YaTeX-visit-main t) | |
379 (setq file (expand-file-name file))))) | |
52 | 380 (let (buf (hilit-auto-highlight (not setbuf))) |
381 (cond | |
382 ((setq buf (get-file-buffer file)) | |
383 (funcall (if setbuf 'set-buffer 'switch-to-buffer) | |
384 (get-file-buffer file)) | |
385 buf) | |
386 ((or YaTeX-create-file-prefix-g (file-exists-p file)) | |
387 (or ;find-file returns nil but set current-buffer... | |
388 (if setbuf (set-buffer (find-file-noselect file)) | |
389 (find-file file)) | |
390 (current-buffer))) | |
391 (t (message "%s was not found in this directory." file) | |
69 | 392 nil)))) |
23 | 393 |
394 ;;;###autoload | |
395 (defun YaTeX-switch-to-buffer-other-window (file) | |
396 "Switch to buffer if buffer exists, find file if not." | |
397 (interactive "Fswitch to file: ") | |
70 | 398 (and (eq major-mode 'yatex-mode) |
399 (stringp file) | |
80 | 400 (YaTeX-relative-path-p file) |
70 | 401 YaTeX-search-file-from-top-directory |
402 (save-excursion | |
403 (YaTeX-visit-main t) | |
404 (setq file (expand-file-name file)))) | |
52 | 405 (if (bufferp file) (setq file (buffer-file-name file))) |
406 (cond | |
407 ((get-file-buffer file) | |
408 (switch-to-buffer-other-window (get-file-buffer file)) | |
409 t) | |
410 ((or YaTeX-create-file-prefix-g (file-exists-p file)) | |
411 (find-file-other-window file) t) | |
412 (t (message "%s was not found in this directory." file) | |
69 | 413 nil))) |
23 | 414 |
70 | 415 (defun YaTeX-get-file-buffer (file) |
416 "Return the FILE's buffer. | |
417 Base directory is that of main file or current directory." | |
418 (let (dir main (cdir default-directory)) | |
419 (or (and (eq major-mode 'yatex-mode) | |
420 YaTeX-search-file-from-top-directory | |
421 (save-excursion | |
422 (YaTeX-visit-main t) | |
423 (get-file-buffer file))) | |
424 (get-file-buffer file)))) | |
425 | |
23 | 426 (defun YaTeX-replace-format-sub (string format repl) |
427 (let ((beg (or (string-match (concat "^\\(%" format "\\)") string) | |
428 (string-match (concat "[^%]\\(%" format "\\)") string))) | |
429 (len (length format))) | |
430 (if (null beg) string ;no conversion | |
431 (concat | |
70 | 432 (substring string 0 (match-beginning 1)) (or repl "") |
69 | 433 (substring string (match-end 1)))))) |
23 | 434 |
435 ;;;###autoload | |
436 (defun YaTeX-replace-format (string format repl) | |
437 "In STRING, replace first appearance of FORMAT to REPL as if | |
438 function `format' does. FORMAT does not contain `%'" | |
80 | 439 (let ((ans string) (case-fold-search nil)) |
23 | 440 (while (not (string= |
441 ans (setq string (YaTeX-replace-format-sub ans format repl)))) | |
442 (setq ans string)) | |
69 | 443 string)) |
23 | 444 |
445 ;;;###autoload | |
70 | 446 (defun YaTeX-replace-formats (string replace-list) |
447 (let ((list replace-list)) | |
448 (while list | |
449 (setq string (YaTeX-replace-format | |
450 string (car (car list)) (cdr (car list))) | |
451 list (cdr list))) | |
452 string)) | |
453 | |
454 ;;;###autoload | |
23 | 455 (defun YaTeX-replace-format-args (string &rest args) |
456 "Translate the argument mark #1, #2, ... #n in the STRING into the | |
457 corresponding real arguments ARGS." | |
458 (let ((argp 1)) | |
459 (while args | |
460 (setq string | |
461 (YaTeX-replace-format string (int-to-string argp) (car args))) | |
462 (setq args (cdr args) argp (1+ argp)))) | |
69 | 463 string) |
23 | 464 |
465 ;;;###autoload | |
466 (defun rindex (string char) | |
467 (let ((pos (1- (length string)))(index -1)) | |
468 (while (>= pos 0) | |
469 (cond | |
470 ((= (aref string pos) char) | |
471 (setq index pos) (setq pos -1)) | |
472 (t (setq pos (1- pos)))) | |
473 ) | |
64 | 474 index)) |
475 | |
476 ;;;###autoload | |
477 (defun point-beginning-of-line () | |
478 (save-excursion (beginning-of-line)(point))) | |
479 | |
480 ;;;###autoload | |
481 (defun point-end-of-line () | |
482 (save-excursion (end-of-line)(point))) | |
483 | |
23 | 484 |
485 ;;;###autoload | |
486 (defun YaTeX-showup-buffer (buffer &optional func select) | |
487 "Make BUFFER show up in certain window (but current window) | |
488 that gives the maximum value by the FUNC. FUNC should take an argument | |
489 of its window object. Non-nil for optional third argument SELECT selects | |
49 | 490 that window. This function never selects minibuffer window." |
86 | 491 (or (and (if (and YaTeX-emacs-19 select window-system) |
47 | 492 (get-buffer-window buffer t) |
493 (get-buffer-window buffer)) | |
494 (progn | |
495 (if select | |
51 | 496 (goto-buffer-window buffer)) |
47 | 497 t)) |
23 | 498 (let ((window (selected-window)) |
499 (wlist (YaTeX-window-list)) win w (x 0)) | |
500 (cond | |
501 ((> (length wlist) 2) | |
502 (if func | |
503 (while wlist | |
504 (setq w (car wlist)) | |
505 (if (and (not (eq window w)) | |
506 (> (funcall func w) x)) | |
507 (setq win w x (funcall func w))) | |
508 (setq wlist (cdr wlist))) | |
509 (setq win (get-lru-window))) | |
510 (select-window win) | |
511 (switch-to-buffer buffer) | |
512 (or select (select-window window))) | |
513 ((= (length wlist) 2) | |
49 | 514 ;(other-window 1);This does not work properly on Emacs-19 |
515 (select-window (get-lru-window)) | |
23 | 516 (switch-to-buffer buffer) |
517 (or select (select-window window))) | |
518 (t ;if one-window | |
519 (cond | |
86 | 520 ((and YaTeX-emacs-19 window-system (get-buffer-window buffer t)) |
47 | 521 nil) ;if found in other frame |
23 | 522 (YaTeX-default-pop-window-height |
51 | 523 (split-window-calculate-height YaTeX-default-pop-window-height) |
59 | 524 ;;(pop-to-buffer buffer) ;damn! emacs-19.30 |
525 (select-window (next-window nil 1)) | |
526 (switch-to-buffer (get-buffer-create buffer)) | |
23 | 527 (or select (select-window window))) |
528 (t nil))) | |
69 | 529 )))) |
530 | |
531 (cond | |
532 ((fboundp 'screen-height) | |
533 (fset 'YaTeX-screen-height 'screen-height) | |
534 (fset 'YaTeX-screen-width 'screen-width)) | |
535 ((fboundp 'frame-height) | |
536 (fset 'YaTeX-screen-height 'frame-height) | |
537 (fset 'YaTeX-screen-width 'frame-width)) | |
538 (t (error "I don't know how to run windows.el on this Emacs..."))) | |
23 | 539 |
540 ;;;###autoload | |
51 | 541 (defun split-window-calculate-height (height) |
542 "Split current window wight specified HEIGHT. | |
59 | 543 If HEIGHT is number, make a new window that has HEIGHT lines. |
544 If HEIGHT is string, make a new window that occupies HEIGT % of screen height. | |
51 | 545 Otherwise split window conventionally." |
59 | 546 (if (one-window-p t) |
51 | 547 (split-window |
548 (selected-window) | |
549 (max | |
550 (min | |
69 | 551 (- (YaTeX-screen-height) |
59 | 552 (if (numberp height) |
553 (+ height 2) | |
69 | 554 (/ (* (YaTeX-screen-height) |
59 | 555 (string-to-int height)) |
51 | 556 100))) |
69 | 557 (- (YaTeX-screen-height) window-min-height 1)) |
558 window-min-height)))) | |
51 | 559 |
560 ;;;###autoload | |
23 | 561 (defun YaTeX-window-list () |
562 (let*((curw (selected-window)) (win curw) (wlist (list curw))) | |
563 (while (not (eq curw (setq win (next-window win)))) | |
564 (or (eq win (minibuffer-window)) | |
565 (setq wlist (cons win wlist)))) | |
69 | 566 wlist)) |
23 | 567 |
72 | 568 (if YaTeX-emacs-21 |
569 ;; Emacs-21's next-window returns other frame's window even if called | |
570 ;; with argument ALL-FRAMES nil, when called from minibuffer context. | |
571 ;; Therefore, check frame identity here. | |
572 (defun YaTeX-window-list () | |
573 (let*((curw (selected-window)) (win curw) (wlist (list curw)) | |
574 (curf (window-frame curw))) | |
575 (while (and (not (eq curw (setq win (next-window win)))) | |
576 (eq curf (window-frame win))) | |
577 (or (eq win (minibuffer-window)) | |
578 (setq wlist (cons win wlist)))) | |
579 wlist))) | |
580 | |
23 | 581 ;;;###autoload |
582 (defun substitute-all-key-definition (olddef newdef keymap) | |
583 "Replace recursively OLDDEF with NEWDEF for any keys in KEYMAP now | |
584 defined as OLDDEF. In other words, OLDDEF is replaced with NEWDEF | |
585 where ever it appears." | |
68 | 586 (if YaTeX-emacs-19 |
587 (substitute-key-definition olddef newdef keymap global-map) | |
588 (mapcar | |
589 (function (lambda (key) (define-key keymap key newdef))) | |
590 (where-is-internal olddef keymap)))) | |
23 | 591 |
592 ;;;###autoload | |
593 (defun YaTeX-match-string (n &optional m) | |
594 "Return (buffer-substring (match-beginning n) (match-beginning m))." | |
595 (if (match-beginning n) | |
80 | 596 (YaTeX-buffer-substring (match-beginning n) |
69 | 597 (match-end (or m n))))) |
23 | 598 |
599 ;;;###autoload | |
600 (defun YaTeX-minibuffer-complete () | |
49 | 601 "Complete in minibuffer. |
51 | 602 If the symbol 'delim is bound and is string, its value is assumed to be |
49 | 603 the character class of delimiters. Completion will be performed on |
51 | 604 the last field separated by those delimiters. |
605 If the symbol 'quick is bound and is 't, when the try-completion results | |
606 in t, exit minibuffer immediately." | |
23 | 607 (interactive) |
72 | 608 (save-restriction |
609 (narrow-to-region | |
610 (if (fboundp 'field-beginning) (field-beginning (point-max)) (point-min)) | |
611 (point-max)) | |
612 (let ((md (match-data)) beg word compl | |
613 (quick (and (boundp 'quick) (eq quick t))) | |
614 (displist ;function to display completion-list | |
615 (function | |
616 (lambda () | |
617 (with-output-to-temp-buffer "*Completions*" | |
618 (display-completion-list | |
619 (all-completions word minibuffer-completion-table))))))) | |
620 (setq beg (if (and (boundp 'delim) (stringp delim)) | |
621 (save-excursion | |
622 (skip-chars-backward (concat "^" delim)) | |
623 (point)) | |
624 (point-min)) | |
625 word (buffer-substring beg (point-max)) | |
626 compl (try-completion word minibuffer-completion-table)) | |
627 (cond | |
628 ((eq compl t) | |
629 (if quick (exit-minibuffer) | |
630 (let ((p (point)) (max (point-max))) | |
631 (unwind-protect | |
632 (progn | |
633 (goto-char max) | |
634 (insert " [Sole completion]") | |
635 (goto-char p) | |
636 (sit-for 1)) | |
637 (delete-region max (point-max)) | |
638 (goto-char p))))) | |
639 ((eq compl nil) | |
640 (ding) | |
641 (save-excursion | |
642 (let (p) | |
643 (unwind-protect | |
644 (progn | |
645 (goto-char (setq p (point-max))) | |
646 (insert " [No match]") | |
647 (goto-char p) | |
648 (sit-for 2)) | |
649 (delete-region p (point-max)))))) | |
650 ((string= compl word) | |
651 (funcall displist)) | |
652 (t (delete-region beg (point-max)) | |
653 (insert compl) | |
654 (if quick | |
655 (if (eq (try-completion compl minibuffer-completion-table) t) | |
656 (exit-minibuffer) | |
657 (funcall displist))))) | |
658 (store-match-data md)))) | |
23 | 659 |
51 | 660 (defun YaTeX-minibuffer-quick-complete () |
661 "Set 'quick to 't and call YaTeX-minibuffer-complete. | |
662 See documentation of YaTeX-minibuffer-complete." | |
663 (interactive) | |
664 (let ((quick t)) | |
665 (self-insert-command 1) | |
666 (YaTeX-minibuffer-complete))) | |
667 | |
168
191cffccc912
Replace all \ref{LABEL} when changing \label{LABEL}.
yuuji@gentei.org
parents:
142
diff
changeset
|
668 (defun YaTeX-yatex-buffer-list () |
191cffccc912
Replace all \ref{LABEL} when changing \label{LABEL}.
yuuji@gentei.org
parents:
142
diff
changeset
|
669 (save-excursion |
191cffccc912
Replace all \ref{LABEL} when changing \label{LABEL}.
yuuji@gentei.org
parents:
142
diff
changeset
|
670 (delq nil (mapcar (function (lambda (buf) |
191cffccc912
Replace all \ref{LABEL} when changing \label{LABEL}.
yuuji@gentei.org
parents:
142
diff
changeset
|
671 (set-buffer buf) |
191cffccc912
Replace all \ref{LABEL} when changing \label{LABEL}.
yuuji@gentei.org
parents:
142
diff
changeset
|
672 (if (eq major-mode 'yatex-mode) buf))) |
191cffccc912
Replace all \ref{LABEL} when changing \label{LABEL}.
yuuji@gentei.org
parents:
142
diff
changeset
|
673 (buffer-list))))) |
191cffccc912
Replace all \ref{LABEL} when changing \label{LABEL}.
yuuji@gentei.org
parents:
142
diff
changeset
|
674 |
51 | 675 (defun foreach-buffers (pattern job) |
676 "For each buffer which matches with PATTERN, do JOB." | |
677 (let ((list (buffer-list))) | |
678 (save-excursion | |
679 (while list | |
680 (set-buffer (car list)) | |
681 (if (or (and (stringp pattern) | |
682 (buffer-file-name) | |
683 (string-match pattern (buffer-file-name))) | |
684 (and (symbolp pattern) major-mode (eq major-mode pattern))) | |
685 (eval job)) | |
69 | 686 (setq list (cdr list)))))) |
51 | 687 |
688 (defun goto-buffer-window (buffer) | |
689 "Select window which is bound to BUFFER. | |
690 If no such window exist, switch to buffer BUFFER." | |
52 | 691 (interactive "BGoto buffer: ") |
51 | 692 (if (stringp buffer) |
693 (setq buffer (or (get-file-buffer buffer) (get-buffer buffer)))) | |
694 (if (get-buffer buffer) | |
695 (cond | |
696 ((get-buffer-window buffer) | |
697 (select-window (get-buffer-window buffer))) | |
698 ((and YaTeX-emacs-19 (get-buffer-window buffer t)) | |
699 (let*((win (get-buffer-window buffer t)) | |
700 (frame (window-frame win))) | |
701 (select-frame frame) | |
702 (raise-frame frame) | |
703 (focus-frame frame) | |
704 (select-window win) | |
705 (set-mouse-position frame 0 0) | |
706 (and (featurep 'windows) (fboundp 'win:adjust-window) | |
707 (win:adjust-window)))) | |
54 | 708 ((and (featurep 'windows) (fboundp 'win:get-buffer-window) |
56 | 709 (let ((w (win:get-buffer-window buffer))) |
710 (and w (win:switch-window w)))) | |
54 | 711 (select-window (get-buffer-window buffer))) |
69 | 712 (t (switch-to-buffer buffer))))) |
51 | 713 |
714 ;; Here starts the functions which support gmhist-vs-Emacs19 compatible | |
715 ;; reading with history. | |
716 ;;;###autoload | |
717 (defun completing-read-with-history | |
718 (prompt table &optional predicate must-match initial hsym) | |
719 "Completing read with general history: gmhist, Emacs-19." | |
720 (let ((minibuffer-history | |
721 (or (symbol-value hsym) | |
722 (and (boundp 'minibuffer-history) minibuffer-history))) | |
723 (minibuffer-history-symbol (or hsym 'minibuffer-history))) | |
724 (prog1 | |
725 (if (fboundp 'completing-read-with-history-in) | |
726 (completing-read-with-history-in | |
727 minibuffer-history-symbol prompt table predicate must-match initial) | |
728 (completing-read prompt table predicate must-match initial)) | |
729 (if (and YaTeX-emacs-19 hsym) (set hsym minibuffer-history))))) | |
730 | |
731 ;;;###autoload | |
732 (defun read-from-minibuffer-with-history (prompt &optional init map read hsym) | |
733 "Read from minibuffer with general history: gmhist, Emacs-19." | |
734 (cond | |
735 (YaTeX-emacs-19 | |
736 (read-from-minibuffer prompt init map read hsym)) | |
737 (t | |
738 (let ((minibuffer-history-symbol hsym)) | |
739 (read-from-minibuffer prompt init map read))))) | |
740 | |
741 ;;;###autoload | |
742 (defun read-string-with-history (prompt &optional init hsym) | |
743 "Read string with history: gmhist(Emacs-18) and Emacs-19." | |
744 (cond | |
745 (YaTeX-emacs-19 | |
746 (read-from-minibuffer prompt init minibuffer-local-map nil hsym)) | |
747 ((featurep 'gmhist-mh) | |
748 (read-with-history-in hsym prompt init)) | |
749 (t (read-string prompt init)))) | |
23 | 750 |
69 | 751 ;;;###autoload |
752 (fset 'YaTeX-rassoc | |
753 (if (and nil (fboundp 'rassoc) (subrp (symbol-function 'rassoc))) | |
754 (symbol-function 'rassoc) | |
70 | 755 (function |
756 (lambda (key list) | |
757 (let ((l list)) | |
758 (catch 'found | |
759 (while l | |
760 (if (equal key (cdr (car l))) | |
761 (throw 'found (car l))) | |
762 (setq l (cdr l))))))))) | |
763 | |
764 (defun YaTeX-insert-file-contents (file visit &optional beg end) | |
765 (cond | |
72 | 766 ((and (string< "19" emacs-version) (not (featurep 'xemacs))) |
70 | 767 (insert-file-contents file visit beg end)) |
77 | 768 ((string-match "unix\\|linux" (symbol-name system-type)) |
70 | 769 (let ((default-process-coding-system |
72 | 770 (and (boundp '*noconv*) (list '*noconv*))) |
771 (file-coding-system (and (boundp '*noconv*) '*noconv*)) | |
70 | 772 kanji-fileio-code |
773 (default-process-kanji-code 0)) | |
774 (call-process shell-file-name file (current-buffer) nil | |
775 (or (and (boundp 'shell-command-option) | |
776 shell-command-option) | |
777 "-c") | |
77 | 778 (format "dd bs=1 count=%d | tail -c +%d" end beg)))) |
70 | 779 (t (insert-file-contents file)))) |
780 | |
781 (defun YaTeX-split-string (str &optional sep null) | |
782 "Split string STR by every occurrence of SEP(regexp). | |
783 If the optional second argument SEP is nil, it defaults to \"[ \f\t\n\r\v]+\". | |
784 Do not include null string by default. Non-nil for optional third argument | |
785 NULL includes null string in a list." | |
786 (let ((sep (or sep "[ \f\t\n\r\v]+")) | |
787 list m) | |
788 (while str | |
789 (if (setq m (string-match sep str)) | |
790 (progn | |
791 (if (or (> m 0) null) | |
792 (setq list (cons (substring str 0 m) list))) | |
793 (setq str (substring str (match-end 0)))) | |
794 (if (or null (string< "" str)) | |
795 (setq list (cons str list))) | |
796 (setq str nil))) | |
797 (nreverse list))) | |
69 | 798 |
73 | 799 ;;;###autoload |
800 (defun YaTeX-delete1 (elt list) | |
801 "Delete" | |
802 (let (e) | |
803 (while (setq e (YaTeX-member elt list)) | |
804 (setq list (delq (car e) list)))) | |
805 list) | |
806 (if (fboundp 'delete) | |
807 (fset 'YaTeX-delete (symbol-function 'delete)) | |
808 (fset 'YaTeX-delete (symbol-function 'YaTeX-delete1))) | |
809 | |
810 (defun YaTeX-member1 (elt list) | |
811 (catch 'found | |
812 (while list | |
813 (if (equal elt (car list)) | |
814 (throw 'found list)) | |
815 (setq list (cdr list))))) | |
816 | |
817 (if (and (fboundp 'member) (subrp (symbol-function 'member))) | |
818 (fset 'YaTeX-member (symbol-function 'member)) | |
819 (fset 'YaTeX-member (symbol-function 'YaTeX-member1))) | |
820 | |
53
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
821 ;;; |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
822 ;; Interface function for windows.el |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
823 ;;; |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
824 ;;;###autoload |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
825 (defun YaTeX-switch-to-window () |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
826 "Switch to windows.el's window decided by last pressed key." |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
827 (interactive) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
828 (or (featurep 'windows) (error "Why don't you use `windows.el'?")) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
829 (win-switch-to-window 1 (- last-command-char win:base-key))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
830 |
64 | 831 ;;;###autoload |
138 | 832 (defun YaTeX-command-to-string (cmd) |
833 (if (fboundp 'shell-command-to-string) | |
834 (funcall 'shell-command-to-string cmd) | |
835 (let ((tbuf " *tmpout*")) | |
836 (if (get-buffer-create tbuf) (kill-buffer tbuf)) | |
837 (let ((standard-output (get-buffer-create tbuf))) | |
838 (unwind-protect | |
839 (save-excursion | |
840 (call-process | |
841 shell-file-name nil tbuf nil YaTeX-shell-command-option cmd) | |
842 (set-buffer tbuf) | |
843 (buffer-string)) | |
844 (kill-buffer tbuf)))))) | |
845 | |
846 ;;;###autoload | |
64 | 847 (defun YaTeX-reindent (col) |
848 "Remove current indentation and reindento to COL column." | |
849 (save-excursion | |
850 (beginning-of-line) | |
851 (skip-chars-forward " \t") | |
852 (if (/= col (current-column)) | |
853 (progn | |
854 (delete-region (point) (progn (beginning-of-line) (point))) | |
855 (indent-to col)))) | |
856 (skip-chars-forward " \t" (point-end-of-line))) | |
857 | |
858 (defun YaTeX-inner-environment (&optional quick) | |
859 "Return current inner-most environment. | |
860 Non-nil for optional argument QUICK restricts search bound to most | |
861 recent sectioning command. Matching point is stored to property 'point | |
862 of 'YaTeX-inner-environment, which can be referred by | |
863 (get 'YaTeX-inner-environment 'point)." | |
73 | 864 (put 'YaTeX-inner-environment 'point (point-min)) |
865 (put 'YaTeX-inner-environment 'indent 0) | |
64 | 866 (let*((nest 0) |
867 (beg (YaTeX-replace-format-args | |
868 (regexp-quote YaTeX-struct-begin) | |
869 ;YaTeX-struct-begin ;=== TENTATIVE!! == | |
870 YaTeX-struct-name-regexp | |
871 (if (eq major-mode 'yahtml-mode) "\\s *.*" "") | |
872 "")) | |
873 (end (YaTeX-replace-format-args | |
874 (regexp-quote YaTeX-struct-end) | |
875 YaTeX-struct-name-regexp "" "")) | |
876 (begend (concat "\\(" beg "\\)\\|\\(" end "\\)")) | |
877 bound m0 | |
878 (htmlp (eq major-mode 'yahtml-mode)) | |
879 (open | |
880 (concat "^" (or (cdr (assq major-mode '((yahtml-mode . "<")))) "{"))) | |
881 (close | |
882 (concat "^" | |
883 (or (cdr(assq major-mode '((yahtml-mode . "\n\t >")))) "}")))) | |
884 (save-excursion | |
885 (if quick | |
886 (setq bound | |
887 (save-excursion | |
888 (if htmlp | |
889 ;;(re-search-backward YaTeX-sectioning-regexp nil 1) | |
73 | 890 ;;(goto-char (point-min)) ;Is this enough? 97/6/26 |
891 (re-search-backward yahtml-indentation-boundary nil 1) | |
64 | 892 (YaTeX-re-search-active-backward |
893 (concat YaTeX-ec-regexp | |
894 "\\(" YaTeX-sectioning-regexp "\\)\\*?{") | |
895 YaTeX-comment-prefix nil 1)) | |
896 (or (bobp) (end-of-line)) | |
897 (point)))) | |
898 (if (catch 'begin | |
899 (if (and (numberp bound) (< (point) bound)) (throw 'begin nil)) | |
900 (while (YaTeX-re-search-active-backward | |
901 begend YaTeX-comment-prefix bound t) | |
902 (setq m0 (match-beginning 0)) | |
903 (if (looking-at end) ;;(match-beginning 2) | |
904 (setq nest (1+ nest)) | |
905 (setq nest (1- nest))) | |
906 (if (< nest 0) | |
907 (progn | |
908 (put 'YaTeX-inner-environment 'point m0) | |
909 (goto-char m0) | |
910 (put 'YaTeX-inner-environment 'indent (current-column)) | |
911 (throw 'begin t))))) | |
912 (buffer-substring | |
913 (progn (skip-chars-forward open) (1+ (point))) | |
69 | 914 (progn (skip-chars-forward close) (point))))))) |
64 | 915 |
73 | 916 (defun YaTeX-goto-corresponding-environment (&optional allow-mismatch noerr) |
917 "Go to corresponding begin/end enclosure. | |
918 Optional argument ALLOW-MISMATCH allows mismatch open/clese. Use this | |
919 for \left(, \right). | |
920 Optional third argument NOERR causes no error for unballanced environment." | |
921 (interactive) | |
922 (if (not (YaTeX-on-begin-end-p)) nil | |
923 (let ((p (match-end 0)) b0 b1 env (nest 0) regexp re-s (op (point)) | |
924 (m0 (match-beginning 0)) ;whole matching | |
925 (m1 (match-beginning 1)) ;environment in \begin{} | |
926 (m2 (match-beginning 2)) ;environment in \end{} | |
927 (m3 (match-beginning 3))) ;environment in \[ \] \( \) | |
928 ;(setq env (regexp-quote (buffer-substring p (match-beginning 0)))) | |
929 (if (cond | |
930 (m1 ;if begin{xxx} | |
931 (setq env | |
932 (if allow-mismatch YaTeX-struct-name-regexp | |
933 (regexp-quote (buffer-substring m1 (match-end 1))))) | |
934 ; (setq regexp (concat "\\(\\\\end{" env "}\\)\\|" | |
935 ; "\\(\\\\begin{" env "}\\)")) | |
936 (setq regexp | |
937 (concat | |
938 "\\(" | |
939 (YaTeX-replace-format-args | |
940 (regexp-quote YaTeX-struct-end) env "" "") | |
941 "\\)\\|\\(" | |
942 (YaTeX-replace-format-args | |
943 (regexp-quote YaTeX-struct-begin) env "" "") | |
944 "\\)")) | |
945 (setq re-s 're-search-forward)) | |
946 (m2 ;if end{xxx} | |
947 (setq env | |
948 (if allow-mismatch YaTeX-struct-name-regexp | |
949 (regexp-quote (buffer-substring m2 (match-end 2))))) | |
950 ; (setq regexp (concat "\\(\\\\begin{" env "}\\)\\|" | |
951 ; "\\(\\\\end{" env "}\\)")) | |
952 (setq regexp | |
953 (concat | |
954 "\\(" | |
955 (YaTeX-replace-format-args | |
956 (regexp-quote YaTeX-struct-begin) env "" "") | |
957 "\\)\\|\\(" | |
958 (YaTeX-replace-format-args | |
959 (regexp-quote YaTeX-struct-end) env "" "") | |
960 "\\)")) | |
961 (setq re-s 're-search-backward)) | |
962 (m3 ;math environment | |
963 (setq env (char-after (1+ m3)) | |
964 regexp (format "\\(%s%s\\)\\|\\(%s%s\\)" | |
965 YaTeX-ec-regexp | |
966 (regexp-quote | |
967 (cdr (assq env '((?( . ")") (?) . "(") | |
968 (?[ . "]") (?] . "["))))) | |
969 YaTeX-ec-regexp | |
970 (regexp-quote (char-to-string env))) | |
971 re-s (if (memq env '(?\( ?\[)) | |
972 're-search-forward | |
973 're-search-backward))) | |
974 (t (if noerr nil (error "Corresponding environment not found.")))) | |
975 (progn | |
976 (while (and (>= nest 0) (funcall re-s regexp nil t)) | |
977 (setq b0 (match-beginning 0) b1 (match-beginning 1)) | |
978 (if (or (equal b0 m0) | |
979 (YaTeX-literal-p b0)) | |
980 nil | |
981 (setq nest (if (equal b0 b1) | |
982 (1- nest) (1+ nest))))) | |
983 (if (< nest 0) | |
984 (goto-char (match-beginning 0)) ;found. | |
985 (goto-char op) | |
986 (funcall | |
987 (if noerr 'message 'error) | |
988 "Corresponding environment `%s' not found." env) | |
989 (sit-for 1) | |
990 nil)))))) | |
991 | |
64 | 992 (defun YaTeX-end-environment () |
993 "Close opening environment" | |
994 (interactive) | |
995 (let ((env (YaTeX-inner-environment))) | |
996 (if (not env) (error "No premature environment") | |
997 (save-excursion | |
998 (if (YaTeX-search-active-forward | |
999 (YaTeX-replace-format-args YaTeX-struct-end env "" "") | |
1000 YaTeX-comment-prefix nil t) | |
1001 (if (y-or-n-p | |
1002 (concat "Environment `" env | |
1003 "' may be already closed. Force close?")) | |
1004 nil | |
1005 (error "end environment aborted.")))) | |
1006 (message "") ;Erase (y or n) message. | |
1007 (YaTeX-insert-struc 'end env) | |
1008 (save-excursion | |
1009 (goto-char (or (get 'YaTeX-inner-environment 'point) (match-end 0))) | |
1010 (if (pos-visible-in-window-p) | |
1011 (sit-for (if YaTeX-dos 2 1)) | |
1012 (message "Matches with %s at line %d" | |
1013 (YaTeX-replace-format-args YaTeX-struct-begin env "" "") | |
69 | 1014 (count-lines (point-min) (point)))))))) |
64 | 1015 |
70 | 1016 (defun YaTeX-beginning-of-environment (&optional limit-search-bound end) |
1017 "Goto the beginning of the current environment. | |
1018 Optional argument LIMIT-SEARCH-BOUND non-nil limits the search bound to | |
1019 most recent sectioning command. Non-nil for optional third argument END | |
1020 goes to end of environment." | |
1021 (interactive) | |
1022 (let ((op (point))) | |
1023 (if (YaTeX-inner-environment limit-search-bound) | |
1024 (progn | |
1025 (goto-char (get 'YaTeX-inner-environment 'point)) | |
1026 (and end (YaTeX-goto-corresponding-environment)) | |
1027 (if (interactive-p) (push-mark op)) | |
80 | 1028 (point))))) |
70 | 1029 |
1030 (defun YaTeX-end-of-environment (&optional limit-search-bound) | |
1031 "Goto the end of the current environment. | |
1032 Optional argument LIMIT-SEARCH-BOUND non-nil limits the search bound | |
1033 to most recent sectioning command." | |
1034 (interactive) | |
1035 (YaTeX-beginning-of-environment limit-search-bound t)) | |
1036 | |
1037 (defun YaTeX-mark-environment () | |
1038 "Mark current position and move point to end of environment." | |
1039 (interactive) | |
130
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1040 (require 'yatexmth) |
70 | 1041 (let ((curp (point))) |
130
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1042 (if (YaTeX-in-math-mode-p) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1043 (YaTeX-mark-mathenv) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1044 (if (and (YaTeX-on-begin-end-p) (match-beginning 1)) ;if on \\begin |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1045 (progn (goto-char (match-end 0))) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1046 (if (= (char-after (point)) ?\\) nil ;if on \\end |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1047 (skip-chars-backward "^\n\\\\") |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1048 (or (bolp) (forward-char -1)))) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1049 (if (not (YaTeX-end-of-environment)) ;arg1 turns to match-beginning 1 |
70 | 1050 (progn |
130
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1051 (goto-char curp) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1052 (error "Cannot found the end of current environment.")) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1053 (YaTeX-goto-corresponding-environment) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1054 (beginning-of-line) ;for confirmation |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1055 (if (< curp (point)) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1056 (progn |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1057 (message "Mark this environment?(y or n): ") |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1058 (if (= (read-char) ?y) nil |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1059 (goto-char curp) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1060 (error "Abort. Please call again at more proper position.")))) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1061 (set-mark-command nil) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1062 (YaTeX-goto-corresponding-environment) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1063 (end-of-line) |
8703f090c628
`[prefix] t e' for YaTeX-typeset-environment.
yuuji@gentei.org
parents:
88
diff
changeset
|
1064 (if (eobp) nil (forward-char 1)))))) |
70 | 1065 |
72 | 1066 (defun YaTeX-kill-buffer (buffer) |
1067 "Make effort to show parent buffer after kill." | |
1068 (interactive "bKill buffer: ") | |
1069 (or (get-buffer buffer) | |
1070 (error "No such buffer %s" buffer)) | |
1071 (let ((pf YaTeX-parent-file)) | |
1072 (kill-buffer buffer) | |
1073 (and pf | |
1074 (get-file-buffer pf) | |
1075 (switch-to-buffer (get-file-buffer pf))))) | |
70 | 1076 |
142 | 1077 (defun YaTeX-get-builtin (key) |
1078 "Read source built-in command of %# usage." | |
1079 (catch 'builtin | |
1080 (let ((bl (delq nil (list (current-buffer) | |
1081 (and YaTeX-parent-file | |
1082 (get-file-buffer YaTeX-parent-file))))) | |
1083 (leader (or (cdr-safe (assq major-mode | |
1084 '((yatex-mode . "%#") | |
1085 (yahtml-mode . "<!-- #")))) | |
1086 ""))) | |
1087 (save-excursion | |
1088 (while bl | |
1089 (set-buffer (car bl)) | |
1090 (save-excursion | |
1091 (goto-char (point-min)) | |
1092 (if (and (re-search-forward | |
1093 (concat "^" (regexp-quote (concat leader key))) nil t) | |
1094 (not (eolp))) | |
1095 (throw 'builtin | |
1096 (YaTeX-buffer-substring | |
1097 (progn | |
1098 (skip-chars-forward " \t" (point-end-of-line)) | |
1099 (point)) | |
1100 (if (string< "" comment-end) | |
1101 (progn | |
1102 (search-forward | |
1103 comment-end (point-end-of-line) t) | |
1104 (match-beginning 0)) | |
1105 (point-end-of-line)))))) | |
1106 (setq bl (cdr bl))))))) | |
1107 | |
64 | 1108 ;;;VER2 |
1109 (defun YaTeX-insert-struc (what env) | |
1110 (cond | |
1111 ((eq what 'begin) | |
1112 (insert (YaTeX-replace-format-args | |
1113 YaTeX-struct-begin env (YaTeX-addin env)))) | |
1114 ((eq what 'end) | |
1115 (insert (YaTeX-replace-format-args YaTeX-struct-end env))) | |
69 | 1116 (t nil))) |
64 | 1117 |
80 | 1118 (defun YaTeX-string-width (str) |
1119 "Return the display width of string." | |
1120 (if (fboundp 'string-width) | |
1121 (string-width str) | |
1122 (length str))) | |
1123 (defun YaTeX-truncate-string-width (str width) | |
1124 (cond | |
1125 ((fboundp 'truncate-string-to-width) (truncate-string-to-width str width)) | |
1126 ((fboundp 'truncate-string) (truncate-string str width)) | |
1127 (t (substring str 0 width)))) | |
1128 | |
142 | 1129 (defun YaTeX-hex (str) |
1130 "Return int expressed by hexadecimal string STR." | |
1131 (if (string< "20" emacs-version) | |
1132 (string-to-number str 16) | |
1133 (let ((md (match-data))) | |
1134 (unwind-protect | |
1135 (if (string-match "[^0-9a-f]" str) | |
1136 (error "Non hexadecimal character in %s" str) | |
1137 (let ((i 0) d) | |
1138 (setq str (downcase str)) | |
1139 (while (string< "" str) | |
1140 (setq d (+ 0 (string-to-char str)) ; + 0 for XEmacs | |
1141 i (+ (* 16 i) (- d (if (<= d ?9) ?0 (- ?a 10)))) | |
1142 str (substring str 1))) | |
1143 i)) | |
1144 (store-match-data md))))) | |
1145 | |
1146 | |
64 | 1147 ;;; Function for menu support |
1148 (defun YaTeX-define-menu (keymap bindlist) | |
1149 "Define KEYMAP(symbol)'s menu-bindings according to BINDLIST. | |
1150 KEYMAP should be a quoted symbol of newly allocated keymap. | |
1151 BINDLIST consists of binding list. Each element is as follows. | |
1152 | |
1153 '(menusymbol DOC_String . contents) | |
1154 | |
1155 CONTENTS is one of lambda-form, interactive function, or other keymap. | |
1156 See yatex19.el for example." | |
1157 (cond | |
1158 ((featurep 'xemacs) | |
1159 (let (name) | |
1160 (if (keymapp (symbol-value keymap)) | |
1161 (progn | |
1162 (setq name (keymap-name (symbol-value keymap))) | |
1163 (set keymap nil)) | |
1164 (setq name (car (symbol-value keymap))) | |
1165 (set keymap (cdr (symbol-value keymap)))) | |
1166 (mapcar | |
1167 (function | |
1168 (lambda (bind) | |
1169 (setq bind (cdr bind)) | |
1170 (if (eq (car-safe (cdr bind)) 'lambda) | |
1171 (setcar (cdr bind) 'progn)) | |
1172 (if (stringp (car-safe (cdr bind))) | |
1173 (set keymap | |
1174 (cons (cdr bind) (symbol-value keymap))) | |
1175 (set keymap | |
1176 (cons (vector (car bind) (cdr bind) t) | |
1177 (symbol-value keymap)))))) | |
1178 bindlist) | |
1179 (set keymap (cons name (symbol-value keymap))))) | |
1180 (t | |
1181 (mapcar | |
1182 (function | |
1183 (lambda (bind) | |
1184 (define-key (symbol-value keymap) (vector (car bind)) (cdr bind)))) | |
1185 bindlist)))) | |
1186 | |
72 | 1187 ;;; |
1188 ;; Emacs 21 compensational wrapper | |
1189 ;;; | |
1190 (defun YaTeX-minibuffer-begin () | |
1191 (if (fboundp 'field-beginning) | |
1192 (field-beginning (point-max)) | |
1193 (point-min))) | |
1194 | |
1195 (defun YaTeX-minibuffer-end () | |
1196 (if (fboundp 'field-end) | |
1197 (field-end (point-max)) | |
1198 (point-max))) | |
1199 | |
1200 (defun YaTeX-minibuffer-string () | |
1201 (buffer-substring (YaTeX-minibuffer-begin) (YaTeX-minibuffer-end))) | |
1202 | |
1203 (defun YaTeX-minibuffer-erase () | |
1204 (if (eq (selected-window) (minibuffer-window)) | |
1205 (if (fboundp 'delete-field) (delete-field) (erase-buffer)))) | |
1206 | |
80 | 1207 (fset 'YaTeX-buffer-substring |
1208 (if (fboundp 'buffer-substring-no-properties) | |
1209 'buffer-substring-no-properties | |
1210 'buffer-substring)) | |
1211 | |
72 | 1212 ;;; |
1213 ;; hilit19 vs. font-lock | |
1214 ;;; | |
80 | 1215 (defvar YaTeX-19-functions-font-lock-direct |
1216 '(YaTeX-19-re-search-in-env)) | |
1217 | |
72 | 1218 (defun YaTeX-convert-pattern-hilit2fontlock (h19pa) |
1219 "Convert hilit19's H19PA patterns alist to font-lock's one. | |
1220 This function is a makeshift for YaTeX and yahtml." | |
1221 (let ((ignorecase (not (null (car h19pa)))) | |
1222 (palist (cdr h19pa)) | |
1223 flpa i newface | |
1224 (mapping | |
1225 '((bold . YaTeX-font-lock-bold-face) | |
1226 (italic . YaTeX-font-lock-italic-face) | |
73 | 1227 (defun . font-lock-function-name-face) |
1228 (define . font-lock-variable-name-face) | |
72 | 1229 (keyword . font-lock-keyword-face) |
1230 (decl . YaTeX-font-lock-declaration-face) | |
1231 (label . YaTeX-font-lock-label-face) | |
1232 (crossref . YaTeX-font-lock-crossref-face) | |
1233 (include . YaTeX-font-lock-include-face) | |
1234 (formula . YaTeX-font-lock-formula-face) | |
80 | 1235 (delimiter . YaTeX-font-lock-delimiter-face) |
72 | 1236 (string . ignore) (comment . ignore) |
1237 ))) | |
1238 (while (setq i (car palist)) | |
1239 (setq newface (nth 2 i) | |
1240 newface (or (cdr (assq newface mapping)) newface)) | |
1241 (cond | |
1242 ((eq newface 'ignore) nil) ;no translation | |
1243 ((stringp (car i)) ;hiliting by regexp | |
1244 (setq flpa | |
1245 (cons | |
1246 (if (numberp (car (cdr i))) | |
1247 (list (car i) ;regexp | |
1248 (car (cdr i)) ;matching group number | |
73 | 1249 newface nil) ;'keep) ;keep is hilit19 taste |
72 | 1250 (list |
1251 (concat | |
1252 (car i) ;original regexp and.. | |
1253 ;;"[^" | |
1254 ;;(regexp-quote (substring (car (cdr i)) 0 1)) | |
1255 ;;"]+" ;for shortest match | |
1256 ".*" | |
1257 (car (cdr i))) | |
73 | 1258 0 (list 'quote newface) nil)) ;;'keep)) |
72 | 1259 flpa))) |
1260 ((and (symbolp (car i)) (fboundp (car i))) | |
80 | 1261 (if (memq (car i) YaTeX-19-functions-font-lock-direct) |
1262 ;; Put direct function call for it. | |
1263 ;; When calling this function, fontify entire matched string. | |
1264 (setq flpa | |
1265 (cons | |
1266 (list | |
1267 (list 'lambda (list 'dummy) ;dummy should be boundary | |
1268 (list (car i) (list 'quote (car (cdr i))))) | |
1269 (list 0 newface)) | |
1270 flpa)) | |
1271 (setq flpa | |
1272 (cons | |
1273 (list (car (cdr i)) ;regexp | |
72 | 1274 (list |
1275 (list | |
80 | 1276 'lambda (list 'dummy) |
1277 '(goto-char (match-beginning 0)) | |
1278 (if (eq (nth 3 i) 'overwrite) | |
1279 nil | |
1280 '(remove-text-properties | |
1281 (point) (min (point-max) (1+ (point))) | |
1282 '(face nil font-lock-multiline nil))) | |
72 | 1283 (list |
80 | 1284 'let (list '(e (match-end 0)) |
1285 (list 'm (list (car i) (car (cdr i))))) | |
1286 (list | |
1287 'if 'm | |
1288 (list | |
1289 'YaTeX-font-lock-fillin | |
1290 (list 'car 'm) | |
1291 (list 'cdr 'm) | |
1292 (list 'quote 'face) | |
1293 (list 'quote 'font-lock) | |
1294 (list 'quote newface)) | |
1295 '(goto-char e) | |
1296 )) | |
1297 nil) ;retun nil to cheat font-lock | |
1298 nil nil)) ;pre-match, post-match both nil | |
1299 flpa))))) | |
72 | 1300 (setq palist (cdr palist)));while |
1301 (if (featurep 'xemacsp) | |
1302 (nreverse flpa) | |
1303 flpa))) | |
1304 | |
73 | 1305 (if (and (boundp 'YaTeX-use-font-lock) |
1306 YaTeX-use-font-lock) | |
1307 (require 'font-lock)) | |
1308 | |
72 | 1309 (cond |
73 | 1310 ((and (featurep 'font-lock) (fboundp 'defface)) |
72 | 1311 ;; In each defface, '(class static-color) is for Emacs-21 -nw |
1312 ;; '(class tty) is for XEmacs-21 -nw | |
1313 (defface YaTeX-font-lock-label-face | |
1314 '((((class static-color)) (:foreground "yellow" :underline t)) | |
1315 (((type tty)) (:foreground "yellow" :underline t)) | |
1316 (((class color) (background dark)) (:foreground "pink" :underline t)) | |
1317 (((class color) (background light)) (:foreground "red" :underline t)) | |
1318 (t (:bold t :underline t))) | |
1319 "Font Lock mode face used to highlight labels." | |
1320 :group 'font-lock-faces) | |
1321 (defvar YaTeX-font-lock-label-face 'YaTeX-font-lock-label-face) | |
1322 | |
1323 (defface YaTeX-font-lock-declaration-face | |
1324 '((((class color) (background dark)) (:foreground "cyan")) | |
1325 (((class color) (background light)) (:foreground "RoyalBlue")) | |
1326 (t (:bold t :underline t))) | |
1327 "Font Lock mode face used to highlight some declarations." | |
1328 :group 'font-lock-faces) | |
1329 (defvar YaTeX-font-lock-declaration-face 'YaTeX-font-lock-declaration-face) | |
1330 | |
1331 (defface YaTeX-font-lock-include-face | |
1332 '((((class color) (background dark)) (:foreground "Plum1")) | |
1333 (((class color) (background light)) (:foreground "purple")) | |
1334 (t (:bold t :underline t))) | |
1335 "Font Lock mode face used to highlight expression for including." | |
1336 :group 'font-lock-faces) | |
1337 (defvar YaTeX-font-lock-include-face 'YaTeX-font-lock-include-face) | |
1338 | |
1339 (defface YaTeX-font-lock-formula-face | |
1340 '((((class static-color)) (:bold t)) | |
1341 (((type tty)) (:bold t)) | |
1342 (((class color) (background dark)) (:foreground "khaki" :bold t)) | |
1343 (((class color) (background light)) (:foreground "Goldenrod")) | |
1344 (t (:bold t :underline t))) | |
1345 "Font Lock mode face used to highlight formula." | |
1346 :group 'font-lock-faces) | |
1347 (defvar YaTeX-font-lock-formula-face 'YaTeX-font-lock-formula-face) | |
1348 | |
80 | 1349 (defface YaTeX-font-lock-delimiter-face |
1350 '((((class static-color)) (:bold t)) | |
1351 (((type tty)) (:bold t)) | |
1352 (((class color) (background dark)) | |
1353 (:foreground "saddlebrown" :background "ivory" :bold t)) | |
1354 (((class color) (background light)) (:foreground "red")) | |
1355 (t (:bold t :underline t))) | |
1356 "Font Lock mode face used to highlight delimiters." | |
1357 :group 'font-lock-faces) | |
1358 (defvar YaTeX-font-lock-delimiter-face 'YaTeX-font-lock-delimiter-face) | |
1359 | |
1360 (defface YaTeX-font-lock-math-sub-face | |
1361 '((((class static-color)) (:bold t)) | |
1362 (((type tty)) (:bold t)) | |
1363 (((class color) (background dark)) | |
1364 (:foreground "khaki" :bold t :underline t)) | |
1365 (((class color) (background light)) | |
1366 (:foreground "Goldenrod" :underline t)) | |
1367 (t (:bold t :underline t))) | |
1368 "Font Lock mode face used to highlight subscripts in formula." | |
1369 :group 'font-lock-faces) | |
1370 (defvar YaTeX-font-lock-math-sub-face 'YaTeX-font-lock-math-sub-face) | |
1371 | |
1372 (defface YaTeX-font-lock-math-sup-face | |
1373 '((((class static-color)) (:bold t)) | |
1374 (((type tty)) (:bold t)) | |
1375 (((class color) (background dark)) | |
1376 (:bold nil :foreground "ivory" :background "lightyellow4")) | |
1377 (((class color) (background light)) | |
1378 (:underline t :foreground "gold")) | |
1379 (t (:bold t :underline t))) | |
1380 "Font Lock mode face used to highlight superscripts in formula." | |
1381 :group 'font-lock-faces) | |
1382 (defvar YaTeX-font-lock-math-sup-face 'YaTeX-font-lock-math-sup-face) | |
1383 | |
72 | 1384 (defface YaTeX-font-lock-crossref-face |
1385 '((((class color) (background dark)) (:foreground "lightgoldenrod")) | |
1386 (((class color) (background light)) (:foreground "DarkGoldenrod")) | |
1387 (t (:bold t :underline t))) | |
80 | 1388 "Font Lock mode face used to highlight cross references." |
72 | 1389 :group 'font-lock-faces) |
1390 (defvar YaTeX-font-lock-crossref-face 'YaTeX-font-lock-crossref-face) | |
1391 | |
1392 (defface YaTeX-font-lock-bold-face | |
1393 '((t (:bold t))) | |
1394 "Font Lock mode face used to express bold itself." | |
1395 :group 'font-lock-faces) | |
1396 (defvar YaTeX-font-lock-bold-face 'YaTeX-font-lock-bold-face) | |
1397 | |
1398 (defface YaTeX-font-lock-italic-face | |
1399 '((t (:italic t))) | |
1400 "Font Lock mode face used to express italic itself." | |
1401 :group 'font-lock-faces) | |
1402 (defvar YaTeX-font-lock-italic-face 'YaTeX-font-lock-italic-face) | |
1403 | |
1404 ;; Make sure the 'YaTeX-font-lock-{italic,bold}-face is bound with | |
1405 ;; italic/bold fontsets | |
1406 (if (and (fboundp 'fontset-list) YaTeX-use-italic-bold) | |
73 | 1407 (let ((flist (fontset-list)) fnt italic bold |
1408 (df (or (and (fboundp 'face-font-name) (face-font-name 'default)) | |
1409 (face-font 'default) | |
1410 (face-font 'italic) | |
1411 (face-font 'bold) | |
1412 "giveup!")) | |
1413 sz medium-i bold-r) | |
1414 (string-match | |
1415 "^-[^-]*-[^-]*-[^-]*-[^-]*-[^-]*-[^-]*-\\(\\([0-9]+\\)\\)" df) | |
1416 (setq sz (or (match-string 1 df) "16")) | |
1417 (setq medium-i (format "-medium-i-[^-]+--%s" sz) | |
1418 bold-r (format "-bold-r-[^-]+--%s" sz)) | |
72 | 1419 (while flist |
1420 (setq fnt (car flist)) | |
1421 (condition-case err | |
1422 (cond | |
73 | 1423 ((and (string-match medium-i fnt) |
1424 (null italic)) | |
72 | 1425 (set-face-font 'YaTeX-font-lock-italic-face (setq italic fnt))) |
73 | 1426 ((and (string-match bold-r fnt) (null bold)) |
72 | 1427 (set-face-font 'YaTeX-font-lock-bold-face (setq bold fnt)))) |
1428 (error nil)) | |
1429 (setq flist (cdr flist))))) | |
1430 | |
1431 ;;Borrowed from XEmacs's font-lock.el | |
1432 (defsubst YaTeX-font-lock-fillin (start end setprop markprop value &optional object) | |
1433 "Fill in one property of the text from START to END. | |
1434 Arguments PROP and VALUE specify the property and value to put where none are | |
1435 already in place. Therefore existing property values are not overwritten. | |
1436 Optional argument OBJECT is the string or buffer containing the text." | |
1437 (let ((start (text-property-any start end markprop nil object)) next | |
1438 (putfunc (if (fboundp 'put-nonduplicable-text-property) | |
1439 'put-nonduplicable-text-property | |
1440 'put-text-property))) | |
1441 (if (eq putfunc 'put-text-property) | |
1442 (setq markprop setprop)) | |
1443 (while start | |
1444 (setq next (next-single-property-change start markprop object end)) | |
1445 (funcall putfunc start next setprop value object) | |
1446 (funcall putfunc start next markprop value object) | |
1447 (setq start (text-property-any next end markprop nil object))))) | |
1448 | |
1449 (defun YaTeX-warning-font-lock (mode) | |
1450 (let ((sw (selected-window))) | |
1451 ;;(pop-to-buffer (format " *%s warning*" mode)) | |
1452 ;;(erase-buffer) | |
1453 (momentary-string-display | |
1454 (cond | |
1455 (YaTeX-japan | |
1456 (concat mode " は、既に font-lock に対応しました。\n" | |
1457 "~/.emacs などにある\n" | |
1458 "\t(put 'yatex-mode 'font-lock-keywords 'tex-mode)\n" | |
1459 "\t(put 'yahtml-mode 'font-lock-keywords 'html-mode)\n" | |
1460 "などの間に合わせの記述はもはや不要です。")) | |
1461 (t | |
1462 (concat mode " now supports the font-lock by itself.\n" | |
1463 "So you can remove the descriptions such as\n" | |
1464 "\t(put 'yatex-mode 'font-lock-keywords 'tex-mode)\n" | |
1465 "\t(put 'yahtml-mode 'font-lock-keywords 'html-mode)\n" | |
1466 "in your ~/.emacs file. Thank you."))) (point)) | |
1467 (select-window sw))) | |
1468 )) | |
1469 | |
80 | 1470 (defun YaTeX-assoc-regexp (elt alist) |
1471 "Like assoc, return a list of whose car match with ELT. Search from ALIST. | |
1472 Note that each car of cons-cell is regexp. ELT is a plain text to be | |
1473 compared by regexp." | |
1474 (let (x) | |
1475 (catch 'found | |
1476 (while alist | |
1477 (setq x (car (car alist))) | |
1478 (if (string-match x elt) | |
1479 (throw 'found (car alist))) | |
1480 (setq alist (cdr alist)))))) | |
64 | 1481 |
68 | 1482 ;;; |
1483 ;; Functions for the Installation time | |
1484 ;;; | |
64 | 1485 |
58
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
56
diff
changeset
|
1486 (defun bcf-and-exit () |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
56
diff
changeset
|
1487 "Byte compile rest of argument and kill-emacs." |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
56
diff
changeset
|
1488 (if command-line-args-left |
68 | 1489 (let ((load-path (cons "." load-path))) |
1490 (and (fboundp 'set-language-environment) | |
1491 (featurep 'mule) | |
1492 (set-language-environment "Japanese")) | |
58
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
56
diff
changeset
|
1493 (mapcar 'byte-compile-file command-line-args-left) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
56
diff
changeset
|
1494 (kill-emacs)))) |
64 | 1495 |
80 | 1496 (defun tfb-and-exit () |
1497 "Texinfo-format-buffer and kill-emacs." | |
1498 (if command-line-args-left | |
1499 (let ((load-path (cons ".." load-path))) | |
1500 (and (fboundp 'set-language-environment) | |
1501 (featurep 'mule) | |
1502 (set-language-environment "Japanese")) | |
1503 (mapcar (function | |
1504 (lambda (arg) | |
1505 (find-file arg) | |
1506 (texinfo-format-buffer) | |
1507 (basic-save-buffer))) | |
1508 command-line-args-left) | |
1509 (kill-emacs)))) | |
1510 | |
23 | 1511 (provide 'yatexlib) |
72 | 1512 ; Local variables: |
1513 ; fill-prefix: ";;; " | |
1514 ; paragraph-start: "^$\\|\\|;;;$" | |
1515 ; paragraph-separate: "^$\\|\\|;;;$" | |
80 | 1516 ; coding: sjis |
72 | 1517 ; End: |