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