yatex

diff 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
line diff
     1.1 --- a/yatexenv.el	Fri Nov 25 08:26:13 1994 +0000
     1.2 +++ b/yatexenv.el	Thu Feb 02 17:18:29 1995 +0000
     1.3 @@ -2,7 +2,7 @@
     1.4  ;;; YaTeX environment-specific functions.
     1.5  ;;; yatexenv.el
     1.6  ;;; (c ) 1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
     1.7 -;;; Last modified Thu Nov 24 04:33:18 1994 on 98fa
     1.8 +;;; Last modified Thu Feb  2 16:11:12 1995 on pajero
     1.9  ;;; $Id$
    1.10  
    1.11  ;;;
    1.12 @@ -165,30 +165,19 @@
    1.13  ;; Functions for itemize/enumerate/list environments
    1.14  ;;;
    1.15  
    1.16 -(defun YaTeX-indent-for-item ()
    1.17 -  (let (col (p (point)) begenv)
    1.18 -    (save-excursion
    1.19 -      (YaTeX-beginning-of-environment t)
    1.20 -      (setq begenv (point-end-of-line))
    1.21 -      (goto-char p)
    1.22 -      (if (YaTeX-search-active-backward "\\item" YaTeX-comment-prefix begenv t)
    1.23 -	  (setq col (current-column))))
    1.24 -    (if col (indent-to col) (YaTeX-indent-line)))
    1.25 -)
    1.26 -
    1.27  (defvar YaTeX-item-for-insert "\\item ")
    1.28  (defun YaTeX-intelligent-newline-itemize ()
    1.29    "Insert '\\item '."
    1.30 -  (YaTeX-indent-for-item)
    1.31    (insert YaTeX-item-for-insert)
    1.32 +  (YaTeX-indent-line)
    1.33  )
    1.34  (fset 'YaTeX-intelligent-newline-enumerate 'YaTeX-intelligent-newline-itemize)
    1.35  (fset 'YaTeX-intelligent-newline-list 'YaTeX-intelligent-newline-itemize)
    1.36  
    1.37  (defun YaTeX-intelligent-newline-description ()
    1.38 -  (YaTeX-indent-for-item)
    1.39    (insert "\\item[] ")
    1.40    (forward-char -2)
    1.41 +  (YaTeX-indent-line)
    1.42  )
    1.43  
    1.44  
    1.45 @@ -211,3 +200,103 @@
    1.46      (if (and env func (fboundp func))
    1.47  	(funcall func)))
    1.48  )
    1.49 +
    1.50 +;;;
    1.51 +;; Environment-specific line indenting functions
    1.52 +;;;
    1.53 +;;;###autoload
    1.54 +(defun YaTeX-indent-line-equation ()
    1.55 +  "Indent a line in equation family."
    1.56 +  (let ((p (point)) (l-r 0) right-p peol depth (mp YaTeX-environment-indent))
    1.57 +    (if (save-excursion
    1.58 +	  (beginning-of-line)
    1.59 +	  (skip-chars-forward " \t")
    1.60 +	  (looking-at "\\\\right\\b"))
    1.61 +	(progn (YaTeX-reindent
    1.62 +		(save-excursion (YaTeX-goto-corresponding-leftright)
    1.63 +				(current-column))))
    1.64 +      (save-excursion
    1.65 +	(forward-line -1)
    1.66 +	(while (and (not (bobp)) (YaTeX-on-comment-p))
    1.67 +	  (forward-line -1))
    1.68 +	;;(beginning-of-line)	;must be unnecessary
    1.69 +	(skip-chars-forward " \t")
    1.70 +	(if (eolp) (error "Math-environment can't have a null line!!"))
    1.71 +	(setq depth (current-column)
    1.72 +	      peol (point-end-of-line))
    1.73 +	(while (re-search-forward
    1.74 +		"\\\\\\(\\(left\\)\\|\\(right\\)\\)\\b" peol t)
    1.75 +	  (setq l-r (+ l-r (if (match-beginning 2) 1 -1))))
    1.76 +	(cond
    1.77 +	 ((progn (beginning-of-line)
    1.78 +		 (re-search-forward "\\\\\\\\\\s *$" (point-end-of-line) t))
    1.79 +	  ;;If previous line has `\\', this indentation is always normal.
    1.80 +	  (setq depth (+ (YaTeX-current-indentation) mp)))
    1.81 +	 ((> l-r 0)
    1.82 +	  (beginning-of-line)
    1.83 +	  (search-forward "\\left" peol)
    1.84 +	  (goto-char (1+ (match-beginning 0)))
    1.85 +	  (setq depth (current-column)))
    1.86 +	 ((< l-r 0)
    1.87 +	  (goto-char (match-beginning 0))	;should be \right
    1.88 +	  (YaTeX-goto-corresponding-leftright)
    1.89 +	  (beginning-of-line)
    1.90 +	  (skip-chars-forward " \t")
    1.91 +	  (setq depth (+ (current-column) mp))) ;+mp is good?
    1.92 +	 (t				;if \left - \right = 0
    1.93 +	  (cond
    1.94 +	   ((re-search-forward "\\\\\\\\\\s *$" peol t)
    1.95 +	    (setq depth (+ (YaTeX-current-indentation) mp)))
    1.96 +	   ((re-search-forward "\\\\end{" peol t)
    1.97 +	    nil)			;same indentation as previous line's
    1.98 +	   ((re-search-forward "\\\\begin{" peol t)
    1.99 +	    (setq depth (+ depth mp)))
   1.100 +	   (t
   1.101 +	    (or (bobp) (forward-line -1))
   1.102 +	    (cond
   1.103 +	     ((re-search-forward
   1.104 +	       "\\\\\\\\\\s *$\\|\\\\begin{" (point-end-of-line) t)
   1.105 +	      (setq depth (+ depth mp)))
   1.106 +	     )))))
   1.107 +	(goto-char p))
   1.108 +      (YaTeX-reindent depth))))
   1.109 +
   1.110 +;;;###autoload
   1.111 +(defun YaTeX-goto-corresponding-leftright ()
   1.112 +  "Go to corresponding \left or \right.
   1.113 +Note that this function assumes the corresponding \left\right
   1.114 +is on another line."
   1.115 +  (let ((YaTeX-struct-begin "\\left%1")
   1.116 +	(YaTeX-struct-end "\\right%1")
   1.117 +	(YaTeX-struct-name-regexp "[][(){}.|]"))
   1.118 +    (YaTeX-goto-corresponding-environment t)))
   1.119 +
   1.120 +;;;
   1.121 +;; Functions for formatting region being enclosed with environment
   1.122 +;;;
   1.123 +; These functions must take two argument; region-beginning, region-end.
   1.124 +
   1.125 +(defun YaTeX-enclose-equation (beg end)
   1.126 +  (goto-char beg)
   1.127 +  (save-restriction
   1.128 +    (let (m0 bsl)
   1.129 +      (narrow-to-region beg end)
   1.130 +      (while (YaTeX-re-search-active-forward
   1.131 +	      "\\(\\$\\)" YaTeX-comment-prefix nil t)
   1.132 +	(goto-char (setq m0 (match-beginning 0)))
   1.133 +	(setq bsl 0)
   1.134 +	(if (and (not (bobp)) (= (char-after (1- (point))) ?\\ ))
   1.135 +	    (while (progn (forward-char -1) (= (char-after (point)) ?\\ ))
   1.136 +	      (setq bsl (1+ bsl))))
   1.137 +	(goto-char m0)
   1.138 +	(if (= 0 (% bsl 2))
   1.139 +	    (delete-char 1)
   1.140 +	  (forward-char 1))))))
   1.141 +
   1.142 +(fset 'YaTeX-enclose-eqnarray 'YaTeX-enclose-equation)
   1.143 +(fset 'YaTeX-enclose-eqnarray* 'YaTeX-enclose-equation)
   1.144 +
   1.145 +(defun YaTeX-enclose-verbatim (beg end)) ;do nothing when enclose verbatim
   1.146 +(fset 'YaTeX-enclose-verbatim* 'YaTeX-enclose-verbatim)
   1.147 +
   1.148 +(provide 'yatexenv)