annotate yatexhlp.el @ 53:5f4b18da14b3

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

yatex.org