auctex-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/auctex f9b378a45c 70/76: Support detached arguments


From: Tassilo Horn
Subject: [elpa] externals/auctex f9b378a45c 70/76: Support detached arguments
Date: Fri, 13 Jan 2023 14:31:07 -0500 (EST)

branch: externals/auctex
commit f9b378a45c89b16a183f46830e4c7ec7b2aec7c5
Author: Ikumi Keita <ikumi@ikumi.que.jp>
Commit: Ikumi Keita <ikumi@ikumi.que.jp>

    Support detached arguments
    
    * tex.el (TeX-find-macro-boundaries): Skip white spaces between a
    macro argument and comment starter.
    Fix doc string.
    Add FIXME comment.
    (TeX-find-macro-end-helper): Skip white spaces at the beginning of
    line even when the preceding line doesn't end with comment.
    * tests/tex/navigation.el (TeX-check-f-m-b): New function.
    (TeX-find-macro-boundaries-detached-arg): New test.
    (TeX-find-macro-end-helper): Integrate similar tests into one test.
    (TeX-check-f-m-e-h): Adapt according to the above integration.
---
 tests/tex/navigation.el | 75 ++++++++++++++++++++++++++++++++++++-------------
 tex.el                  | 17 ++++++++---
 2 files changed, 69 insertions(+), 23 deletions(-)

diff --git a/tests/tex/navigation.el b/tests/tex/navigation.el
index 4debb44f5c..45071bf2b8 100644
--- a/tests/tex/navigation.el
+++ b/tests/tex/navigation.el
@@ -1,6 +1,6 @@
 ;;; navigation.el --- tests for navigation function in TeX buffer  -*- 
lexical-binding: t; -*-
 
-;; Copyright (C) 2019-2021  Free Software Foundation, Inc.
+;; Copyright (C) 2019-2023  Free Software Foundation, Inc.
 
 ;; This file is part of AUCTeX.
 
@@ -26,29 +26,66 @@
 
 (defun TeX-check-f-m-e-h (string &optional position)
   "Check whether `TeX-find-macro-end-helper' works for exceptional case."
+  (erase-buffer)
+  (insert string)
+  (should (= (or position (point-max))
+             (TeX-find-macro-end-helper (point-min)))))
+
+(ert-deftest TeX-find-macro-end-helper ()
   (with-temp-buffer
-    (insert string)
-    (should (= (or position (point-max))
-               (TeX-find-macro-end-helper (point-min))))))
+    (LaTeX-mode)
+
+    ;; single macro ending at EOB
+    (TeX-check-f-m-e-h "\\foo")
+
+    ;; curly braces ending at EOB
+    (TeX-check-f-m-e-h "\\foo{bar}")
+
+    ;; curly brace failing to close at EOB
+    (TeX-check-f-m-e-h "\\foo{bar")
+
+    ;; square brackets ending at EOB
+    (TeX-check-f-m-e-h "\\foo{bar}[baz]")
+
+    ;; square bracket failing to close at EOB
+    (TeX-check-f-m-e-h "\\foo{bar}[baz" (1+ (length "\\foo{bar}")))))
+
+(defun TeX-check-f-m-b (string &optional chars)
+  "Check whether `TeX-find-macro-boundaries' works for exceptional case."
+  (erase-buffer)
+  (insert string)
+  (if chars (backward-char chars))
+  (let ((result (TeX-find-macro-boundaries)))
+    (should (= (point-min)
+               (car result)))
+    (should (= (point-max)
+               (cdr result)))))
+
+(ert-deftest TeX-find-macro-boundaries-detached-arg ()
+  (with-temp-buffer
+    ;; necessary to set comment syntax properly
+    (LaTeX-mode)
+
+    ;; argument separated by newline
+    (TeX-check-f-m-e-h "\\foo{bar}
+{baz}")
+
+    (TeX-check-f-m-e-h "\\foo{bar}
+  {baz}")
 
-(ert-deftest TeX-find-macro-end-helper-single ()
-  ;; single macro ending at EOB
-  (TeX-check-f-m-e-h "\\foo"))
+    (TeX-check-f-m-e-h "\\foo{bar} % comment
+  {baz}")
 
-(ert-deftest TeX-find-macro-end-helper-curly ()
-  ;; curly braces ending at EOB
-  (TeX-check-f-m-e-h "\\foo{bar}"))
+    (TeX-check-f-m-b "\\foo{bar}
+{baz}" 2)
 
-(ert-deftest TeX-find-macro-end-helper-curly-fail ()
-  ;; curly brace failing to close at EOB
-  (TeX-check-f-m-e-h "\\foo{bar"))
+    (TeX-check-f-m-b "\\foo{bar}
+  {baz}" 2)
 
-(ert-deftest TeX-find-macro-end-helper-square ()
-  ;; square brackets ending at EOB
-  (TeX-check-f-m-e-h "\\foo{bar}[baz]"))
+    (TeX-check-f-m-b "\\foo{bar} % comment
+  {baz}" 2)
 
-(ert-deftest TeX-find-macro-end-helper-square-fail ()
-  ;; square bracket failing to close at EOB
-  (TeX-check-f-m-e-h "\\foo{bar}[baz" (1+ (length "\\foo{bar}"))))
+    (TeX-check-f-m-b "\\foo{bar}% comment
+  {baz}" 2)))
 
 ;;; navigation.el ends here
diff --git a/tex.el b/tex.el
index e032d8c5e5..456c0310a1 100644
--- a/tex.el
+++ b/tex.el
@@ -1,6 +1,6 @@
 ;;; tex.el --- Support for TeX documents.  -*- lexical-binding: t; -*-
 
-;; Copyright (C) 1985-2022 Free Software Foundation, Inc.
+;; Copyright (C) 1985-2023 Free Software Foundation, Inc.
 
 ;; Maintainer: auctex-devel@gnu.org
 ;; Keywords: tex
@@ -5573,10 +5573,18 @@ in the buffer."
   (TeX-find-balanced-brace -1 depth limit))
 
 (defun TeX-find-macro-boundaries (&optional lower-bound)
-  "Return a list containing the start and end of a macro.
+  "Return a cons containing the start and end of a macro.
 If LOWER-BOUND is given, do not search backward further than this
 point in buffer.  Arguments enclosed in brackets or braces are
 considered part of the macro."
+  ;; FIXME: Pay attention to `texmathp-allow-detached-args' and
+  ;; `reftex-allow-detached-macro-args'.
+  ;; Should we handle cases like \"{o} and \\[3mm] (that is, a macro
+  ;; whose name is a symbol and takes some arguments) as well?  Note
+  ;; that amsmath package arranges the macro \\ so that white spaces
+  ;; between \\ and [something] prevents the latter to be interpreted
+  ;; as an optional argument.  mathtools package arranges some
+  ;; environments including gathered similarly.
   (save-restriction
     (when lower-bound
       (narrow-to-region lower-bound (point-max)))
@@ -5603,6 +5611,7 @@ considered part of the macro."
                          (condition-case nil (backward-sexp)
                            (error (throw 'abort nil)))
                          (forward-comment -1)
+                         (skip-chars-backward " \t")
                          (and (memq (char-before) '(?\] ?\}))
                               (not (TeX-escaped-p (1- (point)))))))
                 (skip-chars-backward "A-Za-z@*")
@@ -5632,7 +5641,7 @@ those will be considered part of it."
         (while (not (eobp))
           (cond
            ;; Skip over pairs of square brackets
-           ((or (looking-at "[ \t]*\n?\\(\\[\\)") ; Be conservative: Consider
+           ((or (looking-at "[ \t]*\n?[ \t]*\\(\\[\\)") ; Be conservative: 
Consider
                                         ; only consecutive lines.
                 (and (looking-at (concat "[ \t]*" TeX-comment-start-regexp))
                      (save-excursion
@@ -5643,7 +5652,7 @@ those will be considered part of it."
                 (forward-sexp)
               (scan-error (throw 'found (point)))))
            ;; Skip over pairs of curly braces
-           ((or (looking-at "[ \t]*\n?{") ; Be conservative: Consider
+           ((or (looking-at "[ \t]*\n?[ \t]*{") ; Be conservative: Consider
                                         ; only consecutive lines.
                 (and (looking-at (concat "[ \t]*" TeX-comment-start-regexp))
                      (save-excursion




reply via email to

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