yatex

view yatexlib.el @ 47:d7e7b4654058

Support special popup frame. Refine highlightening method. On Emacs-19, couldn't save user completion table correctly, fixed.
author yuuji
date Mon, 24 Oct 1994 17:26:47 +0000
parents cd1b63102eed
children eb0512bfcb7f
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 Mon Oct 10 22:14:14 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 (if func 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."
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)
162 (switch-to-buffer buffer)
163 (or select (select-window window)))
164 (t ;if one-window
165 (cond
166 ((and YaTeX-emacs-19 (get-buffer-window buffer t))
167 nil) ;if found in other frame
168 (YaTeX-default-pop-window-height
169 (split-window
170 (selected-window)
171 (max
172 (min
173 (- (screen-height)
174 (if (numberp YaTeX-default-pop-window-height)
175 (+ YaTeX-default-pop-window-height 2)
176 (/ (* (screen-height)
177 (string-to-int YaTeX-default-pop-window-height))
178 100)))
179 (- (screen-height) window-min-height 1))
180 window-min-height))
181 (pop-to-buffer buffer)
182 (or select (select-window window)))
183 (t nil)))
184 )))
185 )
187 ;;;###autoload
188 (defun YaTeX-window-list ()
189 (let*((curw (selected-window)) (win curw) (wlist (list curw)))
190 (while (not (eq curw (setq win (next-window win))))
191 (or (eq win (minibuffer-window))
192 (setq wlist (cons win wlist))))
193 wlist)
194 )
196 ;;;###autoload
197 (defun substitute-all-key-definition (olddef newdef keymap)
198 "Replace recursively OLDDEF with NEWDEF for any keys in KEYMAP now
199 defined as OLDDEF. In other words, OLDDEF is replaced with NEWDEF
200 where ever it appears."
201 (mapcar
202 (function (lambda (key) (define-key keymap key newdef)))
203 (where-is-internal olddef keymap))
204 )
206 ;;;###autoload
207 (defun YaTeX-match-string (n &optional m)
208 "Return (buffer-substring (match-beginning n) (match-beginning m))."
209 (if (match-beginning n)
210 (buffer-substring (match-beginning n)
211 (match-end (if m m n))))
212 )
214 ;;;###autoload
215 (defun YaTeX-minibuffer-complete ()
216 "Complete in minibuffer"
217 (interactive)
218 (let (beg word compl)
219 (setq beg (if (and (boundp 'delim) delim)
220 (save-excursion
221 (skip-chars-backward (concat "^" delim))
222 (1- (point)))
223 (point-min))
224 word (buffer-substring beg (point-max))
225 compl (try-completion word minibuffer-completion-table))
226 (cond
227 ((eq compl t) nil)
228 ((eq compl nil)
229 (ding)
230 (save-excursion
231 (let (p)
232 (goto-char (setq p (point-max)))
233 (insert " [No match]")
234 (goto-char p)
235 (sit-for 2)
236 (delete-region p (point-max)))))
237 ((string= compl word)
238 (with-output-to-temp-buffer "*Completions*"
239 (display-completion-list
240 (all-completions word minibuffer-completion-table))))
241 (t (delete-region beg (point-max))
242 (insert compl))
243 ))
244 )
247 (provide 'yatexlib)