yatex
annotate yatexsec.el @ 58:3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
author | yuuji |
---|---|
date | Thu, 01 Feb 1996 18:55:47 +0000 |
parents | 5f4b18da14b3 |
children | b9f753846b6b |
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@58 | 5 ;;; Last modified Thu Jan 11 01:07:53 1996 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@58 | 72 (define-key YaTeX-sectioning-buffer-map " " 'YaTeX-sectioning-buffer-jump) |
yuuji@58 | 73 (define-key YaTeX-sectioning-buffer-map "." 'YaTeX-sectioning-buffer-show) |
yuuji@23 | 74 (define-key YaTeX-sectioning-buffer-map (concat YaTeX-prefix "\C-c") |
yuuji@23 | 75 'YaTeX-sectioning-buffer-jump) |
yuuji@58 | 76 (define-key YaTeX-sectioning-buffer-map "u" 'YaTeX-shift-section-up) |
yuuji@58 | 77 (define-key YaTeX-sectioning-buffer-map "d" 'YaTeX-shift-section-down) |
yuuji@58 | 78 (define-key YaTeX-sectioning-buffer-map "U" 'YaTeX-shift-section-up-region) |
yuuji@58 | 79 (define-key YaTeX-sectioning-buffer-map "D" 'YaTeX-shift-section-down-region) |
yuuji@58 | 80 (define-key YaTeX-sectioning-buffer-map "s" 'YaTeX-sync-section-buffer) |
yuuji@58 | 81 (define-key YaTeX-sectioning-buffer-map "n" |
yuuji@58 | 82 'YaTeX-sectioning-buffer-next-line) |
yuuji@58 | 83 (define-key YaTeX-sectioning-buffer-map "p" |
yuuji@58 | 84 'YaTeX-sectioning-buffer-prev-line) |
yuuji@58 | 85 (define-key YaTeX-sectioning-buffer-map "h" 'describe-mode) |
yuuji@58 | 86 (define-key YaTeX-sectioning-buffer-map "o" 'other-window) |
yuuji@58 | 87 (define-key YaTeX-sectioning-buffer-map "-" 'shrink-window) |
yuuji@58 | 88 (define-key YaTeX-sectioning-buffer-map "+" 'enlarge-window) |
yuuji@58 | 89 (define-key YaTeX-sectioning-buffer-map "\C-_" 'YaTeX-shift-section-undo) |
yuuji@58 | 90 (and YaTeX-emacs-19 (boundp 'window-system) (eq window-system 'x) |
yuuji@58 | 91 (define-key YaTeX-sectioning-buffer-map [?\C-/] |
yuuji@58 | 92 'YaTeX-shift-section-undo)) |
yuuji@23 | 93 (YaTeX-sectioning-map-hide YaTeX-sectioning-buffer-map) |
yuuji@23 | 94 ) |
yuuji@23 | 95 |
yuuji@58 | 96 (defun YaTeX-sectioning-mode () |
yuuji@58 | 97 "Mode for browsing document's sectioning structure. |
yuuji@58 | 98 \\[YaTeX-shift-section-up] Shift up a sectioning command |
yuuji@58 | 99 \\[YaTeX-shift-section-down] Shift down a sectioning command |
yuuji@58 | 100 \\[YaTeX-shift-section-up-region] Shift up sectioning commands in region |
yuuji@58 | 101 \\[YaTeX-shift-section-down-region] Shift down sectioning commands in region |
yuuji@58 | 102 \\[YaTeX-shift-section-undo] Undo changes of shifting |
yuuji@58 | 103 \\[YaTeX-sync-section-buffer] Synchronize sectioning buffer with source |
yuuji@58 | 104 \\[YaTeX-sectioning-buffer-next-line] Next line |
yuuji@58 | 105 \\[YaTeX-sectioning-buffer-prev-line] Previous line |
yuuji@58 | 106 \\[YaTeX-sectioning-buffer-jump] Previous line |
yuuji@58 | 107 \\[YaTeX-sectioning-buffer-show] Show curresponding source line |
yuuji@58 | 108 " |
yuuji@58 | 109 (interactive) |
yuuji@58 | 110 (setq major-mode 'YaTeX-sectioning-mode |
yuuji@58 | 111 mode-name "sectioning") |
yuuji@58 | 112 (use-local-map YaTeX-sectioning-buffer-map) |
yuuji@58 | 113 ) |
yuuji@58 | 114 |
yuuji@23 | 115 (defvar YaTeX-sectioning-buffer-parent nil) |
yuuji@58 | 116 (defun YaTeX-sectioning-buffer-jump-internal (&optional keep) |
yuuji@58 | 117 (let (ptn (p (point))) ;save-excursion is NG because |
yuuji@58 | 118 (beginning-of-line) ;this function should switch buffer |
yuuji@58 | 119 (if (re-search-forward YaTeX-sectioning-regexp) |
yuuji@58 | 120 (progn (setq ptn (buffer-substring |
yuuji@58 | 121 (1- (match-beginning 0)) |
yuuji@58 | 122 (progn (skip-chars-forward "^}") (1+ (point))))) |
yuuji@58 | 123 (goto-char p) |
yuuji@58 | 124 (YaTeX-showup-buffer YaTeX-sectioning-buffer-parent nil t) |
yuuji@58 | 125 (goto-char (point-max)) |
yuuji@58 | 126 (search-backward ptn) |
yuuji@58 | 127 (if keep (goto-buffer-window YaTeX-sectioning-buffer)) |
yuuji@58 | 128 (current-buffer)) |
yuuji@58 | 129 nil)) |
yuuji@58 | 130 ) |
yuuji@58 | 131 (defun YaTeX-sectioning-buffer-jump (&optional keep) |
yuuji@58 | 132 "Goto corresponding sectioning unit with current line in the next window. |
yuuji@58 | 133 If optional argument KEEP is non-nil, only shows the line." |
yuuji@23 | 134 (interactive) |
yuuji@23 | 135 (if (and YaTeX-sectioning-buffer-parent |
yuuji@23 | 136 (get-buffer YaTeX-sectioning-buffer-parent)) |
yuuji@58 | 137 (YaTeX-sectioning-buffer-jump-internal keep) |
yuuji@58 | 138 (message "No line number expression.")) |
yuuji@58 | 139 ) |
yuuji@58 | 140 |
yuuji@58 | 141 (defun YaTeX-sectioning-buffer-show () |
yuuji@58 | 142 "Show corresponding sectioning unit with current line." |
yuuji@58 | 143 (interactive) |
yuuji@58 | 144 (YaTeX-sectioning-buffer-jump-internal t) |
yuuji@23 | 145 ) |
yuuji@23 | 146 |
yuuji@23 | 147 (defun YaTeX-sectioning-hide-under (n) |
yuuji@23 | 148 "Hide sectioning commands under level N." |
yuuji@23 | 149 (let ((cw (selected-window))) |
yuuji@23 | 150 (YaTeX-showup-buffer YaTeX-sectioning-buffer nil t) |
yuuji@49 | 151 (if (>= n YaTeX-sectioning-max-level) |
yuuji@23 | 152 (progn |
yuuji@23 | 153 (set-selective-display nil) |
yuuji@23 | 154 (message "Show all.")) |
yuuji@23 | 155 (set-selective-display (1+ n)) |
yuuji@49 | 156 (if (rassq n YaTeX-sectioning-level) |
yuuji@49 | 157 (message "Hide lower than %s" (car (rassq n YaTeX-sectioning-level))) |
yuuji@23 | 158 (message ""))) |
yuuji@23 | 159 (if (numberp selective-display) |
yuuji@23 | 160 (setq mode-name (format "level %d" (1- selective-display))) |
yuuji@23 | 161 (setq mode-name (format "all"))) |
yuuji@23 | 162 (select-window cw)) |
yuuji@23 | 163 ) |
yuuji@23 | 164 (defun YaTeX-sectioning-hide () |
yuuji@23 | 165 "Call YaTeX-sectioning-hide-under with argument according to pressed key." |
yuuji@23 | 166 (interactive) |
yuuji@23 | 167 (YaTeX-sectioning-hide-under (- last-command-char ?0))) |
yuuji@23 | 168 |
yuuji@23 | 169 (defun YaTeX-sectioning-help () |
yuuji@23 | 170 "Show help of sectioning." |
yuuji@23 | 171 (interactive) |
yuuji@23 | 172 (let ((cw (selected-window)) sb (hb (get-buffer-create "*Help*"))) |
yuuji@23 | 173 (unwind-protect |
yuuji@23 | 174 (progn |
yuuji@23 | 175 (other-window 1) |
yuuji@23 | 176 (setq sb (current-buffer)) |
yuuji@23 | 177 (switch-to-buffer hb) |
yuuji@23 | 178 (erase-buffer) |
yuuji@23 | 179 (insert "===== View sectioning ===== |
yuuji@23 | 180 C-p Up sectioning level. 0 Show only \\part, |
yuuji@23 | 181 C-n Down sectioning level. 1 and \\chapter, |
yuuji@23 | 182 C-v Scroll up *Sectioning line* buffer. 2 and \\section, |
yuuji@23 | 183 M-v Scroll down *Sectioning line* buffer. 3 and \\subsection, |
yuuji@49 | 184 C-z Scroll up by 1 line. 4 and \\subsubsection, |
yuuji@49 | 185 C-w Scroll down by 1 line. 5 and \\paragraph. |
yuuji@49 | 186 SPC Complete word. 6 Show all. |
yuuji@49 | 187 TAB Complete word. |
yuuji@49 | 188 C-l Recenter recent line. |
yuuji@23 | 189 RET Select. |
yuuji@23 | 190 ==== End of HELP ===== |
yuuji@23 | 191 ") |
yuuji@23 | 192 (set-buffer-modified-p nil) |
yuuji@23 | 193 (goto-char (point-min)) |
yuuji@23 | 194 (momentary-string-display "" (point-min))) |
yuuji@23 | 195 (bury-buffer hb) |
yuuji@23 | 196 (switch-to-buffer sb) |
yuuji@23 | 197 (select-window cw))) |
yuuji@23 | 198 ) |
yuuji@23 | 199 |
yuuji@23 | 200 (defun YaTeX-sectioning-up (n) |
yuuji@23 | 201 "Up section level. |
yuuji@23 | 202 Refers the YaTeX-read-section-in-minibuffer's local variable minibuffer-start." |
yuuji@23 | 203 (interactive "p") |
yuuji@23 | 204 (if (eq (selected-window) (minibuffer-window)) |
yuuji@23 | 205 (let*((command (buffer-string)) |
yuuji@53 | 206 (aster (and (string< "" command) |
yuuji@53 | 207 (equal (substring command -1) "*"))) |
yuuji@49 | 208 (command (if aster (substring command 0 -1) command)) |
yuuji@23 | 209 (alist YaTeX-sectioning-level) |
yuuji@49 | 210 (level 0)) |
yuuji@49 | 211 (or (assoc command alist) (error "No such sectioning command.")) |
yuuji@49 | 212 (while (not (string= (car (nth level alist)) command)) |
yuuji@49 | 213 (setq level (1+ level))) ;I want to use `member'.... |
yuuji@23 | 214 (setq level (- level n)) |
yuuji@23 | 215 (if (or (< level 0) (>= level (length alist))) |
yuuji@23 | 216 (ding) |
yuuji@23 | 217 (erase-buffer) |
yuuji@49 | 218 (insert (concat (car (nth level alist)) (if aster "*" "")))))) |
yuuji@23 | 219 ) |
yuuji@23 | 220 |
yuuji@23 | 221 (defun YaTeX-sectioning-down (n) |
yuuji@23 | 222 "Down section level." |
yuuji@23 | 223 (interactive "p") |
yuuji@23 | 224 (YaTeX-sectioning-up (- n)) |
yuuji@23 | 225 ) |
yuuji@23 | 226 |
yuuji@23 | 227 (defun YaTeX-sectioning-scroll-up (n) |
yuuji@23 | 228 (interactive "P") |
yuuji@23 | 229 (let ((section-buffer YaTeX-sectioning-buffer) |
yuuji@23 | 230 (cw (selected-window))) |
yuuji@23 | 231 (YaTeX-showup-buffer section-buffer nil t) |
yuuji@23 | 232 (unwind-protect |
yuuji@23 | 233 (scroll-up (or n (- (window-height) 2))) |
yuuji@23 | 234 (select-window cw))) |
yuuji@23 | 235 ) |
yuuji@23 | 236 |
yuuji@23 | 237 (defun YaTeX-sectioning-scroll-down (n) |
yuuji@23 | 238 (interactive "P") |
yuuji@23 | 239 (let ((section-buffer YaTeX-sectioning-buffer) |
yuuji@23 | 240 (cw (selected-window))) |
yuuji@23 | 241 (YaTeX-showup-buffer section-buffer nil t) |
yuuji@23 | 242 (unwind-protect |
yuuji@23 | 243 (scroll-down (or n (- (window-height) 2))) |
yuuji@23 | 244 (select-window cw))) |
yuuji@23 | 245 ) |
yuuji@23 | 246 |
yuuji@23 | 247 (defun YaTeX-sectioning-recenter (arg) |
yuuji@23 | 248 "Recenter `<<--' line" |
yuuji@23 | 249 (interactive "P") |
yuuji@23 | 250 (let ((cw (selected-window))) |
yuuji@23 | 251 (unwind-protect |
yuuji@23 | 252 (progn |
yuuji@23 | 253 (YaTeX-showup-buffer YaTeX-sectioning-buffer nil t) |
yuuji@23 | 254 (or (search-forward "<<--" nil t) |
yuuji@49 | 255 (search-backward "<<--" nil)) |
yuuji@23 | 256 (recenter (or arg (/ (window-height) 2)))) |
yuuji@23 | 257 (select-window cw))) |
yuuji@23 | 258 ) |
yuuji@23 | 259 |
yuuji@23 | 260 (defvar YaTeX-sectioning-minibuffer " *sectioning*" |
yuuji@23 | 261 "Miniuffer used for sectioning") |
yuuji@49 | 262 ;;;###autoload |
yuuji@23 | 263 (defun YaTeX-read-section-in-minibuffer (prompt table &optional default delim) |
yuuji@23 | 264 (interactive) |
yuuji@23 | 265 (let ((minibuffer-completion-table table)) |
yuuji@23 | 266 (read-from-minibuffer |
yuuji@49 | 267 prompt default YaTeX-sectioning-minibuffer-map)) |
yuuji@23 | 268 ) |
yuuji@23 | 269 |
yuuji@23 | 270 (defun YaTeX-get-sectioning-level () |
yuuji@23 | 271 "Get section-level on the cursor." |
yuuji@23 | 272 (cdr-safe (assoc (buffer-substring |
yuuji@23 | 273 (point) |
yuuji@23 | 274 (progn (skip-chars-forward "a-z") (point))) |
yuuji@23 | 275 YaTeX-sectioning-level)) |
yuuji@23 | 276 ) |
yuuji@23 | 277 |
yuuji@23 | 278 (defvar YaTeX-sectioning-buffer "*Sectioning lines*") |
yuuji@23 | 279 (defun YaTeX-colloect-sections () |
yuuji@23 | 280 "Collect all the lines which contains sectioning command." |
yuuji@23 | 281 (let ((cw (selected-window)) level indent begp (prevp 1) (prevl 1) |
yuuji@23 | 282 (pattern (concat YaTeX-ec-regexp |
yuuji@23 | 283 "\\(" YaTeX-sectioning-regexp "\\)\\*?{")) |
yuuji@23 | 284 (cb (current-buffer))) |
yuuji@23 | 285 (save-excursion |
yuuji@58 | 286 (set-buffer (get-buffer-create YaTeX-sectioning-buffer)) |
yuuji@58 | 287 (setq buffer-read-only nil) |
yuuji@58 | 288 (set-buffer cb) |
yuuji@23 | 289 (YaTeX-showup-buffer YaTeX-sectioning-buffer) ;show buffer |
yuuji@23 | 290 (goto-char (point-min)) |
yuuji@23 | 291 (with-output-to-temp-buffer YaTeX-sectioning-buffer |
yuuji@23 | 292 (while (re-search-forward pattern nil t) |
yuuji@23 | 293 (goto-char (1+ (match-beginning 0))) |
yuuji@23 | 294 (setq level (YaTeX-get-sectioning-level) |
yuuji@23 | 295 begp (match-beginning 0)) |
yuuji@23 | 296 ;;(beginning-of-line) |
yuuji@23 | 297 ;;(skip-chars-forward " \t") |
yuuji@23 | 298 (setq indent (format "%%%ds" level)) |
yuuji@23 | 299 (princ (format indent "")) |
yuuji@23 | 300 (if (YaTeX-on-comment-p) (princ "%")) |
yuuji@23 | 301 (princ (buffer-substring begp (progn (forward-list 1) (point)))) |
yuuji@23 | 302 (setq prevl (+ prevl (count-lines prevp (point)) -1) |
yuuji@23 | 303 prevp (point)) |
yuuji@23 | 304 (princ (format " (line:%d)" prevl)) |
yuuji@23 | 305 (princ "\n"))) |
yuuji@23 | 306 (set-buffer YaTeX-sectioning-buffer) |
yuuji@23 | 307 (make-local-variable 'YaTeX-sectioning-buffer-parent) |
yuuji@58 | 308 (YaTeX-sectioning-mode) |
yuuji@23 | 309 (use-local-map YaTeX-sectioning-buffer-map) |
yuuji@23 | 310 (setq YaTeX-sectioning-buffer-parent cb) |
yuuji@23 | 311 (if (numberp selective-display) |
yuuji@23 | 312 (setq mode-name (format "level %d" (1- selective-display)))) |
yuuji@23 | 313 YaTeX-sectioning-buffer)) |
yuuji@23 | 314 ) |
yuuji@23 | 315 |
yuuji@58 | 316 (defvar YaTeX-pending-undo nil) |
yuuji@23 | 317 (defun YaTeX-section-overview () |
yuuji@23 | 318 "Show section overview. Return the nearest sectioning command." |
yuuji@23 | 319 (interactive) |
yuuji@23 | 320 (let ((cw (selected-window)) (ln (count-lines (point-min) (point))) |
yuuji@23 | 321 (pattern "(line:\\([0-9]+\\))") |
yuuji@58 | 322 secbuf (command "")) |
yuuji@23 | 323 (save-excursion |
yuuji@23 | 324 (setq secbuf (YaTeX-colloect-sections)) |
yuuji@23 | 325 (YaTeX-showup-buffer secbuf nil t) |
yuuji@58 | 326 (set-buffer secbuf) |
yuuji@23 | 327 (goto-char (point-max)) |
yuuji@23 | 328 (while (re-search-backward pattern nil t) |
yuuji@23 | 329 (if (< ln (string-to-int (YaTeX-match-string 1))) nil |
yuuji@23 | 330 (beginning-of-line) |
yuuji@23 | 331 (search-forward YaTeX-ec) |
yuuji@23 | 332 (looking-at YaTeX-TeX-token-regexp) |
yuuji@23 | 333 (setq command (YaTeX-match-string 0)) |
yuuji@23 | 334 (end-of-line) |
yuuji@23 | 335 (insert " <<--") |
yuuji@23 | 336 (setq pattern (concat "HackyRegexp" "ForFailure")))) |
yuuji@23 | 337 (set-buffer-modified-p nil) |
yuuji@58 | 338 (setq buffer-read-only t buffer-undo-list nil) |
yuuji@58 | 339 (make-local-variable 'YaTeX-pending-undo) |
yuuji@23 | 340 (forward-line 1) |
yuuji@23 | 341 (if (eobp) (recenter -1) (recenter -3)) |
yuuji@23 | 342 (select-window cw) |
yuuji@23 | 343 command)) |
yuuji@23 | 344 ) |
yuuji@23 | 345 |
yuuji@49 | 346 ;;;###autoload |
yuuji@23 | 347 (defun YaTeX-make-section-with-overview () |
yuuji@23 | 348 "Input sectining command with previous overview." |
yuuji@23 | 349 (interactive) |
yuuji@23 | 350 (insert |
yuuji@23 | 351 YaTeX-ec |
yuuji@23 | 352 (YaTeX-read-section-in-minibuffer |
yuuji@23 | 353 "Sectioning(Up=C-p, Down=C-n, Help=?): " |
yuuji@23 | 354 YaTeX-sectioning-level (YaTeX-section-overview)) |
yuuji@23 | 355 "{}") |
yuuji@23 | 356 (forward-char -1) |
yuuji@23 | 357 ) |
yuuji@23 | 358 |
yuuji@58 | 359 (defun YaTeX-shifted-section (sc n) |
yuuji@58 | 360 "Get SC's N-shifted sectioning command." |
yuuji@58 | 361 (let (lv) |
yuuji@58 | 362 (setq lv (- (cdr (assoc sc YaTeX-sectioning-level)) n) |
yuuji@58 | 363 lv (max (min YaTeX-sectioning-max-level lv) 0)) |
yuuji@58 | 364 (car (nth lv YaTeX-sectioning-level))) |
yuuji@58 | 365 ) |
yuuji@58 | 366 |
yuuji@58 | 367 (defun YaTeX-shift-section-up (n) |
yuuji@58 | 368 "Shift sectioning command down by level N." |
yuuji@58 | 369 (interactive "p") |
yuuji@58 | 370 (let ((cb (current-buffer)) sc nsc lv) |
yuuji@58 | 371 (if (and YaTeX-sectioning-buffer-parent |
yuuji@58 | 372 (get-buffer YaTeX-sectioning-buffer-parent) |
yuuji@58 | 373 (save-excursion |
yuuji@58 | 374 (or (= (char-after (point)) ?\\ ) |
yuuji@58 | 375 (skip-chars-backward "^\\\\" (point-beginning-of-line))) |
yuuji@58 | 376 (YaTeX-on-section-command-p YaTeX-sectioning-regexp))) |
yuuji@58 | 377 (save-excursion |
yuuji@58 | 378 (or (buffer-name (get-buffer YaTeX-sectioning-buffer-parent)) |
yuuji@58 | 379 (error "This buffer is obsolete.")) |
yuuji@58 | 380 (setq nsc (YaTeX-shifted-section (YaTeX-match-string 1) n)) |
yuuji@58 | 381 (YaTeX-sectioning-buffer-jump-internal) |
yuuji@58 | 382 (undo-boundary) |
yuuji@58 | 383 (goto-char (match-beginning 0)) |
yuuji@58 | 384 (skip-chars-forward "\\\\") |
yuuji@58 | 385 (delete-region |
yuuji@58 | 386 (point) (progn (skip-chars-forward "^*{") (point))) |
yuuji@58 | 387 (insert nsc) |
yuuji@58 | 388 (undo-boundary) |
yuuji@58 | 389 ;; Return to *Sectioning Lines* buffer |
yuuji@58 | 390 (select-window (get-buffer-window cb)) |
yuuji@58 | 391 (beginning-of-line) |
yuuji@58 | 392 (let (buffer-read-only) |
yuuji@58 | 393 (delete-region |
yuuji@58 | 394 (point) (progn (skip-chars-forward " \t") (point))) |
yuuji@58 | 395 (indent-to-column (cdr (assoc nsc YaTeX-sectioning-level))) |
yuuji@58 | 396 (skip-chars-forward "^\\\\") |
yuuji@58 | 397 (delete-region |
yuuji@58 | 398 (1+ (point)) (progn (skip-chars-forward "^*{") (point))) |
yuuji@58 | 399 (insert nsc) |
yuuji@58 | 400 (undo-boundary)) |
yuuji@58 | 401 (set-buffer-modified-p nil) |
yuuji@58 | 402 (setq YaTeX-pending-undo pending-undo-list) |
yuuji@58 | 403 ))) |
yuuji@58 | 404 ) |
yuuji@58 | 405 (defun YaTeX-shift-section-down (n) |
yuuji@58 | 406 "Shift sectioning command down by level N." |
yuuji@58 | 407 (interactive "p") |
yuuji@58 | 408 (YaTeX-shift-section-up (- n)) |
yuuji@58 | 409 ) |
yuuji@58 | 410 (defun YaTeX-shift-section-undo (arg) |
yuuji@58 | 411 "Undo YaTeX-shift-section-up/down." |
yuuji@58 | 412 (interactive "p") |
yuuji@58 | 413 (and YaTeX-sectioning-buffer-parent |
yuuji@58 | 414 (get-buffer YaTeX-sectioning-buffer-parent) |
yuuji@58 | 415 (equal (current-buffer) (get-buffer YaTeX-sectioning-buffer)) |
yuuji@58 | 416 (let ((cb (current-buffer)) |
yuuji@58 | 417 (lc (if (eq last-command 'YaTeX-shift-section-undo) 'undo t))) |
yuuji@58 | 418 (let ((pending-undo-list YaTeX-pending-undo) |
yuuji@58 | 419 buffer-read-only (last-command lc)) |
yuuji@58 | 420 (undo arg) |
yuuji@58 | 421 (setq YaTeX-pending-undo pending-undo-list)) |
yuuji@58 | 422 (YaTeX-showup-buffer YaTeX-sectioning-buffer-parent) |
yuuji@58 | 423 (goto-buffer-window YaTeX-sectioning-buffer-parent) |
yuuji@58 | 424 (undo-boundary) |
yuuji@58 | 425 (let ((last-command lc) |
yuuji@58 | 426 (pending-undo-list |
yuuji@58 | 427 (if (eq lc 'undo) YaTeX-pending-undo pending-undo-list))) |
yuuji@58 | 428 (undo arg) |
yuuji@58 | 429 (setq YaTeX-pending-undo pending-undo-list)) |
yuuji@58 | 430 (goto-buffer-window cb) |
yuuji@58 | 431 (setq this-command 'YaTeX-shift-section-undo))) |
yuuji@58 | 432 ) |
yuuji@58 | 433 (defun YaTeX-sync-section-buffer () |
yuuji@58 | 434 "Synchronize *Sectioning Lines* buffer with parent buffer." |
yuuji@58 | 435 (interactive) |
yuuji@58 | 436 (if (and YaTeX-sectioning-buffer-parent |
yuuji@58 | 437 (get-buffer YaTeX-sectioning-buffer-parent)) |
yuuji@58 | 438 (let ((cb (current-buffer)) (p (point))) |
yuuji@58 | 439 (set-buffer (get-buffer YaTeX-sectioning-buffer-parent)) |
yuuji@58 | 440 (YaTeX-section-overview) |
yuuji@58 | 441 (switch-to-buffer cb) |
yuuji@58 | 442 (goto-char p))) |
yuuji@58 | 443 ) |
yuuji@58 | 444 (defun YaTeX-shift-section-up-region (beg end n) |
yuuji@58 | 445 "Shift sectioning commands in region down by level N." |
yuuji@58 | 446 (interactive "r\np") |
yuuji@58 | 447 (or YaTeX-sectioning-buffer-parent |
yuuji@58 | 448 (get-buffer YaTeX-sectioning-buffer-parent) |
yuuji@58 | 449 (error "Can't find corresponding LaTeX buffer")) |
yuuji@58 | 450 (save-excursion |
yuuji@58 | 451 (goto-char beg) |
yuuji@58 | 452 (let ((cb (current-buffer)) nsc from to repllist (e (make-marker))) |
yuuji@58 | 453 (set-marker e end) |
yuuji@58 | 454 (while (progn (skip-chars-forward "^\\\\") (< (point) e)) |
yuuji@58 | 455 (YaTeX-on-section-command-p YaTeX-sectioning-regexp) |
yuuji@58 | 456 (setq from (YaTeX-match-string 0) |
yuuji@58 | 457 nsc (YaTeX-shifted-section (YaTeX-match-string 1) n)) |
yuuji@58 | 458 (goto-char (match-beginning 0)) |
yuuji@58 | 459 (let (buffer-read-only) |
yuuji@58 | 460 (delete-region (point) (progn (beginning-of-line) (point))) |
yuuji@58 | 461 (indent-to-column (cdr (assoc nsc YaTeX-sectioning-level))) |
yuuji@58 | 462 (delete-region |
yuuji@58 | 463 (1+ (point)) (progn (skip-chars-forward "^*{") (point))) |
yuuji@58 | 464 (insert nsc)) |
yuuji@58 | 465 (YaTeX-on-section-command-p YaTeX-sectioning-regexp) |
yuuji@58 | 466 (setq to (YaTeX-match-string 0) |
yuuji@58 | 467 repllist (cons (cons from to) repllist)) |
yuuji@58 | 468 (forward-line 1)) |
yuuji@58 | 469 (YaTeX-showup-buffer YaTeX-sectioning-buffer-parent) |
yuuji@58 | 470 (goto-buffer-window YaTeX-sectioning-buffer-parent) |
yuuji@58 | 471 (save-excursion |
yuuji@58 | 472 (goto-char (point-max)) |
yuuji@58 | 473 (undo-boundary) |
yuuji@58 | 474 (while repllist |
yuuji@58 | 475 (if (search-backward (car (car repllist)) nil t) |
yuuji@58 | 476 (progn |
yuuji@58 | 477 (goto-char (match-beginning 0)) ;confirm |
yuuji@58 | 478 (delete-region (point) (match-end 0)) |
yuuji@58 | 479 (insert (cdr (car repllist))) |
yuuji@58 | 480 (goto-char (match-beginning 0)))) |
yuuji@58 | 481 (setq repllist (cdr repllist)))) |
yuuji@58 | 482 (goto-buffer-window cb))) |
yuuji@58 | 483 ) |
yuuji@58 | 484 (defun YaTeX-shift-section-down-region (beg end n) |
yuuji@58 | 485 "Shift sectioning commands in region down by level N." |
yuuji@58 | 486 (interactive "r\np") |
yuuji@58 | 487 (YaTeX-shift-section-up-region beg end (- n)) |
yuuji@58 | 488 ) |
yuuji@58 | 489 (defun YaTeX-sectioning-buffer-next-line (n) |
yuuji@58 | 490 "Move to next line in *Sectioning Lines* buffer." |
yuuji@58 | 491 (interactive "p") |
yuuji@58 | 492 (forward-line n) |
yuuji@58 | 493 (skip-chars-forward " \t%") |
yuuji@58 | 494 ) |
yuuji@58 | 495 (defun YaTeX-sectioning-buffer-prev-line (n) |
yuuji@58 | 496 "Move to previous line in *Sectioning Lines* buffer." |
yuuji@58 | 497 (interactive "p") |
yuuji@58 | 498 (YaTeX-sectioning-buffer-next-line (- n)) |
yuuji@58 | 499 ) |
yuuji@23 | 500 (provide 'yatexsec) |