yatex
diff 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 |
line diff
1.1 --- a/yatexlib.el Fri Nov 25 08:26:13 1994 +0000 1.2 +++ b/yatexlib.el Tue Dec 20 21:00:21 1994 +0000 1.3 @@ -2,7 +2,7 @@ 1.4 ;;; YaTeX library of general functions. 1.5 ;;; yatexlib.el 1.6 ;;; (c )1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp] 1.7 -;;; Last modified Thu Nov 24 02:20:45 1994 on VFR 1.8 +;;; Last modified Wed Dec 21 05:58:06 1994 on landcruiser 1.9 ;;; $Id$ 1.10 1.11 ;;;###autoload 1.12 @@ -47,15 +47,15 @@ 1.13 Optional second arg SETBUF t make use set-buffer instead of switch-to-buffer." 1.14 (interactive "Fswitch to file: ") 1.15 (let (buf) 1.16 - (if (setq buf (get-buffer (file-name-nondirectory file))) 1.17 + (if (setq buf (get-file-buffer file)) 1.18 (progn 1.19 (funcall (if setbuf 'set-buffer 'switch-to-buffer) 1.20 - (file-name-nondirectory file)) 1.21 + (get-file-buffer file)) 1.22 buf) 1.23 (if (file-exists-p file) 1.24 - (funcall 1.25 - (if setbuf 'find-file-noselect 'find-file) 1.26 - file) 1.27 + (or ;find-file returns nil but set current-buffer... 1.28 + (funcall (if setbuf 'find-file-noselect 'find-file) file) 1.29 + (current-buffer)) 1.30 (message "%s was not found in this directory." file) 1.31 nil))) 1.32 ) 1.33 @@ -64,8 +64,8 @@ 1.34 (defun YaTeX-switch-to-buffer-other-window (file) 1.35 "Switch to buffer if buffer exists, find file if not." 1.36 (interactive "Fswitch to file: ") 1.37 - (if (get-buffer (file-name-nondirectory file)) 1.38 - (progn (switch-to-buffer-other-window file) t) 1.39 + (if (get-file-buffer file) 1.40 + (progn (switch-to-buffer-other-window (get-file-buffer file)) t) 1.41 (if (file-exists-p file) 1.42 (progn (find-file-other-window file) t) 1.43 (message "%s was not found in this directory." file) 1.44 @@ -128,19 +128,7 @@ 1.45 (get-buffer-window buffer)) 1.46 (progn 1.47 (if select 1.48 - (cond 1.49 - (YaTeX-emacs-19 1.50 - (let ((frame (window-frame (get-buffer-window buffer t)))) 1.51 - (select-frame frame) 1.52 - (focus-frame frame) 1.53 - (set-mouse-position frame 0 0) 1.54 - (raise-frame frame) 1.55 - (select-window (get-buffer-window buffer)) 1.56 - (if (and (featurep 'windows) 1.57 - (win:frame-window frame)) 1.58 - (win:adjust-window)))) 1.59 - (t 1.60 - (select-window (get-buffer-window buffer))))) 1.61 + (goto-buffer-window buffer)) 1.62 t)) 1.63 (let ((window (selected-window)) 1.64 (wlist (YaTeX-window-list)) win w (x 0)) 1.65 @@ -167,18 +155,7 @@ 1.66 ((and YaTeX-emacs-19 (get-buffer-window buffer t)) 1.67 nil) ;if found in other frame 1.68 (YaTeX-default-pop-window-height 1.69 - (split-window 1.70 - (selected-window) 1.71 - (max 1.72 - (min 1.73 - (- (screen-height) 1.74 - (if (numberp YaTeX-default-pop-window-height) 1.75 - (+ YaTeX-default-pop-window-height 2) 1.76 - (/ (* (screen-height) 1.77 - (string-to-int YaTeX-default-pop-window-height)) 1.78 - 100))) 1.79 - (- (screen-height) window-min-height 1)) 1.80 - window-min-height)) 1.81 + (split-window-calculate-height YaTeX-default-pop-window-height) 1.82 (pop-to-buffer buffer) 1.83 (or select (select-window window))) 1.84 (t nil))) 1.85 @@ -186,6 +163,27 @@ 1.86 ) 1.87 1.88 ;;;###autoload 1.89 +(defun split-window-calculate-height (height) 1.90 + "Split current window wight specified HEIGHT. 1.91 +If HEIGHT is number, make new window that has HEIGHT lines. 1.92 +If HEIGHT is string, make new window that occupy HEIGT % of screen height. 1.93 +Otherwise split window conventionally." 1.94 + (if (one-window-p) 1.95 + (split-window 1.96 + (selected-window) 1.97 + (max 1.98 + (min 1.99 + (- (screen-height) 1.100 + (if (numberp YaTeX-default-pop-window-height) 1.101 + (+ YaTeX-default-pop-window-height 2) 1.102 + (/ (* (screen-height) 1.103 + (string-to-int YaTeX-default-pop-window-height)) 1.104 + 100))) 1.105 + (- (screen-height) window-min-height 1)) 1.106 + window-min-height))) 1.107 +) 1.108 + 1.109 +;;;###autoload 1.110 (defun YaTeX-window-list () 1.111 (let*((curw (selected-window)) (win curw) (wlist (list curw))) 1.112 (while (not (eq curw (setq win (next-window win)))) 1.113 @@ -215,11 +213,20 @@ 1.114 ;;;###autoload 1.115 (defun YaTeX-minibuffer-complete () 1.116 "Complete in minibuffer. 1.117 -If the symbol 'delim is bound and is string, its value is assumed to be 1.118 + If the symbol 'delim is bound and is string, its value is assumed to be 1.119 the character class of delimiters. Completion will be performed on 1.120 -the last field separated by those delimiters." 1.121 +the last field separated by those delimiters. 1.122 + If the symbol 'quick is bound and is 't, when the try-completion results 1.123 +in t, exit minibuffer immediately." 1.124 (interactive) 1.125 - (let (beg word compl (md (match-data))) 1.126 + (let ((md (match-data)) beg word compl 1.127 + (quick (and (boundp 'quick) (eq quick t))) 1.128 + (displist ;function to display completion-list 1.129 + (function 1.130 + (lambda () 1.131 + (with-output-to-temp-buffer "*Completions*" 1.132 + (display-completion-list 1.133 + (all-completions word minibuffer-completion-table))))))) 1.134 (setq beg (if (and (boundp 'delim) (stringp delim)) 1.135 (save-excursion 1.136 (skip-chars-backward (concat "^" delim)) 1.137 @@ -229,31 +236,117 @@ 1.138 compl (try-completion word minibuffer-completion-table)) 1.139 (cond 1.140 ((eq compl t) 1.141 - (let ((p (point)) (max (point-max))) 1.142 - (goto-char max) 1.143 - (insert " [Sole completion]") 1.144 - (goto-char p) 1.145 - (sit-for 1) 1.146 - (delete-region max (point-max)) 1.147 - (goto-char p))) 1.148 + (if quick (exit-minibuffer) 1.149 + (let ((p (point)) (max (point-max))) 1.150 + (unwind-protect 1.151 + (progn 1.152 + (goto-char max) 1.153 + (insert " [Sole completion]") 1.154 + (goto-char p) 1.155 + (sit-for 1)) 1.156 + (delete-region max (point-max)) 1.157 + (goto-char p))))) 1.158 ((eq compl nil) 1.159 (ding) 1.160 (save-excursion 1.161 (let (p) 1.162 - (goto-char (setq p (point-max))) 1.163 - (insert " [No match]") 1.164 - (goto-char p) 1.165 - (sit-for 2) 1.166 - (delete-region p (point-max))))) 1.167 + (unwind-protect 1.168 + (progn 1.169 + (goto-char (setq p (point-max))) 1.170 + (insert " [No match]") 1.171 + (goto-char p) 1.172 + (sit-for 2)) 1.173 + (delete-region p (point-max)))))) 1.174 ((string= compl word) 1.175 - (with-output-to-temp-buffer "*Completions*" 1.176 - (display-completion-list 1.177 - (all-completions word minibuffer-completion-table)))) 1.178 + (funcall displist)) 1.179 (t (delete-region beg (point-max)) 1.180 - (insert compl)) 1.181 - ) 1.182 + (insert compl) 1.183 + (if quick 1.184 + (if (eq (try-completion compl minibuffer-completion-table) t) 1.185 + (exit-minibuffer) 1.186 + (funcall displist))))) 1.187 (store-match-data md)) 1.188 ) 1.189 1.190 +(defun YaTeX-minibuffer-quick-complete () 1.191 + "Set 'quick to 't and call YaTeX-minibuffer-complete. 1.192 +See documentation of YaTeX-minibuffer-complete." 1.193 + (interactive) 1.194 + (let ((quick t)) 1.195 + (self-insert-command 1) 1.196 + (YaTeX-minibuffer-complete))) 1.197 + 1.198 +(defun foreach-buffers (pattern job) 1.199 + "For each buffer which matches with PATTERN, do JOB." 1.200 + (let ((list (buffer-list))) 1.201 + (save-excursion 1.202 + (while list 1.203 + (set-buffer (car list)) 1.204 + (if (or (and (stringp pattern) 1.205 + (buffer-file-name) 1.206 + (string-match pattern (buffer-file-name))) 1.207 + (and (symbolp pattern) major-mode (eq major-mode pattern))) 1.208 + (eval job)) 1.209 + (setq list (cdr list))))) 1.210 +) 1.211 + 1.212 +(defun goto-buffer-window (buffer) 1.213 + "Select window which is bound to BUFFER. 1.214 +If no such window exist, switch to buffer BUFFER." 1.215 + (if (stringp buffer) 1.216 + (setq buffer (or (get-file-buffer buffer) (get-buffer buffer)))) 1.217 + (if (get-buffer buffer) 1.218 + (cond 1.219 + ((get-buffer-window buffer) 1.220 + (select-window (get-buffer-window buffer))) 1.221 + ((and YaTeX-emacs-19 (get-buffer-window buffer t)) 1.222 + (let*((win (get-buffer-window buffer t)) 1.223 + (frame (window-frame win))) 1.224 + (select-frame frame) 1.225 + (raise-frame frame) 1.226 + (focus-frame frame) 1.227 + (select-window win) 1.228 + (set-mouse-position frame 0 0) 1.229 + (and (featurep 'windows) (fboundp 'win:adjust-window) 1.230 + (win:adjust-window)))) 1.231 + (t (switch-to-buffer buffer)))) 1.232 +) 1.233 + 1.234 +;; Here starts the functions which support gmhist-vs-Emacs19 compatible 1.235 +;; reading with history. 1.236 +;;;###autoload 1.237 +(defun completing-read-with-history 1.238 + (prompt table &optional predicate must-match initial hsym) 1.239 + "Completing read with general history: gmhist, Emacs-19." 1.240 + (let ((minibuffer-history 1.241 + (or (symbol-value hsym) 1.242 + (and (boundp 'minibuffer-history) minibuffer-history))) 1.243 + (minibuffer-history-symbol (or hsym 'minibuffer-history))) 1.244 + (prog1 1.245 + (if (fboundp 'completing-read-with-history-in) 1.246 + (completing-read-with-history-in 1.247 + minibuffer-history-symbol prompt table predicate must-match initial) 1.248 + (completing-read prompt table predicate must-match initial)) 1.249 + (if (and YaTeX-emacs-19 hsym) (set hsym minibuffer-history))))) 1.250 + 1.251 +;;;###autoload 1.252 +(defun read-from-minibuffer-with-history (prompt &optional init map read hsym) 1.253 + "Read from minibuffer with general history: gmhist, Emacs-19." 1.254 + (cond 1.255 + (YaTeX-emacs-19 1.256 + (read-from-minibuffer prompt init map read hsym)) 1.257 + (t 1.258 + (let ((minibuffer-history-symbol hsym)) 1.259 + (read-from-minibuffer prompt init map read))))) 1.260 + 1.261 +;;;###autoload 1.262 +(defun read-string-with-history (prompt &optional init hsym) 1.263 + "Read string with history: gmhist(Emacs-18) and Emacs-19." 1.264 + (cond 1.265 + (YaTeX-emacs-19 1.266 + (read-from-minibuffer prompt init minibuffer-local-map nil hsym)) 1.267 + ((featurep 'gmhist-mh) 1.268 + (read-with-history-in hsym prompt init)) 1.269 + (t (read-string prompt init)))) 1.270 1.271 (provide 'yatexlib)