yatex

view yatexsec.el @ 49:eb0512bfcb7f

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