Mercurial > hgrepos > hgweb.cgi > yatex
comparison yatexlib.el @ 51:b0371b6ed799
Created `ChangeLog'.
Log hereafter will be written in `ChangeLog'.
author | yuuji |
---|---|
date | Tue, 20 Dec 1994 21:00:21 +0000 |
parents | eb0512bfcb7f |
children | 5d94deabb9f9 |
comparison
equal
deleted
inserted
replaced
50:b1e036697b20 | 51:b0371b6ed799 |
---|---|
1 ;;; -*- Emacs-Lisp -*- | 1 ;;; -*- Emacs-Lisp -*- |
2 ;;; YaTeX library of general functions. | 2 ;;; YaTeX library of general functions. |
3 ;;; yatexlib.el | 3 ;;; yatexlib.el |
4 ;;; (c )1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp] | 4 ;;; (c )1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp] |
5 ;;; Last modified Thu Nov 24 02:20:45 1994 on VFR | 5 ;;; Last modified Wed Dec 21 05:58:06 1994 on landcruiser |
6 ;;; $Id$ | 6 ;;; $Id$ |
7 | 7 |
8 ;;;###autoload | 8 ;;;###autoload |
9 (defun YaTeX-search-active-forward (string cmntrx &optional bound err cnt func) | 9 (defun YaTeX-search-active-forward (string cmntrx &optional bound err cnt func) |
10 "Search STRING which is not commented out by CMNTRX. | 10 "Search STRING which is not commented out by CMNTRX. |
45 (defun YaTeX-switch-to-buffer (file &optional setbuf) | 45 (defun YaTeX-switch-to-buffer (file &optional setbuf) |
46 "Switch to buffer if buffer exists, find file if not. | 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." | 47 Optional second arg SETBUF t make use set-buffer instead of switch-to-buffer." |
48 (interactive "Fswitch to file: ") | 48 (interactive "Fswitch to file: ") |
49 (let (buf) | 49 (let (buf) |
50 (if (setq buf (get-buffer (file-name-nondirectory file))) | 50 (if (setq buf (get-file-buffer file)) |
51 (progn | 51 (progn |
52 (funcall (if setbuf 'set-buffer 'switch-to-buffer) | 52 (funcall (if setbuf 'set-buffer 'switch-to-buffer) |
53 (file-name-nondirectory file)) | 53 (get-file-buffer file)) |
54 buf) | 54 buf) |
55 (if (file-exists-p file) | 55 (if (file-exists-p file) |
56 (funcall | 56 (or ;find-file returns nil but set current-buffer... |
57 (if setbuf 'find-file-noselect 'find-file) | 57 (funcall (if setbuf 'find-file-noselect 'find-file) file) |
58 file) | 58 (current-buffer)) |
59 (message "%s was not found in this directory." file) | 59 (message "%s was not found in this directory." file) |
60 nil))) | 60 nil))) |
61 ) | 61 ) |
62 | 62 |
63 ;;;###autoload | 63 ;;;###autoload |
64 (defun YaTeX-switch-to-buffer-other-window (file) | 64 (defun YaTeX-switch-to-buffer-other-window (file) |
65 "Switch to buffer if buffer exists, find file if not." | 65 "Switch to buffer if buffer exists, find file if not." |
66 (interactive "Fswitch to file: ") | 66 (interactive "Fswitch to file: ") |
67 (if (get-buffer (file-name-nondirectory file)) | 67 (if (get-file-buffer file) |
68 (progn (switch-to-buffer-other-window file) t) | 68 (progn (switch-to-buffer-other-window (get-file-buffer file)) t) |
69 (if (file-exists-p file) | 69 (if (file-exists-p file) |
70 (progn (find-file-other-window file) t) | 70 (progn (find-file-other-window file) t) |
71 (message "%s was not found in this directory." file) | 71 (message "%s was not found in this directory." file) |
72 nil)) | 72 nil)) |
73 ) | 73 ) |
126 (or (and (if YaTeX-emacs-19 | 126 (or (and (if YaTeX-emacs-19 |
127 (get-buffer-window buffer t) | 127 (get-buffer-window buffer t) |
128 (get-buffer-window buffer)) | 128 (get-buffer-window buffer)) |
129 (progn | 129 (progn |
130 (if select | 130 (if select |
131 (cond | 131 (goto-buffer-window buffer)) |
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)) | 132 t)) |
145 (let ((window (selected-window)) | 133 (let ((window (selected-window)) |
146 (wlist (YaTeX-window-list)) win w (x 0)) | 134 (wlist (YaTeX-window-list)) win w (x 0)) |
147 (cond | 135 (cond |
148 ((> (length wlist) 2) | 136 ((> (length wlist) 2) |
165 (t ;if one-window | 153 (t ;if one-window |
166 (cond | 154 (cond |
167 ((and YaTeX-emacs-19 (get-buffer-window buffer t)) | 155 ((and YaTeX-emacs-19 (get-buffer-window buffer t)) |
168 nil) ;if found in other frame | 156 nil) ;if found in other frame |
169 (YaTeX-default-pop-window-height | 157 (YaTeX-default-pop-window-height |
170 (split-window | 158 (split-window-calculate-height YaTeX-default-pop-window-height) |
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) | 159 (pop-to-buffer buffer) |
183 (or select (select-window window))) | 160 (or select (select-window window))) |
184 (t nil))) | 161 (t nil))) |
185 ))) | 162 ))) |
163 ) | |
164 | |
165 ;;;###autoload | |
166 (defun split-window-calculate-height (height) | |
167 "Split current window wight specified HEIGHT. | |
168 If HEIGHT is number, make new window that has HEIGHT lines. | |
169 If HEIGHT is string, make new window that occupy HEIGT % of screen height. | |
170 Otherwise split window conventionally." | |
171 (if (one-window-p) | |
172 (split-window | |
173 (selected-window) | |
174 (max | |
175 (min | |
176 (- (screen-height) | |
177 (if (numberp YaTeX-default-pop-window-height) | |
178 (+ YaTeX-default-pop-window-height 2) | |
179 (/ (* (screen-height) | |
180 (string-to-int YaTeX-default-pop-window-height)) | |
181 100))) | |
182 (- (screen-height) window-min-height 1)) | |
183 window-min-height))) | |
186 ) | 184 ) |
187 | 185 |
188 ;;;###autoload | 186 ;;;###autoload |
189 (defun YaTeX-window-list () | 187 (defun YaTeX-window-list () |
190 (let*((curw (selected-window)) (win curw) (wlist (list curw))) | 188 (let*((curw (selected-window)) (win curw) (wlist (list curw))) |
213 ) | 211 ) |
214 | 212 |
215 ;;;###autoload | 213 ;;;###autoload |
216 (defun YaTeX-minibuffer-complete () | 214 (defun YaTeX-minibuffer-complete () |
217 "Complete in minibuffer. | 215 "Complete in minibuffer. |
218 If the symbol 'delim is bound and is string, its value is assumed to be | 216 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 | 217 the character class of delimiters. Completion will be performed on |
220 the last field separated by those delimiters." | 218 the last field separated by those delimiters. |
219 If the symbol 'quick is bound and is 't, when the try-completion results | |
220 in t, exit minibuffer immediately." | |
221 (interactive) | 221 (interactive) |
222 (let (beg word compl (md (match-data))) | 222 (let ((md (match-data)) beg word compl |
223 (quick (and (boundp 'quick) (eq quick t))) | |
224 (displist ;function to display completion-list | |
225 (function | |
226 (lambda () | |
227 (with-output-to-temp-buffer "*Completions*" | |
228 (display-completion-list | |
229 (all-completions word minibuffer-completion-table))))))) | |
223 (setq beg (if (and (boundp 'delim) (stringp delim)) | 230 (setq beg (if (and (boundp 'delim) (stringp delim)) |
224 (save-excursion | 231 (save-excursion |
225 (skip-chars-backward (concat "^" delim)) | 232 (skip-chars-backward (concat "^" delim)) |
226 (point)) | 233 (point)) |
227 (point-min)) | 234 (point-min)) |
228 word (buffer-substring beg (point-max)) | 235 word (buffer-substring beg (point-max)) |
229 compl (try-completion word minibuffer-completion-table)) | 236 compl (try-completion word minibuffer-completion-table)) |
230 (cond | 237 (cond |
231 ((eq compl t) | 238 ((eq compl t) |
232 (let ((p (point)) (max (point-max))) | 239 (if quick (exit-minibuffer) |
233 (goto-char max) | 240 (let ((p (point)) (max (point-max))) |
234 (insert " [Sole completion]") | 241 (unwind-protect |
235 (goto-char p) | 242 (progn |
236 (sit-for 1) | 243 (goto-char max) |
237 (delete-region max (point-max)) | 244 (insert " [Sole completion]") |
238 (goto-char p))) | 245 (goto-char p) |
246 (sit-for 1)) | |
247 (delete-region max (point-max)) | |
248 (goto-char p))))) | |
239 ((eq compl nil) | 249 ((eq compl nil) |
240 (ding) | 250 (ding) |
241 (save-excursion | 251 (save-excursion |
242 (let (p) | 252 (let (p) |
243 (goto-char (setq p (point-max))) | 253 (unwind-protect |
244 (insert " [No match]") | 254 (progn |
245 (goto-char p) | 255 (goto-char (setq p (point-max))) |
246 (sit-for 2) | 256 (insert " [No match]") |
247 (delete-region p (point-max))))) | 257 (goto-char p) |
258 (sit-for 2)) | |
259 (delete-region p (point-max)))))) | |
248 ((string= compl word) | 260 ((string= compl word) |
249 (with-output-to-temp-buffer "*Completions*" | 261 (funcall displist)) |
250 (display-completion-list | |
251 (all-completions word minibuffer-completion-table)))) | |
252 (t (delete-region beg (point-max)) | 262 (t (delete-region beg (point-max)) |
253 (insert compl)) | 263 (insert compl) |
254 ) | 264 (if quick |
265 (if (eq (try-completion compl minibuffer-completion-table) t) | |
266 (exit-minibuffer) | |
267 (funcall displist))))) | |
255 (store-match-data md)) | 268 (store-match-data md)) |
256 ) | 269 ) |
257 | 270 |
271 (defun YaTeX-minibuffer-quick-complete () | |
272 "Set 'quick to 't and call YaTeX-minibuffer-complete. | |
273 See documentation of YaTeX-minibuffer-complete." | |
274 (interactive) | |
275 (let ((quick t)) | |
276 (self-insert-command 1) | |
277 (YaTeX-minibuffer-complete))) | |
278 | |
279 (defun foreach-buffers (pattern job) | |
280 "For each buffer which matches with PATTERN, do JOB." | |
281 (let ((list (buffer-list))) | |
282 (save-excursion | |
283 (while list | |
284 (set-buffer (car list)) | |
285 (if (or (and (stringp pattern) | |
286 (buffer-file-name) | |
287 (string-match pattern (buffer-file-name))) | |
288 (and (symbolp pattern) major-mode (eq major-mode pattern))) | |
289 (eval job)) | |
290 (setq list (cdr list))))) | |
291 ) | |
292 | |
293 (defun goto-buffer-window (buffer) | |
294 "Select window which is bound to BUFFER. | |
295 If no such window exist, switch to buffer BUFFER." | |
296 (if (stringp buffer) | |
297 (setq buffer (or (get-file-buffer buffer) (get-buffer buffer)))) | |
298 (if (get-buffer buffer) | |
299 (cond | |
300 ((get-buffer-window buffer) | |
301 (select-window (get-buffer-window buffer))) | |
302 ((and YaTeX-emacs-19 (get-buffer-window buffer t)) | |
303 (let*((win (get-buffer-window buffer t)) | |
304 (frame (window-frame win))) | |
305 (select-frame frame) | |
306 (raise-frame frame) | |
307 (focus-frame frame) | |
308 (select-window win) | |
309 (set-mouse-position frame 0 0) | |
310 (and (featurep 'windows) (fboundp 'win:adjust-window) | |
311 (win:adjust-window)))) | |
312 (t (switch-to-buffer buffer)))) | |
313 ) | |
314 | |
315 ;; Here starts the functions which support gmhist-vs-Emacs19 compatible | |
316 ;; reading with history. | |
317 ;;;###autoload | |
318 (defun completing-read-with-history | |
319 (prompt table &optional predicate must-match initial hsym) | |
320 "Completing read with general history: gmhist, Emacs-19." | |
321 (let ((minibuffer-history | |
322 (or (symbol-value hsym) | |
323 (and (boundp 'minibuffer-history) minibuffer-history))) | |
324 (minibuffer-history-symbol (or hsym 'minibuffer-history))) | |
325 (prog1 | |
326 (if (fboundp 'completing-read-with-history-in) | |
327 (completing-read-with-history-in | |
328 minibuffer-history-symbol prompt table predicate must-match initial) | |
329 (completing-read prompt table predicate must-match initial)) | |
330 (if (and YaTeX-emacs-19 hsym) (set hsym minibuffer-history))))) | |
331 | |
332 ;;;###autoload | |
333 (defun read-from-minibuffer-with-history (prompt &optional init map read hsym) | |
334 "Read from minibuffer with general history: gmhist, Emacs-19." | |
335 (cond | |
336 (YaTeX-emacs-19 | |
337 (read-from-minibuffer prompt init map read hsym)) | |
338 (t | |
339 (let ((minibuffer-history-symbol hsym)) | |
340 (read-from-minibuffer prompt init map read))))) | |
341 | |
342 ;;;###autoload | |
343 (defun read-string-with-history (prompt &optional init hsym) | |
344 "Read string with history: gmhist(Emacs-18) and Emacs-19." | |
345 (cond | |
346 (YaTeX-emacs-19 | |
347 (read-from-minibuffer prompt init minibuffer-local-map nil hsym)) | |
348 ((featurep 'gmhist-mh) | |
349 (read-with-history-in hsym prompt init)) | |
350 (t (read-string prompt init)))) | |
258 | 351 |
259 (provide 'yatexlib) | 352 (provide 'yatexlib) |