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