yatex

view yatexlib.el @ 578:4dad5f91b26c

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