yatex

view yatexsec.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
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 Tue Jan 24 23:19:14 1995 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 (and (string< "" command)
156 (equal (substring command -1) "*")))
157 (command (if aster (substring command 0 -1) command))
158 (alist YaTeX-sectioning-level)
159 (level 0))
160 (or (assoc command alist) (error "No such sectioning command."))
161 (while (not (string= (car (nth level alist)) command))
162 (setq level (1+ level))) ;I want to use `member'....
163 (setq level (- level n))
164 (if (or (< level 0) (>= level (length alist)))
165 (ding)
166 (erase-buffer)
167 (insert (concat (car (nth level alist)) (if aster "*" ""))))))
168 )
170 (defun YaTeX-sectioning-down (n)
171 "Down section level."
172 (interactive "p")
173 (YaTeX-sectioning-up (- n))
174 )
176 (defun YaTeX-sectioning-scroll-up (n)
177 (interactive "P")
178 (let ((section-buffer YaTeX-sectioning-buffer)
179 (cw (selected-window)))
180 (YaTeX-showup-buffer section-buffer nil t)
181 (unwind-protect
182 (scroll-up (or n (- (window-height) 2)))
183 (select-window cw)))
184 )
186 (defun YaTeX-sectioning-scroll-down (n)
187 (interactive "P")
188 (let ((section-buffer YaTeX-sectioning-buffer)
189 (cw (selected-window)))
190 (YaTeX-showup-buffer section-buffer nil t)
191 (unwind-protect
192 (scroll-down (or n (- (window-height) 2)))
193 (select-window cw)))
194 )
196 (defun YaTeX-sectioning-recenter (arg)
197 "Recenter `<<--' line"
198 (interactive "P")
199 (let ((cw (selected-window)))
200 (unwind-protect
201 (progn
202 (YaTeX-showup-buffer YaTeX-sectioning-buffer nil t)
203 (or (search-forward "<<--" nil t)
204 (search-backward "<<--" nil))
205 (recenter (or arg (/ (window-height) 2))))
206 (select-window cw)))
207 )
209 (defvar YaTeX-sectioning-minibuffer " *sectioning*"
210 "Miniuffer used for sectioning")
211 ;;;###autoload
212 (defun YaTeX-read-section-in-minibuffer (prompt table &optional default delim)
213 (interactive)
214 (let ((minibuffer-completion-table table))
215 (read-from-minibuffer
216 prompt default YaTeX-sectioning-minibuffer-map))
217 )
219 (defun YaTeX-get-sectioning-level ()
220 "Get section-level on the cursor."
221 (cdr-safe (assoc (buffer-substring
222 (point)
223 (progn (skip-chars-forward "a-z") (point)))
224 YaTeX-sectioning-level))
225 )
227 (defvar YaTeX-sectioning-buffer "*Sectioning lines*")
228 (defun YaTeX-colloect-sections ()
229 "Collect all the lines which contains sectioning command."
230 (let ((cw (selected-window)) level indent begp (prevp 1) (prevl 1)
231 (pattern (concat YaTeX-ec-regexp
232 "\\(" YaTeX-sectioning-regexp "\\)\\*?{"))
233 (cb (current-buffer)))
234 (save-excursion
235 (YaTeX-showup-buffer YaTeX-sectioning-buffer) ;show buffer
236 (goto-char (point-min))
237 (with-output-to-temp-buffer YaTeX-sectioning-buffer
238 (while (re-search-forward pattern nil t)
239 (goto-char (1+ (match-beginning 0)))
240 (setq level (YaTeX-get-sectioning-level)
241 begp (match-beginning 0))
242 ;;(beginning-of-line)
243 ;;(skip-chars-forward " \t")
244 (setq indent (format "%%%ds" level))
245 (princ (format indent ""))
246 (if (YaTeX-on-comment-p) (princ "%"))
247 (princ (buffer-substring begp (progn (forward-list 1) (point))))
248 (setq prevl (+ prevl (count-lines prevp (point)) -1)
249 prevp (point))
250 (princ (format " (line:%d)" prevl))
251 (princ "\n")))
252 (set-buffer YaTeX-sectioning-buffer)
253 (make-local-variable 'YaTeX-sectioning-buffer-parent)
254 (use-local-map YaTeX-sectioning-buffer-map)
255 (setq YaTeX-sectioning-buffer-parent cb)
256 (if (numberp selective-display)
257 (setq mode-name (format "level %d" (1- selective-display))))
258 YaTeX-sectioning-buffer))
259 )
261 (defun YaTeX-section-overview ()
262 "Show section overview. Return the nearest sectioning command."
263 (interactive)
264 (let ((cw (selected-window)) (ln (count-lines (point-min) (point)))
265 (pattern "(line:\\([0-9]+\\))")
266 (secbuf YaTeX-sectioning-buffer) (command ""))
267 (save-excursion
268 (setq secbuf (YaTeX-colloect-sections))
269 (YaTeX-showup-buffer secbuf nil t)
270 (goto-char (point-max))
271 (while (re-search-backward pattern nil t)
272 (if (< ln (string-to-int (YaTeX-match-string 1))) nil
273 (beginning-of-line)
274 (search-forward YaTeX-ec)
275 (looking-at YaTeX-TeX-token-regexp)
276 (setq command (YaTeX-match-string 0))
277 (end-of-line)
278 (insert " <<--")
279 (setq pattern (concat "HackyRegexp" "ForFailure"))))
280 (set-buffer-modified-p nil)
281 (forward-line 1)
282 (if (eobp) (recenter -1) (recenter -3))
283 (select-window cw)
284 command))
285 )
287 ;;;###autoload
288 (defun YaTeX-make-section-with-overview ()
289 "Input sectining command with previous overview."
290 (interactive)
291 (insert
292 YaTeX-ec
293 (YaTeX-read-section-in-minibuffer
294 "Sectioning(Up=C-p, Down=C-n, Help=?): "
295 YaTeX-sectioning-level (YaTeX-section-overview))
296 "{}")
297 (forward-char -1)
298 )
300 (provide 'yatexsec)