yatex
diff yatexsec.el @ 45:b0fc9c2950cd
Prepare for supporting Emacs-19.
author | yuuji |
---|---|
date | Sun, 24 Jul 1994 15:07:23 +0000 |
parents | |
children | cd1b63102eed |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/yatexsec.el Sun Jul 24 15:07:23 1994 +0000 1.3 @@ -0,0 +1,281 @@ 1.4 +;;; -*- Emacs-Lisp -*- 1.5 +;;; YaTeX sectioning browser. 1.6 +;;; yatexsec.el 1.7 +;;; (c ) 1994 by HIROSE Yuuji [yuuji@ae.keio.ac.jp] 1.8 +;;; Last modified Thu Jul 7 01:26:26 1994 on 98fa 1.9 +;;; $Id$ 1.10 + 1.11 +(defvar YaTeX-sectioning-level 1.12 + '(("part" . 0) ("chapter" . 1) ("section" . 2) ("subsection" . 3) 1.13 + ("subsubsection" . 4) ("paragraph" . 5) ("subparagraph" . 6)) 1.14 + "Sectioning level.") 1.15 + 1.16 +(defun YaTeX-sectioning-map-hide (map) 1.17 + (let ((ch ?0)) 1.18 + (while (<= ch ?9) 1.19 + (define-key map (char-to-string ch) 'YaTeX-sectioning-hide) 1.20 + (setq ch (1+ ch)))) 1.21 +) 1.22 + 1.23 +(defvar YaTeX-minibuffer-sectioning-map nil 1.24 + "Key map used in minibuffer for sectioning.") 1.25 +(if YaTeX-minibuffer-sectioning-map nil 1.26 + (setq YaTeX-minibuffer-sectioning-map 1.27 + (copy-keymap minibuffer-local-completion-map)) 1.28 + (define-key YaTeX-minibuffer-sectioning-map "\C-p" 1.29 + 'YaTeX-sectioning-up) 1.30 + (define-key YaTeX-minibuffer-sectioning-map "\C-e" 1.31 + 'YaTeX-sectioning-up) 1.32 + (define-key YaTeX-minibuffer-sectioning-map "\C-i" 1.33 + 'YaTeX-minibuffer-complete) 1.34 + (define-key YaTeX-minibuffer-sectioning-map " " 1.35 + 'YaTeX-minibuffer-complete) 1.36 + (define-key YaTeX-minibuffer-sectioning-map "\C-n" 1.37 + 'YaTeX-sectioning-down) 1.38 + (define-key YaTeX-minibuffer-sectioning-map "\C-x" 1.39 + 'YaTeX-sectioning-down) 1.40 + (define-key YaTeX-minibuffer-sectioning-map "\C-v" 1.41 + 'YaTeX-sectioning-scroll-up) 1.42 + (define-key YaTeX-minibuffer-sectioning-map "\C-c" 1.43 + 'YaTeX-sectioning-scroll-up) 1.44 + (define-key YaTeX-minibuffer-sectioning-map "\M-v" 1.45 + 'YaTeX-sectioning-scroll-down) 1.46 + (define-key YaTeX-minibuffer-sectioning-map "\C-r" 1.47 + 'YaTeX-sectioning-scroll-down) 1.48 + (define-key YaTeX-minibuffer-sectioning-map "\C-w" 1.49 + '(lambda () (interactive) (YaTeX-sectioning-scroll-down 1))) 1.50 + (define-key YaTeX-minibuffer-sectioning-map "\C-z" 1.51 + '(lambda () (interactive) (YaTeX-sectioning-scroll-up 1))) 1.52 + (define-key YaTeX-minibuffer-sectioning-map "\C-l" 1.53 + 'YaTeX-sectioning-recenter) 1.54 + (define-key YaTeX-minibuffer-sectioning-map "?" 1.55 + 'YaTeX-sectioning-help) 1.56 + (YaTeX-sectioning-map-hide YaTeX-minibuffer-sectioning-map) 1.57 +) 1.58 + 1.59 +(defvar YaTeX-sectioning-buffer-map nil 1.60 + "Key map used in YaTeX-sectioning-buffer.") 1.61 +(if YaTeX-sectioning-buffer-map nil 1.62 + (setq YaTeX-sectioning-buffer-map (make-sparse-keymap)) 1.63 + (define-key YaTeX-sectioning-buffer-map " " 1.64 + 'YaTeX-sectioning-buffer-jump) 1.65 + (define-key YaTeX-sectioning-buffer-map (concat YaTeX-prefix "\C-c") 1.66 + 'YaTeX-sectioning-buffer-jump) 1.67 + (YaTeX-sectioning-map-hide YaTeX-sectioning-buffer-map) 1.68 +) 1.69 + 1.70 +(defvar YaTeX-sectioning-buffer-parent nil) 1.71 +(defun YaTeX-sectioning-buffer-jump () 1.72 + (interactive) 1.73 + (if (and YaTeX-sectioning-buffer-parent 1.74 + (get-buffer YaTeX-sectioning-buffer-parent)) 1.75 + (let (ptn) 1.76 + (beginning-of-line) 1.77 + (if (re-search-forward YaTeX-sectioning-regexp) 1.78 + (progn (setq ptn (buffer-substring 1.79 + (1- (match-beginning 0)) 1.80 + (progn (skip-chars-forward "^}") (1+ (point))))) 1.81 + (YaTeX-showup-buffer YaTeX-sectioning-buffer-parent nil t) 1.82 + (goto-char (point-max)) 1.83 + (search-backward ptn)) 1.84 + (message "No line number expression.")))) 1.85 +) 1.86 + 1.87 +(defun YaTeX-sectioning-hide-under (n) 1.88 + "Hide sectioning commands under level N." 1.89 + (let ((cw (selected-window))) 1.90 + (YaTeX-showup-buffer YaTeX-sectioning-buffer nil t) 1.91 + (if (>= n (1- (length YaTeX-sectioning-level))) 1.92 + (progn 1.93 + (set-selective-display nil) 1.94 + (message "Show all.")) 1.95 + (set-selective-display (1+ n)) 1.96 + (if (nth n YaTeX-sectioning-level) 1.97 + (message "Hide lower than %s" (car (nth n YaTeX-sectioning-level))) 1.98 + (message ""))) 1.99 + (if (numberp selective-display) 1.100 + (setq mode-name (format "level %d" (1- selective-display))) 1.101 + (setq mode-name (format "all"))) 1.102 + (select-window cw)) 1.103 +) 1.104 +(defun YaTeX-sectioning-hide () 1.105 + "Call YaTeX-sectioning-hide-under with argument according to pressed key." 1.106 + (interactive) 1.107 + (YaTeX-sectioning-hide-under (- last-command-char ?0))) 1.108 + 1.109 +(defun YaTeX-sectioning-help () 1.110 + "Show help of sectioning." 1.111 + (interactive) 1.112 + (let ((cw (selected-window)) sb (hb (get-buffer-create "*Help*"))) 1.113 + (unwind-protect 1.114 + (progn 1.115 + (other-window 1) 1.116 + (setq sb (current-buffer)) 1.117 + (switch-to-buffer hb) 1.118 + (erase-buffer) 1.119 + (insert "===== View sectioning ===== 1.120 +C-p Up sectioning level. 0 Show only \\part, 1.121 +C-n Down sectioning level. 1 and \\chapter, 1.122 +C-v Scroll up *Sectioning line* buffer. 2 and \\section, 1.123 +M-v Scroll down *Sectioning line* buffer. 3 and \\subsection, 1.124 +SPC Complete word. 4 and \\subsubsection, 1.125 +TAB Complete word. 5 and \\paragraph. 1.126 +C-l Recenter recent line. 6 Show all. 1.127 +RET Select. 1.128 +==== End of HELP ===== 1.129 +") 1.130 + (set-buffer-modified-p nil) 1.131 + (goto-char (point-min)) 1.132 + (momentary-string-display "" (point-min))) 1.133 + (bury-buffer hb) 1.134 + (switch-to-buffer sb) 1.135 + (select-window cw))) 1.136 +) 1.137 + 1.138 +(defun YaTeX-sectioning-up (n) 1.139 + "Up section level. 1.140 +Refers the YaTeX-read-section-in-minibuffer's local variable minibuffer-start." 1.141 + (interactive "p") 1.142 + (if (eq (selected-window) (minibuffer-window)) 1.143 + (let*((command (buffer-string)) 1.144 + (alist YaTeX-sectioning-level) 1.145 + (level (cdr-safe (assoc command alist)))) 1.146 + (or level (error "No such sectioning command.")) 1.147 + (setq level (- level n)) 1.148 + (if (or (< level 0) (>= level (length alist))) 1.149 + (ding) 1.150 + (erase-buffer) 1.151 + (insert (car (nth level alist)))) 1.152 + )) 1.153 +) 1.154 + 1.155 +(defun YaTeX-sectioning-down (n) 1.156 + "Down section level." 1.157 + (interactive "p") 1.158 + (YaTeX-sectioning-up (- n)) 1.159 +) 1.160 + 1.161 +(defun YaTeX-sectioning-scroll-up (n) 1.162 + (interactive "P") 1.163 + (let ((section-buffer YaTeX-sectioning-buffer) 1.164 + (cw (selected-window))) 1.165 + (YaTeX-showup-buffer section-buffer nil t) 1.166 + (unwind-protect 1.167 + (scroll-up (or n (- (window-height) 2))) 1.168 + (select-window cw))) 1.169 +) 1.170 + 1.171 +(defun YaTeX-sectioning-scroll-down (n) 1.172 + (interactive "P") 1.173 + (let ((section-buffer YaTeX-sectioning-buffer) 1.174 + (cw (selected-window))) 1.175 + (YaTeX-showup-buffer section-buffer nil t) 1.176 + (unwind-protect 1.177 + (scroll-down (or n (- (window-height) 2))) 1.178 + (select-window cw))) 1.179 +) 1.180 + 1.181 +(defun YaTeX-sectioning-recenter (arg) 1.182 + "Recenter `<<--' line" 1.183 + (interactive "P") 1.184 + (let ((cw (selected-window))) 1.185 + (unwind-protect 1.186 + (progn 1.187 + (YaTeX-showup-buffer YaTeX-sectioning-buffer nil t) 1.188 + (or (search-forward "<<--" nil t) 1.189 + (search-backward "<<--" nil t)) 1.190 + (recenter (or arg (/ (window-height) 2)))) 1.191 + (select-window cw))) 1.192 +) 1.193 + 1.194 +(defvar YaTeX-sectioning-minibuffer " *sectioning*" 1.195 + "Miniuffer used for sectioning") 1.196 +(defun YaTeX-read-section-in-minibuffer (prompt table &optional default delim) 1.197 + (interactive) 1.198 + (let ((minibuffer-completion-table table)) 1.199 + (read-from-minibuffer 1.200 + prompt default YaTeX-minibuffer-sectioning-map)) 1.201 +) 1.202 + 1.203 +(defun YaTeX-get-sectioning-level () 1.204 + "Get section-level on the cursor." 1.205 + (cdr-safe (assoc (buffer-substring 1.206 + (point) 1.207 + (progn (skip-chars-forward "a-z") (point))) 1.208 + YaTeX-sectioning-level)) 1.209 +) 1.210 + 1.211 +(defvar YaTeX-sectioning-buffer "*Sectioning lines*") 1.212 +(defun YaTeX-colloect-sections () 1.213 + "Collect all the lines which contains sectioning command." 1.214 + (let ((cw (selected-window)) level indent begp (prevp 1) (prevl 1) 1.215 + (pattern (concat YaTeX-ec-regexp 1.216 + "\\(" YaTeX-sectioning-regexp "\\)\\*?{")) 1.217 + (cb (current-buffer))) 1.218 + (save-excursion 1.219 + (YaTeX-showup-buffer YaTeX-sectioning-buffer) ;show buffer 1.220 + (goto-char (point-min)) 1.221 + (with-output-to-temp-buffer YaTeX-sectioning-buffer 1.222 + (while (re-search-forward pattern nil t) 1.223 + (goto-char (1+ (match-beginning 0))) 1.224 + (setq level (YaTeX-get-sectioning-level) 1.225 + begp (match-beginning 0)) 1.226 + ;;(beginning-of-line) 1.227 + ;;(skip-chars-forward " \t") 1.228 + (setq indent (format "%%%ds" level)) 1.229 + (princ (format indent "")) 1.230 + (if (YaTeX-on-comment-p) (princ "%")) 1.231 + (princ (buffer-substring begp (progn (forward-list 1) (point)))) 1.232 + (setq prevl (+ prevl (count-lines prevp (point)) -1) 1.233 + prevp (point)) 1.234 + (princ (format " (line:%d)" prevl)) 1.235 + (princ "\n"))) 1.236 + (set-buffer YaTeX-sectioning-buffer) 1.237 + (make-local-variable 'YaTeX-sectioning-buffer-parent) 1.238 + (use-local-map YaTeX-sectioning-buffer-map) 1.239 + (setq YaTeX-sectioning-buffer-parent cb) 1.240 + (if (numberp selective-display) 1.241 + (setq mode-name (format "level %d" (1- selective-display)))) 1.242 + YaTeX-sectioning-buffer)) 1.243 +) 1.244 + 1.245 +(defun YaTeX-section-overview () 1.246 + "Show section overview. Return the nearest sectioning command." 1.247 + (interactive) 1.248 + (let ((cw (selected-window)) (ln (count-lines (point-min) (point))) 1.249 + (pattern "(line:\\([0-9]+\\))") 1.250 + (secbuf YaTeX-sectioning-buffer) (command "")) 1.251 + (save-excursion 1.252 + (setq secbuf (YaTeX-colloect-sections)) 1.253 + (YaTeX-showup-buffer secbuf nil t) 1.254 + (goto-char (point-max)) 1.255 + (while (re-search-backward pattern nil t) 1.256 + (if (< ln (string-to-int (YaTeX-match-string 1))) nil 1.257 + (beginning-of-line) 1.258 + (search-forward YaTeX-ec) 1.259 + (looking-at YaTeX-TeX-token-regexp) 1.260 + (setq command (YaTeX-match-string 0)) 1.261 + (end-of-line) 1.262 + (insert " <<--") 1.263 + (setq pattern (concat "HackyRegexp" "ForFailure")))) 1.264 + (set-buffer-modified-p nil) 1.265 + (forward-line 1) 1.266 + (if (eobp) (recenter -1) (recenter -3)) 1.267 + (select-window cw) 1.268 + command)) 1.269 +) 1.270 + 1.271 +(defun YaTeX-make-section-with-overview () 1.272 + "Input sectining command with previous overview." 1.273 + (interactive) 1.274 + (insert 1.275 + YaTeX-ec 1.276 + (YaTeX-read-section-in-minibuffer 1.277 + "Sectioning(Up=C-p, Down=C-n, Help=?): " 1.278 + YaTeX-sectioning-level (YaTeX-section-overview)) 1.279 + "{}") 1.280 + (forward-char -1) 1.281 +) 1.282 + 1.283 +(provide 'yatexsec) 1.284 +;;(YaTeX-define-key "o" 'YaTeX-make-section-with-overview)