auctex
[Top][All Lists]
Advanced

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

Re: [AUCTeX] Wrong Placement of \end{tabularx}


From: Matthew Leach
Subject: Re: [AUCTeX] Wrong Placement of \end{tabularx}
Date: Wed, 29 Oct 2014 14:38:19 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Hi Mosè,

Mosè Giordano <address@hidden> writes:

[...]

> How about moving the body of that lambda inside `LaTeX-indent-tabular'
> function to let-bind a `tabular-like-end' variable?  In this way the
> variable `LaTeX--tabular-like-end' would not be needed anymore; the
> only drawback is a little performance regression.  Otherwise a new
> function to add the environment to the list and update
> `LaTeX--tabular-like-end' at once.

I believe the attached patch should do the trick.

Comments welcome.
-- 
Matt

Changelog Entry:

2014-10-29  Matthew Leach  <address@hidden>

        * latex.el (LaTeX-indent-environment-list): Remove setter
        lambda.
        (LaTeX--tabular-like-end): Remove variable.
        (LaTeX-indent-tabular): Move setter function from
        LaTeX-indent-environment-list to generate tabular-end regex when
        called.


diff --git a/latex.el b/latex.el
index 565807b..91204e9 100644
--- a/latex.el
+++ b/latex.el
@@ -2850,25 +2850,7 @@ The second element in each entry is the function to 
calculate the
 indentation level in columns."
     :group 'LaTeX-indentation
     :type '(repeat (list (string :tag "Environment")
-                        (option function)))
-    :set (lambda (symbol value)
-           (setq LaTeX--tabular-like-end
-                 (format "\\\\end{%s}"
-                         (regexp-opt
-                          (let (out)
-                            (mapc (lambda (x)
-                                    (when (eq (cadr x) 'LaTeX-indent-tabular)
-                                      (push (car x) out)))
-                                  value)
-                            out))))
-           (set-default symbol value)))
-
-(defvar LaTeX--tabular-like-end nil
-  "A regexp matching tabular-like environment ends.
-Those will be aligned with `LaTeX-indent-tabular'.
-
-Do not set this variable. This variable is auto-set
-by customizing `LaTeX-indent-environment-list'.")
+                        (option function))))
 
 (defcustom LaTeX-indent-environment-check t
   "*If non-nil, check for any special environments."
@@ -6309,23 +6291,33 @@ i.e. you do _not_ have to cater for this yourself by 
adding \\\\' or $."
   "Return indent column for the current tabular-like line."
   (destructuring-bind (beg-pos . beg-col)
       (LaTeX-env-beginning-pos-col)
-    (cond ((looking-at LaTeX--tabular-like-end)
-           beg-col)
-
-          ((looking-at "\\\\\\\\")
-           (+ 2 beg-col))
-
-          ((looking-at "&")
-           (LaTeX-hanging-ampersand-position))
-
-          (t
-           (+ 2
-              (let ((any-col (save-excursion
-                               (when (re-search-backward "\\\\\\\\\\|&" 
beg-pos t)
-                                 (current-column)))))
-                (if (and any-col (string= "&" (match-string 0)))
-                    any-col
-                  beg-col)))))))
+    (let ((tabular-like-end-regex
+           (format "\\\\end{%s}"
+                   (regexp-opt
+                    (let (out)
+                      (mapcar (lambda (x)
+                              (when (eq (cadr x) 'LaTeX-indent-tabular)
+                                (push (car x) out)))
+                              LaTeX-indent-environment-list)
+                      (pp out)
+                      out)))))
+      (cond ((looking-at tabular-like-end-regex)
+             beg-col)
+
+            ((looking-at "\\\\\\\\")
+             (+ 2 beg-col))
+
+            ((looking-at "&")
+             (LaTeX-hanging-ampersand-position))
+
+            (t
+             (+ 2
+                (let ((any-col (save-excursion
+                                 (when (re-search-backward "\\\\\\\\\\|&" 
beg-pos t)
+                                   (current-column)))))
+                  (if (and any-col (string= "&" (match-string 0)))
+                      any-col
+                    beg-col))))))))
 
 (provide 'latex)
 

reply via email to

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