annotate yatexenv.el @ 436:e78a87bc2c9e dev

current file treated as absolute path(YaTeX-preview-jump-line)
author HIROSE Yuuji <yuuji@gentei.org>
date Fri, 08 Jan 2016 08:18:54 +0859
parents 8ee8514e06ed
children 7a9d30752353
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
287
5921f28ef77c Change the first lines.
HIROSE Yuuji <yuuji@gentei.org>
parents: 257
diff changeset
1 ;;; yatexenv.el --- YaTeX environment-specific functions
294
8d3156073892 for 1.77
HIROSE Yuuji <yuuji@gentei.org>
parents: 287
diff changeset
2 ;;; (c) 1994-2013 by HIROSE Yuuji.[yuuji@yatex.org]
359
dbef6cf84f98 Two or more consecutive [Tab] in column of table jump to the next column.
HIROSE Yuuji <yuuji@gentei.org>
parents: 353
diff changeset
3 ;;; Last modified Mon Dec 22 12:49:03 2014 on firestorm
368
8ee8514e06ed Start for 1.79
HIROSE Yuuji <yuuji@gentei.org>
parents: 364
diff changeset
4 ;;; $Id$
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
5
287
5921f28ef77c Change the first lines.
HIROSE Yuuji <yuuji@gentei.org>
parents: 257
diff changeset
6 ;;; Code:
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
7 ;;;
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
8 ;; Functions for tabular environment
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
9 ;;;
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
10
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
11 ;; Showing the matching column of tabular environment.
80
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
12 (defun YaTeX-array-what-column-internal ()
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
13 "Return the cons of matching column and its title of array environment.
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
14 When calling from a program, make sure to be in array/tabular environment."
359
dbef6cf84f98 Two or more consecutive [Tab] in column of table jump to the next column.
HIROSE Yuuji <yuuji@gentei.org>
parents: 353
diff changeset
15 (let ((p (point)) bot beg eot bor eoll (nlptn "\\\\\\\\") (andptn "[^\\]&")
49
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
16 (n 0) j
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
17 (firsterr "This line might be the first row."))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
18 (save-excursion
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
19 (YaTeX-beginning-of-environment)
359
dbef6cf84f98 Two or more consecutive [Tab] in column of table jump to the next column.
HIROSE Yuuji <yuuji@gentei.org>
parents: 353
diff changeset
20 (setq eoll (save-excursion ;end of logical line
dbef6cf84f98 Two or more consecutive [Tab] in column of table jump to the next column.
HIROSE Yuuji <yuuji@gentei.org>
parents: 353
diff changeset
21 (YaTeX-goto-corresponding-environment) (point)))
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
22 (search-forward "{" p) (up-list 1)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
23 (search-forward "{" p) (up-list 1)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
24 ;;(re-search-forward andptn p)
359
dbef6cf84f98 Two or more consecutive [Tab] in column of table jump to the next column.
HIROSE Yuuji <yuuji@gentei.org>
parents: 353
diff changeset
25 (setq bot (point)) ;beginning of tabular
dbef6cf84f98 Two or more consecutive [Tab] in column of table jump to the next column.
HIROSE Yuuji <yuuji@gentei.org>
parents: 353
diff changeset
26 (while (progn (search-forward "&" eoll)
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
27 (equal (char-after (1- (match-beginning 0))) ?\\ )))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
28 (setq beg (1- (point))) ;beg is the point of the first &
359
dbef6cf84f98 Two or more consecutive [Tab] in column of table jump to the next column.
HIROSE Yuuji <yuuji@gentei.org>
parents: 353
diff changeset
29 (or (re-search-forward nlptn eoll t)
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
30 (error firsterr))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
31 (setq eot (point)) ;eot is the point of the first \\
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
32 (goto-char p)
359
dbef6cf84f98 Two or more consecutive [Tab] in column of table jump to the next column.
HIROSE Yuuji <yuuji@gentei.org>
parents: 353
diff changeset
33 (setq bor (if (re-search-backward nlptn bot 1)
dbef6cf84f98 Two or more consecutive [Tab] in column of table jump to the next column.
HIROSE Yuuji <yuuji@gentei.org>
parents: 353
diff changeset
34 (point) ;bor is the beginning of this row.
dbef6cf84f98 Two or more consecutive [Tab] in column of table jump to the next column.
HIROSE Yuuji <yuuji@gentei.org>
parents: 353
diff changeset
35 bot))
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
36 (while (< (1- (point)) p)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
37 (if (equal (following-char) ?&)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
38 (forward-char 1)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
39 (re-search-forward andptn nil 1))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
40 (setq n (1+ n))) ;Check current column number
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
41 (goto-char p)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
42 (cond ;Start searching \multicolumn{N}
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
43 ((> n 1)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
44 (re-search-backward andptn) ;Sure to find!
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
45 (while (re-search-backward "\\\\multicolumn{\\([0-9]+\\)}" bor t)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
46 (setq n (+ n (string-to-int
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
47 (buffer-substring (match-beginning 1)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
48 (match-end 1)))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
49 -1)))))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
50 (message "%s" n)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
51 (goto-char (1- beg))
59
48ac97a6b6ce Call drawing tools
yuuji
parents: 58
diff changeset
52 (beginning-of-line)
49
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
53 (setq j n)
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
54 (while (> j 1)
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
55 (or (re-search-forward andptn p nil)
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
56 (error "This column exceeds the limit."))
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
57 (setq j (1- j)))
eb0512bfcb7f Abolish user-article table.
yuuji
parents: 46
diff changeset
58 (skip-chars-forward "\\s ")
80
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
59 (list n
359
dbef6cf84f98 Two or more consecutive [Tab] in column of table jump to the next column.
HIROSE Yuuji <yuuji@gentei.org>
parents: 353
diff changeset
60 (YaTeX-buffer-substring
dbef6cf84f98 Two or more consecutive [Tab] in column of table jump to the next column.
HIROSE Yuuji <yuuji@gentei.org>
parents: 353
diff changeset
61 (progn (skip-chars-forward "\n \t") (point))
80
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
62 (progn
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
63 (re-search-forward (concat andptn "\\|" nlptn) eot)
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
64 (goto-char (match-beginning 0))
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
65 (if (looking-at andptn)
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
66 (forward-char 1))
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
67 (skip-chars-backward "\\s ")
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
68 (point)))))))
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
69
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
70 (defun YaTeX-array-what-column ()
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
71 "Show matching column title of array environment.
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
72 When calling from a program, make sure to be in array/tabular environment."
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
73 (apply 'message
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
74 "This is the column(#%d) of: %s"
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
75 (YaTeX-array-what-column-internal)))
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
76
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
77 ;;;###autoload
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
78 (defun YaTeX-what-column ()
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
79 "Show which kind of column the current position is belonging to."
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
80 (interactive)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
81 (cond
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
82 ((YaTeX-quick-in-environment-p '("tabular" "tabular*" "array" "array*"))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
83 (YaTeX-array-what-column))
80
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
84 (t (message "Not in array/tabular environment."))))
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
85
80
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
86 (defun YaTeX-tabular-parse-format-count-cols (beg end)
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
87 (goto-char beg)
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
88 (let (elt (cols 0))
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
89 (while (< (point) end)
31
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
90 (setq elt (following-char))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
91 (cond
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
92 ((string-match (char-to-string elt) "clr") ;normal indicators.
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
93 (setq cols (1+ cols))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
94 (forward-char 1))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
95 ((equal elt ?|) ;vertical
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
96 (forward-char 1))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
97 ((string-match (char-to-string elt) "p@") ;p or @ expression
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
98 (setq cols (+ (if (eq elt ?p) 1 0) cols))
80
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
99 ;;(skip-chars-forward "^{" p)
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
100 (skip-chars-forward "^{" end)
56
a9653fbd1c1c Bug fix version
yuuji
parents: 53
diff changeset
101 (forward-list 1))
80
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
102 ((equal elt ?*) ;*{N}{EXP} -> Repeat EXP N times
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
103 (skip-chars-forward "^{" end)
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
104 (setq cols (* (string-to-int
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
105 (buffer-substring
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
106 (1+ (point))
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
107 (progn (forward-list 1) (1- (point)))))
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
108 (YaTeX-tabular-parse-format-count-cols
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
109 (progn (skip-chars-forward "^{" end) (1+ (point)))
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
110 (progn (forward-list 1) (1- (point)))))))
56
a9653fbd1c1c Bug fix version
yuuji
parents: 53
diff changeset
111 (t (forward-char 1)) ;unknown char
a9653fbd1c1c Bug fix version
yuuji
parents: 53
diff changeset
112 ))
80
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
113 cols))
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
114
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
115 (defun YaTeX-tabular-parse-format (&optional type)
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
116 "Parse `tabular' format.
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
117 Return the list of (No.ofCols PointEndofFormat)"
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
118 (let ((p (point)) boform eoform (cols 0))
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
119 (save-excursion
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
120 (if (null (YaTeX-beginning-of-environment t))
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
121 (error "Beginning of tabular not found."))
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
122 (skip-chars-forward "^{")
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
123 (forward-list 1)
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
124 (cond
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
125 ((eq type 'tabular*)
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
126 (skip-chars-forward "^{")
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
127 (forward-list 1)))
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
128 (skip-chars-forward "^{" p)
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
129 (if (/= (following-char) ?\{) (error "Tabular format not found."))
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
130 (setq boform (1+ (point))
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
131 eoform (progn (forward-list 1) (1- (point))))
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
132 (if (> eoform p) (error "Non-terminated tabular format."))
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
133 (goto-char boform)
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
134 (setq cols
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
135 (cond
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
136 ((eq type 'alignat)
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
137 (max
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
138 1
250
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
139 (* 2 (string-to-int
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
140 (buffer-substring
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
141 (point)
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
142 (progn (up-list -1) (forward-list 1) (1- (point))))))))
80
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
143 (t
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
144 (YaTeX-tabular-parse-format-count-cols (point) eoform))))
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
145 (list cols (1+ eoform)))))
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
146
31
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
147 ;; Insert &
80
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
148 (defun YaTeX-intelligent-newline-tabular (&optional type)
31
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
149 "Parse current tabular format and insert that many `&'s."
80
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
150 (let*((p (point)) (format (YaTeX-tabular-parse-format type))
31
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
151 (cols (car format)) (beg (car (cdr format)))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
152 space hline)
58
3a7c0c2bf16d Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents: 56
diff changeset
153 (cond
3a7c0c2bf16d Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents: 56
diff changeset
154 ((search-backward "&" beg t)
3a7c0c2bf16d Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents: 56
diff changeset
155 (goto-char p)
3a7c0c2bf16d Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents: 56
diff changeset
156 (setq hline (search-backward "\\hline" beg t))
3a7c0c2bf16d Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents: 56
diff changeset
157 (setq space (if (search-backward "\t&" beg t) "\t" " "))
3a7c0c2bf16d Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents: 56
diff changeset
158 (goto-char p))
3a7c0c2bf16d Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents: 56
diff changeset
159 (t ;;(insert "\\hline\n")
3a7c0c2bf16d Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents: 56
diff changeset
160 (setq space " ")))
31
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
161 (goto-char p)
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
162 (while (> (1- cols) 0)
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
163 (insert "&" space)
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
164 (setq cols (1- cols)))
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
165 (insert "\\\\")
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
166 (if hline (insert " \\hline"))
58
3a7c0c2bf16d Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents: 56
diff changeset
167 (goto-char p)
80
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
168 (YaTeX-indent-line)))
31
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
169
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
170 (defun YaTeX-intelligent-newline-tabular* ()
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
171 "Parse current tabular* format and insert that many `&'s."
80
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
172 (YaTeX-intelligent-newline-tabular 'tabular*))
31
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
173
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
174 (fset 'YaTeX-intelligent-newline-array 'YaTeX-intelligent-newline-tabular)
80
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
175 (fset 'YaTeX-intelligent-newline-supertabular 'YaTeX-intelligent-newline-tabular)
306
9cfc505ba6aa Utilize M-Ret in `longtable' environment
HIROSE Yuuji <yuuji@gentei.org>
parents: 294
diff changeset
176 (fset 'YaTeX-intelligent-newline-longtable 'YaTeX-intelligent-newline-tabular)
80
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
177
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
178 (defun YaTeX-intelligent-newline-align ()
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
179 "Intelligent newline function for align.
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
180 Count the number of & in the first align line and insert that many &s."
250
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
181 (let*((p (point)) (amps 0))
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
182 (if (string-match "alignat" env)
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
183 (setq amps (1- (car (YaTeX-tabular-parse-format 'alignat))))
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
184 (save-excursion
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
185 (YaTeX-beginning-of-environment)
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
186 (catch 'done
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
187 (while (YaTeX-re-search-active-forward
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
188 "\\(&\\)\\|\\(\\\\\\\\\\)" YaTeX-comment-prefix p t)
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
189 (if (match-beginning 1) (setq amps (1+ amps)) (throw 'done t))))))
80
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
190 (save-excursion
250
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
191 (forward-line -1)
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
192 (skip-chars-forward " \t")
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
193 (or (prog1 (looking-at "\\\\begin{") (end-of-line))
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
194 (save-excursion
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
195 (skip-chars-backward " \t")
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
196 (and (= (preceding-char) ?\\) (= (char-after (- (point) 2)) ?\\)))
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
197 (insert "\\\\")))
80
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
198 (save-excursion
250
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
199 (while (>= (setq amps (1- amps)) 0)
236
328a212a2160 Intelligent newline for align insert no `&' at the first line.
yuuji@gentei.org
parents: 235
diff changeset
200 (insert "& ")))
80
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
201 (YaTeX-indent-line)))
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
202
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
203 (mapcar
353
2a72779d9c50 Rewrite lambda notations to suppress annoying warnings from emacs24
HIROSE Yuuji <yuuji@gentei.org>
parents: 306
diff changeset
204 (function
2a72779d9c50 Rewrite lambda notations to suppress annoying warnings from emacs24
HIROSE Yuuji <yuuji@gentei.org>
parents: 306
diff changeset
205 (lambda (s)
80
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
206 (fset (intern (concat "YaTeX-intelligent-newline-"
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
207 (symbol-name s)))
353
2a72779d9c50 Rewrite lambda notations to suppress annoying warnings from emacs24
HIROSE Yuuji <yuuji@gentei.org>
parents: 306
diff changeset
208 'YaTeX-intelligent-newline-align)))
80
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
209 '(align* flalign flalign* matrix pmatrix bmatrix Bmatrix vmatrix Vmatrix
250
4f73b796ec20 Fix intelligent-newline for alignat(*).
yuuji@gentei.org
parents: 240
diff changeset
210 cases eqnarray eqnarray* alignat alignat*))
31
459e1eca4e10 Stay initial version.
yuuji
parents: 23
diff changeset
211
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
212 ;;;
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
213 ;; Functions for tabbing environment
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
214 ;;;
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
215 (defun YaTeX-intelligent-newline-tabbing ()
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
216 "Check the number of \\= in the first line and insert that many \\>."
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
217 (let ((p (point)) begenv tabcount)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
218 (save-excursion
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
219 (YaTeX-beginning-of-environment)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
220 (setq begenv (point-end-of-line))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
221 (if (YaTeX-search-active-forward "\\\\" YaTeX-comment-prefix p t)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
222 (progn
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
223 (setq tabcount 0)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
224 (while (> (point) begenv)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
225 (if (search-backward "\\=" begenv 1)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
226 (setq tabcount (1+ tabcount)))))))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
227 (YaTeX-indent-line)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
228 (if tabcount
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
229 (progn
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
230 (save-excursion
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
231 (while (> tabcount 0)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
232 (insert "\\>\t")
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
233 (setq tabcount (1- tabcount))))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
234 (forward-char 2))
58
3a7c0c2bf16d Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents: 56
diff changeset
235 (insert "\\= \\\\")
233
699f3c6c8b2c YaTeX-intelligent-newline-equation
yuuji@gentei.org
parents: 80
diff changeset
236 (forward-char -5))))
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
237
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
238 ;;;
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
239 ;; Functions for itemize/enumerate/list environments
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
240 ;;;
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
241
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
242 (defun YaTeX-intelligent-newline-itemize ()
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
243 "Insert '\\item '."
58
3a7c0c2bf16d Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents: 56
diff changeset
244 (insert "\\item ")
233
699f3c6c8b2c YaTeX-intelligent-newline-equation
yuuji@gentei.org
parents: 80
diff changeset
245 (YaTeX-indent-line))
699f3c6c8b2c YaTeX-intelligent-newline-equation
yuuji@gentei.org
parents: 80
diff changeset
246
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
247 (fset 'YaTeX-intelligent-newline-enumerate 'YaTeX-intelligent-newline-itemize)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
248 (fset 'YaTeX-intelligent-newline-list 'YaTeX-intelligent-newline-itemize)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
249
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
250 (defun YaTeX-intelligent-newline-description ()
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
251 (insert "\\item[] ")
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
252 (forward-char -2)
233
699f3c6c8b2c YaTeX-intelligent-newline-equation
yuuji@gentei.org
parents: 80
diff changeset
253 (YaTeX-indent-line))
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
254
64
36a48185b95a Changes are listed in yatex.new.
yuuji
parents: 61
diff changeset
255 (defun YaTeX-intelligent-newline-thebibliography ()
36a48185b95a Changes are listed in yatex.new.
yuuji
parents: 61
diff changeset
256 "Insert '\\bibitem '."
36a48185b95a Changes are listed in yatex.new.
yuuji
parents: 61
diff changeset
257 (YaTeX-indent-line)
36a48185b95a Changes are listed in yatex.new.
yuuji
parents: 61
diff changeset
258 (YaTeX-make-section nil nil nil "bibitem")
233
699f3c6c8b2c YaTeX-intelligent-newline-equation
yuuji@gentei.org
parents: 80
diff changeset
259 (YaTeX-indent-line))
699f3c6c8b2c YaTeX-intelligent-newline-equation
yuuji@gentei.org
parents: 80
diff changeset
260
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
261 ;;;
234
b75390dd4260 C-j can skip further parameter input for table/figure environment.
yuuji@gentei.org
parents: 233
diff changeset
262 ;; For document environment
b75390dd4260 C-j can skip further parameter input for table/figure environment.
yuuji@gentei.org
parents: 233
diff changeset
263 ;;;
b75390dd4260 C-j can skip further parameter input for table/figure environment.
yuuji@gentei.org
parents: 233
diff changeset
264 (defun YaTeX-intelligent-newline-document ()
239
5de195a540c7 YaTeX-intelligent-newline-document recognizes \par lover.
yuuji@gentei.org
parents: 238
diff changeset
265 "New paragraph by null line or `\\par'."
257
2b85ef062ccf Do not put new paragraph at the beginning of document environment.
HIROSE Yuuji <yuuji@gentei.org>
parents: 251
diff changeset
266 (if (< (count-lines
2b85ef062ccf Do not put new paragraph at the beginning of document environment.
HIROSE Yuuji <yuuji@gentei.org>
parents: 251
diff changeset
267 (or (get 'YaTeX-inner-environment 'point)
2b85ef062ccf Do not put new paragraph at the beginning of document environment.
HIROSE Yuuji <yuuji@gentei.org>
parents: 251
diff changeset
268 (max 1 (- (point) 17))) ;"\begin{document}\n" == 17
2b85ef062ccf Do not put new paragraph at the beginning of document environment.
HIROSE Yuuji <yuuji@gentei.org>
parents: 251
diff changeset
269 (point))
2b85ef062ccf Do not put new paragraph at the beginning of document environment.
HIROSE Yuuji <yuuji@gentei.org>
parents: 251
diff changeset
270 2)
2b85ef062ccf Do not put new paragraph at the beginning of document environment.
HIROSE Yuuji <yuuji@gentei.org>
parents: 251
diff changeset
271 nil
2b85ef062ccf Do not put new paragraph at the beginning of document environment.
HIROSE Yuuji <yuuji@gentei.org>
parents: 251
diff changeset
272 (if (save-excursion (re-search-backward "\\\\par\\>" nil t))
2b85ef062ccf Do not put new paragraph at the beginning of document environment.
HIROSE Yuuji <yuuji@gentei.org>
parents: 251
diff changeset
273 (progn
2b85ef062ccf Do not put new paragraph at the beginning of document environment.
HIROSE Yuuji <yuuji@gentei.org>
parents: 251
diff changeset
274 (YaTeX-indent-line)
2b85ef062ccf Do not put new paragraph at the beginning of document environment.
HIROSE Yuuji <yuuji@gentei.org>
parents: 251
diff changeset
275 (insert "\\par")))
2b85ef062ccf Do not put new paragraph at the beginning of document environment.
HIROSE Yuuji <yuuji@gentei.org>
parents: 251
diff changeset
276 (newline))
239
5de195a540c7 YaTeX-intelligent-newline-document recognizes \par lover.
yuuji@gentei.org
parents: 238
diff changeset
277 (YaTeX-indent-line))
234
b75390dd4260 C-j can skip further parameter input for table/figure environment.
yuuji@gentei.org
parents: 233
diff changeset
278
b75390dd4260 C-j can skip further parameter input for table/figure environment.
yuuji@gentei.org
parents: 233
diff changeset
279 ;;;
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
280 ;; Intelligent newline
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
281 ;;;
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
282 ;;;###autoload
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
283 (defun YaTeX-intelligent-newline (arg)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
284 "Insert newline and environment-specific entry.
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
285 `\\item' for some itemizing environment,
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
286 `\\> \\> \\' for tabbing environemnt,
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
287 `& & \\ \hline' for tabular environment."
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
288 (interactive "P")
61
b9f753846b6b Bug fix release
yuuji
parents: 60
diff changeset
289 (let*(env func)
b9f753846b6b Bug fix release
yuuji
parents: 60
diff changeset
290 (end-of-line)
b9f753846b6b Bug fix release
yuuji
parents: 60
diff changeset
291 (setq env (YaTeX-inner-environment))
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
292 (if arg (setq env (YaTeX-read-environment "For what environment? ")))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
293 (setq func (intern-soft (concat "YaTeX-intelligent-newline-" env)))
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
294 (end-of-line)
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
295 (newline)
58
3a7c0c2bf16d Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents: 56
diff changeset
296 (undo-boundary)
23
b00c74813e56 Change the YaTeX-math-mode's prefix from `,' to `;'.
yuuji
parents:
diff changeset
297 (if (and env func (fboundp func))
80
9b4354af748c Too many changes from 1.72.
yuuji
parents: 79
diff changeset
298 (funcall func))))
53
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
299
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
300 ;;;
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
301 ;; Environment-specific line indenting functions
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
302 ;;;
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
303 ;;;###autoload
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
304 (defun YaTeX-indent-line-equation ()
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
305 "Indent a line in equation family."
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
306 (let ((p (point)) (l-r 0) right-p peol depth (mp YaTeX-environment-indent))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
307 (if (save-excursion
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
308 (beginning-of-line)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
309 (skip-chars-forward " \t")
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
310 (looking-at "\\\\right\\b"))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
311 (progn (YaTeX-reindent
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
312 (save-excursion (YaTeX-goto-corresponding-leftright)
73
f41b01fef5d6 Stable version(hope to be)
yuuji
parents: 70
diff changeset
313 (- (current-column) 0))))
53
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
314 (save-excursion
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
315 (forward-line -1)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
316 (while (and (not (bobp)) (YaTeX-on-comment-p))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
317 (forward-line -1))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
318 ;;(beginning-of-line) ;must be unnecessary
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
319 (skip-chars-forward " \t")
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
320 (if (eolp) (error "Math-environment can't have a null line!!"))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
321 (setq depth (current-column)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
322 peol (point-end-of-line))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
323 (while (re-search-forward
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
324 "\\\\\\(\\(left\\)\\|\\(right\\)\\)\\b" peol t)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
325 (setq l-r (+ l-r (if (match-beginning 2) 1 -1))))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
326 (cond
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
327 ((progn (beginning-of-line)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
328 (re-search-forward "\\\\\\\\\\s *$" (point-end-of-line) t))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
329 ;;If previous line has `\\', this indentation is always normal.
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
330 (setq depth (+ (YaTeX-current-indentation) mp)))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
331 ((> l-r 0)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
332 (beginning-of-line)
68
0eb6997bee16 More adjustment for Emacs20 and XEmacs
yuuji
parents: 64
diff changeset
333 (search-forward "\\left" peol nil l-r)
53
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
334 (goto-char (1+ (match-beginning 0)))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
335 (setq depth (current-column)))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
336 ((< l-r 0)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
337 (goto-char (match-beginning 0)) ;should be \right
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
338 (YaTeX-goto-corresponding-leftright)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
339 (beginning-of-line)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
340 (skip-chars-forward " \t")
68
0eb6997bee16 More adjustment for Emacs20 and XEmacs
yuuji
parents: 64
diff changeset
341 ;(setq depth (+ (current-column) mp)) ;+mp is good?
0eb6997bee16 More adjustment for Emacs20 and XEmacs
yuuji
parents: 64
diff changeset
342 (setq depth (current-column)))
53
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
343 (t ;if \left - \right = 0
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
344 (cond
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
345 ((re-search-forward "\\\\\\\\\\s *$" peol t)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
346 (setq depth (+ (YaTeX-current-indentation) mp)))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
347 ((re-search-forward "\\\\end{" peol t)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
348 nil) ;same indentation as previous line's
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
349 ((re-search-forward "\\\\begin{" peol t)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
350 (setq depth (+ depth mp)))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
351 (t
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
352 (or (bobp) (forward-line -1))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
353 (cond
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
354 ((re-search-forward
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
355 "\\\\\\\\\\s *$\\|\\\\begin{" (point-end-of-line) t)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
356 (setq depth (+ depth mp)))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
357 )))))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
358 (goto-char p))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
359 (YaTeX-reindent depth))))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
360
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
361 ;;;###autoload
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
362 (defun YaTeX-goto-corresponding-leftright ()
77
1b172d26b55e Fix auto-fill movement on Emacs21.
yuuji
parents: 73
diff changeset
363 "Go to corresponding \left or \right."
53
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
364 (let ((YaTeX-struct-begin "\\left%1")
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
365 (YaTeX-struct-end "\\right%1")
77
1b172d26b55e Fix auto-fill movement on Emacs21.
yuuji
parents: 73
diff changeset
366 (YaTeX-struct-name-regexp "[][(){}\\.|]")
1b172d26b55e Fix auto-fill movement on Emacs21.
yuuji
parents: 73
diff changeset
367 (in-leftright-p t))
53
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
368 (YaTeX-goto-corresponding-environment t)))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
369
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
370 ;;;
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
371 ;; Functions for formatting region being enclosed with environment
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
372 ;;;
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
373 ; These functions must take two argument; region-beginning, region-end.
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
374
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
375 (defun YaTeX-enclose-equation (beg end)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
376 (goto-char beg)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
377 (save-restriction
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
378 (let (m0 bsl)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
379 (narrow-to-region beg end)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
380 (while (YaTeX-re-search-active-forward
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
381 "\\(\\$\\)" YaTeX-comment-prefix nil t)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
382 (goto-char (setq m0 (match-beginning 0)))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
383 (setq bsl 0)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
384 (if (and (not (bobp)) (= (char-after (1- (point))) ?\\ ))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
385 (while (progn (forward-char -1) (= (char-after (point)) ?\\ ))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
386 (setq bsl (1+ bsl))))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
387 (goto-char m0)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
388 (if (= 0 (% bsl 2))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
389 (delete-char 1)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
390 (forward-char 1))))))
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
391
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
392 (fset 'YaTeX-enclose-eqnarray 'YaTeX-enclose-equation)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
393 (fset 'YaTeX-enclose-eqnarray* 'YaTeX-enclose-equation)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
394
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
395 (defun YaTeX-enclose-verbatim (beg end)) ;do nothing when enclose verbatim
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
396 (fset 'YaTeX-enclose-verbatim* 'YaTeX-enclose-verbatim)
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
397
5f4b18da14b3 Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents: 49
diff changeset
398 (provide 'yatexenv)

yatex.org