yatex

annotate yatexenv.el @ 34:c61405ef1bd1

Change the message of dictionary selection menu.
author yuuji
date Wed, 13 Jul 1994 16:11:27 +0000
parents b00c74813e56
children cd1b63102eed
rev   line source
yuuji@23 1 ;;; -*- Emacs-Lisp -*-
yuuji@23 2 ;;; YaTeX environment-specific functions.
yuuji@23 3 ;;; yatexenv.el
yuuji@23 4 ;;; (c ) 1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
yuuji@31 5 ;;; Last modified Mon Jul 11 02:01:18 1994 on 98fa
yuuji@23 6 ;;; $Id$
yuuji@23 7
yuuji@23 8 ;;;
yuuji@23 9 ;; Functions for tabular environment
yuuji@23 10 ;;;
yuuji@23 11
yuuji@23 12 ;; Showing the matching column of tabular environment.
yuuji@23 13 (defun YaTeX-array-what-column ()
yuuji@23 14 "Show matching columne title of array environment.
yuuji@23 15 When calling from a program, make sure to be in array/tabular environment."
yuuji@23 16 (let ((p (point)) beg eot bor (nlptn "\\\\\\\\") (andptn "[^\\]&") (n 0)
yuuji@23 17 (firsterr "This line might be the first row."))
yuuji@23 18 (save-excursion
yuuji@23 19 (YaTeX-beginning-of-environment)
yuuji@23 20 (search-forward "{" p) (up-list 1)
yuuji@23 21 (search-forward "{" p) (up-list 1)
yuuji@23 22 ;;(re-search-forward andptn p)
yuuji@23 23 (while (progn (search-forward "&" p)
yuuji@23 24 (equal (char-after (1- (match-beginning 0))) ?\\ )))
yuuji@23 25 (setq beg (1- (point))) ;beg is the point of the first &
yuuji@23 26 (or (re-search-forward nlptn p t)
yuuji@23 27 (error firsterr))
yuuji@23 28 (setq eot (point)) ;eot is the point of the first \\
yuuji@23 29 (goto-char p)
yuuji@23 30 (or (re-search-backward nlptn beg t)
yuuji@23 31 (error firsterr))
yuuji@23 32 (setq bor (point)) ;bor is the beginning of this row.
yuuji@23 33 (while (< (1- (point)) p)
yuuji@23 34 (if (equal (following-char) ?&)
yuuji@23 35 (forward-char 1)
yuuji@23 36 (re-search-forward andptn nil 1))
yuuji@23 37 (setq n (1+ n))) ;Check current column number
yuuji@23 38 (goto-char p)
yuuji@23 39 (cond ;Start searching \multicolumn{N}
yuuji@23 40 ((> n 1)
yuuji@23 41 (re-search-backward andptn) ;Sure to find!
yuuji@23 42 (while (re-search-backward "\\\\multicolumn{\\([0-9]+\\)}" bor t)
yuuji@23 43 (setq n (+ n (string-to-int
yuuji@23 44 (buffer-substring (match-beginning 1)
yuuji@23 45 (match-end 1)))
yuuji@23 46 -1)))))
yuuji@23 47 (message "%s" n)
yuuji@23 48 (goto-char (1- beg))
yuuji@23 49 (cond
yuuji@23 50 ((= n 1) (message "Here is the FIRST column!"))
yuuji@23 51 (t (while (> n 1)
yuuji@23 52 (or (re-search-forward andptn p nil)
yuuji@23 53 (error "This column exceeds the limit."))
yuuji@23 54 (setq n (1- n)))
yuuji@23 55 (skip-chars-forward "\\s ")
yuuji@23 56 (message
yuuji@23 57 "Here is the column of: %s"
yuuji@23 58 (buffer-substring
yuuji@23 59 (point)
yuuji@23 60 (progn
yuuji@23 61 (re-search-forward (concat andptn "\\|" nlptn) eot)
yuuji@23 62 (goto-char (match-beginning 0))
yuuji@23 63 (if (looking-at andptn)
yuuji@23 64 (forward-char 1))
yuuji@23 65 (skip-chars-backward "\\s ")
yuuji@23 66 (point))))))))
yuuji@23 67 )
yuuji@23 68
yuuji@23 69 ;;;###autoload
yuuji@23 70 (defun YaTeX-what-column ()
yuuji@23 71 "Show which kind of column the current position is belonging to."
yuuji@23 72 (interactive)
yuuji@23 73 (cond
yuuji@23 74 ((YaTeX-quick-in-environment-p '("tabular" "tabular*" "array" "array*"))
yuuji@23 75 (YaTeX-array-what-column))
yuuji@23 76 (t (message "Not in array/tabuar environment.")))
yuuji@23 77 )
yuuji@23 78
yuuji@31 79 (defun YaTeX-tabular-parse-format (&optional tabular*)
yuuji@31 80 "Parse `tabular' format.
yuuji@31 81 Return the list of (No.ofCols PointEndofFormat)"
yuuji@31 82 (let ((p (point)) elt boform eoform (cols 0))
yuuji@31 83 (save-excursion
yuuji@31 84 (if (null (YaTeX-beginning-of-environment t))
yuuji@31 85 (error "Beginning of tabular not found."))
yuuji@31 86 (skip-chars-forward "^{")
yuuji@31 87 (forward-list 1)
yuuji@31 88 (if tabular*
yuuji@31 89 (progn (skip-chars-forward "^{")
yuuji@31 90 (forward-list 1)))
yuuji@31 91 (skip-chars-forward "^{" p)
yuuji@31 92 (if (/= (following-char) ?\{) (error "Tabular format not found."))
yuuji@31 93 (setq boform (1+ (point))
yuuji@31 94 eoform (progn (forward-list 1) (1- (point))))
yuuji@31 95 (if (> eoform p) (error "Non-terminated tabular format."))
yuuji@31 96 (goto-char boform)
yuuji@31 97 (while (< (point) eoform)
yuuji@31 98 (setq elt (following-char))
yuuji@31 99 (cond
yuuji@31 100 ((string-match (char-to-string elt) "clr") ;normal indicators.
yuuji@31 101 (setq cols (1+ cols))
yuuji@31 102 (forward-char 1))
yuuji@31 103 ((equal elt ?|) ;vertical
yuuji@31 104 (forward-char 1))
yuuji@31 105 ((string-match (char-to-string elt) "p@") ;p or @ expression
yuuji@31 106 (setq cols (+ (if (eq elt ?p) 1 0) cols))
yuuji@31 107 (skip-chars-forward "^{" p)
yuuji@31 108 (forward-list 1))))
yuuji@31 109 (list cols (1+ eoform))))
yuuji@31 110 )
yuuji@31 111 ;; Insert &
yuuji@31 112 (defun YaTeX-intelligent-newline-tabular (&optional tabular*)
yuuji@31 113 "Parse current tabular format and insert that many `&'s."
yuuji@31 114 (let*((p (point)) (format (YaTeX-tabular-parse-format tabular*))
yuuji@31 115 (cols (car format)) (beg (car (cdr format)))
yuuji@31 116 space hline)
yuuji@31 117 (setq hline (search-backward "\\hline" beg t))
yuuji@31 118 (goto-char p)
yuuji@31 119 (setq space (if (search-backward "\t&" beg t) "\t" " "))
yuuji@31 120 (goto-char p)
yuuji@31 121 (YaTeX-indent-line)
yuuji@31 122 (setq p (point))
yuuji@31 123 (while (> (1- cols) 0)
yuuji@31 124 (insert "&" space)
yuuji@31 125 (setq cols (1- cols)))
yuuji@31 126 (insert "\\\\")
yuuji@31 127 (if hline (insert " \\hline"))
yuuji@31 128 (goto-char p))
yuuji@31 129 )
yuuji@31 130
yuuji@31 131 (defun YaTeX-intelligent-newline-tabular* ()
yuuji@31 132 "Parse current tabular* format and insert that many `&'s."
yuuji@31 133 (YaTeX-intelligent-newline-tabular t)
yuuji@31 134 )
yuuji@31 135
yuuji@31 136 (fset 'YaTeX-intelligent-newline-array 'YaTeX-intelligent-newline-tabular)
yuuji@31 137
yuuji@23 138 ;;;
yuuji@23 139 ;; Functions for tabbing environment
yuuji@23 140 ;;;
yuuji@23 141 (defun YaTeX-intelligent-newline-tabbing ()
yuuji@23 142 "Check the number of \\= in the first line and insert that many \\>."
yuuji@23 143 (let ((p (point)) begenv tabcount)
yuuji@23 144 (save-excursion
yuuji@23 145 (YaTeX-beginning-of-environment)
yuuji@23 146 (setq begenv (point-end-of-line))
yuuji@23 147 (if (YaTeX-search-active-forward "\\\\" YaTeX-comment-prefix p t)
yuuji@23 148 (progn
yuuji@23 149 (setq tabcount 0)
yuuji@23 150 (while (> (point) begenv)
yuuji@23 151 (if (search-backward "\\=" begenv 1)
yuuji@23 152 (setq tabcount (1+ tabcount)))))))
yuuji@23 153 (YaTeX-indent-line)
yuuji@23 154 (if tabcount
yuuji@23 155 (progn
yuuji@23 156 (save-excursion
yuuji@23 157 (while (> tabcount 0)
yuuji@23 158 (insert "\\>\t")
yuuji@23 159 (setq tabcount (1- tabcount))))
yuuji@23 160 (forward-char 2))
yuuji@23 161 (insert "\\=")))
yuuji@23 162 )
yuuji@23 163
yuuji@23 164 ;;;
yuuji@23 165 ;; Functions for itemize/enumerate/list environments
yuuji@23 166 ;;;
yuuji@23 167
yuuji@23 168 (defun YaTeX-indent-for-item ()
yuuji@23 169 (let (col (p (point)) begenv)
yuuji@23 170 (save-excursion
yuuji@23 171 (YaTeX-beginning-of-environment t)
yuuji@23 172 (setq begenv (point-end-of-line))
yuuji@23 173 (goto-char p)
yuuji@23 174 (if (YaTeX-search-active-backward "\\item" YaTeX-comment-prefix begenv t)
yuuji@23 175 (setq col (current-column))))
yuuji@23 176 (if col (indent-to col) (YaTeX-indent-line)))
yuuji@23 177 )
yuuji@23 178
yuuji@23 179 (defvar YaTeX-item-for-insert "\\item ")
yuuji@23 180 (defun YaTeX-intelligent-newline-itemize ()
yuuji@23 181 "Insert '\\item '."
yuuji@23 182 (YaTeX-indent-for-item)
yuuji@23 183 (insert YaTeX-item-for-insert)
yuuji@23 184 )
yuuji@23 185 (fset 'YaTeX-intelligent-newline-enumerate 'YaTeX-intelligent-newline-itemize)
yuuji@23 186 (fset 'YaTeX-intelligent-newline-list 'YaTeX-intelligent-newline-itemize)
yuuji@23 187
yuuji@23 188 (defun YaTeX-intelligent-newline-description ()
yuuji@23 189 (YaTeX-indent-for-item)
yuuji@23 190 (insert "\\item[] ")
yuuji@23 191 (forward-char -2)
yuuji@23 192 )
yuuji@23 193
yuuji@23 194
yuuji@23 195 ;;;
yuuji@23 196 ;; Intelligent newline
yuuji@23 197 ;;;
yuuji@23 198 ;;;###autoload
yuuji@23 199 (defun YaTeX-intelligent-newline (arg)
yuuji@23 200 "Insert newline and environment-specific entry.
yuuji@23 201 `\\item' for some itemizing environment,
yuuji@23 202 `\\> \\> \\' for tabbing environemnt,
yuuji@23 203 `& & \\ \hline' for tabular environment."
yuuji@23 204 (interactive "P")
yuuji@23 205 (let*((env (YaTeX-inner-environment))
yuuji@23 206 func)
yuuji@23 207 (if arg (setq env (YaTeX-read-environment "For what environment? ")))
yuuji@23 208 (setq func (intern-soft (concat "YaTeX-intelligent-newline-" env)))
yuuji@23 209 (end-of-line)
yuuji@23 210 (newline)
yuuji@23 211 (if (and env func (fboundp func))
yuuji@23 212 (funcall func)))
yuuji@23 213 )