comparison yatexenv.el @ 80:9b4354af748c

Too many changes from 1.72. See yatex.new. (Japanese)
author yuuji
date Sun, 24 Dec 2006 06:16:52 +0000
parents 0734be649cb8
children 699f3c6c8b2c
comparison
equal deleted inserted replaced
79:0734be649cb8 80:9b4354af748c
1 ;;; -*- Emacs-Lisp -*- 1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX environment-specific functions. 2 ;;; YaTeX environment-specific functions.
3 ;;; yatexenv.el 3 ;;; yatexenv.el
4 ;;; (c) 1994-2003 by HIROSE Yuuji.[yuuji@yatex.org] 4 ;;; (c) 1994-2006 by HIROSE Yuuji.[yuuji@yatex.org]
5 ;;; Last modified Fri Jun 27 12:09:30 2003 on firestorm 5 ;;; Last modified Sat Jun 24 08:14:11 2006 on firestorm
6 ;;; $Id$ 6 ;;; $Id$
7 7
8 ;;; 8 ;;;
9 ;; Functions for tabular environment 9 ;; Functions for tabular environment
10 ;;; 10 ;;;
11 11
12 ;; Showing the matching column of tabular environment. 12 ;; Showing the matching column of tabular environment.
13 (defun YaTeX-array-what-column () 13 (defun YaTeX-array-what-column-internal ()
14 "Show matching columne title of array environment. 14 "Return the cons of matching column and its title of array environment.
15 When calling from a program, make sure to be in array/tabular environment." 15 When calling from a program, make sure to be in array/tabular environment."
16 (let ((p (point)) beg eot bor (nlptn "\\\\\\\\") (andptn "[^\\]&") 16 (let ((p (point)) beg eot bor (nlptn "\\\\\\\\") (andptn "[^\\]&")
17 (n 0) j 17 (n 0) j
18 (firsterr "This line might be the first row.")) 18 (firsterr "This line might be the first row."))
19 (save-excursion 19 (save-excursion
52 (while (> j 1) 52 (while (> j 1)
53 (or (re-search-forward andptn p nil) 53 (or (re-search-forward andptn p nil)
54 (error "This column exceeds the limit.")) 54 (error "This column exceeds the limit."))
55 (setq j (1- j))) 55 (setq j (1- j)))
56 (skip-chars-forward "\\s ") 56 (skip-chars-forward "\\s ")
57 (message 57 (list n
58 "This is the column(#%d) of: %s" n 58 (buffer-substring
59 (buffer-substring 59 (point)
60 (point) 60 (progn
61 (progn 61 (re-search-forward (concat andptn "\\|" nlptn) eot)
62 (re-search-forward (concat andptn "\\|" nlptn) eot) 62 (goto-char (match-beginning 0))
63 (goto-char (match-beginning 0)) 63 (if (looking-at andptn)
64 (if (looking-at andptn) 64 (forward-char 1))
65 (forward-char 1)) 65 (skip-chars-backward "\\s ")
66 (skip-chars-backward "\\s ") 66 (point)))))))
67 (point)))))) 67
68 ) 68 (defun YaTeX-array-what-column ()
69 "Show matching column title of array environment.
70 When calling from a program, make sure to be in array/tabular environment."
71 (apply 'message
72 "This is the column(#%d) of: %s"
73 (YaTeX-array-what-column-internal)))
69 74
70 ;;;###autoload 75 ;;;###autoload
71 (defun YaTeX-what-column () 76 (defun YaTeX-what-column ()
72 "Show which kind of column the current position is belonging to." 77 "Show which kind of column the current position is belonging to."
73 (interactive) 78 (interactive)
74 (cond 79 (cond
75 ((YaTeX-quick-in-environment-p '("tabular" "tabular*" "array" "array*")) 80 ((YaTeX-quick-in-environment-p '("tabular" "tabular*" "array" "array*"))
76 (YaTeX-array-what-column)) 81 (YaTeX-array-what-column))
77 (t (message "Not in array/tabular environment."))) 82 (t (message "Not in array/tabular environment."))))
78 ) 83
79 84 (defun YaTeX-tabular-parse-format-count-cols (beg end)
80 (defun YaTeX-tabular-parse-format (&optional tabular*) 85 (goto-char beg)
81 "Parse `tabular' format. 86 (let (elt (cols 0))
82 Return the list of (No.ofCols PointEndofFormat)" 87 (while (< (point) end)
83 (let ((p (point)) elt boform eoform (cols 0))
84 (save-excursion
85 (if (null (YaTeX-beginning-of-environment t))
86 (error "Beginning of tabular not found."))
87 (skip-chars-forward "^{")
88 (forward-list 1)
89 (if tabular*
90 (progn (skip-chars-forward "^{")
91 (forward-list 1)))
92 (skip-chars-forward "^{" p)
93 (if (/= (following-char) ?\{) (error "Tabular format not found."))
94 (setq boform (1+ (point))
95 eoform (progn (forward-list 1) (1- (point))))
96 (if (> eoform p) (error "Non-terminated tabular format."))
97 (goto-char boform)
98 (while (< (point) eoform)
99 (setq elt (following-char)) 88 (setq elt (following-char))
100 (cond 89 (cond
101 ((string-match (char-to-string elt) "clr") ;normal indicators. 90 ((string-match (char-to-string elt) "clr") ;normal indicators.
102 (setq cols (1+ cols)) 91 (setq cols (1+ cols))
103 (forward-char 1)) 92 (forward-char 1))
104 ((equal elt ?|) ;vertical 93 ((equal elt ?|) ;vertical
105 (forward-char 1)) 94 (forward-char 1))
106 ((string-match (char-to-string elt) "p@") ;p or @ expression 95 ((string-match (char-to-string elt) "p@") ;p or @ expression
107 (setq cols (+ (if (eq elt ?p) 1 0) cols)) 96 (setq cols (+ (if (eq elt ?p) 1 0) cols))
108 (skip-chars-forward "^{" p) 97 ;;(skip-chars-forward "^{" p)
98 (skip-chars-forward "^{" end)
109 (forward-list 1)) 99 (forward-list 1))
100 ((equal elt ?*) ;*{N}{EXP} -> Repeat EXP N times
101 (skip-chars-forward "^{" end)
102 (setq cols (* (string-to-int
103 (buffer-substring
104 (1+ (point))
105 (progn (forward-list 1) (1- (point)))))
106 (YaTeX-tabular-parse-format-count-cols
107 (progn (skip-chars-forward "^{" end) (1+ (point)))
108 (progn (forward-list 1) (1- (point)))))))
110 (t (forward-char 1)) ;unknown char 109 (t (forward-char 1)) ;unknown char
111 )) 110 ))
112 (list cols (1+ eoform)))) 111 cols))
113 ) 112
113 (defun YaTeX-tabular-parse-format (&optional type)
114 "Parse `tabular' format.
115 Return the list of (No.ofCols PointEndofFormat)"
116 (let ((p (point)) boform eoform (cols 0))
117 (save-excursion
118 (if (null (YaTeX-beginning-of-environment t))
119 (error "Beginning of tabular not found."))
120 (skip-chars-forward "^{")
121 (forward-list 1)
122 (cond
123 ((eq type 'tabular*)
124 (skip-chars-forward "^{")
125 (forward-list 1)))
126 (skip-chars-forward "^{" p)
127 (if (/= (following-char) ?\{) (error "Tabular format not found."))
128 (setq boform (1+ (point))
129 eoform (progn (forward-list 1) (1- (point))))
130 (if (> eoform p) (error "Non-terminated tabular format."))
131 (goto-char boform)
132 (setq cols
133 (cond
134 ((eq type 'alignat)
135 (max
136 1
137 (1-
138 (* 2
139 (string-to-int
140 (buffer-substring
141 (point)
142 (progn (up-list -1) (forward-list 1) (1- (point)))))))))
143 (t
144 (YaTeX-tabular-parse-format-count-cols (point) eoform))))
145 (list cols (1+ eoform)))))
146
114 ;; Insert & 147 ;; Insert &
115 (defun YaTeX-intelligent-newline-tabular (&optional tabular*) 148 (defun YaTeX-intelligent-newline-tabular (&optional type)
116 "Parse current tabular format and insert that many `&'s." 149 "Parse current tabular format and insert that many `&'s."
117 (let*((p (point)) (format (YaTeX-tabular-parse-format tabular*)) 150 (let*((p (point)) (format (YaTeX-tabular-parse-format type))
118 (cols (car format)) (beg (car (cdr format))) 151 (cols (car format)) (beg (car (cdr format)))
119 space hline) 152 space hline)
120 (cond 153 (cond
121 ((search-backward "&" beg t) 154 ((search-backward "&" beg t)
122 (goto-char p) 155 (goto-char p)
130 (insert "&" space) 163 (insert "&" space)
131 (setq cols (1- cols))) 164 (setq cols (1- cols)))
132 (insert "\\\\") 165 (insert "\\\\")
133 (if hline (insert " \\hline")) 166 (if hline (insert " \\hline"))
134 (goto-char p) 167 (goto-char p)
135 (YaTeX-indent-line) 168 (YaTeX-indent-line)))
136 )
137 )
138 169
139 (defun YaTeX-intelligent-newline-tabular* () 170 (defun YaTeX-intelligent-newline-tabular* ()
140 "Parse current tabular* format and insert that many `&'s." 171 "Parse current tabular* format and insert that many `&'s."
141 (YaTeX-intelligent-newline-tabular t) 172 (YaTeX-intelligent-newline-tabular 'tabular*))
142 )
143 173
144 (fset 'YaTeX-intelligent-newline-array 'YaTeX-intelligent-newline-tabular) 174 (fset 'YaTeX-intelligent-newline-array 'YaTeX-intelligent-newline-tabular)
175 (fset 'YaTeX-intelligent-newline-supertabular 'YaTeX-intelligent-newline-tabular)
176
177 (defun YaTeX-intelligent-newline-alignat ()
178 (YaTeX-intelligent-newline-tabular 'alignat))
179 (fset 'YaTeX-intelligent-newline-alignat* 'YaTeX-intelligent-newline-alignat)
180
181 (defun YaTeX-intelligent-newline-align ()
182 "Intelligent newline function for align.
183 Count the number of & in the first align line and insert that many &s."
184 (let*((p (point)) (cols 0))
185 (save-excursion
186 (YaTeX-beginning-of-environment)
187 (catch 'done
188 (while (YaTeX-re-search-active-forward
189 "\\(&\\)\\|\\(\\\\\\\\\\)" YaTeX-comment-prefix p t)
190 (if (match-beginning 1) (setq cols (1+ cols)) (throw 'done t)))))
191 (save-excursion
192 (if (= cols 0)
193 (insert "&")
194 (while (>= (setq cols (1- cols)) 0)
195 (insert "& "))))
196 (YaTeX-indent-line)))
197
198 (mapcar
199 '(lambda (s)
200 (fset (intern (concat "YaTeX-intelligent-newline-"
201 (symbol-name s)))
202 'YaTeX-intelligent-newline-align))
203 '(align* flalign flalign* matrix pmatrix bmatrix Bmatrix vmatrix Vmatrix
204 cases))
145 205
146 ;;; 206 ;;;
147 ;; Functions for tabbing environment 207 ;; Functions for tabbing environment
148 ;;; 208 ;;;
149 (defun YaTeX-intelligent-newline-tabbing () 209 (defun YaTeX-intelligent-newline-tabbing ()
212 (setq func (intern-soft (concat "YaTeX-intelligent-newline-" env))) 272 (setq func (intern-soft (concat "YaTeX-intelligent-newline-" env)))
213 (end-of-line) 273 (end-of-line)
214 (newline) 274 (newline)
215 (undo-boundary) 275 (undo-boundary)
216 (if (and env func (fboundp func)) 276 (if (and env func (fboundp func))
217 (funcall func))) 277 (funcall func))))
218 )
219 278
220 ;;; 279 ;;;
221 ;; Environment-specific line indenting functions 280 ;; Environment-specific line indenting functions
222 ;;; 281 ;;;
223 ;;;###autoload 282 ;;;###autoload

yatex.org