annotate yatexenv.el @ 353:2a72779d9c50 dev

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

yatex.org