branch: externals/auctex commit 2f1369fc0115addb375df0064460178705ff658c Author: Ikumi Keita <ik...@ikumi.que.jp> Commit: Ikumi Keita <ik...@ikumi.que.jp>
Fix false negative of texmathp (bug#41559) * texmathp.el (texmathp-compile): Fix `texmathp-onoff-regexp' to allow switch to begin at (point-min). Use `regexp-opt' instead of `mapconcat'+`regexp-quote'. (texmathp): Use `>=' instead of `>' so that match is updated even when arg-on or sw-on begins at (point-min). * tests/latex/texmathp-test.el: New test. --- tests/latex/texmathp-test.el | 51 ++++++++++++++++++++++++++++++++++++++++++++ texmathp.el | 17 ++++++++------- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/tests/latex/texmathp-test.el b/tests/latex/texmathp-test.el new file mode 100644 index 0000000..a1313b9 --- /dev/null +++ b/tests/latex/texmathp-test.el @@ -0,0 +1,51 @@ +;;; texmathp-test.el --- tests for texmathp + +;; Copyright (C) 2020 Free Software Foundation, Inc. + +;; This file is part of AUCTeX. + +;; AUCTeX is free software; you can redistribute it and/or modify it +;; under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. + +;; AUCTeX is distributed in the hope that it will be useful, but +;; WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;; General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with AUCTeX; see the file COPYING. If not, write to the Free +;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +;; 02110-1301, USA. + +;;; Code: + +(require 'ert) +(require 'latex) +(require 'texmathp) + +;; bug#41559 +(ert-deftest texmathp-bob () + "Test math expressions beginning at BOB are identified correctly." + (should (with-temp-buffer + (insert "\\(") + (LaTeX-mode) + (texmathp))) + + (should (with-temp-buffer + (insert "\\[") + (LaTeX-mode) + (texmathp))) + + (should (with-temp-buffer + (insert "\\ensuremath{") + (LaTeX-mode) + (texmathp))) + + (should (with-temp-buffer + (insert "$") + (LaTeX-mode) + (texmathp)))) + +;;; texmathp-test.el ends here diff --git a/texmathp.el b/texmathp.el index ba5aba3..723623b 100644 --- a/texmathp.el +++ b/texmathp.el @@ -185,13 +185,11 @@ customize (customize calls it when setting the variable)." ((memq type '(sw-toggle)) 'togglers))) (set var (cons (car entry) (symbol-value var)))) (setq texmathp-onoff-regexp - (concat "[^\\\\]\\(" - (mapconcat 'regexp-quote switches "\\|") - "\\)") + (concat "\\(?:[^\\\\]\\|\\`\\)" + (regexp-opt switches t)) texmathp-toggle-regexp - (concat "\\([^\\\\\\$]\\|\\`\\)\\(" - (mapconcat 'regexp-quote togglers "\\|") - "\\)")))) + (concat "\\([^\\\\\\$]\\|\\`\\)" + (regexp-opt togglers t))))) (defcustom texmathp-tex-commands nil "List of environments and macros influencing (La)TeX math mode. @@ -287,14 +285,17 @@ See the variable `texmathp-tex-commands' about which commands are checked." ;; Select the nearer match (and env-match (setq match env-match)) - (and mac-match (> (cdr mac-match) (cdr match)) (setq match mac-match)) + ;; Use `>=' instead of `>' in case called inside \ensuremath{..} + ;; beginning just at (point-min). + (and mac-match (>= (cdr mac-match) (cdr match)) (setq match mac-match)) (setq math-on (memq (nth 1 (assoc (car match) texmathp-tex-commands1)) '(env-on arg-on))) ;; Check for switches (and (not math-on) (setq sw-match (texmathp-match-switch bound)) - (> (cdr sw-match) (cdr match)) + ;; Use `>=' instead of `>' by similar reason as above. (bug#41559) + (>= (cdr sw-match) (cdr match)) (eq (nth 1 (assoc (car sw-match) texmathp-tex-commands1)) 'sw-on) (setq match sw-match math-on t))