[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [BUG] issue with texmathp [9.6 (release_9.6-22-g78d283 @ /home/jds66
From: |
Ihor Radchenko |
Subject: |
Re: [BUG] issue with texmathp [9.6 (release_9.6-22-g78d283 @ /home/jds6696/.emacs.d/straight/build/org-mode/)] |
Date: |
Sat, 07 Jan 2023 11:23:07 +0000 |
Daniel Fleischer <danflscr@gmail.com> writes:
> I just found this thread after math-related things stopped working. I
> have two use cases that don't work now:
>
> 1. Inserting a dollar pair $$ using `cdlatex-dollar` (it thinks we're
> inside a math environment).
>
> 2. Inserting of cdlatex environments using their built-in completions, e.g.
> ali<TAB>
> eqn<TAB>
> stopped working.
Thanks for reporting!
So, the docstring was erroneous at the end.
Can you try to test the attached patch?
>From bce44c75b73fa0b935a9f991624a292e061f5c73 Mon Sep 17 00:00:00 2001
Message-Id:
<bce44c75b73fa0b935a9f991624a292e061f5c73.1673090538.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Sat, 7 Jan 2023 14:17:26 +0300
Subject: [PATCH] org-cdlatex-mode: Fix regression from f01390cf05
* lisp/org.el (org--math-always-on): Rename to `org--math-p' and only
override `texmathp' when current command is `cdlatex-math-symbol' or
when we are inside Org LaTeX math fragment. Only these two scenarios
are the places where `texmathp' may not work properly in Org files.
We must not return t outside latex fragments as initially suggested by
the docstring because it would break, for example, `cdlatex-dollar'
command.
(org-cdlatex-mode): Use the new function name for advice.
* lisp/org-compat.el (org--math-always-on): Declare obsolete.
Reported-by: Daniel Fleischer <danflscr@gmail.com>
Link: m2cz7sj5zt.fsf@gmail.com">https://orgmode.org/list/m2cz7sj5zt.fsf@gmail.com
---
lisp/org-compat.el | 3 +++
lisp/org.el | 27 ++++++++++++++++-----------
2 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index 6c5085255..0f6dc831a 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -568,6 +568,9 @@ (defun org-let2 (list1 list2 &rest body) ;FIXME: Where did
our karma go?
(make-obsolete 'org-let "to be removed" "9.6")
(make-obsolete 'org-let2 "to be removed" "9.6")
+(define-obsolete-function-alias 'org--math-always-on
+ 'org--math-p "9.7")
+
(defun org-compatible-face (inherits specs)
"Make a compatible face specification.
If INHERITS is an existing face and if the Emacs version supports
diff --git a/lisp/org.el b/lisp/org.el
index ae6250e52..44c41a729 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -15434,13 +15434,15 @@ (define-minor-mode org-cdlatex-mode
(cdlatex-compute-tables))
(unless org-cdlatex-texmathp-advice-is-done
(setq org-cdlatex-texmathp-advice-is-done t)
- (advice-add 'texmathp :around #'org--math-always-on)))
+ (advice-add 'texmathp :around #'org--math-p)))
-(defun org--math-always-on (orig-fun &rest args)
- "Always return t in Org buffers.
-This is because we want to insert math symbols without dollars even outside
-the LaTeX math segments. If Org mode thinks that point is actually inside
-an embedded LaTeX fragment, let `texmathp' do its job.
+(defun org--math-p (orig-fun &rest args)
+ "Return t inside math fragments or running `cdlatex-math-symbol'.
+This function is intended to be an :around advice for `texmathp'.
+
+If Org mode thinks that point is actually inside
+an embedded LaTeX environment, return t when the environment is math
+or let `texmathp' do its job otherwise.
`\\[org-cdlatex-mode-map]'"
(interactive)
(cond
@@ -15450,11 +15452,14 @@ (defun org--math-always-on (orig-fun &rest args)
t)
(t
(let ((element (org-element-context)))
- (or (not (org-inside-LaTeX-fragment-p element))
- (if (not (eq (org-element-type element) 'latex-fragment))
- (apply orig-fun args)
- (setq texmathp-why '("Org mode embedded math" . 0))
- t))))))
+ (when (org-inside-LaTeX-fragment-p element)
+ (pcase (substring-no-properties
+ (org-element-property :value element)
+ 0 2)
+ ((or "\\(" "\\[" (pred (string-match-p (rx string-start "$"))))
+ (setq texmathp-why '("Org mode embedded math" . 0))
+ t)
+ (_ (apply orig-fun args))))))))
(defun turn-on-org-cdlatex ()
"Unconditionally turn on `org-cdlatex-mode'."
--
2.38.1
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>