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