Mercurial > hgrepos > hgweb.cgi > yatex
annotate yatexenv.el @ 236:328a212a2160 dev
Intelligent newline for align insert no `&' at the first line.
author | yuuji@gentei.org |
---|---|
date | Sat, 28 Jan 2012 22:32:30 +0900 |
parents | f70aae80489e |
children | 5260b7ee9fdf |
rev | line source |
---|---|
23 | 1 ;;; -*- Emacs-Lisp -*- |
2 ;;; YaTeX environment-specific functions. | |
3 ;;; yatexenv.el | |
80 | 4 ;;; (c) 1994-2006 by HIROSE Yuuji.[yuuji@yatex.org] |
236
328a212a2160
Intelligent newline for align insert no `&' at the first line.
yuuji@gentei.org
parents:
235
diff
changeset
|
5 ;;; Last modified Sat Jan 28 22:27:24 2012 on firestorm |
23 | 6 ;;; $Id$ |
7 | |
8 ;;; | |
9 ;; Functions for tabular environment | |
10 ;;; | |
11 | |
12 ;; Showing the matching column of tabular environment. | |
80 | 13 (defun YaTeX-array-what-column-internal () |
14 "Return the cons of matching column and its title of array environment. | |
23 | 15 When calling from a program, make sure to be in array/tabular environment." |
49 | 16 (let ((p (point)) beg eot bor (nlptn "\\\\\\\\") (andptn "[^\\]&") |
17 (n 0) j | |
23 | 18 (firsterr "This line might be the first row.")) |
19 (save-excursion | |
20 (YaTeX-beginning-of-environment) | |
21 (search-forward "{" p) (up-list 1) | |
22 (search-forward "{" p) (up-list 1) | |
23 ;;(re-search-forward andptn p) | |
24 (while (progn (search-forward "&" p) | |
25 (equal (char-after (1- (match-beginning 0))) ?\\ ))) | |
26 (setq beg (1- (point))) ;beg is the point of the first & | |
27 (or (re-search-forward nlptn p t) | |
28 (error firsterr)) | |
29 (setq eot (point)) ;eot is the point of the first \\ | |
30 (goto-char p) | |
31 (or (re-search-backward nlptn beg t) | |
32 (error firsterr)) | |
33 (setq bor (point)) ;bor is the beginning of this row. | |
34 (while (< (1- (point)) p) | |
35 (if (equal (following-char) ?&) | |
36 (forward-char 1) | |
37 (re-search-forward andptn nil 1)) | |
38 (setq n (1+ n))) ;Check current column number | |
39 (goto-char p) | |
40 (cond ;Start searching \multicolumn{N} | |
41 ((> n 1) | |
42 (re-search-backward andptn) ;Sure to find! | |
43 (while (re-search-backward "\\\\multicolumn{\\([0-9]+\\)}" bor t) | |
44 (setq n (+ n (string-to-int | |
45 (buffer-substring (match-beginning 1) | |
46 (match-end 1))) | |
47 -1))))) | |
48 (message "%s" n) | |
49 (goto-char (1- beg)) | |
59 | 50 (beginning-of-line) |
49 | 51 (setq j n) |
52 (while (> j 1) | |
53 (or (re-search-forward andptn p nil) | |
54 (error "This column exceeds the limit.")) | |
55 (setq j (1- j))) | |
56 (skip-chars-forward "\\s ") | |
80 | 57 (list n |
58 (buffer-substring | |
59 (point) | |
60 (progn | |
61 (re-search-forward (concat andptn "\\|" nlptn) eot) | |
62 (goto-char (match-beginning 0)) | |
63 (if (looking-at andptn) | |
64 (forward-char 1)) | |
65 (skip-chars-backward "\\s ") | |
66 (point))))))) | |
67 | |
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))) | |
23 | 74 |
75 ;;;###autoload | |
76 (defun YaTeX-what-column () | |
77 "Show which kind of column the current position is belonging to." | |
78 (interactive) | |
79 (cond | |
80 ((YaTeX-quick-in-environment-p '("tabular" "tabular*" "array" "array*")) | |
81 (YaTeX-array-what-column)) | |
80 | 82 (t (message "Not in array/tabular environment.")))) |
23 | 83 |
80 | 84 (defun YaTeX-tabular-parse-format-count-cols (beg end) |
85 (goto-char beg) | |
86 (let (elt (cols 0)) | |
87 (while (< (point) end) | |
31 | 88 (setq elt (following-char)) |
89 (cond | |
90 ((string-match (char-to-string elt) "clr") ;normal indicators. | |
91 (setq cols (1+ cols)) | |
92 (forward-char 1)) | |
93 ((equal elt ?|) ;vertical | |
94 (forward-char 1)) | |
95 ((string-match (char-to-string elt) "p@") ;p or @ expression | |
96 (setq cols (+ (if (eq elt ?p) 1 0) cols)) | |
80 | 97 ;;(skip-chars-forward "^{" p) |
98 (skip-chars-forward "^{" end) | |
56 | 99 (forward-list 1)) |
80 | 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))))))) | |
56 | 109 (t (forward-char 1)) ;unknown char |
110 )) | |
80 | 111 cols)) |
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 | |
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) |
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 | |
236
328a212a2160
Intelligent newline for align insert no `&' at the first line.
yuuji@gentei.org
parents:
235
diff
changeset
|
192 (while (>= (setq cols (1- cols)) 0) |
328a212a2160
Intelligent newline for align insert no `&' at the first line.
yuuji@gentei.org
parents:
235
diff
changeset
|
193 (insert "& "))) |
80 | 194 (YaTeX-indent-line))) |
195 | |
196 (mapcar | |
197 '(lambda (s) | |
198 (fset (intern (concat "YaTeX-intelligent-newline-" | |
199 (symbol-name s))) | |
200 'YaTeX-intelligent-newline-align)) | |
201 '(align* flalign flalign* matrix pmatrix bmatrix Bmatrix vmatrix Vmatrix | |
202 cases)) | |
31 | 203 |
23 | 204 ;;; |
205 ;; Functions for tabbing environment | |
206 ;;; | |
207 (defun YaTeX-intelligent-newline-tabbing () | |
208 "Check the number of \\= in the first line and insert that many \\>." | |
209 (let ((p (point)) begenv tabcount) | |
210 (save-excursion | |
211 (YaTeX-beginning-of-environment) | |
212 (setq begenv (point-end-of-line)) | |
213 (if (YaTeX-search-active-forward "\\\\" YaTeX-comment-prefix p t) | |
214 (progn | |
215 (setq tabcount 0) | |
216 (while (> (point) begenv) | |
217 (if (search-backward "\\=" begenv 1) | |
218 (setq tabcount (1+ tabcount))))))) | |
219 (YaTeX-indent-line) | |
220 (if tabcount | |
221 (progn | |
222 (save-excursion | |
223 (while (> tabcount 0) | |
224 (insert "\\>\t") | |
225 (setq tabcount (1- tabcount)))) | |
226 (forward-char 2)) | |
58
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
56
diff
changeset
|
227 (insert "\\= \\\\") |
233 | 228 (forward-char -5)))) |
23 | 229 |
230 ;;; | |
231 ;; Functions for itemize/enumerate/list environments | |
232 ;;; | |
233 | |
234 (defun YaTeX-intelligent-newline-itemize () | |
235 "Insert '\\item '." | |
58
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
56
diff
changeset
|
236 (insert "\\item ") |
233 | 237 (YaTeX-indent-line)) |
238 | |
23 | 239 (fset 'YaTeX-intelligent-newline-enumerate 'YaTeX-intelligent-newline-itemize) |
240 (fset 'YaTeX-intelligent-newline-list 'YaTeX-intelligent-newline-itemize) | |
241 | |
242 (defun YaTeX-intelligent-newline-description () | |
243 (insert "\\item[] ") | |
244 (forward-char -2) | |
233 | 245 (YaTeX-indent-line)) |
23 | 246 |
64 | 247 (defun YaTeX-intelligent-newline-thebibliography () |
248 "Insert '\\bibitem '." | |
249 (YaTeX-indent-line) | |
250 (YaTeX-make-section nil nil nil "bibitem") | |
233 | 251 (YaTeX-indent-line)) |
252 | |
23 | 253 ;;; |
234
b75390dd4260
C-j can skip further parameter input for table/figure environment.
yuuji@gentei.org
parents:
233
diff
changeset
|
254 ;; For document environment |
b75390dd4260
C-j can skip further parameter input for table/figure environment.
yuuji@gentei.org
parents:
233
diff
changeset
|
255 ;;; |
b75390dd4260
C-j can skip further parameter input for table/figure environment.
yuuji@gentei.org
parents:
233
diff
changeset
|
256 (defun YaTeX-intelligent-newline-document () |
b75390dd4260
C-j can skip further parameter input for table/figure environment.
yuuji@gentei.org
parents:
233
diff
changeset
|
257 "New paragraph." |
b75390dd4260
C-j can skip further parameter input for table/figure environment.
yuuji@gentei.org
parents:
233
diff
changeset
|
258 (newline)) ;Do you prefer `\par'? |
b75390dd4260
C-j can skip further parameter input for table/figure environment.
yuuji@gentei.org
parents:
233
diff
changeset
|
259 |
b75390dd4260
C-j can skip further parameter input for table/figure environment.
yuuji@gentei.org
parents:
233
diff
changeset
|
260 ;;; |
23 | 261 ;; Intelligent newline |
262 ;;; | |
263 ;;;###autoload | |
264 (defun YaTeX-intelligent-newline (arg) | |
265 "Insert newline and environment-specific entry. | |
266 `\\item' for some itemizing environment, | |
267 `\\> \\> \\' for tabbing environemnt, | |
268 `& & \\ \hline' for tabular environment." | |
269 (interactive "P") | |
61 | 270 (let*(env func) |
271 (end-of-line) | |
272 (setq env (YaTeX-inner-environment)) | |
23 | 273 (if arg (setq env (YaTeX-read-environment "For what environment? "))) |
274 (setq func (intern-soft (concat "YaTeX-intelligent-newline-" env))) | |
275 (end-of-line) | |
276 (newline) | |
58
3a7c0c2bf16d
Official support for AMS-LaTeX, HTML, xdvi -remote, Netscape
yuuji
parents:
56
diff
changeset
|
277 (undo-boundary) |
23 | 278 (if (and env func (fboundp func)) |
80 | 279 (funcall func)))) |
53
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
280 |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
281 ;;; |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
282 ;; Environment-specific line indenting functions |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
283 ;;; |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
284 ;;;###autoload |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
285 (defun YaTeX-indent-line-equation () |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
286 "Indent a line in equation family." |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
287 (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
|
288 (if (save-excursion |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
289 (beginning-of-line) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
290 (skip-chars-forward " \t") |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
291 (looking-at "\\\\right\\b")) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
292 (progn (YaTeX-reindent |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
293 (save-excursion (YaTeX-goto-corresponding-leftright) |
73 | 294 (- (current-column) 0)))) |
53
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
295 (save-excursion |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
296 (forward-line -1) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
297 (while (and (not (bobp)) (YaTeX-on-comment-p)) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
298 (forward-line -1)) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
299 ;;(beginning-of-line) ;must be unnecessary |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
300 (skip-chars-forward " \t") |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
301 (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
|
302 (setq depth (current-column) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
303 peol (point-end-of-line)) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
304 (while (re-search-forward |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
305 "\\\\\\(\\(left\\)\\|\\(right\\)\\)\\b" peol t) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
306 (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
|
307 (cond |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
308 ((progn (beginning-of-line) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
309 (re-search-forward "\\\\\\\\\\s *$" (point-end-of-line) t)) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
310 ;;If previous line has `\\', this indentation is always normal. |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
311 (setq depth (+ (YaTeX-current-indentation) mp))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
312 ((> l-r 0) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
313 (beginning-of-line) |
68 | 314 (search-forward "\\left" peol nil l-r) |
53
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
315 (goto-char (1+ (match-beginning 0))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
316 (setq depth (current-column))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
317 ((< l-r 0) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
318 (goto-char (match-beginning 0)) ;should be \right |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
319 (YaTeX-goto-corresponding-leftright) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
320 (beginning-of-line) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
321 (skip-chars-forward " \t") |
68 | 322 ;(setq depth (+ (current-column) mp)) ;+mp is good? |
323 (setq depth (current-column))) | |
53
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
324 (t ;if \left - \right = 0 |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
325 (cond |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
326 ((re-search-forward "\\\\\\\\\\s *$" peol t) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
327 (setq depth (+ (YaTeX-current-indentation) mp))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
328 ((re-search-forward "\\\\end{" peol t) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
329 nil) ;same indentation as previous line's |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
330 ((re-search-forward "\\\\begin{" peol t) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
331 (setq depth (+ depth mp))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
332 (t |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
333 (or (bobp) (forward-line -1)) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
334 (cond |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
335 ((re-search-forward |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
336 "\\\\\\\\\\s *$\\|\\\\begin{" (point-end-of-line) t) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
337 (setq depth (+ depth mp))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
338 ))))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
339 (goto-char p)) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
340 (YaTeX-reindent depth)))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
341 |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
342 ;;;###autoload |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
343 (defun YaTeX-goto-corresponding-leftright () |
77 | 344 "Go to corresponding \left or \right." |
53
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
345 (let ((YaTeX-struct-begin "\\left%1") |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
346 (YaTeX-struct-end "\\right%1") |
77 | 347 (YaTeX-struct-name-regexp "[][(){}\\.|]") |
348 (in-leftright-p t)) | |
53
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
349 (YaTeX-goto-corresponding-environment t))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
350 |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
351 ;;; |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
352 ;; Functions for formatting region being enclosed with environment |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
353 ;;; |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
354 ; These functions must take two argument; region-beginning, region-end. |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
355 |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
356 (defun YaTeX-enclose-equation (beg end) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
357 (goto-char beg) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
358 (save-restriction |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
359 (let (m0 bsl) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
360 (narrow-to-region beg end) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
361 (while (YaTeX-re-search-active-forward |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
362 "\\(\\$\\)" YaTeX-comment-prefix nil t) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
363 (goto-char (setq m0 (match-beginning 0))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
364 (setq bsl 0) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
365 (if (and (not (bobp)) (= (char-after (1- (point))) ?\\ )) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
366 (while (progn (forward-char -1) (= (char-after (point)) ?\\ )) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
367 (setq bsl (1+ bsl)))) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
368 (goto-char m0) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
369 (if (= 0 (% bsl 2)) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
370 (delete-char 1) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
371 (forward-char 1)))))) |
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 (fset 'YaTeX-enclose-eqnarray 'YaTeX-enclose-equation) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
374 (fset 'YaTeX-enclose-eqnarray* 'YaTeX-enclose-equation) |
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-verbatim (beg end)) ;do nothing when enclose verbatim |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
377 (fset 'YaTeX-enclose-verbatim* 'YaTeX-enclose-verbatim) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
378 |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
49
diff
changeset
|
379 (provide 'yatexenv) |