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