yatex

annotate yatexhlp.el @ 23:b00c74813e56

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