comparison yatexenv.el @ 53:5f4b18da14b3

Fix functions relating YaTeX-beginning-of-environment or YaTeX-end-of-environment. Line indentation by TAB much improved. Functions that work at enclosing environments, YaTeX-enclose-<ENVNAME>, introduced. Functions for enclosing verbatim and equations are supplied. SPC, DEL, +, - in YaTeX-hierarchy buffer. Compensate odd highlighting of hilit19.
author yuuji
date Thu, 02 Feb 1995 17:18:29 +0000
parents eb0512bfcb7f
children a9653fbd1c1c
comparison
equal deleted inserted replaced
52:5d94deabb9f9 53:5f4b18da14b3
1 ;;; -*- Emacs-Lisp -*- 1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX environment-specific functions. 2 ;;; YaTeX environment-specific functions.
3 ;;; yatexenv.el 3 ;;; yatexenv.el
4 ;;; (c ) 1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp] 4 ;;; (c ) 1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
5 ;;; Last modified Thu Nov 24 04:33:18 1994 on 98fa 5 ;;; Last modified Thu Feb 2 16:11:12 1995 on pajero
6 ;;; $Id$ 6 ;;; $Id$
7 7
8 ;;; 8 ;;;
9 ;; Functions for tabular environment 9 ;; Functions for tabular environment
10 ;;; 10 ;;;
163 163
164 ;;; 164 ;;;
165 ;; Functions for itemize/enumerate/list environments 165 ;; Functions for itemize/enumerate/list environments
166 ;;; 166 ;;;
167 167
168 (defun YaTeX-indent-for-item ()
169 (let (col (p (point)) begenv)
170 (save-excursion
171 (YaTeX-beginning-of-environment t)
172 (setq begenv (point-end-of-line))
173 (goto-char p)
174 (if (YaTeX-search-active-backward "\\item" YaTeX-comment-prefix begenv t)
175 (setq col (current-column))))
176 (if col (indent-to col) (YaTeX-indent-line)))
177 )
178
179 (defvar YaTeX-item-for-insert "\\item ") 168 (defvar YaTeX-item-for-insert "\\item ")
180 (defun YaTeX-intelligent-newline-itemize () 169 (defun YaTeX-intelligent-newline-itemize ()
181 "Insert '\\item '." 170 "Insert '\\item '."
182 (YaTeX-indent-for-item)
183 (insert YaTeX-item-for-insert) 171 (insert YaTeX-item-for-insert)
172 (YaTeX-indent-line)
184 ) 173 )
185 (fset 'YaTeX-intelligent-newline-enumerate 'YaTeX-intelligent-newline-itemize) 174 (fset 'YaTeX-intelligent-newline-enumerate 'YaTeX-intelligent-newline-itemize)
186 (fset 'YaTeX-intelligent-newline-list 'YaTeX-intelligent-newline-itemize) 175 (fset 'YaTeX-intelligent-newline-list 'YaTeX-intelligent-newline-itemize)
187 176
188 (defun YaTeX-intelligent-newline-description () 177 (defun YaTeX-intelligent-newline-description ()
189 (YaTeX-indent-for-item)
190 (insert "\\item[] ") 178 (insert "\\item[] ")
191 (forward-char -2) 179 (forward-char -2)
180 (YaTeX-indent-line)
192 ) 181 )
193 182
194 183
195 ;;; 184 ;;;
196 ;; Intelligent newline 185 ;; Intelligent newline
209 (end-of-line) 198 (end-of-line)
210 (newline) 199 (newline)
211 (if (and env func (fboundp func)) 200 (if (and env func (fboundp func))
212 (funcall func))) 201 (funcall func)))
213 ) 202 )
203
204 ;;;
205 ;; Environment-specific line indenting functions
206 ;;;
207 ;;;###autoload
208 (defun YaTeX-indent-line-equation ()
209 "Indent a line in equation family."
210 (let ((p (point)) (l-r 0) right-p peol depth (mp YaTeX-environment-indent))
211 (if (save-excursion
212 (beginning-of-line)
213 (skip-chars-forward " \t")
214 (looking-at "\\\\right\\b"))
215 (progn (YaTeX-reindent
216 (save-excursion (YaTeX-goto-corresponding-leftright)
217 (current-column))))
218 (save-excursion
219 (forward-line -1)
220 (while (and (not (bobp)) (YaTeX-on-comment-p))
221 (forward-line -1))
222 ;;(beginning-of-line) ;must be unnecessary
223 (skip-chars-forward " \t")
224 (if (eolp) (error "Math-environment can't have a null line!!"))
225 (setq depth (current-column)
226 peol (point-end-of-line))
227 (while (re-search-forward
228 "\\\\\\(\\(left\\)\\|\\(right\\)\\)\\b" peol t)
229 (setq l-r (+ l-r (if (match-beginning 2) 1 -1))))
230 (cond
231 ((progn (beginning-of-line)
232 (re-search-forward "\\\\\\\\\\s *$" (point-end-of-line) t))
233 ;;If previous line has `\\', this indentation is always normal.
234 (setq depth (+ (YaTeX-current-indentation) mp)))
235 ((> l-r 0)
236 (beginning-of-line)
237 (search-forward "\\left" peol)
238 (goto-char (1+ (match-beginning 0)))
239 (setq depth (current-column)))
240 ((< l-r 0)
241 (goto-char (match-beginning 0)) ;should be \right
242 (YaTeX-goto-corresponding-leftright)
243 (beginning-of-line)
244 (skip-chars-forward " \t")
245 (setq depth (+ (current-column) mp))) ;+mp is good?
246 (t ;if \left - \right = 0
247 (cond
248 ((re-search-forward "\\\\\\\\\\s *$" peol t)
249 (setq depth (+ (YaTeX-current-indentation) mp)))
250 ((re-search-forward "\\\\end{" peol t)
251 nil) ;same indentation as previous line's
252 ((re-search-forward "\\\\begin{" peol t)
253 (setq depth (+ depth mp)))
254 (t
255 (or (bobp) (forward-line -1))
256 (cond
257 ((re-search-forward
258 "\\\\\\\\\\s *$\\|\\\\begin{" (point-end-of-line) t)
259 (setq depth (+ depth mp)))
260 )))))
261 (goto-char p))
262 (YaTeX-reindent depth))))
263
264 ;;;###autoload
265 (defun YaTeX-goto-corresponding-leftright ()
266 "Go to corresponding \left or \right.
267 Note that this function assumes the corresponding \left\right
268 is on another line."
269 (let ((YaTeX-struct-begin "\\left%1")
270 (YaTeX-struct-end "\\right%1")
271 (YaTeX-struct-name-regexp "[][(){}.|]"))
272 (YaTeX-goto-corresponding-environment t)))
273
274 ;;;
275 ;; Functions for formatting region being enclosed with environment
276 ;;;
277 ; These functions must take two argument; region-beginning, region-end.
278
279 (defun YaTeX-enclose-equation (beg end)
280 (goto-char beg)
281 (save-restriction
282 (let (m0 bsl)
283 (narrow-to-region beg end)
284 (while (YaTeX-re-search-active-forward
285 "\\(\\$\\)" YaTeX-comment-prefix nil t)
286 (goto-char (setq m0 (match-beginning 0)))
287 (setq bsl 0)
288 (if (and (not (bobp)) (= (char-after (1- (point))) ?\\ ))
289 (while (progn (forward-char -1) (= (char-after (point)) ?\\ ))
290 (setq bsl (1+ bsl))))
291 (goto-char m0)
292 (if (= 0 (% bsl 2))
293 (delete-char 1)
294 (forward-char 1))))))
295
296 (fset 'YaTeX-enclose-eqnarray 'YaTeX-enclose-equation)
297 (fset 'YaTeX-enclose-eqnarray* 'YaTeX-enclose-equation)
298
299 (defun YaTeX-enclose-verbatim (beg end)) ;do nothing when enclose verbatim
300 (fset 'YaTeX-enclose-verbatim* 'YaTeX-enclose-verbatim)
301
302 (provide 'yatexenv)

yatex.org