auctex-diffs
[Top][All Lists]
Advanced

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

master 74844995: New option `TeX-refuse-unmatched-dollar'


From: Ikumi Keita
Subject: master 74844995: New option `TeX-refuse-unmatched-dollar'
Date: Fri, 4 Nov 2022 11:56:14 -0400 (EDT)

branch: master
commit 748449959c74220b40aff5bd69676bc0722ec8a9
Author: Ikumi Keita <ikumi@ikumi.que.jp>
Commit: Ikumi Keita <ikumi@ikumi.que.jp>

    New option `TeX-refuse-unmatched-dollar'
    
    * tex.el (TeX-refuse-unmatched-dollar): New option.
    (TeX-insert-dollar): When the new option is enabled, retain the former
    behavior.
    Arrange the doc string.
    * doc/auctex.texi (Quotes):
    * doc/changes.texi:
    Mention the change in the behavior of `TeX-insert-dollar'.
---
 doc/auctex.texi  | 14 ++++++++++++++
 doc/changes.texi |  9 +++++++++
 tex.el           | 26 +++++++++++++++++++++++---
 3 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/doc/auctex.texi b/doc/auctex.texi
index 5f8c7257..682e4ed8 100644
--- a/doc/auctex.texi
+++ b/doc/auctex.texi
@@ -468,6 +468,20 @@ following to your init file
                           (cons "\\(" "\\)"))))
 @end lisp
 
+Math mode which didn't start with dollar(s) shouldn't be closed with dollar.
+@defopt TeX-refuse-unmatched-dollar
+This option determines the behavior when the user types @kbd{$} at a
+position where @AUCTeX{} thinks that it is in math mode which didn't start
+with dollar(s).
+
+When this option is @code{nil}, @AUCTeX{} behaves in the same way as
+non-math mode, assuming that the user knows it isn't in math mode
+actually.  This is the default.
+
+When this option is non-@code{nil}, @AUCTeX{} refuses to insert @samp{$}
+to prevent unmatched dollar.
+@end defopt
+
 Note that Texinfo mode does nothing special for @kbd{$}.  It inserts
 dollar sign(s) just in the same way as the other normal keys do.
 
diff --git a/doc/changes.texi b/doc/changes.texi
index 67e9e458..d6973153 100644
--- a/doc/changes.texi
+++ b/doc/changes.texi
@@ -11,6 +11,15 @@
 @heading News since last release
 
 @itemize @bullet
+@item
+@AUCTeX{} no longer refuses to insert dollar sign when you type @kbd{$} at
+point where @AUCTeX{} thinks the current math mode didn't start with
+dollar(s).  @AUCTeX{} assumes the user knows that it isn't in math mode
+actually.
+
+You can keep the former behavior by enabling the new customize option
+@code{TeX-refuse-unmatched-dollar}.
+
 @item
 @AUCTeX{} supports completion-at-point of macro and environment arguments
 in @LaTeX{} buffers.  The responsible function recognizes the argument
diff --git a/tex.el b/tex.el
index 9a57d458..976fafba 100644
--- a/tex.el
+++ b/tex.el
@@ -5939,9 +5939,24 @@ point.  You can choose between \"$...$\" and 
\"\\(...\\)\"."
                        (string :tag "Insert before point")
                        (string :tag "Insert after point"))))
 
+(defcustom TeX-refuse-unmatched-dollar nil
+  "When non-nil, don't insert unmatched dollar sign.
+That is, `TeX-insert-dollar' refuses to insert \"$\" when
+`texmathp' tells that the current position is in math mode which
+didn't start with dollar(s).
+
+When nil, `TeX-insert-dollar' assumes the user knows that the
+current position is not in math mode actually and behaves in the
+same way as non-math mode."
+  :group 'TeX-macro
+  :type 'boolean)
+
 (defun TeX-insert-dollar (&optional arg)
   "Insert dollar sign.
 
+If current math mode was not entered with a dollar, refuse to
+insert one when `TeX-refuse-unmatched-dollar' is non-nil.
+
 Show matching dollar sign if this dollar sign ends the TeX math
 mode and `blink-matching-paren' is non-nil.
 
@@ -5994,10 +6009,15 @@ With optional ARG, insert that many dollar signs."
             (message "Matches %s"
                      (buffer-substring
                       (point) (progn (end-of-line) (point))))))))
+
+     ;; Math mode was not entered with dollar according to `texmathp'.
+     (TeX-refuse-unmatched-dollar
+      ;; We trust `texmathp' and refuse to finish it with one.
+      (message "Math mode started with `%s' cannot be closed with dollar"
+               (car texmathp-why)))
      (t
-      ;; Math mode was not entered with dollar - we assume that
-      ;; `texmathp' was wrong and behave as if not in math
-      ;; mode. (bug#57626)
+      ;; We assume that `texmathp' was wrong and behave as if not in
+      ;; math mode. (bug#57626)
       (TeX--insert-dollar-1))))
    (t
     ;; Just somewhere in the text.



reply via email to

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