yatex

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