branch: externals/auctex
commit 686a8ed3b0cf091bb24d3db826a3f8ad1047f6c0
Author: Ikumi Keita <[email protected]>
Commit: Ikumi Keita <[email protected]>
Elaborate LaTeX math insertion command
* latex.el (LaTeX-math-insert): Put the point after the closing dollar
sign when appropriate. This fixes bug#35128.
In addtion, wrap the text in the active region suitably.
---
latex.el | 30 +++++++++++++++++++++++++-----
1 file changed, 25 insertions(+), 5 deletions(-)
diff --git a/latex.el b/latex.el
index d260006..510d4bf 100644
--- a/latex.el
+++ b/latex.el
@@ -5362,11 +5362,31 @@ commands are defined:
"Insert \\STRING{}. If DOLLAR is non-nil, put $'s around it.
If `TeX-electric-math' is non-nil wrap that symbols around the
string."
- (when dollar
- (insert (or (car TeX-electric-math) "$"))
- (save-excursion
- (insert (or (cdr TeX-electric-math) "$"))))
- (funcall LaTeX-math-insert-function string))
+ (let ((active (TeX-active-mark))
+ m closer)
+ (if (and active (> (point) (mark)))
+ (exchange-point-and-mark))
+ (when dollar
+ (insert (or (car TeX-electric-math) "$"))
+ (save-excursion
+ (if active (goto-char (mark)))
+ ;; Store closer string for later reference.
+ (setq closer (or (cdr TeX-electric-math) "$"))
+ (insert closer)
+ ;; Set temporal marker to decide whether to put the point
+ ;; after the math mode closer or not.
+ (setq m (point-marker))))
+ (funcall LaTeX-math-insert-function string)
+ (when dollar
+ ;; If the above `LaTeX-math-insert-function' resulted in
+ ;; inserting, e.g., a pair of "\langle" and "\rangle" by
+ ;; typing "`(", keep the point between them. Otherwise
+ ;; move the point after the math mode closer.
+ (if (= m (+ (point) (length closer)))
+ (goto-char m))
+ ;; Make temporal marker point nowhere not to slow down the
+ ;; subsequent editing in the buffer.
+ (set-marker m nil))))
(defun LaTeX-math-cal (char dollar)
"Insert a {\\cal CHAR}. If DOLLAR is non-nil, put $'s around it.