yatex
annotate yatexlib.el @ 49:eb0512bfcb7f
Abolish user-article table.
Use normal read-string instead.
Supply smart add-in function for documentstyle.
Update user dictionary whenever new words entered.
Enhance [prefix] c.
Allow user defined sectioning commands in yatexsec.
author | yuuji |
---|---|
date | Fri, 25 Nov 1994 08:26:13 +0000 |
parents | d7e7b4654058 |
children | b0371b6ed799 |
rev | line source |
---|---|
yuuji@23 | 1 ;;; -*- Emacs-Lisp -*- |
yuuji@23 | 2 ;;; YaTeX library of general functions. |
yuuji@23 | 3 ;;; yatexlib.el |
yuuji@23 | 4 ;;; (c )1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp] |
yuuji@49 | 5 ;;; Last modified Thu Nov 24 02:20:45 1994 on VFR |
yuuji@23 | 6 ;;; $Id$ |
yuuji@23 | 7 |
yuuji@23 | 8 ;;;###autoload |
yuuji@23 | 9 (defun YaTeX-search-active-forward (string cmntrx &optional bound err cnt func) |
yuuji@23 | 10 "Search STRING which is not commented out by CMNTRX. |
yuuji@23 | 11 Optional arguments after BOUND, ERR, CNT are passed literally to search-forward |
yuuji@23 | 12 or search-backward. |
yuuji@23 | 13 Optional sixth argument FUNC changes search-function." |
yuuji@49 | 14 (let ((sfunc (or func 'search-forward)) found md) |
yuuji@23 | 15 (while (and (prog1 |
yuuji@23 | 16 (setq found (funcall sfunc string bound err cnt)) |
yuuji@23 | 17 (setq md (match-data))) |
yuuji@23 | 18 (or |
yuuji@23 | 19 (YaTeX-in-verb-p (match-beginning 0)) |
yuuji@23 | 20 (save-excursion |
yuuji@23 | 21 (beginning-of-line) |
yuuji@23 | 22 (re-search-forward cmntrx (match-beginning 0) t))))) |
yuuji@23 | 23 (store-match-data md) |
yuuji@23 | 24 found) |
yuuji@23 | 25 ) |
yuuji@23 | 26 |
yuuji@23 | 27 (defun YaTeX-re-search-active-forward (regexp cmntrx &optional bound err cnt) |
yuuji@23 | 28 "Search REGEXP backward which is not commented out by regexp CMNTRX. |
yuuji@23 | 29 See also YaTeX-search-active-forward." |
yuuji@23 | 30 (YaTeX-search-active-forward regexp cmntrx bound err cnt 're-search-forward) |
yuuji@23 | 31 ) |
yuuji@23 | 32 (defun YaTeX-search-active-backward (string cmntrx &optional bound err cnt) |
yuuji@23 | 33 "Search STRING backward which is not commented out by regexp CMNTRX. |
yuuji@23 | 34 See also YaTeX-search-active-forward." |
yuuji@23 | 35 (YaTeX-search-active-forward string cmntrx bound err cnt 'search-backward) |
yuuji@23 | 36 ) |
yuuji@23 | 37 (defun YaTeX-re-search-active-backward (regexp cmntrx &optional bound err cnt) |
yuuji@23 | 38 "Search REGEXP backward which is not commented out by regexp CMNTRX. |
yuuji@23 | 39 See also YaTeX-search-active-forward." |
yuuji@23 | 40 (YaTeX-search-active-forward regexp cmntrx bound err cnt 're-search-backward) |
yuuji@23 | 41 ) |
yuuji@23 | 42 |
yuuji@23 | 43 |
yuuji@23 | 44 ;;;###autoload |
yuuji@23 | 45 (defun YaTeX-switch-to-buffer (file &optional setbuf) |
yuuji@23 | 46 "Switch to buffer if buffer exists, find file if not. |
yuuji@23 | 47 Optional second arg SETBUF t make use set-buffer instead of switch-to-buffer." |
yuuji@23 | 48 (interactive "Fswitch to file: ") |
yuuji@23 | 49 (let (buf) |
yuuji@23 | 50 (if (setq buf (get-buffer (file-name-nondirectory file))) |
yuuji@23 | 51 (progn |
yuuji@23 | 52 (funcall (if setbuf 'set-buffer 'switch-to-buffer) |
yuuji@23 | 53 (file-name-nondirectory file)) |
yuuji@23 | 54 buf) |
yuuji@23 | 55 (if (file-exists-p file) |
yuuji@46 | 56 (funcall |
yuuji@46 | 57 (if setbuf 'find-file-noselect 'find-file) |
yuuji@46 | 58 file) |
yuuji@23 | 59 (message "%s was not found in this directory." file) |
yuuji@23 | 60 nil))) |
yuuji@23 | 61 ) |
yuuji@23 | 62 |
yuuji@23 | 63 ;;;###autoload |
yuuji@23 | 64 (defun YaTeX-switch-to-buffer-other-window (file) |
yuuji@23 | 65 "Switch to buffer if buffer exists, find file if not." |
yuuji@23 | 66 (interactive "Fswitch to file: ") |
yuuji@23 | 67 (if (get-buffer (file-name-nondirectory file)) |
yuuji@23 | 68 (progn (switch-to-buffer-other-window file) t) |
yuuji@23 | 69 (if (file-exists-p file) |
yuuji@23 | 70 (progn (find-file-other-window file) t) |
yuuji@23 | 71 (message "%s was not found in this directory." file) |
yuuji@23 | 72 nil)) |
yuuji@23 | 73 ) |
yuuji@23 | 74 |
yuuji@23 | 75 (defun YaTeX-replace-format-sub (string format repl) |
yuuji@23 | 76 (let ((beg (or (string-match (concat "^\\(%" format "\\)") string) |
yuuji@23 | 77 (string-match (concat "[^%]\\(%" format "\\)") string))) |
yuuji@23 | 78 (len (length format))) |
yuuji@23 | 79 (if (null beg) string ;no conversion |
yuuji@23 | 80 (concat |
yuuji@23 | 81 (substring string 0 (match-beginning 1)) repl |
yuuji@23 | 82 (substring string (match-end 1))))) |
yuuji@23 | 83 ) |
yuuji@23 | 84 |
yuuji@23 | 85 ;;;###autoload |
yuuji@23 | 86 (defun YaTeX-replace-format (string format repl) |
yuuji@23 | 87 "In STRING, replace first appearance of FORMAT to REPL as if |
yuuji@23 | 88 function `format' does. FORMAT does not contain `%'" |
yuuji@23 | 89 (let ((ans string)) |
yuuji@23 | 90 (while (not (string= |
yuuji@23 | 91 ans (setq string (YaTeX-replace-format-sub ans format repl)))) |
yuuji@23 | 92 (setq ans string)) |
yuuji@23 | 93 string) |
yuuji@23 | 94 ) |
yuuji@23 | 95 |
yuuji@23 | 96 ;;;###autoload |
yuuji@23 | 97 (defun YaTeX-replace-format-args (string &rest args) |
yuuji@23 | 98 "Translate the argument mark #1, #2, ... #n in the STRING into the |
yuuji@23 | 99 corresponding real arguments ARGS." |
yuuji@23 | 100 (let ((argp 1)) |
yuuji@23 | 101 (while args |
yuuji@23 | 102 (setq string |
yuuji@23 | 103 (YaTeX-replace-format string (int-to-string argp) (car args))) |
yuuji@23 | 104 (setq args (cdr args) argp (1+ argp)))) |
yuuji@23 | 105 string |
yuuji@23 | 106 ) |
yuuji@23 | 107 |
yuuji@23 | 108 ;;;###autoload |
yuuji@23 | 109 (defun rindex (string char) |
yuuji@23 | 110 (let ((pos (1- (length string)))(index -1)) |
yuuji@23 | 111 (while (>= pos 0) |
yuuji@23 | 112 (cond |
yuuji@23 | 113 ((= (aref string pos) char) |
yuuji@23 | 114 (setq index pos) (setq pos -1)) |
yuuji@23 | 115 (t (setq pos (1- pos)))) |
yuuji@23 | 116 ) |
yuuji@23 | 117 index) |
yuuji@23 | 118 ) |
yuuji@23 | 119 |
yuuji@23 | 120 ;;;###autoload |
yuuji@23 | 121 (defun YaTeX-showup-buffer (buffer &optional func select) |
yuuji@23 | 122 "Make BUFFER show up in certain window (but current window) |
yuuji@23 | 123 that gives the maximum value by the FUNC. FUNC should take an argument |
yuuji@23 | 124 of its window object. Non-nil for optional third argument SELECT selects |
yuuji@49 | 125 that window. This function never selects minibuffer window." |
yuuji@47 | 126 (or (and (if YaTeX-emacs-19 |
yuuji@47 | 127 (get-buffer-window buffer t) |
yuuji@47 | 128 (get-buffer-window buffer)) |
yuuji@47 | 129 (progn |
yuuji@47 | 130 (if select |
yuuji@47 | 131 (cond |
yuuji@47 | 132 (YaTeX-emacs-19 |
yuuji@47 | 133 (let ((frame (window-frame (get-buffer-window buffer t)))) |
yuuji@47 | 134 (select-frame frame) |
yuuji@47 | 135 (focus-frame frame) |
yuuji@47 | 136 (set-mouse-position frame 0 0) |
yuuji@47 | 137 (raise-frame frame) |
yuuji@47 | 138 (select-window (get-buffer-window buffer)) |
yuuji@47 | 139 (if (and (featurep 'windows) |
yuuji@47 | 140 (win:frame-window frame)) |
yuuji@47 | 141 (win:adjust-window)))) |
yuuji@47 | 142 (t |
yuuji@47 | 143 (select-window (get-buffer-window buffer))))) |
yuuji@47 | 144 t)) |
yuuji@23 | 145 (let ((window (selected-window)) |
yuuji@23 | 146 (wlist (YaTeX-window-list)) win w (x 0)) |
yuuji@23 | 147 (cond |
yuuji@23 | 148 ((> (length wlist) 2) |
yuuji@23 | 149 (if func |
yuuji@23 | 150 (while wlist |
yuuji@23 | 151 (setq w (car wlist)) |
yuuji@23 | 152 (if (and (not (eq window w)) |
yuuji@23 | 153 (> (funcall func w) x)) |
yuuji@23 | 154 (setq win w x (funcall func w))) |
yuuji@23 | 155 (setq wlist (cdr wlist))) |
yuuji@23 | 156 (setq win (get-lru-window))) |
yuuji@23 | 157 (select-window win) |
yuuji@23 | 158 (switch-to-buffer buffer) |
yuuji@23 | 159 (or select (select-window window))) |
yuuji@23 | 160 ((= (length wlist) 2) |
yuuji@49 | 161 ;(other-window 1);This does not work properly on Emacs-19 |
yuuji@49 | 162 (select-window (get-lru-window)) |
yuuji@23 | 163 (switch-to-buffer buffer) |
yuuji@23 | 164 (or select (select-window window))) |
yuuji@23 | 165 (t ;if one-window |
yuuji@23 | 166 (cond |
yuuji@47 | 167 ((and YaTeX-emacs-19 (get-buffer-window buffer t)) |
yuuji@47 | 168 nil) ;if found in other frame |
yuuji@23 | 169 (YaTeX-default-pop-window-height |
yuuji@23 | 170 (split-window |
yuuji@23 | 171 (selected-window) |
yuuji@23 | 172 (max |
yuuji@23 | 173 (min |
yuuji@23 | 174 (- (screen-height) |
yuuji@23 | 175 (if (numberp YaTeX-default-pop-window-height) |
yuuji@23 | 176 (+ YaTeX-default-pop-window-height 2) |
yuuji@23 | 177 (/ (* (screen-height) |
yuuji@23 | 178 (string-to-int YaTeX-default-pop-window-height)) |
yuuji@23 | 179 100))) |
yuuji@23 | 180 (- (screen-height) window-min-height 1)) |
yuuji@23 | 181 window-min-height)) |
yuuji@23 | 182 (pop-to-buffer buffer) |
yuuji@23 | 183 (or select (select-window window))) |
yuuji@23 | 184 (t nil))) |
yuuji@23 | 185 ))) |
yuuji@23 | 186 ) |
yuuji@23 | 187 |
yuuji@23 | 188 ;;;###autoload |
yuuji@23 | 189 (defun YaTeX-window-list () |
yuuji@23 | 190 (let*((curw (selected-window)) (win curw) (wlist (list curw))) |
yuuji@23 | 191 (while (not (eq curw (setq win (next-window win)))) |
yuuji@23 | 192 (or (eq win (minibuffer-window)) |
yuuji@23 | 193 (setq wlist (cons win wlist)))) |
yuuji@23 | 194 wlist) |
yuuji@23 | 195 ) |
yuuji@23 | 196 |
yuuji@23 | 197 ;;;###autoload |
yuuji@23 | 198 (defun substitute-all-key-definition (olddef newdef keymap) |
yuuji@23 | 199 "Replace recursively OLDDEF with NEWDEF for any keys in KEYMAP now |
yuuji@23 | 200 defined as OLDDEF. In other words, OLDDEF is replaced with NEWDEF |
yuuji@23 | 201 where ever it appears." |
yuuji@23 | 202 (mapcar |
yuuji@23 | 203 (function (lambda (key) (define-key keymap key newdef))) |
yuuji@47 | 204 (where-is-internal olddef keymap)) |
yuuji@23 | 205 ) |
yuuji@23 | 206 |
yuuji@23 | 207 ;;;###autoload |
yuuji@23 | 208 (defun YaTeX-match-string (n &optional m) |
yuuji@23 | 209 "Return (buffer-substring (match-beginning n) (match-beginning m))." |
yuuji@23 | 210 (if (match-beginning n) |
yuuji@23 | 211 (buffer-substring (match-beginning n) |
yuuji@49 | 212 (match-end (or m n)))) |
yuuji@23 | 213 ) |
yuuji@23 | 214 |
yuuji@23 | 215 ;;;###autoload |
yuuji@23 | 216 (defun YaTeX-minibuffer-complete () |
yuuji@49 | 217 "Complete in minibuffer. |
yuuji@49 | 218 If the symbol 'delim is bound and is string, its value is assumed to be |
yuuji@49 | 219 the character class of delimiters. Completion will be performed on |
yuuji@49 | 220 the last field separated by those delimiters." |
yuuji@23 | 221 (interactive) |
yuuji@49 | 222 (let (beg word compl (md (match-data))) |
yuuji@49 | 223 (setq beg (if (and (boundp 'delim) (stringp delim)) |
yuuji@23 | 224 (save-excursion |
yuuji@23 | 225 (skip-chars-backward (concat "^" delim)) |
yuuji@49 | 226 (point)) |
yuuji@23 | 227 (point-min)) |
yuuji@23 | 228 word (buffer-substring beg (point-max)) |
yuuji@23 | 229 compl (try-completion word minibuffer-completion-table)) |
yuuji@23 | 230 (cond |
yuuji@49 | 231 ((eq compl t) |
yuuji@49 | 232 (let ((p (point)) (max (point-max))) |
yuuji@49 | 233 (goto-char max) |
yuuji@49 | 234 (insert " [Sole completion]") |
yuuji@49 | 235 (goto-char p) |
yuuji@49 | 236 (sit-for 1) |
yuuji@49 | 237 (delete-region max (point-max)) |
yuuji@49 | 238 (goto-char p))) |
yuuji@23 | 239 ((eq compl nil) |
yuuji@23 | 240 (ding) |
yuuji@23 | 241 (save-excursion |
yuuji@23 | 242 (let (p) |
yuuji@23 | 243 (goto-char (setq p (point-max))) |
yuuji@23 | 244 (insert " [No match]") |
yuuji@23 | 245 (goto-char p) |
yuuji@23 | 246 (sit-for 2) |
yuuji@23 | 247 (delete-region p (point-max))))) |
yuuji@23 | 248 ((string= compl word) |
yuuji@23 | 249 (with-output-to-temp-buffer "*Completions*" |
yuuji@23 | 250 (display-completion-list |
yuuji@23 | 251 (all-completions word minibuffer-completion-table)))) |
yuuji@23 | 252 (t (delete-region beg (point-max)) |
yuuji@23 | 253 (insert compl)) |
yuuji@49 | 254 ) |
yuuji@49 | 255 (store-match-data md)) |
yuuji@23 | 256 ) |
yuuji@23 | 257 |
yuuji@23 | 258 |
yuuji@23 | 259 (provide 'yatexlib) |