Mercurial > hgrepos > hgweb.cgi > yatex
annotate yatexlib.el @ 59:48ac97a6b6ce
Call drawing tools
ID completion (yahtml)
author | yuuji |
---|---|
date | Wed, 01 May 1996 15:35:40 +0000 |
parents | 3a7c0c2bf16d |
children | 36a48185b95a |
rev | line source |
---|---|
23 | 1 ;;; -*- Emacs-Lisp -*- |
2 ;;; YaTeX library of general functions. | |
3 ;;; yatexlib.el | |
52 | 4 ;;; (c )1994-1995 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp] |
59 | 5 ;;; Last modified Fri Apr 5 17:56:43 1996 on supra |
23 | 6 ;;; $Id$ |
7 | |
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." | |
49 | 14 (let ((sfunc (or func 'search-forward)) found md) |
23 | 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 ) | |
26 | |
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 ) | |
42 | |
43 | |
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: ") | |
52 | 49 (if (bufferp file) (setq file (buffer-file-name file))) |
50 (let (buf (hilit-auto-highlight (not setbuf))) | |
51 (cond | |
52 ((setq buf (get-file-buffer file)) | |
53 (funcall (if setbuf 'set-buffer 'switch-to-buffer) | |
54 (get-file-buffer file)) | |
55 buf) | |
56 ((or YaTeX-create-file-prefix-g (file-exists-p file)) | |
57 (or ;find-file returns nil but set current-buffer... | |
58 (if setbuf (set-buffer (find-file-noselect file)) | |
59 (find-file file)) | |
60 (current-buffer))) | |
61 (t (message "%s was not found in this directory." file) | |
23 | 62 nil))) |
63 ) | |
64 | |
65 ;;;###autoload | |
66 (defun YaTeX-switch-to-buffer-other-window (file) | |
67 "Switch to buffer if buffer exists, find file if not." | |
68 (interactive "Fswitch to file: ") | |
52 | 69 (if (bufferp file) (setq file (buffer-file-name file))) |
70 (cond | |
71 ((get-file-buffer file) | |
72 (switch-to-buffer-other-window (get-file-buffer file)) | |
73 t) | |
74 ((or YaTeX-create-file-prefix-g (file-exists-p file)) | |
75 (find-file-other-window file) t) | |
76 (t (message "%s was not found in this directory." file) | |
23 | 77 nil)) |
78 ) | |
79 | |
80 (defun YaTeX-replace-format-sub (string format repl) | |
81 (let ((beg (or (string-match (concat "^\\(%" format "\\)") string) | |
82 (string-match (concat "[^%]\\(%" format "\\)") string))) | |
83 (len (length format))) | |
84 (if (null beg) string ;no conversion | |
85 (concat | |
86 (substring string 0 (match-beginning 1)) repl | |
87 (substring string (match-end 1))))) | |
88 ) | |
89 | |
90 ;;;###autoload | |
91 (defun YaTeX-replace-format (string format repl) | |
92 "In STRING, replace first appearance of FORMAT to REPL as if | |
93 function `format' does. FORMAT does not contain `%'" | |
94 (let ((ans string)) | |
95 (while (not (string= | |
96 ans (setq string (YaTeX-replace-format-sub ans format repl)))) | |
97 (setq ans string)) | |
98 string) | |
99 ) | |
100 | |
101 ;;;###autoload | |
102 (defun YaTeX-replace-format-args (string &rest args) | |
103 "Translate the argument mark #1, #2, ... #n in the STRING into the | |
104 corresponding real arguments ARGS." | |
105 (let ((argp 1)) | |
106 (while args | |
107 (setq string | |
108 (YaTeX-replace-format string (int-to-string argp) (car args))) | |
109 (setq args (cdr args) argp (1+ argp)))) | |
110 string | |
111 ) | |
112 | |
113 ;;;###autoload | |
114 (defun rindex (string char) | |
115 (let ((pos (1- (length string)))(index -1)) | |
116 (while (>= pos 0) | |
117 (cond | |
118 ((= (aref string pos) char) | |
119 (setq index pos) (setq pos -1)) | |
120 (t (setq pos (1- pos)))) | |
121 ) | |
122 index) | |
123 ) | |
124 | |
125 ;;;###autoload | |
126 (defun YaTeX-showup-buffer (buffer &optional func select) | |
127 "Make BUFFER show up in certain window (but current window) | |
128 that gives the maximum value by the FUNC. FUNC should take an argument | |
129 of its window object. Non-nil for optional third argument SELECT selects | |
49 | 130 that window. This function never selects minibuffer window." |
53
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
131 (or (and (if (and YaTeX-emacs-19 select) |
47 | 132 (get-buffer-window buffer t) |
133 (get-buffer-window buffer)) | |
134 (progn | |
135 (if select | |
51 | 136 (goto-buffer-window buffer)) |
47 | 137 t)) |
23 | 138 (let ((window (selected-window)) |
139 (wlist (YaTeX-window-list)) win w (x 0)) | |
140 (cond | |
141 ((> (length wlist) 2) | |
142 (if func | |
143 (while wlist | |
144 (setq w (car wlist)) | |
145 (if (and (not (eq window w)) | |
146 (> (funcall func w) x)) | |
147 (setq win w x (funcall func w))) | |
148 (setq wlist (cdr wlist))) | |
149 (setq win (get-lru-window))) | |
150 (select-window win) | |
151 (switch-to-buffer buffer) | |
152 (or select (select-window window))) | |
153 ((= (length wlist) 2) | |
49 | 154 ;(other-window 1);This does not work properly on Emacs-19 |
155 (select-window (get-lru-window)) | |
23 | 156 (switch-to-buffer buffer) |
157 (or select (select-window window))) | |
158 (t ;if one-window | |
159 (cond | |
47 | 160 ((and YaTeX-emacs-19 (get-buffer-window buffer t)) |
161 nil) ;if found in other frame | |
23 | 162 (YaTeX-default-pop-window-height |
51 | 163 (split-window-calculate-height YaTeX-default-pop-window-height) |
59 | 164 ;;(pop-to-buffer buffer) ;damn! emacs-19.30 |
165 (select-window (next-window nil 1)) | |
166 (switch-to-buffer (get-buffer-create buffer)) | |
23 | 167 (or select (select-window window))) |
168 (t nil))) | |
169 ))) | |
170 ) | |
171 | |
172 ;;;###autoload | |
51 | 173 (defun split-window-calculate-height (height) |
174 "Split current window wight specified HEIGHT. | |
59 | 175 If HEIGHT is number, make a new window that has HEIGHT lines. |
176 If HEIGHT is string, make a new window that occupies HEIGT % of screen height. | |
51 | 177 Otherwise split window conventionally." |
59 | 178 (if (one-window-p t) |
51 | 179 (split-window |
180 (selected-window) | |
181 (max | |
182 (min | |
183 (- (screen-height) | |
59 | 184 (if (numberp height) |
185 (+ height 2) | |
51 | 186 (/ (* (screen-height) |
59 | 187 (string-to-int height)) |
51 | 188 100))) |
189 (- (screen-height) window-min-height 1)) | |
190 window-min-height))) | |
191 ) | |
192 | |
193 ;;;###autoload | |
23 | 194 (defun YaTeX-window-list () |
195 (let*((curw (selected-window)) (win curw) (wlist (list curw))) | |
196 (while (not (eq curw (setq win (next-window win)))) | |
197 (or (eq win (minibuffer-window)) | |
198 (setq wlist (cons win wlist)))) | |
199 wlist) | |
200 ) | |
201 | |
202 ;;;###autoload | |
203 (defun substitute-all-key-definition (olddef newdef keymap) | |
204 "Replace recursively OLDDEF with NEWDEF for any keys in KEYMAP now | |
205 defined as OLDDEF. In other words, OLDDEF is replaced with NEWDEF | |
206 where ever it appears." | |
207 (mapcar | |
208 (function (lambda (key) (define-key keymap key newdef))) | |
47 | 209 (where-is-internal olddef keymap)) |
23 | 210 ) |
211 | |
212 ;;;###autoload | |
213 (defun YaTeX-match-string (n &optional m) | |
214 "Return (buffer-substring (match-beginning n) (match-beginning m))." | |
215 (if (match-beginning n) | |
216 (buffer-substring (match-beginning n) | |
49 | 217 (match-end (or m n)))) |
23 | 218 ) |
219 | |
220 ;;;###autoload | |
221 (defun YaTeX-minibuffer-complete () | |
49 | 222 "Complete in minibuffer. |
51 | 223 If the symbol 'delim is bound and is string, its value is assumed to be |
49 | 224 the character class of delimiters. Completion will be performed on |
51 | 225 the last field separated by those delimiters. |
226 If the symbol 'quick is bound and is 't, when the try-completion results | |
227 in t, exit minibuffer immediately." | |
23 | 228 (interactive) |
51 | 229 (let ((md (match-data)) beg word compl |
230 (quick (and (boundp 'quick) (eq quick t))) | |
231 (displist ;function to display completion-list | |
232 (function | |
233 (lambda () | |
234 (with-output-to-temp-buffer "*Completions*" | |
235 (display-completion-list | |
236 (all-completions word minibuffer-completion-table))))))) | |
49 | 237 (setq beg (if (and (boundp 'delim) (stringp delim)) |
23 | 238 (save-excursion |
239 (skip-chars-backward (concat "^" delim)) | |
49 | 240 (point)) |
23 | 241 (point-min)) |
242 word (buffer-substring beg (point-max)) | |
243 compl (try-completion word minibuffer-completion-table)) | |
244 (cond | |
49 | 245 ((eq compl t) |
51 | 246 (if quick (exit-minibuffer) |
247 (let ((p (point)) (max (point-max))) | |
248 (unwind-protect | |
249 (progn | |
250 (goto-char max) | |
251 (insert " [Sole completion]") | |
252 (goto-char p) | |
253 (sit-for 1)) | |
254 (delete-region max (point-max)) | |
255 (goto-char p))))) | |
23 | 256 ((eq compl nil) |
257 (ding) | |
258 (save-excursion | |
259 (let (p) | |
51 | 260 (unwind-protect |
261 (progn | |
262 (goto-char (setq p (point-max))) | |
263 (insert " [No match]") | |
264 (goto-char p) | |
265 (sit-for 2)) | |
266 (delete-region p (point-max)))))) | |
23 | 267 ((string= compl word) |
51 | 268 (funcall displist)) |
23 | 269 (t (delete-region beg (point-max)) |
51 | 270 (insert compl) |
271 (if quick | |
272 (if (eq (try-completion compl minibuffer-completion-table) t) | |
273 (exit-minibuffer) | |
274 (funcall displist))))) | |
49 | 275 (store-match-data md)) |
23 | 276 ) |
277 | |
51 | 278 (defun YaTeX-minibuffer-quick-complete () |
279 "Set 'quick to 't and call YaTeX-minibuffer-complete. | |
280 See documentation of YaTeX-minibuffer-complete." | |
281 (interactive) | |
282 (let ((quick t)) | |
283 (self-insert-command 1) | |
284 (YaTeX-minibuffer-complete))) | |
285 | |
286 (defun foreach-buffers (pattern job) | |
287 "For each buffer which matches with PATTERN, do JOB." | |
288 (let ((list (buffer-list))) | |
289 (save-excursion | |
290 (while list | |
291 (set-buffer (car list)) | |
292 (if (or (and (stringp pattern) | |
293 (buffer-file-name) | |
294 (string-match pattern (buffer-file-name))) | |
295 (and (symbolp pattern) major-mode (eq major-mode pattern))) | |
296 (eval job)) | |
297 (setq list (cdr list))))) | |
298 ) | |
299 | |
300 (defun goto-buffer-window (buffer) | |
301 "Select window which is bound to BUFFER. | |
302 If no such window exist, switch to buffer BUFFER." | |
52 | 303 (interactive "BGoto buffer: ") |
51 | 304 (if (stringp buffer) |
305 (setq buffer (or (get-file-buffer buffer) (get-buffer buffer)))) | |
306 (if (get-buffer buffer) | |
307 (cond | |
308 ((get-buffer-window buffer) | |
309 (select-window (get-buffer-window buffer))) | |
310 ((and YaTeX-emacs-19 (get-buffer-window buffer t)) | |
311 (let*((win (get-buffer-window buffer t)) | |
312 (frame (window-frame win))) | |
313 (select-frame frame) | |
314 (raise-frame frame) | |
315 (focus-frame frame) | |
316 (select-window win) | |
317 (set-mouse-position frame 0 0) | |
318 (and (featurep 'windows) (fboundp 'win:adjust-window) | |
319 (win:adjust-window)))) | |
54 | 320 ((and (featurep 'windows) (fboundp 'win:get-buffer-window) |
56 | 321 (let ((w (win:get-buffer-window buffer))) |
322 (and w (win:switch-window w)))) | |
54 | 323 (select-window (get-buffer-window buffer))) |
51 | 324 (t (switch-to-buffer buffer)))) |
325 ) | |
326 | |
327 ;; Here starts the functions which support gmhist-vs-Emacs19 compatible | |
328 ;; reading with history. | |
329 ;;;###autoload | |
330 (defun completing-read-with-history | |
331 (prompt table &optional predicate must-match initial hsym) | |
332 "Completing read with general history: gmhist, Emacs-19." | |
333 (let ((minibuffer-history | |
334 (or (symbol-value hsym) | |
335 (and (boundp 'minibuffer-history) minibuffer-history))) | |
336 (minibuffer-history-symbol (or hsym 'minibuffer-history))) | |
337 (prog1 | |
338 (if (fboundp 'completing-read-with-history-in) | |
339 (completing-read-with-history-in | |
340 minibuffer-history-symbol prompt table predicate must-match initial) | |
341 (completing-read prompt table predicate must-match initial)) | |
342 (if (and YaTeX-emacs-19 hsym) (set hsym minibuffer-history))))) | |
343 | |
344 ;;;###autoload | |
345 (defun read-from-minibuffer-with-history (prompt &optional init map read hsym) | |
346 "Read from minibuffer with general history: gmhist, Emacs-19." | |
347 (cond | |
348 (YaTeX-emacs-19 | |
349 (read-from-minibuffer prompt init map read hsym)) | |
350 (t | |
351 (let ((minibuffer-history-symbol hsym)) | |
352 (read-from-minibuffer prompt init map read))))) | |
353 | |
354 ;;;###autoload | |
355 (defun read-string-with-history (prompt &optional init hsym) | |
356 "Read string with history: gmhist(Emacs-18) and Emacs-19." | |
357 (cond | |
358 (YaTeX-emacs-19 | |
359 (read-from-minibuffer prompt init minibuffer-local-map nil hsym)) | |
360 ((featurep 'gmhist-mh) | |
361 (read-with-history-in hsym prompt init)) | |
362 (t (read-string prompt init)))) | |
23 | 363 |
53
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
364 ;;; |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
365 ;; Interface function for windows.el |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
366 ;;; |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
367 ;;;###autoload |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
368 (defun YaTeX-switch-to-window () |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
369 "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
|
370 (interactive) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
371 (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
|
372 (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
|
373 |
58
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
56
diff
changeset
|
374 (defun bcf-and-exit () |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
56
diff
changeset
|
375 "Byte compile rest of argument and kill-emacs." |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
56
diff
changeset
|
376 (if command-line-args-left |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
56
diff
changeset
|
377 (progn |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
56
diff
changeset
|
378 (mapcar 'byte-compile-file command-line-args-left) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
56
diff
changeset
|
379 (kill-emacs)))) |
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
56
diff
changeset
|
380 |
23 | 381 (provide 'yatexlib) |