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: https://orgmode.org/list/m2cz7sj5zt.fsf@gmail.com
This commit is contained in:
Ihor Radchenko 2023-01-07 14:17:26 +03:00
parent 2f7052619b
commit dfcf500df5
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 19 additions and 11 deletions

View File

@ -568,6 +568,9 @@ Counting starts at 1."
(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

View File

@ -15434,13 +15434,15 @@ in Org 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 @@ an embedded LaTeX fragment, let `texmathp' do its job.
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'."