yatex
diff yatexmth.el @ 77:1b172d26b55e
Fix auto-fill movement on Emacs21.
Fix YaTeX:ref.
Support jump/change on AMS-LaTeX's parentheses.
author | yuuji |
---|---|
date | Thu, 01 May 2003 13:38:27 +0000 |
parents | 0aaebd07dad0 |
children | 9b4354af748c |
line diff
1.1 --- a/yatexmth.el Mon Dec 25 10:19:28 2000 +0000 1.2 +++ b/yatexmth.el Thu May 01 13:38:27 2003 +0000 1.3 @@ -1,8 +1,8 @@ 1.4 ;;; -*- Emacs-Lisp -*- 1.5 ;;; YaTeX math-mode-specific functions. 1.6 ;;; yatexmth.el 1.7 -;;; (c)1993-2000 by HIROSE Yuuji [yuuji@yatex.org] 1.8 -;;; Last modified Tue Dec 19 11:03:51 2000 on buell 1.9 +;;; (c)1993-2003 by HIROSE Yuuji [yuuji@yatex.org] 1.10 +;;; Last modified Sun Mar 30 19:56:00 2003 on firestorm 1.11 ;;; $Id$ 1.12 1.13 ;;; [Customization guide] 1.14 @@ -466,6 +466,10 @@ 1.15 (defun YaTeX-math-get-sign (list) 1.16 (YaTeX-math-gets (car (cdr-safe (cdr-safe list)))) 1.17 ) 1.18 +(defvar YaTeX-math-section-type-regexp 1.19 + "eqn\\\\\\sw+\\b" 1.20 + "*Regexp of section-type math-mode macro") 1.21 + 1.22 (defun YaTeX-in-math-mode-p () 1.23 "If current position is supposed to be in LaTeX-math-mode, return t." 1.24 (or (YaTeX-quick-in-environment-p 1.25 @@ -477,7 +481,7 @@ 1.26 "gather*" "aligned*" "gathered" "gathered*" "alignat" 1.27 "equation*" "cases" 1.28 "alignat*" "xalignat" "xalignat*" "xxalignat" "xxalignat*")))) 1.29 - (let*((p (point)) (nest 0) me0 1.30 + (let*((p (point)) (nest 0) me0 r 1.31 (delim (concat YaTeX-sectioning-regexp "\\|^$\\|^\C-l")) 1.32 (boundary 1.33 (save-excursion 1.34 @@ -503,6 +507,11 @@ 1.35 (setq nest (1- nest)))))) 1.36 (if (< nest 0) (throw 'open t)))) 1.37 t) 1.38 + ((and (setq r (YaTeX-on-section-command-p 1.39 + YaTeX-math-section-type-regexp)) 1.40 + (numberp r) 1.41 + (> r 0)) 1.42 + t) 1.43 (t (catch 'dollar 1.44 (while ;(search-backward "$" boundary t);little bit fast. 1.45 (YaTeX-re-search-active-backward ;;;;;; Too slow??? 1.46 @@ -824,8 +833,9 @@ 1.47 (if (<= move (length (match-string 0))) 1.48 (match-string 0))))))) 1.49 1.50 -(defun YaTeX-goto-open-paren () 1.51 - "Jump to the exact position of open parenthesis" 1.52 +(defun YaTeX-goto-open-paren (&optional jumpto-co) 1.53 + "Jump to the exact position of open parenthesis. 1.54 +If optional argument JUMPTO-CO is non-nil, goto corresponding parentheses." 1.55 (interactive) 1.56 (let ((paren) 1.57 (backslash-syntax (char-to-string (char-syntax ?\\)))) 1.58 @@ -833,14 +843,30 @@ 1.59 (if (string-match "(\\|{\\|\\[" paren (1- (length paren))) 1.60 (progn 1.61 (re-search-forward "(\\|{\\|\\[" (+ (point) (length paren)) t) 1.62 - (backward-char)) 1.63 + (backward-char) 1.64 + (if jumpto-co 1.65 + (unwind-protect 1.66 + (progn 1.67 + (modify-syntax-entry ?\\ " ") 1.68 + (forward-list) 1.69 + (backward-char)) 1.70 + (modify-syntax-entry ?\\ backslash-syntax))) 1.71 + (point)) 1.72 (re-search-forward ")\\|}\\|\\]" (+ (point) (length paren)) t) 1.73 (unwind-protect 1.74 (progn 1.75 (modify-syntax-entry ?\\ " ") 1.76 - (backward-list)) 1.77 + (backward-list) 1.78 + (point)) 1.79 (modify-syntax-entry ?\\ backslash-syntax)))))) 1.80 1.81 +;;;###autoload 1.82 +(defun YaTeX-goto-corresponding-paren () 1.83 + "Go to corresponding mathematical parentheses." 1.84 + (if (YaTeX-on-parenthesis-p) 1.85 + (YaTeX-goto-open-paren t) 1.86 + nil)) 1.87 + 1.88 (defun YaTeX-change-parentheses () 1.89 "Change the size of parentheses, braces, and brackets of AMS-LaTeX." 1.90 (interactive) 1.91 @@ -855,6 +881,7 @@ 1.92 (length (+ mod-length paren-length)) ;; length of whole string 1.93 (big-p t) ;; flag whether new modifier is "[Bb]ig+" or not. 1.94 size ;; left, big, Big etc. 1.95 + type ;; parentheses type 1.96 lr ;; "l" or "r". 1.97 char newsize newsize-length 1.98 (backslash-syntax (char-to-string (char-syntax ?\\))) 1.99 @@ -876,7 +903,7 @@ 1.100 (while (not newsize) 1.101 (message (format (concat "Change from %s: " 1.102 "l(big) L(Big) h(bigg) H(Bigg) " 1.103 - "r(left-right) n(NONE) ") size)) 1.104 + "r(left-right) n(NONE) ( { [") size)) 1.105 (setq char (read-char) 1.106 newsize (cond ((char-equal char ?l) "\\big") 1.107 ((char-equal char ?L) "\\Big") 1.108 @@ -884,28 +911,43 @@ 1.109 ((char-equal char ?H) "\\Bigg") 1.110 ((char-equal char ?r) 1.111 (setq big-p nil) "\\left") 1.112 + ((memq char '(?\( ?\))) 1.113 + (setq big-p nil type '("(" . ")")) "") 1.114 + ((memq char '(?\{ ?\})) 1.115 + (setq big-p nil type '("\\{" . "\\}")) "") 1.116 + ((memq char '(?\[ ?\])) 1.117 + (setq big-p nil type '("[" . "]")) "") 1.118 ((char-equal char ?n) 1.119 (setq big-p nil) "") 1.120 (t nil)) 1.121 newsize-length (length newsize))) 1.122 (YaTeX-goto-open-paren) 1.123 (forward-char) 1.124 - (delete-region (- (point) length) (- (point) paren-length)) 1.125 - (backward-char paren-length) 1.126 + (cond 1.127 + (type 1.128 + (delete-region (point) (- (point) paren-length)) 1.129 + (save-excursion (insert (car type)))) 1.130 + (t 1.131 + (delete-region (- (point) length) (- (point) paren-length)) 1.132 + (backward-char paren-length))) 1.133 (insert-string newsize) 1.134 (if big-p (insert ?l)) 1.135 - (forward-char (1- paren-length)) 1.136 (unwind-protect 1.137 (progn 1.138 (modify-syntax-entry ?\\ " ") 1.139 (forward-list) 1.140 (if (string= size "left-right") (setq length (1+ length))) 1.141 (if (eq char ?r) (setq newsize "\\right")) 1.142 - (delete-region (- (point) length) (- (point) paren-length)) 1.143 - (backward-char paren-length) 1.144 - (insert-string newsize) 1.145 - (if big-p (insert ?r)) 1.146 - (forward-char paren-length) 1.147 + (cond 1.148 + (type 1.149 + (delete-region (point) (- (point) paren-length)) 1.150 + (insert (cdr type))) 1.151 + (t 1.152 + (delete-region (- (point) length) (- (point) paren-length)) 1.153 + (backward-char paren-length) 1.154 + (insert-string newsize) 1.155 + (if big-p (insert ?r)) 1.156 + (forward-char paren-length))) 1.157 (if (string= lr "l") (backward-list))) 1.158 (modify-syntax-entry ?\\ backslash-syntax)) 1.159 t)))