yatex

view yatexhlp.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 cd1b63102eed
children 5f4b18da14b3
line source
1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX helper with LaTeX commands and macros.
3 ;;; yatexhlp.el
4 ;;; (c )1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
5 ;;; Last modified Sat Nov 12 04:20:26 1994 on VFR
6 ;;; $Id$
8 (let ((help-file (concat "YATEXHLP."
9 (cond (YaTeX-japan "jp")
10 (t "eng"))))
11 (help-dir
12 (cond
13 (YaTeX-emacs-19 (expand-file-name "../../site-lisp" exec-directory))
14 (t exec-directory))))
15 (defvar YaTeX-help-file
16 (expand-file-name help-file help-dir)
17 "*Help file of LaTeX/TeX commands or macros.")
18 (defvar YaTeX-help-file-private
19 (expand-file-name (concat "~/" help-file))
20 "*Private help file of LaTeX/TeX macros.")
21 )
22 (defvar YaTeX-help-delimiter "\C-_" "Delimiter of each help entry.")
23 (defvar YaTeX-help-entry-map (copy-keymap YaTeX-mode-map)
24 "Key map used in help entry.")
25 (defvar YaTeX-help-file-current nil
26 "Holds help file name to which the description in current buffer should go.")
27 (defvar YaTeX-help-command-current nil
28 "Holds command name on which the user currently write description.")
29 (defvar YaTeX-help-saved-config nil
30 "Holds window configruation before the editing of manual.")
31 (defvar YaTeX-help-synopsis
32 (cond (YaTeX-japan "【書式】")
33 (t "[[ Synopsis ]]"))
34 "Section header of synopsis.")
35 (defvar YaTeX-help-description
36 (cond (YaTeX-japan "【説明】")
37 (t "[[ Description ]]"))
38 "Section header of description.")
40 (defvar YaTeX-help-reference-regexp "<refer\\s +\\([^>]+\\)>"
41 "Regexp of reference format of YaTeX-help file.")
42 (defvar YaTeX-help-buffer "** YaTeX HELP **" "Help buffer name for yatexhlp")
44 (defun YaTeX-help-entries ()
45 "Return the alist which contains all the entries in YaTeX-help file."
46 (let (entries entry)
47 (save-excursion
48 (mapcar
49 (function
50 (lambda (help)
51 (if (file-exists-p help)
52 (progn
53 (set-buffer (find-file-noselect help))
54 (save-excursion
55 (goto-char (point-min))
56 (while (re-search-forward
57 (concat "^" (regexp-quote YaTeX-help-delimiter)
58 "\\(.+\\)$") nil t)
59 (setq entry (buffer-substring
60 (match-beginning 1) (match-end 1)))
61 (or (assoc entry entries)
62 (setq entries (cons (list entry) entries)))))))))
63 (list YaTeX-help-file YaTeX-help-file-private)))
64 entries)
65 )
67 (defvar YaTeX-help-entries (YaTeX-help-entries))
69 (defun YaTeX-help-resolve-reference (buffer1 buffer2 &optional done-list)
70 "Replace reference format in buffer1 with refered contents in buffer2."
71 (let (ref ref-list beg end)
72 (save-excursion
73 (switch-to-buffer buffer1)
74 (goto-char (point-min))
75 (while (re-search-forward YaTeX-help-reference-regexp nil t)
76 (setq ref (buffer-substring (match-beginning 1) (match-end 1))
77 ref-list (cons (list ref) ref-list))
78 (replace-match "")
79 (if (assoc ref done-list) nil ;already documented.
80 (switch-to-buffer buffer2)
81 (save-excursion
82 (goto-char (point-min))
83 (if (re-search-forward
84 (concat (regexp-quote YaTeX-help-delimiter)
85 (regexp-quote ref)
86 "$") nil t)
87 (progn
88 (setq beg (progn (forward-line 2) (point))
89 end (progn
90 (re-search-forward
91 (concat "^" (regexp-quote YaTeX-help-delimiter))
92 nil 1)
93 (goto-char (match-beginning 0))
94 (forward-line -1)
95 (while (and (bolp) (eolp) (not (bobp)))
96 (forward-char -1))
97 (point)))
98 (switch-to-buffer buffer1)
99 (insert-buffer-substring buffer2 beg end))))
100 (switch-to-buffer buffer1)))
101 (if beg (YaTeX-help-resolve-reference
102 buffer1 buffer2 (append done-list ref-list))))
103 )
104 )
106 (defun YaTeX-refer-help (command help-file &optional append)
107 "Refer the COMMAND's help into HELP-FILE.
108 \[Help-file format\]
109 <DELIM><LaTeX/TeX command without escape character(\\)><NL>
110 <Synopsis><NL>
111 <Documentation><TERM>
112 Where: <DELIM> is the value of YaTeX-help-delimiter.
113 <NL> is newline.
114 <TERM> is newline or end of buffer."
115 (let ((hfbuf (find-file-noselect help-file))
116 (hbuf (get-buffer-create YaTeX-help-buffer))
117 (curwin (selected-window))
118 sb se db de)
119 (set-buffer hfbuf)
120 (goto-char (point-min))
121 (if (null
122 (let ((case-fold-search nil))
123 (re-search-forward
124 (concat (regexp-quote YaTeX-help-delimiter)
125 (regexp-quote command)
126 "$") nil t)))
127 nil ;if not found, return nil
128 (forward-line 1)
129 (setq sb (point)
130 se (progn (forward-line 1) (point))
131 db (point)
132 de (progn
133 (re-search-forward
134 (concat "^" (regexp-quote YaTeX-help-delimiter)) nil 1)
135 (- (point) (length YaTeX-help-delimiter))))
136 (YaTeX-showup-buffer
137 hbuf (function (lambda (x) (nth 3 (window-edges x)))))
138 (pop-to-buffer hbuf)
139 (if append (goto-char (point-max)) (erase-buffer))
140 (insert YaTeX-help-synopsis "\n")
141 (insert-buffer-substring hfbuf sb se)
142 (insert "\n" YaTeX-help-description "\n")
143 (insert-buffer-substring hfbuf db de)
144 (YaTeX-help-resolve-reference hbuf hfbuf (list (list command)))
145 (goto-char (point-min))
146 (select-window curwin)
147 t))
148 )
149 (defun YaTeX-help-newline (&optional arg)
150 (interactive "P")
151 (if (and (= (current-column) 1) (= (preceding-char) ?.) (eolp))
152 (let ((cbuf (current-buffer)))
153 (beginning-of-line)
154 (kill-line 1)
155 (save-excursion
156 (YaTeX-help-add-entry
157 YaTeX-help-command-current YaTeX-help-file-current))
158 (set-window-configuration YaTeX-help-saved-config)
159 (bury-buffer cbuf))
160 (newline arg))
161 )
162 (defun YaTeX-help-add-entry (command help-file)
163 (let ((hfbuf (find-file-noselect help-file))
164 (dbuf (current-buffer)) beg end)
165 (goto-char (point-min))
166 (re-search-forward (concat "^" (regexp-quote YaTeX-help-synopsis)))
167 (forward-line 1) (setq beg (point))
168 (end-of-line) (setq end (point))
169 (set-buffer hfbuf)
170 (goto-char (point-min))
171 (insert YaTeX-help-delimiter command "\n")
172 (insert-buffer-substring dbuf beg end)
173 (insert "\n")
174 (set-buffer dbuf)
175 (re-search-forward (concat "^" (regexp-quote YaTeX-help-description)))
176 (forward-line 1)
177 (setq beg (point))
178 (setq end (point-max))
179 (set-buffer hfbuf)
180 (insert-buffer-substring dbuf beg end)
181 (insert "\n\n")
182 (forward-line -1)
183 (delete-blank-lines)
184 (let ((make-backup-files t))
185 (basic-save-buffer))
186 (bury-buffer hfbuf)
187 (setq YaTeX-help-entries (cons (list command) YaTeX-help-entries)))
188 )
189 (defun YaTeX-help-prepare-entry (command help-file)
190 "Read help description on COMMAND and add it to HELP-FILE."
191 (let ((buf (get-buffer-create "**Description**"))
192 (conf (current-window-configuration)))
193 (YaTeX-showup-buffer
194 buf (function (lambda (x) (nth 3 (window-edges x)))))
195 (pop-to-buffer buf)
196 (make-local-variable 'YaTeX-help-file-current)
197 (make-local-variable 'YaTeX-help-command-current)
198 (make-local-variable 'YaTeX-help-saved-config)
199 (setq YaTeX-help-file-current help-file
200 YaTeX-help-command-current command
201 YaTeX-help-saved-config conf
202 mode-name "Text"
203 major-mode 'text)
204 (erase-buffer)
205 (insert YaTeX-help-synopsis "\n\n" YaTeX-help-description "\n\n")
206 (define-key YaTeX-help-entry-map "\r" 'YaTeX-help-newline)
207 (use-local-map YaTeX-help-entry-map)
208 (message
209 (cond (YaTeX-japan "入力を終えたら . のみ入力してRET")
210 (t "Type only `.' and RET to exit."))))
211 )
212 (defun YaTeX-enrich-help (command)
213 "Add the COMMAND's help to help file."
214 (if (y-or-n-p (format "No help on `%s'. Create help?" command))
215 (YaTeX-help-prepare-entry
216 command
217 (if (y-or-n-p "Add help to global documentation?")
218 YaTeX-help-file YaTeX-help-file-private)))
219 )
221 (defun YaTeX-help-sort (&optional help-file)
222 "Sort help file HELP-FILE.
223 If HELP-FILE is nil or called interactively, sort current buffer
224 as a help file."
225 (interactive)
226 (if help-file (set-buffer (find-file-noselect help-file)))
227 (sort-regexp-fields
228 nil "\\(\\sw+\\)\\([^]+\\|\\s'\\)" "\\1" (point-min) (point-max))
229 )
231 (defun YaTeX-apropos-file (keyword help-file &optional append)
232 (let ((hb (find-file-noselect help-file))
233 (ab (get-buffer-create YaTeX-help-buffer))
234 (sw (selected-window))
235 (head (concat "^" (regexp-quote YaTeX-help-delimiter)))
236 pt command)
237 (YaTeX-showup-buffer
238 ab (function (lambda (x) (nth 3 (window-edges x)))))
239 (select-window (get-buffer-window ab))
240 (set-buffer ab) ;assertion
241 (or append (erase-buffer))
242 (set-buffer hb)
243 (goto-char (point-min))
244 (while (re-search-forward keyword nil t)
245 (setq pt (point))
246 (re-search-backward head nil t)
247 (setq command (buffer-substring (match-end 0) (point-end-of-line)))
248 (switch-to-buffer ab)
249 (goto-char (point-max))
250 (insert-char ?- (1- (window-width)))
251 (insert (format "\n<<%s>>\n" command))
252 (YaTeX-refer-help command help-file t) ;append mode
253 (set-buffer hb)
254 (goto-char pt)
255 (if (re-search-forward head nil 1)
256 (goto-char (1- (match-beginning 0)))))
257 (select-window sw)
258 pt)
259 )
261 ;;;###autoload
262 (defun YaTeX-apropos (key)
263 (interactive "sLaTeX apropos (regexp): ")
264 (or (YaTeX-apropos-file key YaTeX-help-file)
265 (YaTeX-apropos-file key YaTeX-help-file-private t)
266 (message "No matches found."))
267 )
269 ;;;###autoload
270 (defun YaTeX-help ()
271 "Show help buffer of LaTeX/TeX commands or macros."
272 (interactive)
273 (let (p beg end command)
274 (save-excursion
275 (if (looking-at YaTeX-ec-regexp)
276 (goto-char (match-end 0)))
277 (setq p (point)) ;remember current position.
278 (cond
279 ((YaTeX-on-begin-end-p)
280 ;;if on \begin or \end, extract its environment.
281 (setq command
282 (cond ((match-beginning 1)
283 (buffer-substring (match-beginning 1) (match-end 1)))
284 ((match-beginning 2)
285 (buffer-substring (match-beginning 2) (match-end 2))))))
286 ((search-backward YaTeX-ec (point-beginning-of-line) t)
287 (goto-char (setq beg (match-end 0)))
288 (re-search-forward YaTeX-TeX-token-regexp (point-end-of-line) t)
289 (setq end (point))
290 (if (and (<= beg p) (<= p end))
291 (setq command (buffer-substring beg end)))))
292 (if (or (string= command "begin") (string= command "end"))
293 (progn
294 (search-forward "{" (point-end-of-line))
295 (setq beg (point))
296 (search-forward "}" (point-end-of-line))
297 (setq command (buffer-substring beg (match-beginning 0)))))
298 (setq command
299 (completing-read
300 "Describe (La)TeX command: "
301 YaTeX-help-entries nil nil command))
302 );end excursion
303 (or (YaTeX-refer-help command YaTeX-help-file)
304 (YaTeX-refer-help command YaTeX-help-file-private)
305 (YaTeX-enrich-help command)))
306 )