yatex

view yatexlib.el @ 49:eb0512bfcb7f

Abolish user-article table. Use normal read-string instead. Supply smart add-in function for documentstyle. Update user dictionary whenever new words entered. Enhance [prefix] c. Allow user defined sectioning commands in yatexsec.
author yuuji
date Fri, 25 Nov 1994 08:26:13 +0000
parents d7e7b4654058
children b0371b6ed799
line source
1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX library of general functions.
3 ;;; yatexlib.el
4 ;;; (c )1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
5 ;;; Last modified Thu Nov 24 02:20:45 1994 on VFR
6 ;;; $Id$
8 ;;;###autoload
9 (defun YaTeX-search-active-forward (string cmntrx &optional bound err cnt func)
10 "Search STRING which is not commented out by CMNTRX.
11 Optional arguments after BOUND, ERR, CNT are passed literally to search-forward
12 or search-backward.
13 Optional sixth argument FUNC changes search-function."
14 (let ((sfunc (or func 'search-forward)) found md)
15 (while (and (prog1
16 (setq found (funcall sfunc string bound err cnt))
17 (setq md (match-data)))
18 (or
19 (YaTeX-in-verb-p (match-beginning 0))
20 (save-excursion
21 (beginning-of-line)
22 (re-search-forward cmntrx (match-beginning 0) t)))))
23 (store-match-data md)
24 found)
25 )
27 (defun YaTeX-re-search-active-forward (regexp cmntrx &optional bound err cnt)
28 "Search REGEXP backward which is not commented out by regexp CMNTRX.
29 See also YaTeX-search-active-forward."
30 (YaTeX-search-active-forward regexp cmntrx bound err cnt 're-search-forward)
31 )
32 (defun YaTeX-search-active-backward (string cmntrx &optional bound err cnt)
33 "Search STRING backward which is not commented out by regexp CMNTRX.
34 See also YaTeX-search-active-forward."
35 (YaTeX-search-active-forward string cmntrx bound err cnt 'search-backward)
36 )
37 (defun YaTeX-re-search-active-backward (regexp cmntrx &optional bound err cnt)
38 "Search REGEXP backward which is not commented out by regexp CMNTRX.
39 See also YaTeX-search-active-forward."
40 (YaTeX-search-active-forward regexp cmntrx bound err cnt 're-search-backward)
41 )
44 ;;;###autoload
45 (defun YaTeX-switch-to-buffer (file &optional setbuf)
46 "Switch to buffer if buffer exists, find file if not.
47 Optional second arg SETBUF t make use set-buffer instead of switch-to-buffer."
48 (interactive "Fswitch to file: ")
49 (let (buf)
50 (if (setq buf (get-buffer (file-name-nondirectory file)))
51 (progn
52 (funcall (if setbuf 'set-buffer 'switch-to-buffer)
53 (file-name-nondirectory file))
54 buf)
55 (if (file-exists-p file)
56 (funcall
57 (if setbuf 'find-file-noselect 'find-file)
58 file)
59 (message "%s was not found in this directory." file)
60 nil)))
61 )
63 ;;;###autoload
64 (defun YaTeX-switch-to-buffer-other-window (file)
65 "Switch to buffer if buffer exists, find file if not."
66 (interactive "Fswitch to file: ")
67 (if (get-buffer (file-name-nondirectory file))
68 (progn (switch-to-buffer-other-window file) t)
69 (if (file-exists-p file)
70 (progn (find-file-other-window file) t)
71 (message "%s was not found in this directory." file)
72 nil))
73 )
75 (defun YaTeX-replace-format-sub (string format repl)
76 (let ((beg (or (string-match (concat "^\\(%" format "\\)") string)
77 (string-match (concat "[^%]\\(%" format "\\)") string)))
78 (len (length format)))
79 (if (null beg) string ;no conversion
80 (concat
81 (substring string 0 (match-beginning 1)) repl
82 (substring string (match-end 1)))))
83 )
85 ;;;###autoload
86 (defun YaTeX-replace-format (string format repl)
87 "In STRING, replace first appearance of FORMAT to REPL as if
88 function `format' does. FORMAT does not contain `%'"
89 (let ((ans string))
90 (while (not (string=
91 ans (setq string (YaTeX-replace-format-sub ans format repl))))
92 (setq ans string))
93 string)
94 )
96 ;;;###autoload
97 (defun YaTeX-replace-format-args (string &rest args)
98 "Translate the argument mark #1, #2, ... #n in the STRING into the
99 corresponding real arguments ARGS."
100 (let ((argp 1))
101 (while args
102 (setq string
103 (YaTeX-replace-format string (int-to-string argp) (car args)))
104 (setq args (cdr args) argp (1+ argp))))
105 string
106 )
108 ;;;###autoload
109 (defun rindex (string char)
110 (let ((pos (1- (length string)))(index -1))
111 (while (>= pos 0)
112 (cond
113 ((= (aref string pos) char)
114 (setq index pos) (setq pos -1))
115 (t (setq pos (1- pos))))
116 )
117 index)
118 )
120 ;;;###autoload
121 (defun YaTeX-showup-buffer (buffer &optional func select)
122 "Make BUFFER show up in certain window (but current window)
123 that gives the maximum value by the FUNC. FUNC should take an argument
124 of its window object. Non-nil for optional third argument SELECT selects
125 that window. This function never selects minibuffer window."
126 (or (and (if YaTeX-emacs-19
127 (get-buffer-window buffer t)
128 (get-buffer-window buffer))
129 (progn
130 (if select
131 (cond
132 (YaTeX-emacs-19
133 (let ((frame (window-frame (get-buffer-window buffer t))))
134 (select-frame frame)
135 (focus-frame frame)
136 (set-mouse-position frame 0 0)
137 (raise-frame frame)
138 (select-window (get-buffer-window buffer))
139 (if (and (featurep 'windows)
140 (win:frame-window frame))
141 (win:adjust-window))))
142 (t
143 (select-window (get-buffer-window buffer)))))
144 t))
145 (let ((window (selected-window))
146 (wlist (YaTeX-window-list)) win w (x 0))
147 (cond
148 ((> (length wlist) 2)
149 (if func
150 (while wlist
151 (setq w (car wlist))
152 (if (and (not (eq window w))
153 (> (funcall func w) x))
154 (setq win w x (funcall func w)))
155 (setq wlist (cdr wlist)))
156 (setq win (get-lru-window)))
157 (select-window win)
158 (switch-to-buffer buffer)
159 (or select (select-window window)))
160 ((= (length wlist) 2)
161 ;(other-window 1);This does not work properly on Emacs-19
162 (select-window (get-lru-window))
163 (switch-to-buffer buffer)
164 (or select (select-window window)))
165 (t ;if one-window
166 (cond
167 ((and YaTeX-emacs-19 (get-buffer-window buffer t))
168 nil) ;if found in other frame
169 (YaTeX-default-pop-window-height
170 (split-window
171 (selected-window)
172 (max
173 (min
174 (- (screen-height)
175 (if (numberp YaTeX-default-pop-window-height)
176 (+ YaTeX-default-pop-window-height 2)
177 (/ (* (screen-height)
178 (string-to-int YaTeX-default-pop-window-height))
179 100)))
180 (- (screen-height) window-min-height 1))
181 window-min-height))
182 (pop-to-buffer buffer)
183 (or select (select-window window)))
184 (t nil)))
185 )))
186 )
188 ;;;###autoload
189 (defun YaTeX-window-list ()
190 (let*((curw (selected-window)) (win curw) (wlist (list curw)))
191 (while (not (eq curw (setq win (next-window win))))
192 (or (eq win (minibuffer-window))
193 (setq wlist (cons win wlist))))
194 wlist)
195 )
197 ;;;###autoload
198 (defun substitute-all-key-definition (olddef newdef keymap)
199 "Replace recursively OLDDEF with NEWDEF for any keys in KEYMAP now
200 defined as OLDDEF. In other words, OLDDEF is replaced with NEWDEF
201 where ever it appears."
202 (mapcar
203 (function (lambda (key) (define-key keymap key newdef)))
204 (where-is-internal olddef keymap))
205 )
207 ;;;###autoload
208 (defun YaTeX-match-string (n &optional m)
209 "Return (buffer-substring (match-beginning n) (match-beginning m))."
210 (if (match-beginning n)
211 (buffer-substring (match-beginning n)
212 (match-end (or m n))))
213 )
215 ;;;###autoload
216 (defun YaTeX-minibuffer-complete ()
217 "Complete in minibuffer.
218 If the symbol 'delim is bound and is string, its value is assumed to be
219 the character class of delimiters. Completion will be performed on
220 the last field separated by those delimiters."
221 (interactive)
222 (let (beg word compl (md (match-data)))
223 (setq beg (if (and (boundp 'delim) (stringp delim))
224 (save-excursion
225 (skip-chars-backward (concat "^" delim))
226 (point))
227 (point-min))
228 word (buffer-substring beg (point-max))
229 compl (try-completion word minibuffer-completion-table))
230 (cond
231 ((eq compl t)
232 (let ((p (point)) (max (point-max)))
233 (goto-char max)
234 (insert " [Sole completion]")
235 (goto-char p)
236 (sit-for 1)
237 (delete-region max (point-max))
238 (goto-char p)))
239 ((eq compl nil)
240 (ding)
241 (save-excursion
242 (let (p)
243 (goto-char (setq p (point-max)))
244 (insert " [No match]")
245 (goto-char p)
246 (sit-for 2)
247 (delete-region p (point-max)))))
248 ((string= compl word)
249 (with-output-to-temp-buffer "*Completions*"
250 (display-completion-list
251 (all-completions word minibuffer-completion-table))))
252 (t (delete-region beg (point-max))
253 (insert compl))
254 )
255 (store-match-data md))
256 )
259 (provide 'yatexlib)