comparison yatexenv.el @ 366:77a2fd4fd634

merged
author HIROSE Yuuji <yuuji@gentei.org>
date Fri, 26 Dec 2014 01:06:32 +0900
parents d69fd7b1ac4d
children 7a9d30752353
comparison
equal deleted inserted replaced
300:30f1a2659a39 366:77a2fd4fd634
1 ;;; yatexenv.el --- YaTeX environment-specific functions 1 ;;; yatexenv.el --- YaTeX environment-specific functions
2 ;;; (c) 1994-2013 by HIROSE Yuuji.[yuuji@yatex.org] 2 ;;; (c) 1994-2013 by HIROSE Yuuji.[yuuji@yatex.org]
3 ;;; Last modified Mon Apr 1 22:43:10 2013 on firestorm 3 ;;; Last modified Mon Dec 22 12:49:03 2014 on firestorm
4 ;;; $Id$ 4 ;;; $Id$
5 5
6 ;;; Code: 6 ;;; Code:
7 ;;; 7 ;;;
8 ;; Functions for tabular environment 8 ;; Functions for tabular environment
10 10
11 ;; Showing the matching column of tabular environment. 11 ;; Showing the matching column of tabular environment.
12 (defun YaTeX-array-what-column-internal () 12 (defun YaTeX-array-what-column-internal ()
13 "Return the cons of matching column and its title of array environment. 13 "Return the cons of matching column and its title of array environment.
14 When calling from a program, make sure to be in array/tabular environment." 14 When calling from a program, make sure to be in array/tabular environment."
15 (let ((p (point)) beg eot bor (nlptn "\\\\\\\\") (andptn "[^\\]&") 15 (let ((p (point)) bot beg eot bor eoll (nlptn "\\\\\\\\") (andptn "[^\\]&")
16 (n 0) j 16 (n 0) j
17 (firsterr "This line might be the first row.")) 17 (firsterr "This line might be the first row."))
18 (save-excursion 18 (save-excursion
19 (YaTeX-beginning-of-environment) 19 (YaTeX-beginning-of-environment)
20 (setq eoll (save-excursion ;end of logical line
21 (YaTeX-goto-corresponding-environment) (point)))
20 (search-forward "{" p) (up-list 1) 22 (search-forward "{" p) (up-list 1)
21 (search-forward "{" p) (up-list 1) 23 (search-forward "{" p) (up-list 1)
22 ;;(re-search-forward andptn p) 24 ;;(re-search-forward andptn p)
23 (while (progn (search-forward "&" p) 25 (setq bot (point)) ;beginning of tabular
26 (while (progn (search-forward "&" eoll)
24 (equal (char-after (1- (match-beginning 0))) ?\\ ))) 27 (equal (char-after (1- (match-beginning 0))) ?\\ )))
25 (setq beg (1- (point))) ;beg is the point of the first & 28 (setq beg (1- (point))) ;beg is the point of the first &
26 (or (re-search-forward nlptn p t) 29 (or (re-search-forward nlptn eoll t)
27 (error firsterr)) 30 (error firsterr))
28 (setq eot (point)) ;eot is the point of the first \\ 31 (setq eot (point)) ;eot is the point of the first \\
29 (goto-char p) 32 (goto-char p)
30 (or (re-search-backward nlptn beg t) 33 (setq bor (if (re-search-backward nlptn bot 1)
31 (error firsterr)) 34 (point) ;bor is the beginning of this row.
32 (setq bor (point)) ;bor is the beginning of this row. 35 bot))
33 (while (< (1- (point)) p) 36 (while (< (1- (point)) p)
34 (if (equal (following-char) ?&) 37 (if (equal (following-char) ?&)
35 (forward-char 1) 38 (forward-char 1)
36 (re-search-forward andptn nil 1)) 39 (re-search-forward andptn nil 1))
37 (setq n (1+ n))) ;Check current column number 40 (setq n (1+ n))) ;Check current column number
52 (or (re-search-forward andptn p nil) 55 (or (re-search-forward andptn p nil)
53 (error "This column exceeds the limit.")) 56 (error "This column exceeds the limit."))
54 (setq j (1- j))) 57 (setq j (1- j)))
55 (skip-chars-forward "\\s ") 58 (skip-chars-forward "\\s ")
56 (list n 59 (list n
57 (buffer-substring 60 (YaTeX-buffer-substring
58 (point) 61 (progn (skip-chars-forward "\n \t") (point))
59 (progn 62 (progn
60 (re-search-forward (concat andptn "\\|" nlptn) eot) 63 (re-search-forward (concat andptn "\\|" nlptn) eot)
61 (goto-char (match-beginning 0)) 64 (goto-char (match-beginning 0))
62 (if (looking-at andptn) 65 (if (looking-at andptn)
63 (forward-char 1)) 66 (forward-char 1))
168 "Parse current tabular* format and insert that many `&'s." 171 "Parse current tabular* format and insert that many `&'s."
169 (YaTeX-intelligent-newline-tabular 'tabular*)) 172 (YaTeX-intelligent-newline-tabular 'tabular*))
170 173
171 (fset 'YaTeX-intelligent-newline-array 'YaTeX-intelligent-newline-tabular) 174 (fset 'YaTeX-intelligent-newline-array 'YaTeX-intelligent-newline-tabular)
172 (fset 'YaTeX-intelligent-newline-supertabular 'YaTeX-intelligent-newline-tabular) 175 (fset 'YaTeX-intelligent-newline-supertabular 'YaTeX-intelligent-newline-tabular)
176 (fset 'YaTeX-intelligent-newline-longtable 'YaTeX-intelligent-newline-tabular)
173 177
174 (defun YaTeX-intelligent-newline-align () 178 (defun YaTeX-intelligent-newline-align ()
175 "Intelligent newline function for align. 179 "Intelligent newline function for align.
176 Count the number of & in the first align line and insert that many &s." 180 Count the number of & in the first align line and insert that many &s."
177 (let*((p (point)) (amps 0)) 181 (let*((p (point)) (amps 0))
195 (while (>= (setq amps (1- amps)) 0) 199 (while (>= (setq amps (1- amps)) 0)
196 (insert "& "))) 200 (insert "& ")))
197 (YaTeX-indent-line))) 201 (YaTeX-indent-line)))
198 202
199 (mapcar 203 (mapcar
200 '(lambda (s) 204 (function
205 (lambda (s)
201 (fset (intern (concat "YaTeX-intelligent-newline-" 206 (fset (intern (concat "YaTeX-intelligent-newline-"
202 (symbol-name s))) 207 (symbol-name s)))
203 'YaTeX-intelligent-newline-align)) 208 'YaTeX-intelligent-newline-align)))
204 '(align* flalign flalign* matrix pmatrix bmatrix Bmatrix vmatrix Vmatrix 209 '(align* flalign flalign* matrix pmatrix bmatrix Bmatrix vmatrix Vmatrix
205 cases eqnarray eqnarray* alignat alignat*)) 210 cases eqnarray eqnarray* alignat alignat*))
206 211
207 ;;; 212 ;;;
208 ;; Functions for tabbing environment 213 ;; Functions for tabbing environment

yatex.org