Mercurial > hgrepos > hgweb.cgi > yatex
comparison yatexsec.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 | |
children | cd1b63102eed |
comparison
equal
deleted
inserted
replaced
22:9d2387100375 | 23:b00c74813e56 |
---|---|
1 ;;; -*- Emacs-Lisp -*- | |
2 ;;; YaTeX sectioning browser. | |
3 ;;; yatexsec.el | |
4 ;;; (c ) 1994 by HIROSE Yuuji [yuuji@ae.keio.ac.jp] | |
5 ;;; Last modified Thu Jul 7 01:26:26 1994 on 98fa | |
6 ;;; $Id$ | |
7 | |
8 (defvar YaTeX-sectioning-level | |
9 '(("part" . 0) ("chapter" . 1) ("section" . 2) ("subsection" . 3) | |
10 ("subsubsection" . 4) ("paragraph" . 5) ("subparagraph" . 6)) | |
11 "Sectioning level.") | |
12 | |
13 (defun YaTeX-sectioning-map-hide (map) | |
14 (let ((ch ?0)) | |
15 (while (<= ch ?9) | |
16 (define-key map (char-to-string ch) 'YaTeX-sectioning-hide) | |
17 (setq ch (1+ ch)))) | |
18 ) | |
19 | |
20 (defvar YaTeX-minibuffer-sectioning-map nil | |
21 "Key map used in minibuffer for sectioning.") | |
22 (if YaTeX-minibuffer-sectioning-map nil | |
23 (setq YaTeX-minibuffer-sectioning-map | |
24 (copy-keymap minibuffer-local-completion-map)) | |
25 (define-key YaTeX-minibuffer-sectioning-map "\C-p" | |
26 'YaTeX-sectioning-up) | |
27 (define-key YaTeX-minibuffer-sectioning-map "\C-e" | |
28 'YaTeX-sectioning-up) | |
29 (define-key YaTeX-minibuffer-sectioning-map "\C-i" | |
30 'YaTeX-minibuffer-complete) | |
31 (define-key YaTeX-minibuffer-sectioning-map " " | |
32 'YaTeX-minibuffer-complete) | |
33 (define-key YaTeX-minibuffer-sectioning-map "\C-n" | |
34 'YaTeX-sectioning-down) | |
35 (define-key YaTeX-minibuffer-sectioning-map "\C-x" | |
36 'YaTeX-sectioning-down) | |
37 (define-key YaTeX-minibuffer-sectioning-map "\C-v" | |
38 'YaTeX-sectioning-scroll-up) | |
39 (define-key YaTeX-minibuffer-sectioning-map "\C-c" | |
40 'YaTeX-sectioning-scroll-up) | |
41 (define-key YaTeX-minibuffer-sectioning-map "\M-v" | |
42 'YaTeX-sectioning-scroll-down) | |
43 (define-key YaTeX-minibuffer-sectioning-map "\C-r" | |
44 'YaTeX-sectioning-scroll-down) | |
45 (define-key YaTeX-minibuffer-sectioning-map "\C-w" | |
46 '(lambda () (interactive) (YaTeX-sectioning-scroll-down 1))) | |
47 (define-key YaTeX-minibuffer-sectioning-map "\C-z" | |
48 '(lambda () (interactive) (YaTeX-sectioning-scroll-up 1))) | |
49 (define-key YaTeX-minibuffer-sectioning-map "\C-l" | |
50 'YaTeX-sectioning-recenter) | |
51 (define-key YaTeX-minibuffer-sectioning-map "?" | |
52 'YaTeX-sectioning-help) | |
53 (YaTeX-sectioning-map-hide YaTeX-minibuffer-sectioning-map) | |
54 ) | |
55 | |
56 (defvar YaTeX-sectioning-buffer-map nil | |
57 "Key map used in YaTeX-sectioning-buffer.") | |
58 (if YaTeX-sectioning-buffer-map nil | |
59 (setq YaTeX-sectioning-buffer-map (make-sparse-keymap)) | |
60 (define-key YaTeX-sectioning-buffer-map " " | |
61 'YaTeX-sectioning-buffer-jump) | |
62 (define-key YaTeX-sectioning-buffer-map (concat YaTeX-prefix "\C-c") | |
63 'YaTeX-sectioning-buffer-jump) | |
64 (YaTeX-sectioning-map-hide YaTeX-sectioning-buffer-map) | |
65 ) | |
66 | |
67 (defvar YaTeX-sectioning-buffer-parent nil) | |
68 (defun YaTeX-sectioning-buffer-jump () | |
69 (interactive) | |
70 (if (and YaTeX-sectioning-buffer-parent | |
71 (get-buffer YaTeX-sectioning-buffer-parent)) | |
72 (let (ptn) | |
73 (beginning-of-line) | |
74 (if (re-search-forward YaTeX-sectioning-regexp) | |
75 (progn (setq ptn (buffer-substring | |
76 (1- (match-beginning 0)) | |
77 (progn (skip-chars-forward "^}") (1+ (point))))) | |
78 (YaTeX-showup-buffer YaTeX-sectioning-buffer-parent nil t) | |
79 (goto-char (point-max)) | |
80 (search-backward ptn)) | |
81 (message "No line number expression.")))) | |
82 ) | |
83 | |
84 (defun YaTeX-sectioning-hide-under (n) | |
85 "Hide sectioning commands under level N." | |
86 (let ((cw (selected-window))) | |
87 (YaTeX-showup-buffer YaTeX-sectioning-buffer nil t) | |
88 (if (>= n (1- (length YaTeX-sectioning-level))) | |
89 (progn | |
90 (set-selective-display nil) | |
91 (message "Show all.")) | |
92 (set-selective-display (1+ n)) | |
93 (if (nth n YaTeX-sectioning-level) | |
94 (message "Hide lower than %s" (car (nth n YaTeX-sectioning-level))) | |
95 (message ""))) | |
96 (if (numberp selective-display) | |
97 (setq mode-name (format "level %d" (1- selective-display))) | |
98 (setq mode-name (format "all"))) | |
99 (select-window cw)) | |
100 ) | |
101 (defun YaTeX-sectioning-hide () | |
102 "Call YaTeX-sectioning-hide-under with argument according to pressed key." | |
103 (interactive) | |
104 (YaTeX-sectioning-hide-under (- last-command-char ?0))) | |
105 | |
106 (defun YaTeX-sectioning-help () | |
107 "Show help of sectioning." | |
108 (interactive) | |
109 (let ((cw (selected-window)) sb (hb (get-buffer-create "*Help*"))) | |
110 (unwind-protect | |
111 (progn | |
112 (other-window 1) | |
113 (setq sb (current-buffer)) | |
114 (switch-to-buffer hb) | |
115 (erase-buffer) | |
116 (insert "===== View sectioning ===== | |
117 C-p Up sectioning level. 0 Show only \\part, | |
118 C-n Down sectioning level. 1 and \\chapter, | |
119 C-v Scroll up *Sectioning line* buffer. 2 and \\section, | |
120 M-v Scroll down *Sectioning line* buffer. 3 and \\subsection, | |
121 SPC Complete word. 4 and \\subsubsection, | |
122 TAB Complete word. 5 and \\paragraph. | |
123 C-l Recenter recent line. 6 Show all. | |
124 RET Select. | |
125 ==== End of HELP ===== | |
126 ") | |
127 (set-buffer-modified-p nil) | |
128 (goto-char (point-min)) | |
129 (momentary-string-display "" (point-min))) | |
130 (bury-buffer hb) | |
131 (switch-to-buffer sb) | |
132 (select-window cw))) | |
133 ) | |
134 | |
135 (defun YaTeX-sectioning-up (n) | |
136 "Up section level. | |
137 Refers the YaTeX-read-section-in-minibuffer's local variable minibuffer-start." | |
138 (interactive "p") | |
139 (if (eq (selected-window) (minibuffer-window)) | |
140 (let*((command (buffer-string)) | |
141 (alist YaTeX-sectioning-level) | |
142 (level (cdr-safe (assoc command alist)))) | |
143 (or level (error "No such sectioning command.")) | |
144 (setq level (- level n)) | |
145 (if (or (< level 0) (>= level (length alist))) | |
146 (ding) | |
147 (erase-buffer) | |
148 (insert (car (nth level alist)))) | |
149 )) | |
150 ) | |
151 | |
152 (defun YaTeX-sectioning-down (n) | |
153 "Down section level." | |
154 (interactive "p") | |
155 (YaTeX-sectioning-up (- n)) | |
156 ) | |
157 | |
158 (defun YaTeX-sectioning-scroll-up (n) | |
159 (interactive "P") | |
160 (let ((section-buffer YaTeX-sectioning-buffer) | |
161 (cw (selected-window))) | |
162 (YaTeX-showup-buffer section-buffer nil t) | |
163 (unwind-protect | |
164 (scroll-up (or n (- (window-height) 2))) | |
165 (select-window cw))) | |
166 ) | |
167 | |
168 (defun YaTeX-sectioning-scroll-down (n) | |
169 (interactive "P") | |
170 (let ((section-buffer YaTeX-sectioning-buffer) | |
171 (cw (selected-window))) | |
172 (YaTeX-showup-buffer section-buffer nil t) | |
173 (unwind-protect | |
174 (scroll-down (or n (- (window-height) 2))) | |
175 (select-window cw))) | |
176 ) | |
177 | |
178 (defun YaTeX-sectioning-recenter (arg) | |
179 "Recenter `<<--' line" | |
180 (interactive "P") | |
181 (let ((cw (selected-window))) | |
182 (unwind-protect | |
183 (progn | |
184 (YaTeX-showup-buffer YaTeX-sectioning-buffer nil t) | |
185 (or (search-forward "<<--" nil t) | |
186 (search-backward "<<--" nil t)) | |
187 (recenter (or arg (/ (window-height) 2)))) | |
188 (select-window cw))) | |
189 ) | |
190 | |
191 (defvar YaTeX-sectioning-minibuffer " *sectioning*" | |
192 "Miniuffer used for sectioning") | |
193 (defun YaTeX-read-section-in-minibuffer (prompt table &optional default delim) | |
194 (interactive) | |
195 (let ((minibuffer-completion-table table)) | |
196 (read-from-minibuffer | |
197 prompt default YaTeX-minibuffer-sectioning-map)) | |
198 ) | |
199 | |
200 (defun YaTeX-get-sectioning-level () | |
201 "Get section-level on the cursor." | |
202 (cdr-safe (assoc (buffer-substring | |
203 (point) | |
204 (progn (skip-chars-forward "a-z") (point))) | |
205 YaTeX-sectioning-level)) | |
206 ) | |
207 | |
208 (defvar YaTeX-sectioning-buffer "*Sectioning lines*") | |
209 (defun YaTeX-colloect-sections () | |
210 "Collect all the lines which contains sectioning command." | |
211 (let ((cw (selected-window)) level indent begp (prevp 1) (prevl 1) | |
212 (pattern (concat YaTeX-ec-regexp | |
213 "\\(" YaTeX-sectioning-regexp "\\)\\*?{")) | |
214 (cb (current-buffer))) | |
215 (save-excursion | |
216 (YaTeX-showup-buffer YaTeX-sectioning-buffer) ;show buffer | |
217 (goto-char (point-min)) | |
218 (with-output-to-temp-buffer YaTeX-sectioning-buffer | |
219 (while (re-search-forward pattern nil t) | |
220 (goto-char (1+ (match-beginning 0))) | |
221 (setq level (YaTeX-get-sectioning-level) | |
222 begp (match-beginning 0)) | |
223 ;;(beginning-of-line) | |
224 ;;(skip-chars-forward " \t") | |
225 (setq indent (format "%%%ds" level)) | |
226 (princ (format indent "")) | |
227 (if (YaTeX-on-comment-p) (princ "%")) | |
228 (princ (buffer-substring begp (progn (forward-list 1) (point)))) | |
229 (setq prevl (+ prevl (count-lines prevp (point)) -1) | |
230 prevp (point)) | |
231 (princ (format " (line:%d)" prevl)) | |
232 (princ "\n"))) | |
233 (set-buffer YaTeX-sectioning-buffer) | |
234 (make-local-variable 'YaTeX-sectioning-buffer-parent) | |
235 (use-local-map YaTeX-sectioning-buffer-map) | |
236 (setq YaTeX-sectioning-buffer-parent cb) | |
237 (if (numberp selective-display) | |
238 (setq mode-name (format "level %d" (1- selective-display)))) | |
239 YaTeX-sectioning-buffer)) | |
240 ) | |
241 | |
242 (defun YaTeX-section-overview () | |
243 "Show section overview. Return the nearest sectioning command." | |
244 (interactive) | |
245 (let ((cw (selected-window)) (ln (count-lines (point-min) (point))) | |
246 (pattern "(line:\\([0-9]+\\))") | |
247 (secbuf YaTeX-sectioning-buffer) (command "")) | |
248 (save-excursion | |
249 (setq secbuf (YaTeX-colloect-sections)) | |
250 (YaTeX-showup-buffer secbuf nil t) | |
251 (goto-char (point-max)) | |
252 (while (re-search-backward pattern nil t) | |
253 (if (< ln (string-to-int (YaTeX-match-string 1))) nil | |
254 (beginning-of-line) | |
255 (search-forward YaTeX-ec) | |
256 (looking-at YaTeX-TeX-token-regexp) | |
257 (setq command (YaTeX-match-string 0)) | |
258 (end-of-line) | |
259 (insert " <<--") | |
260 (setq pattern (concat "HackyRegexp" "ForFailure")))) | |
261 (set-buffer-modified-p nil) | |
262 (forward-line 1) | |
263 (if (eobp) (recenter -1) (recenter -3)) | |
264 (select-window cw) | |
265 command)) | |
266 ) | |
267 | |
268 (defun YaTeX-make-section-with-overview () | |
269 "Input sectining command with previous overview." | |
270 (interactive) | |
271 (insert | |
272 YaTeX-ec | |
273 (YaTeX-read-section-in-minibuffer | |
274 "Sectioning(Up=C-p, Down=C-n, Help=?): " | |
275 YaTeX-sectioning-level (YaTeX-section-overview)) | |
276 "{}") | |
277 (forward-char -1) | |
278 ) | |
279 | |
280 (provide 'yatexsec) | |
281 ;;(YaTeX-define-key "o" 'YaTeX-make-section-with-overview) |