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