yatex

view yatexhlp.el @ 16:cb9afa9c1213

Auto-indentation at begin-type completion works correctly. Hack for gmhist&gmhist-mh. Fix the bug on \ref-completion. YaTeX-help is now available.
author yuuji
date Fri, 06 May 1994 21:14:11 +0000
parents
children b00c74813e56
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 Thu May 5 16:09:42 1994 on 98fa
6 ;;; $Id$
8 (let ((help-file
9 (concat "YATEXHLP."
10 (cond (YaTeX-japan "jp")
11 (t "eng")))))
12 (defvar YaTeX-help-file
13 (expand-file-name help-file exec-directory)
14 "*Help file of LaTeX/TeX commands or macros.")
15 (defvar YaTeX-help-file-private
16 (expand-file-name (concat "~/" help-file))
17 "*Private help file of LaTeX/TeX macros.")
18 )
19 (defvar YaTeX-help-delimiter "\C-_" "Delimiter of each help entry.")
20 (defvar YaTeX-help-entry-map (copy-keymap YaTeX-mode-map)
21 "Key map used in help entry.")
22 (defvar YaTeX-help-file-current nil
23 "Holds help file name to which the description in current buffer should go.")
24 (defvar YaTeX-help-command-current nil
25 "Holds command name on which the user currently write description.")
26 (defvar YaTeX-help-saved-config nil
27 "Holds window configruation before the editing of manual.")
28 (defvar YaTeX-help-synopsis
29 (cond (YaTeX-japan "【書式】")
30 (t "[[ Synopsis ]]"))
31 "Section header of synopsis.")
32 (defvar YaTeX-help-description
33 (cond (YaTeX-japan "【説明】")
34 (t "[[ Description ]]"))
35 "Section header of description.")
37 (defun YaTeX-refer-help (command help-file)
38 "Refer the COMMAND's help into HELP-FILE.
39 \[Help-file format\]
40 <DELIM><LaTeX/TeX command without escape character(\\)><NL>
41 <Synopsis><NL>
42 <Documentation><TERM>
43 Where: <DELIM> is the value of YaTeX-help-delimiter.
44 <NL> is newline.
45 <TERM> is newline or end of buffer."
46 (let ((hfbuf (find-file-noselect help-file))
47 (hbuf (get-buffer-create "** YaTeX HELP **"))
48 (curwin (selected-window))
49 sb se db de)
50 (set-buffer hfbuf)
51 (goto-char (point-min))
52 (if (null
53 (re-search-forward
54 (concat (regexp-quote YaTeX-help-delimiter)
55 (regexp-quote command)
56 "$") nil t))
57 nil ;if not found, return nil
58 (forward-line 1)
59 (setq sb (point)
60 se (progn (forward-line 1) (point))
61 db (point)
62 de (progn
63 (re-search-forward (regexp-quote YaTeX-help-delimiter) nil 1)
64 (1- (match-beginning 0))))
65 (YaTeX-showup-buffer hbuf)
66 (pop-to-buffer hbuf)
67 (erase-buffer)
68 (insert YaTeX-help-synopsis "\n")
69 (insert-buffer-substring hfbuf sb se)
70 (insert "\n" YaTeX-help-description "\n")
71 (insert-buffer-substring hfbuf db de)
72 (goto-char (point-min))
73 (select-window curwin)
74 t))
75 )
76 (defun YaTeX-help-newline (&optional arg)
77 (interactive "P")
78 (if (and (= (current-column) 1) (= (preceding-char) ?.) (eolp))
79 (let ((cbuf (current-buffer)))
80 (beginning-of-line)
81 (kill-line 1)
82 (save-excursion
83 (YaTeX-help-add-entry
84 YaTeX-help-command-current YaTeX-help-file-current))
85 (set-window-configuration YaTeX-help-saved-config)
86 (bury-buffer cbuf))
87 (newline arg))
88 )
89 (defun YaTeX-help-add-entry (command help-file)
90 (let ((hfbuf (find-file-noselect help-file))
91 (dbuf (current-buffer)) beg end)
92 (goto-char (point-min))
93 (re-search-forward (concat "^" (regexp-quote YaTeX-help-synopsis)))
94 (forward-line 1) (setq beg (point))
95 (end-of-line) (setq end (point))
96 (set-buffer hfbuf)
97 (goto-char (point-min))
98 (insert YaTeX-help-delimiter command "\n")
99 (insert-buffer-substring dbuf beg end)
100 (insert "\n")
101 (set-buffer dbuf)
102 (re-search-forward (concat "^" (regexp-quote YaTeX-help-description)))
103 (forward-line 1)
104 (setq beg (point))
105 (setq end (point-max))
106 (set-buffer hfbuf)
107 (insert-buffer-substring dbuf beg end)
108 (insert "\n\n")
109 (forward-line -1)
110 (delete-blank-lines)
111 (let ((make-backup-files t))
112 (basic-save-buffer))
113 (bury-buffer hfbuf))
114 )
115 (defun YaTeX-help-prepare-entry (command help-file)
116 "Read help description on COMMAND and add it to HELP-FILE."
117 (let ((buf (get-buffer-create "**Description**"))
118 (conf (current-window-configuration)))
119 (YaTeX-showup-buffer buf)
120 (pop-to-buffer buf)
121 (make-local-variable 'YaTeX-help-file-current)
122 (make-local-variable 'YaTeX-help-command-current)
123 (make-local-variable 'YaTeX-help-saved-config)
124 (setq YaTeX-help-file-current help-file
125 YaTeX-help-command-current command
126 YaTeX-help-saved-config conf
127 mode-name "Text"
128 major-mode 'text)
129 (erase-buffer)
130 (insert YaTeX-help-synopsis "\n\n" YaTeX-help-description "\n\n")
131 (define-key YaTeX-help-entry-map "\r" 'YaTeX-help-newline)
132 (use-local-map YaTeX-help-entry-map)
133 (message
134 (cond (YaTeX-japan "入力を終えたら . のみ入力してRET")
135 (t "Type only `.' and RET to exit."))))
136 )
137 (defun YaTeX-enrich-help (command)
138 "Add the COMMAND's help to help file."
139 (if (y-or-n-p (format "No help on `%s'. Create help?" command))
140 (YaTeX-help-prepare-entry
141 command
142 (if (y-or-n-p "Add help to global documentation?")
143 YaTeX-help-file YaTeX-help-file-private)))
144 )
146 (defun YaTeX-help-sort (&optional help-file)
147 "Sort help file HELP-FILE.
148 If HELP-FILE is nil or called interactively, sort current buffer
149 as a help file."
150 (interactive)
151 (if help-file (set-buffer (find-file-noselect help-file)))
152 (sort-regexp-fields
153 nil "\\(\\sw+\\)\\([^]+\\|\\s'\\)" "\\1" (point-min) (point-max))
154 )
156 ;;;###autoload
157 (defun YaTeX-help ()
158 "Show help buffer of LaTeX/TeX commands or macros."
159 (interactive)
160 (let (p beg end command)
161 (save-excursion
162 (if (looking-at YaTeX-ec-regexp)
163 (goto-char (match-end 0)))
164 (setq p (point)) ;remember current position.
165 (cond
166 ((YaTeX-on-begin-end-p)
167 ;;if on \begin or \end, extract its environment.
168 (setq command
169 (cond ((match-beginning 1)
170 (buffer-substring (match-beginning 1) (match-end 1)))
171 ((match-beginning 2)
172 (buffer-substring (match-beginning 2) (match-end 2))))))
173 ((search-backward YaTeX-ec (point-beginning-of-line) t)
174 (goto-char (setq beg (match-end 0)))
175 (re-search-forward "\\sw+")
176 (setq end (point))
177 (if (and (<= beg p) (<= p end))
178 (setq command (buffer-substring beg end)))))
179 (if (or (string= command "begin") (string= command "end"))
180 (progn
181 (search-forward "{" (point-end-of-line))
182 (setq beg (point))
183 (search-forward "}" (point-end-of-line))
184 (setq command (buffer-substring beg (match-beginning 0)))))
185 (setq command
186 (completing-read
187 "Describe (La)TeX command: "
188 (append
189 section-table user-section-table tmp-section-table
190 article-table user-article-table
191 env-table user-env-table tmp-env-table
192 singlecmd-table user-singlecmd-table tmp-singlecmd-table)
193 nil nil command)) ;no-predicate, not require match
194 );end excursion
195 (or (YaTeX-refer-help command YaTeX-help-file)
196 (YaTeX-refer-help command YaTeX-help-file-private)
197 (YaTeX-enrich-help command)))
198 )