forked from mirrors/org-mode
org-latex-preview: Improved face adaptation
* lisp/org-latex-preview.el (org-latex-preview--face-around): Instead of only examining the face immediately before the LaTeX snippet, also look at the face immediately after before determining the appropriate face to use. This is relevant when the prior face is uninformative (e.g. org-indent) but the latter face contains the applicable face (e.g. org-list-dt). Determination of the applicable face is now performed in the new function `org-latex-preview--face-around'. (org-latex-preview--colors-at, org-latex-preview--update-overlay): Rename `org-latex-preview--colors-at' to `org-latex-preview--colors-around', and use `org-latex-preview--face-around' for better face determination. (org-latex-preview-place, org-latex-preview-clear-cache): Update to provide an "end" value to `org-latex-preview--colors-around'.
This commit is contained in:
parent
ec8662aa82
commit
febabadb99
|
@ -480,21 +480,38 @@ overlay face is set to `org-latex-preview-processing-face'."
|
||||||
(overlay-put
|
(overlay-put
|
||||||
ov 'face
|
ov 'face
|
||||||
(or (and errors 'error)
|
(or (and errors 'error)
|
||||||
(and (> (overlay-start ov) (point-min))
|
(org-latex-preview--face-around
|
||||||
(not (eq (char-before (overlay-start ov)) ?\n))
|
(overlay-start ov) (overlay-end ov)))))
|
||||||
(let ((face (get-text-property (1- (overlay-start ov)) 'face)))
|
|
||||||
(cond
|
|
||||||
((consp face)
|
|
||||||
(cl-set-difference face org-latex-preview--ignored-faces))
|
|
||||||
((not (memq face org-latex-preview--ignored-faces))
|
|
||||||
face))))
|
|
||||||
'default)))
|
|
||||||
(errors
|
(errors
|
||||||
(overlay-put
|
(overlay-put
|
||||||
ov 'before-string
|
ov 'before-string
|
||||||
(propertize "!" 'display
|
(propertize "!" 'display
|
||||||
`(left-fringe exclamation-mark error)))))))
|
`(left-fringe exclamation-mark error)))))))
|
||||||
|
|
||||||
|
(defun org-latex-preview--face-around (start end)
|
||||||
|
"Return the relevant face symbol around the region START to END.
|
||||||
|
A relevant face symbol before START is prefered, with END
|
||||||
|
examined if none could be found, and finally the default face
|
||||||
|
used as the final fallback.
|
||||||
|
Faces in `org-latex-preview--ignored-faces' are ignored."
|
||||||
|
(or (and (> start (point-min))
|
||||||
|
(not (eq (char-before start) ?\n))
|
||||||
|
(let ((face (get-text-property (1- start) 'face)))
|
||||||
|
(cond
|
||||||
|
((consp face)
|
||||||
|
(cl-set-difference face org-latex-preview--ignored-faces))
|
||||||
|
((not (memq face org-latex-preview--ignored-faces))
|
||||||
|
face))))
|
||||||
|
(and (> (point-max) end)
|
||||||
|
(not (eq (char-after end) ?\n))
|
||||||
|
(let ((face (get-text-property end 'face)))
|
||||||
|
(cond
|
||||||
|
((consp face)
|
||||||
|
(cl-set-difference face org-latex-preview--ignored-faces))
|
||||||
|
((not (memq face org-latex-preview--ignored-faces))
|
||||||
|
face))))
|
||||||
|
'default))
|
||||||
|
|
||||||
;; Code for `org-latex-preview-auto-mode':
|
;; Code for `org-latex-preview-auto-mode':
|
||||||
;;
|
;;
|
||||||
;; The boundaries of latex preview image overlays are automatically
|
;; The boundaries of latex preview image overlays are automatically
|
||||||
|
@ -1068,7 +1085,7 @@ is either the substring between BEG and END or (when provided) VALUE."
|
||||||
(pcase-let* ((`(,beg ,end ,provided-value) entry)
|
(pcase-let* ((`(,beg ,end ,provided-value) entry)
|
||||||
(value (or provided-value
|
(value (or provided-value
|
||||||
(buffer-substring-no-properties beg end)))
|
(buffer-substring-no-properties beg end)))
|
||||||
(`(,fg ,bg) (org-latex-preview--colors-at beg))
|
(`(,fg ,bg) (org-latex-preview--colors-around beg end))
|
||||||
(number (car (setq numbering-offsets (cdr numbering-offsets))))
|
(number (car (setq numbering-offsets (cdr numbering-offsets))))
|
||||||
(hash (org-latex-preview--hash
|
(hash (org-latex-preview--hash
|
||||||
processing-type value imagetype fg bg number))
|
processing-type value imagetype fg bg number))
|
||||||
|
@ -1100,11 +1117,9 @@ is either the substring between BEG and END or (when provided) VALUE."
|
||||||
:latex-preamble latex-preamble
|
:latex-preamble latex-preamble
|
||||||
:place-preview-p t))))
|
:place-preview-p t))))
|
||||||
|
|
||||||
(defun org-latex-preview--colors-at (pos)
|
(defun org-latex-preview--colors-around (start end)
|
||||||
"Find colors for LaTeX previews to be inserted at POS."
|
"Find colors for LaTeX previews occuping the region START to END."
|
||||||
(let* ((face (or (and (> pos 1)
|
(let* ((face (org-latex-preview--face-around start end))
|
||||||
(get-text-property (1- pos) 'face))
|
|
||||||
'default))
|
|
||||||
(fg (pcase (plist-get org-latex-preview-options :foreground)
|
(fg (pcase (plist-get org-latex-preview-options :foreground)
|
||||||
('auto
|
('auto
|
||||||
(org-latex-preview--resolved-faces-attr face :foreground))
|
(org-latex-preview--resolved-faces-attr face :foreground))
|
||||||
|
@ -2129,7 +2144,12 @@ the *entire* preview cache will be cleared, and `org-persist-gc' run."
|
||||||
(dolist (element (org-latex-preview-collect-fragments beg end))
|
(dolist (element (org-latex-preview-collect-fragments beg end))
|
||||||
(pcase-let* ((begin (or (org-element-property :post-affiliated element)
|
(pcase-let* ((begin (or (org-element-property :post-affiliated element)
|
||||||
(org-element-property :begin element)))
|
(org-element-property :begin element)))
|
||||||
(`(,fg ,bg) (org-latex-preview--colors-at begin))
|
(end (- (org-element-property :end element)
|
||||||
|
(or (org-element-property :post-blank element) 0)
|
||||||
|
(if (eq (char-before (org-element-property :end element))
|
||||||
|
?\n)
|
||||||
|
1 0)))
|
||||||
|
(`(,fg ,bg) (org-latex-preview--colors-around begin end))
|
||||||
(value (org-element-property :value element))
|
(value (org-element-property :value element))
|
||||||
(number (and numbering-table
|
(number (and numbering-table
|
||||||
(eq (org-element-type element)
|
(eq (org-element-type element)
|
||||||
|
|
Loading…
Reference in New Issue