emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/textmodes/tex-mode.el,v


From: Glenn Morris
Subject: [Emacs-diffs] Changes to emacs/lisp/textmodes/tex-mode.el,v
Date: Fri, 21 Sep 2007 07:56:11 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Glenn Morris <gm>       07/09/21 07:56:11

Index: tex-mode.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/textmodes/tex-mode.el,v
retrieving revision 1.202
retrieving revision 1.203
diff -u -b -r1.202 -r1.203
--- tex-mode.el 21 Sep 2007 03:07:36 -0000      1.202
+++ tex-mode.el 21 Sep 2007 07:56:11 -0000      1.203
@@ -1403,7 +1403,7 @@
 
 (defun tex-next-unmatched-eparen (otype)
   "Leave point after the next unmatched escaped closing parenthesis.
-The string OPAREN is an opening parenthesis type: `(', `{', or `['."
+The string OTYPE is an opening parenthesis type: `(', `{', or `['."
   (condition-case nil
       (let ((ctype (char-to-string (cdr (aref (syntax-table)
                                              (string-to-char otype))))))
@@ -1416,6 +1416,19 @@
     (wrong-type-argument (error "Unknown opening parenthesis type: %s" otype))
     (search-failed (error "Couldn't find closing escaped paren"))))
 
+(defun tex-last-unended-eparen (ctype)
+  "Leave point at the start of the last unended escaped opening parenthesis.
+The string CTYPE is a closing parenthesis type:  `)', `}', or `]'."
+  (condition-case nil
+      (let ((otype (char-to-string (cdr (aref (syntax-table)
+                                             (string-to-char ctype))))))
+       (while (and (tex-search-noncomment
+                    (re-search-backward (format "\\\\[%s%s]" ctype otype)))
+                   (looking-at (format "\\\\%s" (regexp-quote ctype))))
+         (tex-last-unended-eparen ctype)))
+    (wrong-type-argument (error "Unknown opening parenthesis type: %s" ctype))
+    (search-failed (error "Couldn't find unended escaped paren"))))
+
 (defun tex-goto-last-unclosed-latex-block ()
   "Move point to the last unclosed \\begin{...}.
 Mark is left at original location."
@@ -1427,16 +1440,20 @@
     (push-mark)
     (goto-char spot)))
 
+;; Don't think this one actually _needs_ (for the purposes of
+;; tex-mode) to handle escaped parens.
 (defun latex-backward-sexp-1 ()
-  "Like (backward-sexp 1) but aware of multi-char elements."
+  "Like (backward-sexp 1) but aware of multi-char elements and escaped parens."
   (let ((pos (point))
        (forward-sexp-function))
     (backward-sexp 1)
-    (if (looking-at "\\\\begin\\>")
+    (cond ((looking-at "\\\\\\(begin\\>\\|[[({]\\)")
        (signal 'scan-error
                (list "Containing expression ends prematurely"
-                     (point) (prog1 (point) (goto-char pos))))
-      (when (eq (char-after) ?{)
+                        (point) (prog1 (point) (goto-char pos)))))
+         ((looking-at "\\\\\\([])}]\\)")
+          (tex-last-unended-eparen (match-string 1)))
+         ((eq (char-after) ?{)
        (let ((newpos (point)))
          (when (ignore-errors (backward-sexp 1) t)
            (if (or (looking-at "\\\\end\\>")
@@ -1447,6 +1464,8 @@
 
 ;; Note this does not handle things like mismatched brackets inside
 ;; begin/end blocks.
+;; Needs to handle escaped parens for tex-validate-*.
+;; http://lists.gnu.org/archive/html/bug-gnu-emacs/2007-09/msg00038.html
 (defun latex-forward-sexp-1 ()
   "Like (forward-sexp 1) but aware of multi-char elements and escaped parens."
   (let ((pos (point))
@@ -1465,6 +1484,8 @@
        ((looking-at "\\\\begin\\>")
        (goto-char (match-end 0))
        (tex-next-unmatched-end))
+       ;; A better way to handle this, \( .. \) etc, is probably to
+       ;; temporarily change the syntax of the \ in \( to punctuation.
        ((looking-back "\\\\[])}]")
        (signal 'scan-error
                (list "Containing expression ends prematurely"




reply via email to

[Prev in Thread] Current Thread [Next in Thread]