yatex
diff yatexlib.el @ 26:abf840be9939
version 1.50
author | yuuji |
---|---|
date | Fri, 08 Jul 1994 19:39:38 +0000 |
parents | |
children | cd1b63102eed |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/yatexlib.el Fri Jul 08 19:39:38 1994 +0000 1.3 @@ -0,0 +1,227 @@ 1.4 +;;; -*- Emacs-Lisp -*- 1.5 +;;; YaTeX library of general functions. 1.6 +;;; yatexlib.el 1.7 +;;; (c )1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp] 1.8 +;;; Last modified Fri Jul 8 00:44:41 1994 on figaro 1.9 +;;; $Id$ 1.10 + 1.11 +;;;###autoload 1.12 +(defun YaTeX-search-active-forward (string cmntrx &optional bound err cnt func) 1.13 + "Search STRING which is not commented out by CMNTRX. 1.14 +Optional arguments after BOUND, ERR, CNT are passed literally to search-forward 1.15 +or search-backward. 1.16 +Optional sixth argument FUNC changes search-function." 1.17 + (let ((sfunc (if func func 'search-forward)) found md) 1.18 + (while (and (prog1 1.19 + (setq found (funcall sfunc string bound err cnt)) 1.20 + (setq md (match-data))) 1.21 + (or 1.22 + (YaTeX-in-verb-p (match-beginning 0)) 1.23 + (save-excursion 1.24 + (beginning-of-line) 1.25 + (re-search-forward cmntrx (match-beginning 0) t))))) 1.26 + (store-match-data md) 1.27 + found) 1.28 +) 1.29 + 1.30 +(defun YaTeX-re-search-active-forward (regexp cmntrx &optional bound err cnt) 1.31 + "Search REGEXP backward which is not commented out by regexp CMNTRX. 1.32 +See also YaTeX-search-active-forward." 1.33 + (YaTeX-search-active-forward regexp cmntrx bound err cnt 're-search-forward) 1.34 +) 1.35 +(defun YaTeX-search-active-backward (string cmntrx &optional bound err cnt) 1.36 + "Search STRING backward which is not commented out by regexp CMNTRX. 1.37 +See also YaTeX-search-active-forward." 1.38 + (YaTeX-search-active-forward string cmntrx bound err cnt 'search-backward) 1.39 +) 1.40 +(defun YaTeX-re-search-active-backward (regexp cmntrx &optional bound err cnt) 1.41 + "Search REGEXP backward which is not commented out by regexp CMNTRX. 1.42 +See also YaTeX-search-active-forward." 1.43 + (YaTeX-search-active-forward regexp cmntrx bound err cnt 're-search-backward) 1.44 +) 1.45 + 1.46 + 1.47 +;;;###autoload 1.48 +(defun YaTeX-switch-to-buffer (file &optional setbuf) 1.49 + "Switch to buffer if buffer exists, find file if not. 1.50 +Optional second arg SETBUF t make use set-buffer instead of switch-to-buffer." 1.51 + (interactive "Fswitch to file: ") 1.52 + (let (buf) 1.53 + (if (setq buf (get-buffer (file-name-nondirectory file))) 1.54 + (progn 1.55 + (funcall (if setbuf 'set-buffer 'switch-to-buffer) 1.56 + (file-name-nondirectory file)) 1.57 + buf) 1.58 + (if (file-exists-p file) 1.59 + (progn (find-file file) (current-buffer)) 1.60 + (message "%s was not found in this directory." file) 1.61 + nil))) 1.62 +) 1.63 + 1.64 +;;;###autoload 1.65 +(defun YaTeX-switch-to-buffer-other-window (file) 1.66 + "Switch to buffer if buffer exists, find file if not." 1.67 + (interactive "Fswitch to file: ") 1.68 + (if (get-buffer (file-name-nondirectory file)) 1.69 + (progn (switch-to-buffer-other-window file) t) 1.70 + (if (file-exists-p file) 1.71 + (progn (find-file-other-window file) t) 1.72 + (message "%s was not found in this directory." file) 1.73 + nil)) 1.74 +) 1.75 + 1.76 +(defun YaTeX-replace-format-sub (string format repl) 1.77 + (let ((beg (or (string-match (concat "^\\(%" format "\\)") string) 1.78 + (string-match (concat "[^%]\\(%" format "\\)") string))) 1.79 + (len (length format))) 1.80 + (if (null beg) string ;no conversion 1.81 + (concat 1.82 + (substring string 0 (match-beginning 1)) repl 1.83 + (substring string (match-end 1))))) 1.84 +) 1.85 + 1.86 +;;;###autoload 1.87 +(defun YaTeX-replace-format (string format repl) 1.88 + "In STRING, replace first appearance of FORMAT to REPL as if 1.89 +function `format' does. FORMAT does not contain `%'" 1.90 + (let ((ans string)) 1.91 + (while (not (string= 1.92 + ans (setq string (YaTeX-replace-format-sub ans format repl)))) 1.93 + (setq ans string)) 1.94 + string) 1.95 +) 1.96 + 1.97 +;;;###autoload 1.98 +(defun YaTeX-replace-format-args (string &rest args) 1.99 + "Translate the argument mark #1, #2, ... #n in the STRING into the 1.100 +corresponding real arguments ARGS." 1.101 + (let ((argp 1)) 1.102 + (while args 1.103 + (setq string 1.104 + (YaTeX-replace-format string (int-to-string argp) (car args))) 1.105 + (setq args (cdr args) argp (1+ argp)))) 1.106 + string 1.107 +) 1.108 + 1.109 +;;;###autoload 1.110 +(defun rindex (string char) 1.111 + (let ((pos (1- (length string)))(index -1)) 1.112 + (while (>= pos 0) 1.113 + (cond 1.114 + ((= (aref string pos) char) 1.115 + (setq index pos) (setq pos -1)) 1.116 + (t (setq pos (1- pos)))) 1.117 + ) 1.118 + index) 1.119 +) 1.120 + 1.121 +;;;###autoload 1.122 +(defun YaTeX-showup-buffer (buffer &optional func select) 1.123 + "Make BUFFER show up in certain window (but current window) 1.124 +that gives the maximum value by the FUNC. FUNC should take an argument 1.125 +of its window object. Non-nil for optional third argument SELECT selects 1.126 +that window." 1.127 + (or (and (get-buffer-window buffer) 1.128 + (progn (if select (select-window (get-buffer-window buffer))) 1.129 + t)) 1.130 + (let ((window (selected-window)) 1.131 + (wlist (YaTeX-window-list)) win w (x 0)) 1.132 + (cond 1.133 + ((> (length wlist) 2) 1.134 + (if func 1.135 + (while wlist 1.136 + (setq w (car wlist)) 1.137 + (if (and (not (eq window w)) 1.138 + (> (funcall func w) x)) 1.139 + (setq win w x (funcall func w))) 1.140 + (setq wlist (cdr wlist))) 1.141 + (setq win (get-lru-window))) 1.142 + (select-window win) 1.143 + (switch-to-buffer buffer) 1.144 + (or select (select-window window))) 1.145 + ((= (length wlist) 2) 1.146 + (other-window 1) 1.147 + (switch-to-buffer buffer) 1.148 + (or select (select-window window))) 1.149 + (t ;if one-window 1.150 + (cond 1.151 + (YaTeX-default-pop-window-height 1.152 + (split-window 1.153 + (selected-window) 1.154 + (max 1.155 + (min 1.156 + (- (screen-height) 1.157 + (if (numberp YaTeX-default-pop-window-height) 1.158 + (+ YaTeX-default-pop-window-height 2) 1.159 + (/ (* (screen-height) 1.160 + (string-to-int YaTeX-default-pop-window-height)) 1.161 + 100))) 1.162 + (- (screen-height) window-min-height 1)) 1.163 + window-min-height)) 1.164 + (pop-to-buffer buffer) 1.165 + (or select (select-window window))) 1.166 + (t nil))) 1.167 + ))) 1.168 +) 1.169 + 1.170 +;;;###autoload 1.171 +(defun YaTeX-window-list () 1.172 + (let*((curw (selected-window)) (win curw) (wlist (list curw))) 1.173 + (while (not (eq curw (setq win (next-window win)))) 1.174 + (or (eq win (minibuffer-window)) 1.175 + (setq wlist (cons win wlist)))) 1.176 + wlist) 1.177 +) 1.178 + 1.179 +;;;###autoload 1.180 +(defun substitute-all-key-definition (olddef newdef keymap) 1.181 + "Replace recursively OLDDEF with NEWDEF for any keys in KEYMAP now 1.182 +defined as OLDDEF. In other words, OLDDEF is replaced with NEWDEF 1.183 +where ever it appears." 1.184 + (mapcar 1.185 + (function (lambda (key) (define-key keymap key newdef))) 1.186 + (where-is-internal olddef)) 1.187 +) 1.188 + 1.189 +;;;###autoload 1.190 +(defun YaTeX-match-string (n &optional m) 1.191 + "Return (buffer-substring (match-beginning n) (match-beginning m))." 1.192 + (if (match-beginning n) 1.193 + (buffer-substring (match-beginning n) 1.194 + (match-end (if m m n)))) 1.195 +) 1.196 + 1.197 +;;;###autoload 1.198 +(defun YaTeX-minibuffer-complete () 1.199 + "Complete in minibuffer" 1.200 + (interactive) 1.201 + (let (beg word compl) 1.202 + (setq beg (if (and (boundp 'delim) delim) 1.203 + (save-excursion 1.204 + (skip-chars-backward (concat "^" delim)) 1.205 + (1- (point))) 1.206 + (point-min)) 1.207 + word (buffer-substring beg (point-max)) 1.208 + compl (try-completion word minibuffer-completion-table)) 1.209 + (cond 1.210 + ((eq compl t) nil) 1.211 + ((eq compl nil) 1.212 + (ding) 1.213 + (save-excursion 1.214 + (let (p) 1.215 + (goto-char (setq p (point-max))) 1.216 + (insert " [No match]") 1.217 + (goto-char p) 1.218 + (sit-for 2) 1.219 + (delete-region p (point-max))))) 1.220 + ((string= compl word) 1.221 + (with-output-to-temp-buffer "*Completions*" 1.222 + (display-completion-list 1.223 + (all-completions word minibuffer-completion-table)))) 1.224 + (t (delete-region beg (point-max)) 1.225 + (insert compl)) 1.226 + )) 1.227 +) 1.228 + 1.229 + 1.230 +(provide 'yatexlib)