Mercurial > hgrepos > hgweb.cgi > yatex
annotate yatexenv.el @ 580:89a13c59674f
Merged to default branch
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Thu, 26 Dec 2019 13:27:55 +0859 |
parents | 714f3527b4a1 |
children |
rev | line source |
---|---|
287 | 1 ;;; yatexenv.el --- YaTeX environment-specific functions |
572
714f3527b4a1
Add add-in for tabularx environment
HIROSE Yuuji <yuuji@gentei.org>
parents:
497
diff
changeset
|
2 ;;; (c) 1994-2019 by HIROSE Yuuji.[yuuji@yatex.org] |
714f3527b4a1
Add add-in for tabularx environment
HIROSE Yuuji <yuuji@gentei.org>
parents:
497
diff
changeset
|
3 ;;; Last modified Sat May 25 14:46:33 2019 on firestorm |
366 | 4 ;;; $Id$ |
23 | 5 |
287 | 6 ;;; Code: |
23 | 7 ;;; |
8 ;; Functions for tabular environment | |
9 ;;; | |
10 | |
11 ;; Showing the matching column of tabular environment. | |
80 | 12 (defun YaTeX-array-what-column-internal () |
13 "Return the cons of matching column and its title of array environment. | |
23 | 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 | 16 (n 0) j |
23 | 17 (firsterr "This line might be the first row.")) |
18 (save-excursion | |
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 | 22 (search-forward "{" p) (up-list 1) |
23 (search-forward "{" p) (up-list 1) | |
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 | 27 (equal (char-after (1- (match-beginning 0))) ?\\ ))) |
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 | 30 (error firsterr)) |
31 (setq eot (point)) ;eot is the point of the first \\ | |
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 | 36 (while (< (1- (point)) p) |
37 (if (equal (following-char) ?&) | |
38 (forward-char 1) | |
39 (re-search-forward andptn nil 1)) | |
40 (setq n (1+ n))) ;Check current column number | |
41 (goto-char p) | |
42 (cond ;Start searching \multicolumn{N} | |
43 ((> n 1) | |
44 (re-search-backward andptn) ;Sure to find! | |
45 (while (re-search-backward "\\\\multicolumn{\\([0-9]+\\)}" bor t) | |
452 | 46 (setq n (+ n (YaTeX-str2int |
23 | 47 (buffer-substring (match-beginning 1) |
48 (match-end 1))) | |
49 -1))))) | |
50 (message "%s" n) | |
51 (goto-char (1- beg)) | |
59 | 52 (beginning-of-line) |
49 | 53 (setq j n) |
54 (while (> j 1) | |
55 (or (re-search-forward andptn p nil) | |
56 (error "This column exceeds the limit.")) | |
57 (setq j (1- j))) | |
58 (skip-chars-forward "\\s ") | |
80 | 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 | 62 (progn |
63 (re-search-forward (concat andptn "\\|" nlptn) eot) | |
64 (goto-char (match-beginning 0)) | |
65 (if (looking-at andptn) | |
66 (forward-char 1)) | |
67 (skip-chars-backward "\\s ") | |
68 (point))))))) | |
69 | |
70 (defun YaTeX-array-what-column () | |
71 "Show matching column title of array environment. | |
72 When calling from a program, make sure to be in array/tabular environment." | |
73 (apply 'message | |
74 "This is the column(#%d) of: %s" | |
75 (YaTeX-array-what-column-internal))) | |
23 | 76 |
77 ;;;###autoload | |
78 (defun YaTeX-what-column () | |
79 "Show which kind of column the current position is belonging to." | |
80 (interactive) | |
81 (cond | |
82 ((YaTeX-quick-in-environment-p '("tabular" "tabular*" "array" "array*")) | |
83 (YaTeX-array-what-column)) | |
80 | 84 (t (message "Not in array/tabular environment.")))) |
23 | 85 |
80 | 86 (defun YaTeX-tabular-parse-format-count-cols (beg end) |
87 (goto-char beg) | |
88 (let (elt (cols 0)) | |
89 (while (< (point) end) | |
31 | 90 (setq elt (following-char)) |
91 (cond | |
572
714f3527b4a1
Add add-in for tabularx environment
HIROSE Yuuji <yuuji@gentei.org>
parents:
497
diff
changeset
|
92 ((string-match (char-to-string elt) "clrX") ;normal indicators. |
31 | 93 (setq cols (1+ cols)) |
94 (forward-char 1)) | |
95 ((equal elt ?|) ;vertical | |
96 (forward-char 1)) | |
97 ((string-match (char-to-string elt) "p@") ;p or @ expression | |
98 (setq cols (+ (if (eq elt ?p) 1 0) cols)) | |
80 | 99 ;;(skip-chars-forward "^{" p) |
100 (skip-chars-forward "^{" end) | |
56 | 101 (forward-list 1)) |
80 | 102 ((equal elt ?*) ;*{N}{EXP} -> Repeat EXP N times |
103 (skip-chars-forward "^{" end) | |
452 | 104 (setq cols (* (YaTeX-str2int |
80 | 105 (buffer-substring |
106 (1+ (point)) | |
107 (progn (forward-list 1) (1- (point))))) | |
108 (YaTeX-tabular-parse-format-count-cols | |
109 (progn (skip-chars-forward "^{" end) (1+ (point))) | |
110 (progn (forward-list 1) (1- (point))))))) | |
56 | 111 (t (forward-char 1)) ;unknown char |
112 )) | |
80 | 113 cols)) |
114 | |
115 (defun YaTeX-tabular-parse-format (&optional type) | |
116 "Parse `tabular' format. | |
117 Return the list of (No.ofCols PointEndofFormat)" | |
118 (let ((p (point)) boform eoform (cols 0)) | |
119 (save-excursion | |
120 (if (null (YaTeX-beginning-of-environment t)) | |
121 (error "Beginning of tabular not found.")) | |
122 (skip-chars-forward "^{") | |
123 (forward-list 1) | |
124 (cond | |
125 ((eq type 'tabular*) | |
126 (skip-chars-forward "^{") | |
127 (forward-list 1))) | |
128 (skip-chars-forward "^{" p) | |
129 (if (/= (following-char) ?\{) (error "Tabular format not found.")) | |
130 (setq boform (1+ (point)) | |
131 eoform (progn (forward-list 1) (1- (point)))) | |
132 (if (> eoform p) (error "Non-terminated tabular format.")) | |
133 (goto-char boform) | |
134 (setq cols | |
135 (cond | |
136 ((eq type 'alignat) | |
137 (max | |
138 1 | |
452 | 139 (* 2 (YaTeX-str2int |
250 | 140 (buffer-substring |
141 (point) | |
142 (progn (up-list -1) (forward-list 1) (1- (point)))))))) | |
80 | 143 (t |
144 (YaTeX-tabular-parse-format-count-cols (point) eoform)))) | |
145 (list cols (1+ eoform))))) | |
146 | |
31 | 147 ;; Insert & |
80 | 148 (defun YaTeX-intelligent-newline-tabular (&optional type) |
31 | 149 "Parse current tabular format and insert that many `&'s." |
80 | 150 (let*((p (point)) (format (YaTeX-tabular-parse-format type)) |
31 | 151 (cols (car format)) (beg (car (cdr format))) |
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 | 161 (goto-char p) |
162 (while (> (1- cols) 0) | |
163 (insert "&" space) | |
164 (setq cols (1- cols))) | |
165 (insert "\\\\") | |
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 | 168 (YaTeX-indent-line))) |
31 | 169 |
170 (defun YaTeX-intelligent-newline-tabular* () | |
171 "Parse current tabular* format and insert that many `&'s." | |
80 | 172 (YaTeX-intelligent-newline-tabular 'tabular*)) |
31 | 173 |
174 (fset 'YaTeX-intelligent-newline-array 'YaTeX-intelligent-newline-tabular) | |
80 | 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) |
572
714f3527b4a1
Add add-in for tabularx environment
HIROSE Yuuji <yuuji@gentei.org>
parents:
497
diff
changeset
|
177 (fset 'YaTeX-intelligent-newline-tabularx 'YaTeX-intelligent-newline-tabular*) |
80 | 178 |
179 (defun YaTeX-intelligent-newline-align () | |
180 "Intelligent newline function for align. | |
181 Count the number of & in the first align line and insert that many &s." | |
250 | 182 (let*((p (point)) (amps 0)) |
183 (if (string-match "alignat" env) | |
184 (setq amps (1- (car (YaTeX-tabular-parse-format 'alignat)))) | |
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 amps (1+ amps)) (throw 'done t)))))) | |
80 | 191 (save-excursion |
250 | 192 (forward-line -1) |
193 (skip-chars-forward " \t") | |
194 (or (prog1 (looking-at "\\\\begin{") (end-of-line)) | |
195 (save-excursion | |
196 (skip-chars-backward " \t") | |
197 (and (= (preceding-char) ?\\) (= (char-after (- (point) 2)) ?\\))) | |
198 (insert "\\\\"))) | |
80 | 199 (save-excursion |
250 | 200 (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
|
201 (insert "& "))) |
80 | 202 (YaTeX-indent-line))) |
203 | |
204 (mapcar | |
353
2a72779d9c50
Rewrite lambda notations to suppress annoying warnings from emacs24
HIROSE Yuuji <yuuji@gentei.org>
parents:
306
diff
changeset
|
205 (function |
2a72779d9c50
Rewrite lambda notations to suppress annoying warnings from emacs24
HIROSE Yuuji <yuuji@gentei.org>
parents:
306
diff
changeset
|
206 (lambda (s) |
80 | 207 (fset (intern (concat "YaTeX-intelligent-newline-" |
208 (symbol-name s))) | |
353
2a72779d9c50
Rewrite lambda notations to suppress annoying warnings from emacs24
HIROSE Yuuji <yuuji@gentei.org>
parents:
306
diff
changeset
|
209 'YaTeX-intelligent-newline-align))) |
80 | 210 '(align* flalign flalign* matrix pmatrix bmatrix Bmatrix vmatrix Vmatrix |
250 | 211 cases eqnarray eqnarray* alignat alignat*)) |
31 | 212 |
23 | 213 ;;; |
214 ;; Functions for tabbing environment | |
215 ;;; | |
216 (defun YaTeX-intelligent-newline-tabbing () | |
217 "Check the number of \\= in the first line and insert that many \\>." | |
218 (let ((p (point)) begenv tabcount) | |
219 (save-excursion | |
220 (YaTeX-beginning-of-environment) | |
221 (setq begenv (point-end-of-line)) | |
222 (if (YaTeX-search-active-forward "\\\\" YaTeX-comment-prefix p t) | |
223 (progn | |
224 (setq tabcount 0) | |
225 (while (> (point) begenv) | |
226 (if (search-backward "\\=" begenv 1) | |
227 (setq tabcount (1+ tabcount))))))) | |
228 (YaTeX-indent-line) | |
229 (if tabcount | |
230 (progn | |
231 (save-excursion | |
232 (while (> tabcount 0) | |
233 (insert "\\>\t") | |
234 (setq tabcount (1- tabcount)))) | |
235 (forward-char 2)) | |
58
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
56
diff
changeset
|
236 (insert "\\= \\\\") |
233 | 237 (forward-char -5)))) |
23 | 238 |
239 ;;; | |
240 ;; Functions for itemize/enumerate/list environments | |
241 ;;; | |
242 | |
243 (defun YaTeX-intelligent-newline-itemize () | |
244 "Insert '\\item '." | |
58
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
56
diff
changeset
|
245 (insert "\\item ") |
233 | 246 (YaTeX-indent-line)) |
247 | |
23 | 248 (fset 'YaTeX-intelligent-newline-enumerate 'YaTeX-intelligent-newline-itemize) |
249 (fset 'YaTeX-intelligent-newline-list 'YaTeX-intelligent-newline-itemize) | |
250 | |
251 (defun YaTeX-intelligent-newline-description () | |
252 (insert "\\item[] ") | |
253 (forward-char -2) | |
233 | 254 (YaTeX-indent-line)) |
23 | 255 |
64 | 256 (defun YaTeX-intelligent-newline-thebibliography () |
257 "Insert '\\bibitem '." | |
258 (YaTeX-indent-line) | |
259 (YaTeX-make-section nil nil nil "bibitem") | |
233 | 260 (YaTeX-indent-line)) |
261 | |
23 | 262 ;;; |
234
b75390dd4260
C-j can skip further parameter input for table/figure environment.
yuuji@gentei.org
parents:
233
diff
changeset
|
263 ;; For document environment |
b75390dd4260
C-j can skip further parameter input for table/figure environment.
yuuji@gentei.org
parents:
233
diff
changeset
|
264 ;;; |
b75390dd4260
C-j can skip further parameter input for table/figure environment.
yuuji@gentei.org
parents:
233
diff
changeset
|
265 (defun YaTeX-intelligent-newline-document () |
239
5de195a540c7
YaTeX-intelligent-newline-document recognizes \par lover.
yuuji@gentei.org
parents:
238
diff
changeset
|
266 "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
|
267 (if (< (count-lines |
2b85ef062ccf
Do not put new paragraph at the beginning of document environment.
HIROSE Yuuji <yuuji@gentei.org>
parents:
251
diff
changeset
|
268 (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
|
269 (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
|
270 (point)) |
2b85ef062ccf
Do not put new paragraph at the beginning of document environment.
HIROSE Yuuji <yuuji@gentei.org>
parents:
251
diff
changeset
|
271 2) |
2b85ef062ccf
Do not put new paragraph at the beginning of document environment.
HIROSE Yuuji <yuuji@gentei.org>
parents:
251
diff
changeset
|
272 nil |
2b85ef062ccf
Do not put new paragraph at the beginning of document environment.
HIROSE Yuuji <yuuji@gentei.org>
parents:
251
diff
changeset
|
273 (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
|
274 (progn |
2b85ef062ccf
Do not put new paragraph at the beginning of document environment.
HIROSE Yuuji <yuuji@gentei.org>
parents:
251
diff
changeset
|
275 (YaTeX-indent-line) |
2b85ef062ccf
Do not put new paragraph at the beginning of document environment.
HIROSE Yuuji <yuuji@gentei.org>
parents:
251
diff
changeset
|
276 (insert "\\par"))) |
2b85ef062ccf
Do not put new paragraph at the beginning of document environment.
HIROSE Yuuji <yuuji@gentei.org>
parents:
251
diff
changeset
|
277 (newline)) |
239
5de195a540c7
YaTeX-intelligent-newline-document recognizes \par lover.
yuuji@gentei.org
parents:
238
diff
changeset
|
278 (YaTeX-indent-line)) |
234
b75390dd4260
C-j can skip further parameter input for table/figure environment.
yuuji@gentei.org
parents:
233
diff
changeset
|
279 |
b75390dd4260
C-j can skip further parameter input for table/figure environment.
yuuji@gentei.org
parents:
233
diff
changeset
|
280 ;;; |
23 | 281 ;; Intelligent newline |
282 ;;; | |
283 ;;;###autoload | |
284 (defun YaTeX-intelligent-newline (arg) | |
285 "Insert newline and environment-specific entry. | |
286 `\\item' for some itemizing environment, | |
287 `\\> \\> \\' for tabbing environemnt, | |
288 `& & \\ \hline' for tabular environment." | |
289 (interactive "P") | |
61 | 290 (let*(env func) |
291 (end-of-line) | |
292 (setq env (YaTeX-inner-environment)) | |
23 | 293 (if arg (setq env (YaTeX-read-environment "For what environment? "))) |
294 (setq func (intern-soft (concat "YaTeX-intelligent-newline-" env))) | |
295 (end-of-line) | |
296 (newline) | |
58
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
56
diff
changeset
|
297 (undo-boundary) |
23 | 298 (if (and env func (fboundp func)) |
80 | 299 (funcall func)))) |
53
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 ;;; |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
302 ;; Environment-specific line indenting functions |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
303 ;;; |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
304 ;;;###autoload |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
305 (defun YaTeX-indent-line-equation () |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
306 "Indent a line in equation family." |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
307 (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
|
308 (if (save-excursion |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
309 (beginning-of-line) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
310 (skip-chars-forward " \t") |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
311 (looking-at "\\\\right\\b")) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
312 (progn (YaTeX-reindent |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
313 (save-excursion (YaTeX-goto-corresponding-leftright) |
73 | 314 (- (current-column) 0)))) |
53
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
315 (save-excursion |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
316 (forward-line -1) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
317 (while (and (not (bobp)) (YaTeX-on-comment-p)) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
318 (forward-line -1)) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
319 ;;(beginning-of-line) ;must be unnecessary |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
320 (skip-chars-forward " \t") |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
321 (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
|
322 (setq depth (current-column) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
323 peol (point-end-of-line)) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
324 (while (re-search-forward |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
325 "\\\\\\(\\(left\\)\\|\\(right\\)\\)\\b" peol t) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
326 (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
|
327 (cond |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
328 ((progn (beginning-of-line) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
329 (re-search-forward "\\\\\\\\\\s *$" (point-end-of-line) t)) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
330 ;;If previous line has `\\', this indentation is always normal. |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
331 (setq depth (+ (YaTeX-current-indentation) mp))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
332 ((> l-r 0) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
333 (beginning-of-line) |
68 | 334 (search-forward "\\left" peol nil l-r) |
53
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
335 (goto-char (1+ (match-beginning 0))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
336 (setq depth (current-column))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
337 ((< l-r 0) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
338 (goto-char (match-beginning 0)) ;should be \right |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
339 (YaTeX-goto-corresponding-leftright) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
340 (beginning-of-line) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
341 (skip-chars-forward " \t") |
68 | 342 ;(setq depth (+ (current-column) mp)) ;+mp is good? |
343 (setq depth (current-column))) | |
53
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
344 (t ;if \left - \right = 0 |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
345 (cond |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
346 ((re-search-forward "\\\\\\\\\\s *$" peol t) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
347 (setq depth (+ (YaTeX-current-indentation) mp))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
348 ((re-search-forward "\\\\end{" peol t) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
349 nil) ;same indentation as previous line's |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
350 ((re-search-forward "\\\\begin{" peol t) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
351 (setq depth (+ depth mp))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
352 (t |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
353 (or (bobp) (forward-line -1)) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
354 (cond |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
355 ((re-search-forward |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
356 "\\\\\\\\\\s *$\\|\\\\begin{" (point-end-of-line) t) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
357 (setq depth (+ depth mp))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
358 ))))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
359 (goto-char p)) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
360 (YaTeX-reindent depth)))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
361 |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
362 ;;;###autoload |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
363 (defun YaTeX-goto-corresponding-leftright () |
77 | 364 "Go to corresponding \left or \right." |
53
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
365 (let ((YaTeX-struct-begin "\\left%1") |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
366 (YaTeX-struct-end "\\right%1") |
77 | 367 (YaTeX-struct-name-regexp "[][(){}\\.|]") |
368 (in-leftright-p t)) | |
53
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
369 (YaTeX-goto-corresponding-environment t))) |
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 ;;; |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
372 ;; Functions for formatting region being enclosed with environment |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
373 ;;; |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
374 ; These functions must take two argument; region-beginning, region-end. |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
375 |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
376 (defun YaTeX-enclose-equation (beg end) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
377 (goto-char beg) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
378 (save-restriction |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
379 (let (m0 bsl) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
380 (narrow-to-region beg end) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
381 (while (YaTeX-re-search-active-forward |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
382 "\\(\\$\\)" YaTeX-comment-prefix nil t) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
383 (goto-char (setq m0 (match-beginning 0))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
384 (setq bsl 0) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
385 (if (and (not (bobp)) (= (char-after (1- (point))) ?\\ )) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
386 (while (progn (forward-char -1) (= (char-after (point)) ?\\ )) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
387 (setq bsl (1+ bsl)))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
388 (goto-char m0) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
389 (if (= 0 (% bsl 2)) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
390 (delete-char 1) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
391 (forward-char 1)))))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
392 |
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 (fset 'YaTeX-enclose-eqnarray* 'YaTeX-enclose-equation) |
457
428584533eab
Enclosing with amsmath envs strips $...$
HIROSE Yuuji <yuuji@gentei.org>
parents:
452
diff
changeset
|
395 (mapcar (function ;; Add all AMS LaTeX envs |
428584533eab
Enclosing with amsmath envs strips $...$
HIROSE Yuuji <yuuji@gentei.org>
parents:
452
diff
changeset
|
396 (lambda (sym) |
428584533eab
Enclosing with amsmath envs strips $...$
HIROSE Yuuji <yuuji@gentei.org>
parents:
452
diff
changeset
|
397 (fset (intern (concat "YaTeX-enclose-" (car sym))) |
428584533eab
Enclosing with amsmath envs strips $...$
HIROSE Yuuji <yuuji@gentei.org>
parents:
452
diff
changeset
|
398 'YaTeX-enclose-equation))) |
428584533eab
Enclosing with amsmath envs strips $...$
HIROSE Yuuji <yuuji@gentei.org>
parents:
452
diff
changeset
|
399 YaTeX-ams-math-begin-alist) |
53
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
400 |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
401 (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
|
402 (fset 'YaTeX-enclose-verbatim* 'YaTeX-enclose-verbatim) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
403 |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
404 (provide 'yatexenv) |