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