forked from mirrors/org-mode
org-latex-preview: Respect auto-generate option
* lisp/org-latex-preview.el (org-latex-preview-auto--detect-fragments-in-change): Respect the user option `org-latex-preview-auto-generate' when `org-latex-preview-auto-mode' is active. (This was lost when the auto-generation code was rewritten.)
This commit is contained in:
parent
5ca232e8ea
commit
1323115972
|
@ -598,64 +598,65 @@ This is intended to be placed in `post-command-hook'."
|
||||||
|
|
||||||
(defun org-latex-preview-auto--detect-fragments-in-change (beg end _)
|
(defun org-latex-preview-auto--detect-fragments-in-change (beg end _)
|
||||||
"Examine the content between BEG and END, and preview LaTeX fragments found."
|
"Examine the content between BEG and END, and preview LaTeX fragments found."
|
||||||
(let ((initial-point (point))
|
(when org-latex-preview-auto-generate
|
||||||
fragments)
|
(let ((initial-point (point))
|
||||||
(save-excursion
|
fragments)
|
||||||
;; Find every location in the changed region where a backslash
|
(save-excursion
|
||||||
;; is succeeded by a parenthesis or square bracket, and check
|
;; Find every location in the changed region where a backslash
|
||||||
;; for a LaTeX fragment.
|
;; is succeeded by a parenthesis or square bracket, and check
|
||||||
(goto-char beg)
|
;; for a LaTeX fragment.
|
||||||
(unless (eobp)
|
(goto-char beg)
|
||||||
(while (search-forward "\\" end t)
|
(unless (eobp)
|
||||||
(and (memq (char-after) '(?\( ?\) ?\[ ?\]))
|
(while (search-forward "\\" end t)
|
||||||
(push (org-latex-preview-auto--maybe-track-element-here
|
(and (memq (char-after) '(?\( ?\) ?\[ ?\]))
|
||||||
'latex-fragment initial-point)
|
|
||||||
fragments))))
|
|
||||||
;; Find every location in the changed region where a parenthesis
|
|
||||||
;; or square bracket is preceeded by a backslash, and check for
|
|
||||||
;; a LaTeX fragment.
|
|
||||||
(goto-char beg)
|
|
||||||
(unless (bobp)
|
|
||||||
(while (re-search-forward "[][()]" end t)
|
|
||||||
(and (eq (char-before (1- (point))) ?\\)
|
|
||||||
(push (org-latex-preview-auto--maybe-track-element-here
|
|
||||||
'latex-fragment initial-point)
|
|
||||||
fragments))))
|
|
||||||
;; Check for LaTeX environments on lines affected by the change.
|
|
||||||
;; Start by finding all affected lines with at least four
|
|
||||||
;; characters of content. Then we can check if the line starts
|
|
||||||
;; with "\beg" or "\end", and if so check for a LaTeX environment.
|
|
||||||
(goto-char beg)
|
|
||||||
(beginning-of-line)
|
|
||||||
(skip-chars-forward " \t")
|
|
||||||
(when (< (point) end)
|
|
||||||
(let ((line-start-positions
|
|
||||||
(and (> (point-max) (+ 4 (point)))
|
|
||||||
(list (point)))))
|
|
||||||
(while (and (< (point) end)
|
|
||||||
(search-forward "\n" end t))
|
|
||||||
(skip-chars-forward " \t")
|
|
||||||
(when (> (point-max) (+ 4 (point)))
|
|
||||||
(push (point) line-start-positions)))
|
|
||||||
(dolist (line-start line-start-positions)
|
|
||||||
(goto-char line-start)
|
|
||||||
(and (eq (char-after) ?\\)
|
|
||||||
(member (buffer-substring (point) (+ (point) 4))
|
|
||||||
'("\\beg" "\\end"))
|
|
||||||
(push (org-latex-preview-auto--maybe-track-element-here
|
(push (org-latex-preview-auto--maybe-track-element-here
|
||||||
'latex-environment initial-point)
|
'latex-fragment initial-point)
|
||||||
fragments))))))
|
fragments))))
|
||||||
(when (setq fragments (delq nil fragments))
|
;; Find every location in the changed region where a parenthesis
|
||||||
(when (and org-latex-preview-numbered
|
;; or square bracket is preceeded by a backslash, and check for
|
||||||
(cl-find 'latex-environment fragments
|
;; a LaTeX fragment.
|
||||||
|
(goto-char beg)
|
||||||
|
(unless (bobp)
|
||||||
|
(while (re-search-forward "[][()]" end t)
|
||||||
|
(and (eq (char-before (1- (point))) ?\\)
|
||||||
|
(push (org-latex-preview-auto--maybe-track-element-here
|
||||||
|
'latex-fragment initial-point)
|
||||||
|
fragments))))
|
||||||
|
;; Check for LaTeX environments on lines affected by the change.
|
||||||
|
;; Start by finding all affected lines with at least four
|
||||||
|
;; characters of content. Then we can check if the line starts
|
||||||
|
;; with "\beg" or "\end", and if so check for a LaTeX environment.
|
||||||
|
(goto-char beg)
|
||||||
|
(beginning-of-line)
|
||||||
|
(skip-chars-forward " \t")
|
||||||
|
(when (< (point) end)
|
||||||
|
(let ((line-start-positions
|
||||||
|
(and (> (point-max) (+ 4 (point)))
|
||||||
|
(list (point)))))
|
||||||
|
(while (and (< (point) end)
|
||||||
|
(search-forward "\n" end t))
|
||||||
|
(skip-chars-forward " \t")
|
||||||
|
(when (> (point-max) (+ 4 (point)))
|
||||||
|
(push (point) line-start-positions)))
|
||||||
|
(dolist (line-start line-start-positions)
|
||||||
|
(goto-char line-start)
|
||||||
|
(and (eq (char-after) ?\\)
|
||||||
|
(member (buffer-substring (point) (+ (point) 4))
|
||||||
|
'("\\beg" "\\end"))
|
||||||
|
(push (org-latex-preview-auto--maybe-track-element-here
|
||||||
|
'latex-environment initial-point)
|
||||||
|
fragments))))))
|
||||||
|
(when (setq fragments (delq nil fragments))
|
||||||
|
(when (and org-latex-preview-numbered
|
||||||
|
(cl-find 'latex-environment fragments
|
||||||
:key #'org-element-type :test #'eq))
|
:key #'org-element-type :test #'eq))
|
||||||
(setq fragments
|
(setq fragments
|
||||||
(append fragments
|
(append fragments
|
||||||
(org-latex-preview--get-numbered-environments
|
(org-latex-preview--get-numbered-environments
|
||||||
end nil))))
|
end nil))))
|
||||||
(org-latex-preview--create
|
(org-latex-preview--create
|
||||||
org-latex-preview-default-process
|
org-latex-preview-default-process
|
||||||
fragments))))
|
fragments)))))
|
||||||
|
|
||||||
(defun org-latex-preview-auto--maybe-track-element-here (type pos)
|
(defun org-latex-preview-auto--maybe-track-element-here (type pos)
|
||||||
"Check for an org element of TYPE at `point' and ensure an overlay exists.
|
"Check for an org element of TYPE at `point' and ensure an overlay exists.
|
||||||
|
|
Loading…
Reference in New Issue