yatex

view yatexlib.el @ 46:cd1b63102eed

Support Mule2
author yuuji
date Mon, 19 Sep 1994 16:54:19 +0000
parents b00c74813e56
children d7e7b4654058
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 Fri Sep 16 01:50:34 1994 on figaro
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 (get-buffer-window buffer)
127 (progn (if select (select-window (get-buffer-window buffer)))
128 t))
129 (let ((window (selected-window))
130 (wlist (YaTeX-window-list)) win w (x 0))
131 (cond
132 ((> (length wlist) 2)
133 (if func
134 (while wlist
135 (setq w (car wlist))
136 (if (and (not (eq window w))
137 (> (funcall func w) x))
138 (setq win w x (funcall func w)))
139 (setq wlist (cdr wlist)))
140 (setq win (get-lru-window)))
141 (select-window win)
142 (switch-to-buffer buffer)
143 (or select (select-window window)))
144 ((= (length wlist) 2)
145 (other-window 1)
146 (switch-to-buffer buffer)
147 (or select (select-window window)))
148 (t ;if one-window
149 (cond
150 (YaTeX-default-pop-window-height
151 (split-window
152 (selected-window)
153 (max
154 (min
155 (- (screen-height)
156 (if (numberp YaTeX-default-pop-window-height)
157 (+ YaTeX-default-pop-window-height 2)
158 (/ (* (screen-height)
159 (string-to-int YaTeX-default-pop-window-height))
160 100)))
161 (- (screen-height) window-min-height 1))
162 window-min-height))
163 (pop-to-buffer buffer)
164 (or select (select-window window)))
165 (t nil)))
166 )))
167 )
169 ;;;###autoload
170 (defun YaTeX-window-list ()
171 (let*((curw (selected-window)) (win curw) (wlist (list curw)))
172 (while (not (eq curw (setq win (next-window win))))
173 (or (eq win (minibuffer-window))
174 (setq wlist (cons win wlist))))
175 wlist)
176 )
178 ;;;###autoload
179 (defun substitute-all-key-definition (olddef newdef keymap)
180 "Replace recursively OLDDEF with NEWDEF for any keys in KEYMAP now
181 defined as OLDDEF. In other words, OLDDEF is replaced with NEWDEF
182 where ever it appears."
183 (mapcar
184 (function (lambda (key) (define-key keymap key newdef)))
185 (where-is-internal olddef))
186 )
188 ;;;###autoload
189 (defun YaTeX-match-string (n &optional m)
190 "Return (buffer-substring (match-beginning n) (match-beginning m))."
191 (if (match-beginning n)
192 (buffer-substring (match-beginning n)
193 (match-end (if m m n))))
194 )
196 ;;;###autoload
197 (defun YaTeX-minibuffer-complete ()
198 "Complete in minibuffer"
199 (interactive)
200 (let (beg word compl)
201 (setq beg (if (and (boundp 'delim) delim)
202 (save-excursion
203 (skip-chars-backward (concat "^" delim))
204 (1- (point)))
205 (point-min))
206 word (buffer-substring beg (point-max))
207 compl (try-completion word minibuffer-completion-table))
208 (cond
209 ((eq compl t) nil)
210 ((eq compl nil)
211 (ding)
212 (save-excursion
213 (let (p)
214 (goto-char (setq p (point-max)))
215 (insert " [No match]")
216 (goto-char p)
217 (sit-for 2)
218 (delete-region p (point-max)))))
219 ((string= compl word)
220 (with-output-to-temp-buffer "*Completions*"
221 (display-completion-list
222 (all-completions word minibuffer-completion-table))))
223 (t (delete-region beg (point-max))
224 (insert compl))
225 ))
226 )
229 (provide 'yatexlib)