yatex
diff yatexhlp.el @ 45:b0fc9c2950cd
Prepare for supporting Emacs-19.
author | yuuji |
---|---|
date | Sun, 24 Jul 1994 15:07:23 +0000 |
parents | cb9afa9c1213 |
children | cd1b63102eed |
line diff
1.1 --- a/yatexhlp.el Fri May 06 21:14:11 1994 +0000 1.2 +++ b/yatexhlp.el Sun Jul 24 15:07:23 1994 +0000 1.3 @@ -2,7 +2,7 @@ 1.4 ;;; YaTeX helper with LaTeX commands and macros. 1.5 ;;; yatexhlp.el 1.6 ;;; (c )1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp] 1.7 -;;; Last modified Thu May 5 16:09:42 1994 on 98fa 1.8 +;;; Last modified Fri Jul 1 17:03:23 1994 on VFR 1.9 ;;; $Id$ 1.10 1.11 (let ((help-file 1.12 @@ -34,7 +34,73 @@ 1.13 (t "[[ Description ]]")) 1.14 "Section header of description.") 1.15 1.16 -(defun YaTeX-refer-help (command help-file) 1.17 +(defvar YaTeX-help-reference-regexp "<refer\\s +\\([^>]+\\)>" 1.18 + "Regexp of reference format of YaTeX-help file.") 1.19 +(defvar YaTeX-help-buffer "** YaTeX HELP **" "Help buffer name for yatexhlp") 1.20 + 1.21 +(defun YaTeX-help-entries () 1.22 + "Return the alist which contains all the entries in YaTeX-help file." 1.23 + (let (entries entry) 1.24 + (save-excursion 1.25 + (mapcar 1.26 + (function 1.27 + (lambda (help) 1.28 + (if (file-exists-p help) 1.29 + (progn 1.30 + (set-buffer (find-file-noselect help)) 1.31 + (save-excursion 1.32 + (goto-char (point-min)) 1.33 + (while (re-search-forward 1.34 + (concat "^" (regexp-quote YaTeX-help-delimiter) 1.35 + "\\(.+\\)$") nil t) 1.36 + (setq entry (buffer-substring 1.37 + (match-beginning 1) (match-end 1))) 1.38 + (or (assoc entry entries) 1.39 + (setq entries (cons (list entry) entries))))))))) 1.40 + (list YaTeX-help-file YaTeX-help-file-private))) 1.41 + entries) 1.42 +) 1.43 + 1.44 +(defvar YaTeX-help-entries (YaTeX-help-entries)) 1.45 + 1.46 +(defun YaTeX-help-resolve-reference (buffer1 buffer2 &optional done-list) 1.47 + "Replace reference format in buffer1 with refered contents in buffer2." 1.48 + (let (ref ref-list beg end) 1.49 + (save-excursion 1.50 + (switch-to-buffer buffer1) 1.51 + (goto-char (point-min)) 1.52 + (while (re-search-forward YaTeX-help-reference-regexp nil t) 1.53 + (setq ref (buffer-substring (match-beginning 1) (match-end 1)) 1.54 + ref-list (cons (list ref) ref-list)) 1.55 + (replace-match "") 1.56 + (if (assoc ref done-list) nil ;already documented. 1.57 + (switch-to-buffer buffer2) 1.58 + (save-excursion 1.59 + (goto-char (point-min)) 1.60 + (if (re-search-forward 1.61 + (concat (regexp-quote YaTeX-help-delimiter) 1.62 + (regexp-quote ref) 1.63 + "$") nil t) 1.64 + (progn 1.65 + (setq beg (progn (forward-line 2) (point)) 1.66 + end (progn 1.67 + (re-search-forward 1.68 + (concat "^" (regexp-quote YaTeX-help-delimiter)) 1.69 + nil 1) 1.70 + (goto-char (match-beginning 0)) 1.71 + (forward-line -1) 1.72 + (while (and (bolp) (eolp) (not (bobp))) 1.73 + (forward-char -1)) 1.74 + (point))) 1.75 + (switch-to-buffer buffer1) 1.76 + (insert-buffer-substring buffer2 beg end)))) 1.77 + (switch-to-buffer buffer1))) 1.78 + (if beg (YaTeX-help-resolve-reference 1.79 + buffer1 buffer2 (append done-list ref-list)))) 1.80 + ) 1.81 +) 1.82 + 1.83 +(defun YaTeX-refer-help (command help-file &optional append) 1.84 "Refer the COMMAND's help into HELP-FILE. 1.85 \[Help-file format\] 1.86 <DELIM><LaTeX/TeX command without escape character(\\)><NL> 1.87 @@ -44,31 +110,35 @@ 1.88 <NL> is newline. 1.89 <TERM> is newline or end of buffer." 1.90 (let ((hfbuf (find-file-noselect help-file)) 1.91 - (hbuf (get-buffer-create "** YaTeX HELP **")) 1.92 + (hbuf (get-buffer-create YaTeX-help-buffer)) 1.93 (curwin (selected-window)) 1.94 sb se db de) 1.95 (set-buffer hfbuf) 1.96 (goto-char (point-min)) 1.97 (if (null 1.98 - (re-search-forward 1.99 - (concat (regexp-quote YaTeX-help-delimiter) 1.100 - (regexp-quote command) 1.101 - "$") nil t)) 1.102 + (let ((case-fold-search nil)) 1.103 + (re-search-forward 1.104 + (concat (regexp-quote YaTeX-help-delimiter) 1.105 + (regexp-quote command) 1.106 + "$") nil t))) 1.107 nil ;if not found, return nil 1.108 (forward-line 1) 1.109 (setq sb (point) 1.110 se (progn (forward-line 1) (point)) 1.111 db (point) 1.112 de (progn 1.113 - (re-search-forward (regexp-quote YaTeX-help-delimiter) nil 1) 1.114 - (1- (match-beginning 0)))) 1.115 - (YaTeX-showup-buffer hbuf) 1.116 + (re-search-forward 1.117 + (concat "^" (regexp-quote YaTeX-help-delimiter)) nil 1) 1.118 + (- (point) (length YaTeX-help-delimiter)))) 1.119 + (YaTeX-showup-buffer 1.120 + hbuf (function (lambda (x) (nth 3 (window-edges x))))) 1.121 (pop-to-buffer hbuf) 1.122 - (erase-buffer) 1.123 + (if append (goto-char (point-max)) (erase-buffer)) 1.124 (insert YaTeX-help-synopsis "\n") 1.125 (insert-buffer-substring hfbuf sb se) 1.126 (insert "\n" YaTeX-help-description "\n") 1.127 (insert-buffer-substring hfbuf db de) 1.128 + (YaTeX-help-resolve-reference hbuf hfbuf (list (list command))) 1.129 (goto-char (point-min)) 1.130 (select-window curwin) 1.131 t)) 1.132 @@ -110,13 +180,15 @@ 1.133 (delete-blank-lines) 1.134 (let ((make-backup-files t)) 1.135 (basic-save-buffer)) 1.136 - (bury-buffer hfbuf)) 1.137 + (bury-buffer hfbuf) 1.138 + (setq YaTeX-help-entries (cons (list command) YaTeX-help-entries))) 1.139 ) 1.140 (defun YaTeX-help-prepare-entry (command help-file) 1.141 "Read help description on COMMAND and add it to HELP-FILE." 1.142 (let ((buf (get-buffer-create "**Description**")) 1.143 (conf (current-window-configuration))) 1.144 - (YaTeX-showup-buffer buf) 1.145 + (YaTeX-showup-buffer 1.146 + buf (function (lambda (x) (nth 3 (window-edges x))))) 1.147 (pop-to-buffer buf) 1.148 (make-local-variable 'YaTeX-help-file-current) 1.149 (make-local-variable 'YaTeX-help-command-current) 1.150 @@ -153,6 +225,44 @@ 1.151 nil "\\(\\sw+\\)\\([^]+\\|\\s'\\)" "\\1" (point-min) (point-max)) 1.152 ) 1.153 1.154 +(defun YaTeX-apropos-file (keyword help-file &optional append) 1.155 + (let ((hb (find-file-noselect help-file)) 1.156 + (ab (get-buffer-create YaTeX-help-buffer)) 1.157 + (sw (selected-window)) 1.158 + (head (concat "^" (regexp-quote YaTeX-help-delimiter))) 1.159 + pt command) 1.160 + (YaTeX-showup-buffer 1.161 + ab (function (lambda (x) (nth 3 (window-edges x))))) 1.162 + (select-window (get-buffer-window ab)) 1.163 + (set-buffer ab) ;assertion 1.164 + (or append (erase-buffer)) 1.165 + (set-buffer hb) 1.166 + (goto-char (point-min)) 1.167 + (while (re-search-forward keyword nil t) 1.168 + (setq pt (point)) 1.169 + (re-search-backward head nil t) 1.170 + (setq command (buffer-substring (match-end 0) (point-end-of-line))) 1.171 + (switch-to-buffer ab) 1.172 + (goto-char (point-max)) 1.173 + (insert-char ?- (1- (window-width))) 1.174 + (insert (format "\n<<%s>>\n" command)) 1.175 + (YaTeX-refer-help command help-file t) ;append mode 1.176 + (set-buffer hb) 1.177 + (goto-char pt) 1.178 + (if (re-search-forward head nil 1) 1.179 + (goto-char (1- (match-beginning 0))))) 1.180 + (select-window sw) 1.181 + pt) 1.182 +) 1.183 + 1.184 +;;;###autoload 1.185 +(defun YaTeX-apropos (key) 1.186 + (interactive "sLaTeX apropos (regexp): ") 1.187 + (or (YaTeX-apropos-file key YaTeX-help-file) 1.188 + (YaTeX-apropos-file key YaTeX-help-file-private t) 1.189 + (message "No matches found.")) 1.190 +) 1.191 + 1.192 ;;;###autoload 1.193 (defun YaTeX-help () 1.194 "Show help buffer of LaTeX/TeX commands or macros." 1.195 @@ -172,7 +282,7 @@ 1.196 (buffer-substring (match-beginning 2) (match-end 2)))))) 1.197 ((search-backward YaTeX-ec (point-beginning-of-line) t) 1.198 (goto-char (setq beg (match-end 0))) 1.199 - (re-search-forward "\\sw+") 1.200 + (re-search-forward YaTeX-TeX-token-regexp (point-end-of-line) t) 1.201 (setq end (point)) 1.202 (if (and (<= beg p) (<= p end)) 1.203 (setq command (buffer-substring beg end))))) 1.204 @@ -185,12 +295,7 @@ 1.205 (setq command 1.206 (completing-read 1.207 "Describe (La)TeX command: " 1.208 - (append 1.209 - section-table user-section-table tmp-section-table 1.210 - article-table user-article-table 1.211 - env-table user-env-table tmp-env-table 1.212 - singlecmd-table user-singlecmd-table tmp-singlecmd-table) 1.213 - nil nil command)) ;no-predicate, not require match 1.214 + YaTeX-help-entries nil nil command)) 1.215 );end excursion 1.216 (or (YaTeX-refer-help command YaTeX-help-file) 1.217 (YaTeX-refer-help command YaTeX-help-file-private)