yatex

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