yatex
annotate yatexhie.el @ 623:6a0fea36298f
Code cleaning for Emacs31
| author | HIROSE Yuuji <yuuji@gentei.org> |
|---|---|
| date | Sat, 01 Aug 2026 13:51:09 +0900 |
| parents | 77a2fd4fd634 |
| children |
| rev | line source |
|---|---|
| yuuji@623 | 1 ;;; yatexhie.el --- YaTeX hierarchy browser -*- lexical-binding: nil -*- |
| yuuji@287 | 2 ;;; |
| yuuji@623 | 3 ;;; (c)1995-2013,2026 by HIROSE Yuuji [yuuji@yatex.org] |
| yuuji@623 | 4 ;;; Last modified Sat Aug 1 12:48:10 2026 on firestorm |
| yuuji@366 | 5 ;;; $Id$ |
| yuuji@52 | 6 |
| yuuji@287 | 7 ;;; Code: |
| yuuji@52 | 8 ;; ----- Customizable variables ----- |
| yuuji@53 | 9 (defvar YaTeX-hierarchy-ignore-heading-regexp |
| yuuji@53 | 10 "\\$[A-Z][a-z]+: .* \\$\\|-\\*- .* -\\*-" |
| yuuji@53 | 11 "*Regexp of lines to ignore as files' headline.") |
| yuuji@52 | 12 |
| yuuji@52 | 13 ;; ----- General variables ----- |
| yuuji@52 | 14 (defvar YaTeX-default-TeX-extensions "\\.\\(tex\\|sty\\)") |
| yuuji@52 | 15 (defvar YaTeX-hierarchy-current-main nil) |
| yuuji@52 | 16 (defvar YaTeX-hierarchy-buffer-message |
| yuuji@52 | 17 (concat |
| yuuji@53 | 18 "n)ext p)rev N)extsame P)revsame u)p K)illbuf RET)select" |
| yuuji@53 | 19 (if (and YaTeX-emacs-19 window-system) " Mouse2)select" "") |
| yuuji@53 | 20 " ?)help")) |
| yuuji@52 | 21 (defvar YaTeX-hierarchy-saved-wc nil "Saved window configuration.") |
| yuuji@623 | 22 (defvar YaTeX-hierarchy-mode-map nil "Keymap used in YaTeX-hierarchy-mode.") |
| yuuji@52 | 23 |
| yuuji@52 | 24 ;; ----- Functions for parsing hierarchy ----- |
| yuuji@52 | 25 |
| yuuji@52 | 26 (defun YaTeX-all-included-files (&optional file) |
| yuuji@52 | 27 "Return all included files from FILE as a list. |
| yuuji@52 | 28 If FILE is nil, use current buffer." |
| yuuji@52 | 29 (save-excursion |
| yuuji@52 | 30 (let ((include-regex (concat YaTeX-ec-regexp |
| yuuji@52 | 31 "\\(\\(input\\)\\|" ;match#2 |
| yuuji@52 | 32 "\\(include\\)\\)\\b")) ;match#3 |
| yuuji@52 | 33 list file (cb (current-buffer))) |
| yuuji@52 | 34 (if file (set-buffer (YaTeX-switch-to-buffer file t))) |
| yuuji@52 | 35 (goto-char (point-min)) |
| yuuji@52 | 36 (while (YaTeX-re-search-active-forward |
| yuuji@52 | 37 include-regex YaTeX-comment-prefix nil t) |
| yuuji@52 | 38 (cond |
| yuuji@52 | 39 ((match-beginning 2) ;\input, {} is optional, 1 argument |
| yuuji@52 | 40 (skip-chars-forward " {") |
| yuuji@52 | 41 (setq file (buffer-substring |
| yuuji@52 | 42 (point) |
| yuuji@52 | 43 (progn |
| yuuji@52 | 44 (skip-chars-forward |
| yuuji@52 | 45 (concat "^ \t\n\r" YaTeX-ec-regexp "{}")) |
| yuuji@52 | 46 (point))))) |
| yuuji@68 | 47 ((and (match-beginning 3) (looking-at "{")) |
| yuuji@52 | 48 (skip-chars-forward "{") |
| yuuji@52 | 49 (setq file (buffer-substring |
| yuuji@52 | 50 (point) |
| yuuji@52 | 51 (progn |
| yuuji@52 | 52 (forward-char -1) (forward-list 1) (1- (point))))))) |
| yuuji@52 | 53 (or (string-match YaTeX-default-TeX-extensions file) |
| yuuji@52 | 54 (setq file (concat file ".tex"))) |
| yuuji@52 | 55 (setq list (cons file list))) |
| yuuji@52 | 56 (set-buffer cb) |
| yuuji@52 | 57 (nreverse list)))) |
| yuuji@52 | 58 |
| yuuji@70 | 59 (defun YaTeX-document-hierarchy (&optional file basedir) |
| yuuji@52 | 60 "Return the document hierarchy beginning from FILE as a list. |
| yuuji@52 | 61 If FILE is nil, beginning with current buffer's file." |
| yuuji@52 | 62 (setq file (or file buffer-file-name)) |
| yuuji@70 | 63 (and YaTeX-search-file-from-top-directory |
| yuuji@70 | 64 (not (file-exists-p file)) |
| yuuji@70 | 65 (string-match "^[^/].*/" file) |
| yuuji@70 | 66 (setq file (expand-file-name file basedir))) |
| yuuji@52 | 67 (message "Parsing [%s]..." (file-name-nondirectory file)) |
| yuuji@52 | 68 (prog1 |
| yuuji@52 | 69 (save-excursion |
| yuuji@52 | 70 (if (or (file-exists-p file) (null file)) |
| yuuji@52 | 71 (progn |
| yuuji@52 | 72 (if file |
| yuuji@52 | 73 (let ((parent buffer-file-name)) |
| yuuji@52 | 74 (YaTeX-switch-to-buffer file t) ;set buffer to file |
| yuuji@52 | 75 (or YaTeX-parent-file |
| yuuji@52 | 76 (YaTeX-get-builtin "!") |
| yuuji@52 | 77 (setq YaTeX-parent-file parent)))) |
| yuuji@52 | 78 (cons (buffer-file-name (current-buffer)) |
| yuuji@353 | 79 (mapcar (function ;return value |
| yuuji@353 | 80 (lambda (f) |
| yuuji@353 | 81 (YaTeX-document-hierarchy f basedir))) |
| yuuji@52 | 82 (YaTeX-all-included-files)))))) |
| yuuji@52 | 83 (message "Parsing [%s]...done" (file-name-nondirectory file)))) |
| yuuji@52 | 84 |
| yuuji@52 | 85 ;; ----- Functions for displaying hierarchy ----- |
| yuuji@52 | 86 |
| yuuji@52 | 87 (defun YaTeX-hierarchy-get-file-heading (file) |
| yuuji@52 | 88 "Get a FILE's heading." |
| yuuji@52 | 89 (save-excursion |
| yuuji@52 | 90 (set-buffer (find-file-noselect file)) |
| yuuji@52 | 91 (save-excursion |
| yuuji@53 | 92 (let (p) |
| yuuji@53 | 93 (goto-char (point-min)) |
| yuuji@53 | 94 (cond |
| yuuji@53 | 95 ((re-search-forward |
| yuuji@53 | 96 (concat YaTeX-ec-regexp YaTeX-sectioning-regexp) nil t) |
| yuuji@53 | 97 (search-forward "{") |
| yuuji@53 | 98 (forward-char -1) |
| yuuji@53 | 99 (setq p (condition-case nil |
| yuuji@53 | 100 (progn (forward-list 1) (1- (point))) |
| yuuji@53 | 101 (error (point-end-of-line)))) |
| yuuji@53 | 102 (goto-char (1+ (match-beginning 0))) |
| yuuji@53 | 103 (skip-chars-forward " \t\n") |
| yuuji@53 | 104 (buffer-substring (point) (min (point-end-of-line) p))) |
| yuuji@53 | 105 ((catch 'found |
| yuuji@53 | 106 (while (re-search-forward "^ *%\\([^#]\\)" nil t) |
| yuuji@53 | 107 (or (re-search-forward |
| yuuji@53 | 108 YaTeX-hierarchy-ignore-heading-regexp |
| yuuji@53 | 109 (point-end-of-line) t) |
| yuuji@53 | 110 (throw 'found t)))) |
| yuuji@53 | 111 (beginning-of-line) |
| yuuji@53 | 112 (search-forward "%") |
| yuuji@53 | 113 (skip-chars-forward "% \t") |
| yuuji@53 | 114 (buffer-substring (point) (point-end-of-line))) |
| yuuji@53 | 115 (t "")))))) |
| yuuji@52 | 116 |
| yuuji@52 | 117 (defun YaTeX-display-a-hierachy (hier level) |
| yuuji@52 | 118 "Put a HIER of document hierarchy. |
| yuuji@52 | 119 LEVEL is including depth." |
| yuuji@52 | 120 (message "Formatting hierarchy buffer...") |
| yuuji@52 | 121 (let ((lastatomcol 0) list i p) |
| yuuji@52 | 122 (cond |
| yuuji@52 | 123 ((listp hier) |
| yuuji@52 | 124 (setq list hier) |
| yuuji@52 | 125 (while list |
| yuuji@52 | 126 (YaTeX-display-a-hierachy (car list) (1+ level)) |
| yuuji@52 | 127 (setq list (cdr list)))) |
| yuuji@52 | 128 ((stringp hier) ;is an atom |
| yuuji@52 | 129 (insert " ") |
| yuuji@52 | 130 (setq i level) |
| yuuji@52 | 131 (while (> i 2) |
| yuuji@52 | 132 (insert "| ") |
| yuuji@52 | 133 (setq i (1- i))) |
| yuuji@52 | 134 (if (> level 1) (insert "+---")) |
| yuuji@52 | 135 (setq p (point)) |
| yuuji@52 | 136 (insert (or (buffer-name (get-file-buffer hier)) |
| yuuji@52 | 137 (file-name-nondirectory hier))) |
| yuuji@52 | 138 (if (and window-system YaTeX-emacs-19) |
| yuuji@52 | 139 (put-text-property p (point) 'mouse-face 'underline)) |
| yuuji@52 | 140 (insert " ") |
| yuuji@52 | 141 (indent-to-column (1- (/ (window-width) 2))) |
| yuuji@52 | 142 (insert "% " (YaTeX-hierarchy-get-file-heading hier)) |
| yuuji@52 | 143 (insert "\n")))) |
| yuuji@52 | 144 (message "Formatting hierarchy buffer...")) |
| yuuji@52 | 145 |
| yuuji@52 | 146 (defun YaTeX-display-hierarchy (file &optional use-default) |
| yuuji@52 | 147 "Display document hierarchy that is beginning from FILE." |
| yuuji@52 | 148 (interactive "P") |
| yuuji@52 | 149 (setq YaTeX-hierarchy-saved-wc |
| yuuji@52 | 150 (list (current-window-configuration) |
| yuuji@52 | 151 (and (featurep 'windows) |
| yuuji@52 | 152 (boundp 'win:current-config) |
| yuuji@52 | 153 win:current-config))) |
| yuuji@52 | 154 (let*((b-in (YaTeX-get-builtin "!")) |
| yuuji@70 | 155 default) |
| yuuji@52 | 156 ;;む・踉擦鵙髟阡鮫このへんの仕様どう瘢雹したらいいか良く分からん... |
| yuuji@52 | 157 (if default (setq default (expand-file-name default))) |
| yuuji@52 | 158 (YaTeX-visit-main t) ;move to parent file |
| yuuji@70 | 159 (setq default buffer-file-name) |
| yuuji@52 | 160 (setq file |
| yuuji@52 | 161 (or (if use-default default file) |
| yuuji@52 | 162 (read-file-name |
| yuuji@52 | 163 (format |
| yuuji@52 | 164 "Main .tex file%s: " |
| yuuji@52 | 165 (if default |
| yuuji@52 | 166 (format "(default %s)"(file-name-nondirectory default)) |
| yuuji@52 | 167 "")) |
| yuuji@52 | 168 "" default 1)))) |
| yuuji@52 | 169 (setq file (expand-file-name file)) |
| yuuji@52 | 170 (setq YaTeX-hierarchy-current-main file) |
| yuuji@70 | 171 (let ((dbuf "*document hierarchy*") |
| yuuji@70 | 172 (topdir default-directory)) |
| yuuji@52 | 173 (YaTeX-showup-buffer dbuf nil t) |
| yuuji@52 | 174 (set-buffer (get-buffer dbuf)) |
| yuuji@52 | 175 (setq truncate-lines t) |
| yuuji@52 | 176 (let ((buffer-read-only nil)) |
| yuuji@52 | 177 (erase-buffer) |
| yuuji@70 | 178 (YaTeX-display-a-hierachy (YaTeX-document-hierarchy file topdir) 0)) |
| yuuji@52 | 179 (goto-char (point-min)) |
| yuuji@52 | 180 (YaTeX-hierarchy-next 0) |
| yuuji@52 | 181 (set-buffer-modified-p nil) |
| yuuji@52 | 182 (YaTeX-hierarchy-mode) |
| yuuji@52 | 183 )) |
| yuuji@52 | 184 |
| yuuji@52 | 185 (defun YaTeX-display-hierarchy-directly () |
| yuuji@52 | 186 "Same as YaTeX-display-hierarchy. Call from mouse." |
| yuuji@52 | 187 (interactive) |
| yuuji@52 | 188 (YaTeX-display-hierarchy nil t)) |
| yuuji@52 | 189 |
| yuuji@52 | 190 (defun YaTeX-hierarchy-mode () |
| yuuji@52 | 191 "Major mode to browse and select document hierarchy. |
| yuuji@52 | 192 |
| yuuji@52 | 193 \\[YaTeX-hierarchy-next] next line |
| yuuji@52 | 194 \\[YaTeX-hierarchy-prev] previous line |
| yuuji@53 | 195 \\[YaTeX-hierarchy-forward] move forward in the same level |
| yuuji@53 | 196 \\[YaTeX-hierarchy-backward] move backward in the same level |
| yuuji@52 | 197 \\[YaTeX-hierarchy-up-document] move to parent file |
| yuuji@52 | 198 \\[delete-other-windows] delete other windows |
| yuuji@52 | 199 \\[other-window] other window |
| yuuji@53 | 200 \\[shrink-window] shrink window |
| yuuji@53 | 201 \\[enlarge-window] enlarge window |
| yuuji@53 | 202 \\[YaTeX-hierarchy-show] show file contents in the next window |
| yuuji@53 | 203 \\[YaTeX-hierarchy-scroll-up] scroll up file contents buffer |
| yuuji@53 | 204 \\[YaTeX-hierarchy-scroll-down] scroll down file contents buffer |
| yuuji@53 | 205 \\[YaTeX-hierarchy-top] show the top of file contents |
| yuuji@53 | 206 \\[YaTeX-hierarchy-bottom] show the bottom of file contents |
| yuuji@53 | 207 \\[YaTeX-hierarchy-lastpos] return to the previous position |
| yuuji@52 | 208 \\[YaTeX-hierarchy-select] select file |
| yuuji@52 | 209 \\[YaTeX-hierarchy-mouse-select] select |
| yuuji@52 | 210 " |
| yuuji@52 | 211 (setq major-mode 'YaTeX-hierarchy-mode |
| yuuji@52 | 212 mode-name "YaTeX hier") |
| yuuji@52 | 213 (use-local-map YaTeX-hierarchy-mode-map) |
| yuuji@52 | 214 (setq buffer-read-only t) |
| yuuji@52 | 215 (message YaTeX-hierarchy-buffer-message)) |
| yuuji@52 | 216 |
| yuuji@52 | 217 ;; ----- Subfunctions for interactive functions ----- |
| yuuji@52 | 218 (defun YaTeX-hierarchy-get-current-file-buffer () |
| yuuji@52 | 219 "Return the buffer associated with current line's file." |
| yuuji@52 | 220 (let ((file (buffer-substring |
| yuuji@52 | 221 (point) |
| yuuji@52 | 222 (save-excursion |
| yuuji@52 | 223 (skip-chars-forward "^ \t" (point-end-of-line)) (point)))) |
| yuuji@52 | 224 (hilit-auto-highlight) buffer) |
| yuuji@52 | 225 (set-buffer (find-file-noselect YaTeX-hierarchy-current-main)) |
| yuuji@52 | 226 (if (get-buffer file) ;buffer is active |
| yuuji@52 | 227 (setq buffer (get-buffer file)) ;may contain `<2>' |
| yuuji@52 | 228 (if (string-match "<[2-9]>$" file) |
| yuuji@52 | 229 (setq file (substring file 0 -3))) |
| yuuji@52 | 230 (save-excursion |
| yuuji@52 | 231 (setq buffer (YaTeX-switch-to-buffer file t)))))) ; open it! |
| yuuji@52 | 232 |
| yuuji@52 | 233 ;; ----- Interactive functions ----- |
| yuuji@52 | 234 (defun YaTeX-hierarchy-next (arg &optional quiet) |
| yuuji@52 | 235 "Move to next line's file in YaTeX document hierarchy buffer." |
| yuuji@52 | 236 (interactive "p") |
| yuuji@52 | 237 (forward-line arg) |
| yuuji@52 | 238 (skip-chars-forward "- +\\|") |
| yuuji@53 | 239 (if (and (/= arg 0) (not quiet)) |
| yuuji@52 | 240 (YaTeX-hierarchy-select t)) |
| yuuji@52 | 241 (message YaTeX-hierarchy-buffer-message)) |
| yuuji@52 | 242 |
| yuuji@52 | 243 (defun YaTeX-hierarchy-prev (arg) |
| yuuji@52 | 244 "Move to previous line's file in YaTeX document hierarchy buffer." |
| yuuji@52 | 245 (interactive "p") |
| yuuji@52 | 246 (YaTeX-hierarchy-next (- arg))) |
| yuuji@52 | 247 |
| yuuji@52 | 248 (defun YaTeX-hierarchy-next-line (arg) |
| yuuji@52 | 249 (interactive "p") |
| yuuji@52 | 250 (YaTeX-hierarchy-next arg t)) |
| yuuji@52 | 251 |
| yuuji@52 | 252 (defun YaTeX-hierarchy-prev-line (arg) |
| yuuji@52 | 253 (interactive "p") |
| yuuji@52 | 254 (YaTeX-hierarchy-next (- arg) t)) |
| yuuji@52 | 255 |
| yuuji@52 | 256 (defun YaTeX-hierarchy-forward (arg) |
| yuuji@52 | 257 "Move to forward file in same hierarchy level." |
| yuuji@52 | 258 (interactive "p") |
| yuuji@52 | 259 (YaTeX-hierarchy-next 0) |
| yuuji@52 | 260 (let ((p (point))(column (current-column)) (i (if (> arg 0) arg (- arg)))) |
| yuuji@52 | 261 (if (= column 0) (error "Not on file line.")) |
| yuuji@52 | 262 (while (> i 0) |
| yuuji@52 | 263 (if (catch 'found |
| yuuji@52 | 264 (while (and (not (eobp)) (not (bobp))) |
| yuuji@52 | 265 (forward-line (if (> arg 0) 1 -1)) |
| yuuji@52 | 266 (move-to-column column) |
| yuuji@52 | 267 (if (looking-at "[- +\\|]") nil |
| yuuji@52 | 268 (YaTeX-hierarchy-next 0) |
| yuuji@52 | 269 (if (= (current-column) column) (throw 'found t))) |
| yuuji@52 | 270 (beginning-of-line))) |
| yuuji@52 | 271 nil |
| yuuji@52 | 272 (goto-char p) |
| yuuji@52 | 273 (error "No same level file.")) |
| yuuji@52 | 274 (setq i (1- i))))) |
| yuuji@52 | 275 |
| yuuji@52 | 276 (defun YaTeX-hierarchy-backward (arg) |
| yuuji@52 | 277 "Move to backward file in same hierarchy level." |
| yuuji@52 | 278 (interactive "p") |
| yuuji@52 | 279 (YaTeX-hierarchy-forward (- arg))) |
| yuuji@52 | 280 |
| yuuji@52 | 281 (defun YaTeX-hierarchy-up-document () |
| yuuji@52 | 282 "Up level, that is, move to parent file position." |
| yuuji@52 | 283 (interactive) |
| yuuji@52 | 284 (YaTeX-hierarchy-next 0) ;adjust column |
| yuuji@52 | 285 (let ((p (point)) (line (count-lines (point-min) (point))) column) |
| yuuji@52 | 286 (if (or (<= line 1) (< (current-column) 6)) |
| yuuji@52 | 287 (message "No more parent") |
| yuuji@52 | 288 (backward-char 1) |
| yuuji@52 | 289 (or (= (char-after (point)) ?-) (error "Unexpected hierarchy buffer")) |
| yuuji@52 | 290 (setq column (current-column)) |
| yuuji@52 | 291 (while (and (> line 1) (looking-at "[- +\\|]")) |
| yuuji@52 | 292 (forward-line -1) |
| yuuji@52 | 293 (move-to-column column)) |
| yuuji@52 | 294 (YaTeX-hierarchy-next 0) |
| yuuji@52 | 295 (push-mark p t) |
| yuuji@52 | 296 (message "Mark set to last position")))) |
| yuuji@52 | 297 |
| yuuji@52 | 298 (defun YaTeX-hierarchy-kill-buffer (arg) |
| yuuji@52 | 299 "Kill buffer associated with current line's file." |
| yuuji@52 | 300 (interactive "p") |
| yuuji@52 | 301 (YaTeX-hierarchy-next 0) ;move to file name column |
| yuuji@52 | 302 (if (bolp) (error "Not on file name line")) |
| yuuji@53 | 303 (let ((file (buffer-substring |
| yuuji@53 | 304 (point) |
| yuuji@53 | 305 (progn (skip-chars-forward "^ \t") (point))))) |
| yuuji@52 | 306 (YaTeX-hierarchy-next arg) |
| yuuji@52 | 307 (cond |
| yuuji@52 | 308 ((get-buffer file) |
| yuuji@52 | 309 (kill-buffer (get-buffer file)) |
| yuuji@52 | 310 (message "Buffer [%s] was killed" file)) |
| yuuji@52 | 311 (t (message "Buffer [%s] is not active." file))))) |
| yuuji@52 | 312 |
| yuuji@52 | 313 (defun YaTeX-hierarchy-select (arg) |
| yuuji@52 | 314 "Select current line's file in YaTeX document hierarchy buffer. |
| yuuji@52 | 315 If ARG is non-nil, show the buffer in the next window." |
| yuuji@52 | 316 (interactive "P") |
| yuuji@52 | 317 (beginning-of-line) |
| yuuji@52 | 318 (skip-chars-forward "- +\\|") |
| yuuji@52 | 319 (or (eolp) |
| yuuji@52 | 320 (let ((buffer (YaTeX-hierarchy-get-current-file-buffer))) |
| yuuji@52 | 321 (if buffer ;if file was found |
| yuuji@52 | 322 (if arg |
| yuuji@52 | 323 (YaTeX-showup-buffer buffer nil) |
| yuuji@52 | 324 (if (and YaTeX-emacs-19 window-system |
| yuuji@52 | 325 (get-buffer-window buffer t)) |
| yuuji@52 | 326 (goto-buffer-window buffer) ;select currently displaying |
| yuuji@52 | 327 (YaTeX-switch-to-buffer-other-window buffer))))))) |
| yuuji@52 | 328 |
| yuuji@52 | 329 (defun YaTeX-hierarchy-show () |
| yuuji@52 | 330 "Show current line's file in the next window." |
| yuuji@52 | 331 (interactive) |
| yuuji@52 | 332 (YaTeX-hierarchy-select t)) |
| yuuji@52 | 333 |
| yuuji@52 | 334 (defun YaTeX-hierarchy-mouse-select (event) |
| yuuji@52 | 335 (interactive "e") |
| yuuji@52 | 336 (mouse-set-point event) |
| yuuji@52 | 337 (YaTeX-hierarchy-select nil)) |
| yuuji@52 | 338 |
| yuuji@52 | 339 (defun YaTeX-hierarchy-quit () |
| yuuji@52 | 340 "Quit from YaTeX-hierarchy buffer and restore window configuration." |
| yuuji@52 | 341 (interactive) |
| yuuji@52 | 342 (if (or (not (featurep 'windows)) |
| yuuji@52 | 343 (car YaTeX-hierarchy-saved-wc) |
| yuuji@52 | 344 (and (= (car (cdr YaTeX-hierarchy-saved-wc)) win:current-config))) |
| yuuji@52 | 345 (set-window-configuration (car YaTeX-hierarchy-saved-wc)) |
| yuuji@52 | 346 (bury-buffer nil))) |
| yuuji@52 | 347 |
| yuuji@53 | 348 (defun YaTeX-hierarchy-scroll-up (arg &optional action) |
| yuuji@53 | 349 "Scroll up file contents of YaTeX-hierarchy." |
| yuuji@52 | 350 (interactive "P") |
| yuuji@53 | 351 (YaTeX-hierarchy-next 0 t) |
| yuuji@53 | 352 (let*((bufname (buffer-substring |
| yuuji@53 | 353 (point) |
| yuuji@53 | 354 (save-excursion (skip-chars-forward "^ \t") (point)))) |
| yuuji@53 | 355 (buf (get-buffer bufname)) |
| yuuji@53 | 356 (cw (selected-window))) |
| yuuji@53 | 357 (cond |
| yuuji@53 | 358 ((and buf (get-buffer-window buf)) |
| yuuji@53 | 359 (select-window (get-buffer-window buf))) |
| yuuji@53 | 360 ((and buf (YaTeX-showup-buffer buf nil t)) t) |
| yuuji@53 | 361 (t (YaTeX-hierarchy-select nil))) |
| yuuji@53 | 362 (unwind-protect |
| yuuji@53 | 363 (cond |
| yuuji@53 | 364 ((eq action 'down) (scroll-down arg)) |
| yuuji@53 | 365 ((eq action 'top) (beginning-of-buffer)) |
| yuuji@53 | 366 ((eq action 'bottom) (end-of-buffer)) |
| yuuji@53 | 367 ((eq action 'last) (exchange-point-and-mark)) |
| yuuji@53 | 368 (t (scroll-up arg))) |
| yuuji@53 | 369 (select-window cw)))) |
| yuuji@53 | 370 |
| yuuji@53 | 371 (defun YaTeX-hierarchy-scroll-down (arg) |
| yuuji@53 | 372 "Scroll down file contents of YaTeX-hierarchy." |
| yuuji@53 | 373 (interactive "P") |
| yuuji@53 | 374 (YaTeX-hierarchy-scroll-up arg 'down)) |
| yuuji@53 | 375 |
| yuuji@53 | 376 (defun YaTeX-hierarchy-top () |
| yuuji@53 | 377 "Show the top of YaTeX-hierarchy inspection buffer's." |
| yuuji@53 | 378 (interactive) |
| yuuji@53 | 379 (YaTeX-hierarchy-scroll-up nil 'top) |
| yuuji@53 | 380 ) |
| yuuji@53 | 381 |
| yuuji@53 | 382 (defun YaTeX-hierarchy-bottom () |
| yuuji@53 | 383 "Show the top of YaTeX-hierarchy inspection buffer's." |
| yuuji@53 | 384 (interactive) |
| yuuji@53 | 385 (YaTeX-hierarchy-scroll-up nil 'bottom) |
| yuuji@53 | 386 ) |
| yuuji@53 | 387 |
| yuuji@53 | 388 (defun YaTeX-hierarchy-lastpos () |
| yuuji@53 | 389 "Go to last position in YaTeX-hierarchy buffer." |
| yuuji@53 | 390 (interactive) |
| yuuji@53 | 391 (YaTeX-hierarchy-scroll-up nil 'last) |
| yuuji@53 | 392 ) |
| yuuji@52 | 393 |
| yuuji@52 | 394 ;; ----- Setting up keymap ----- |
| yuuji@52 | 395 (if YaTeX-hierarchy-mode-map nil |
| yuuji@52 | 396 (setq YaTeX-hierarchy-mode-map (make-sparse-keymap)) |
| yuuji@52 | 397 (define-key YaTeX-hierarchy-mode-map "n" 'YaTeX-hierarchy-next) |
| yuuji@52 | 398 (define-key YaTeX-hierarchy-mode-map "p" 'YaTeX-hierarchy-prev) |
| yuuji@52 | 399 (define-key YaTeX-hierarchy-mode-map "j" 'YaTeX-hierarchy-next-line) |
| yuuji@52 | 400 (define-key YaTeX-hierarchy-mode-map "k" 'YaTeX-hierarchy-prev-line) |
| yuuji@52 | 401 (substitute-all-key-definition |
| yuuji@52 | 402 'next-line 'YaTeX-hierarchy-next-line YaTeX-hierarchy-mode-map) |
| yuuji@52 | 403 (substitute-all-key-definition |
| yuuji@52 | 404 'previous-line 'YaTeX-hierarchy-prev-line YaTeX-hierarchy-mode-map) |
| yuuji@52 | 405 (define-key YaTeX-hierarchy-mode-map "N" 'YaTeX-hierarchy-forward) |
| yuuji@52 | 406 (define-key YaTeX-hierarchy-mode-map "P" 'YaTeX-hierarchy-backward) |
| yuuji@52 | 407 (define-key YaTeX-hierarchy-mode-map "u" 'YaTeX-hierarchy-up-document) |
| yuuji@52 | 408 (define-key YaTeX-hierarchy-mode-map "K" 'YaTeX-hierarchy-kill-buffer) |
| yuuji@52 | 409 (define-key YaTeX-hierarchy-mode-map "1" 'delete-other-windows) |
| yuuji@52 | 410 (define-key YaTeX-hierarchy-mode-map "o" 'other-window) |
| yuuji@53 | 411 (define-key YaTeX-hierarchy-mode-map "-" 'shrink-window) |
| yuuji@53 | 412 (define-key YaTeX-hierarchy-mode-map "+" 'enlarge-window) |
| yuuji@52 | 413 (define-key YaTeX-hierarchy-mode-map "." 'YaTeX-hierarchy-show) |
| yuuji@53 | 414 (define-key YaTeX-hierarchy-mode-map " " 'YaTeX-hierarchy-scroll-up) |
| yuuji@53 | 415 (define-key YaTeX-hierarchy-mode-map "b" 'YaTeX-hierarchy-scroll-down) |
| yuuji@53 | 416 (define-key YaTeX-hierarchy-mode-map "\C-?" 'YaTeX-hierarchy-scroll-down) |
| yuuji@52 | 417 (define-key YaTeX-hierarchy-mode-map "\C-m" 'YaTeX-hierarchy-select) |
| yuuji@53 | 418 (define-key YaTeX-hierarchy-mode-map "<" 'YaTeX-hierarchy-top) |
| yuuji@53 | 419 (define-key YaTeX-hierarchy-mode-map ">" 'YaTeX-hierarchy-bottom) |
| yuuji@53 | 420 (define-key YaTeX-hierarchy-mode-map "'" 'YaTeX-hierarchy-lastpos) |
| yuuji@53 | 421 (define-key YaTeX-hierarchy-mode-map "g" 'YaTeX-hierarchy-select) |
| yuuji@52 | 422 (define-key YaTeX-hierarchy-mode-map "q" 'YaTeX-hierarchy-quit) |
| yuuji@52 | 423 (define-key YaTeX-hierarchy-mode-map "?" 'describe-mode) |
| yuuji@52 | 424 (if (and YaTeX-emacs-19 window-system) |
| yuuji@52 | 425 (define-key YaTeX-hierarchy-mode-map |
| yuuji@52 | 426 [mouse-2] 'YaTeX-hierarchy-mouse-select)) |
| yuuji@52 | 427 ) |
| yuuji@52 | 428 |
| yuuji@52 | 429 (provide 'yatexhie) |
| yuuji@52 | 430 ;;end of yatexhie.el |
