forked from mirrors/org-mode
org-latex-preview: Use a fragment info plists
* lisp/org-latex-preview.el (org-latex-preview--cleanup-callback, org-create-formula-image-async, org-create-latex-preview): Instead of using lists of the same length for fragment information, use a single list of fragment information plists. This allows for more information to be stored/used without ending up with half a dozen disparate lists that we rely on lining up.
This commit is contained in:
parent
9ecfa904a2
commit
cb225ab2f2
|
@ -531,6 +531,7 @@ Some of the options can be changed using the variable
|
||||||
(cdr (assq processing-type org-preview-latex-process-alist)))
|
(cdr (assq processing-type org-preview-latex-process-alist)))
|
||||||
(imagetype (or (plist-get processing-info :image-output-type) "png"))
|
(imagetype (or (plist-get processing-info :image-output-type) "png"))
|
||||||
document-strings
|
document-strings
|
||||||
|
fragment-info
|
||||||
locations keys)
|
locations keys)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(dolist (element elements)
|
(dolist (element elements)
|
||||||
|
@ -568,22 +569,27 @@ Some of the options can be changed using the variable
|
||||||
(org-place-latex-image beg end path-info)
|
(org-place-latex-image beg end path-info)
|
||||||
(push (org-preview-latex--tex-styled value options)
|
(push (org-preview-latex--tex-styled value options)
|
||||||
document-strings)
|
document-strings)
|
||||||
|
(push (list :buffer-location (cons beg end)
|
||||||
|
:key hash)
|
||||||
|
fragment-info)
|
||||||
(push (cons beg end) locations)
|
(push (cons beg end) locations)
|
||||||
(push hash keys)))))
|
(push hash keys)))))
|
||||||
(when locations
|
(when locations
|
||||||
(org-create-formula-image-async
|
(org-create-formula-image-async
|
||||||
processing-type
|
processing-type
|
||||||
(nreverse document-strings)
|
(nreverse document-strings)
|
||||||
(nreverse locations)
|
(nreverse fragment-info)))))
|
||||||
(nreverse keys)))))
|
|
||||||
|
|
||||||
(defun org-create-formula-image-async (processing-type preview-strings locations keys)
|
(defun org-create-formula-image-async (processing-type preview-strings fragment-info)
|
||||||
"Preview PREVIEW-STRINGS asynchronously with method PROCESSING-TYPE.
|
"Preview PREVIEW-STRINGS asynchronously with method PROCESSING-TYPE.
|
||||||
|
|
||||||
LOCATIONS are buffer locations denoting the beginning and end of
|
FRAGMENT-INFO is a list of plists, where the Nth plist gives
|
||||||
each snippet of PREVIEW-STRINGS. Each entry is a cons cell.
|
information on the Nth fragment of PREVIEW-STRINGS. Each
|
||||||
|
FRAGMENT-INFO plist should have the following structure:
|
||||||
|
(:buffer-location (begin-pos . end-pos) :key fragment-hash)
|
||||||
|
|
||||||
The previews are cached with associated KEYS."
|
It is worth noting the FRAGMENT-INFO plists will be modified
|
||||||
|
during processing to hold more information on the fragments."
|
||||||
(let* ((processing-type
|
(let* ((processing-type
|
||||||
(or processing-type org-preview-latex-default-process))
|
(or processing-type org-preview-latex-default-process))
|
||||||
(processing-info
|
(processing-info
|
||||||
|
@ -594,8 +600,7 @@ The previews are cached with associated KEYS."
|
||||||
(org-check-external-command program error-message))
|
(org-check-external-command program error-message))
|
||||||
(let* ((extended-info
|
(let* ((extended-info
|
||||||
(append processing-info
|
(append processing-info
|
||||||
(list :locations locations
|
(list :fragments fragment-info
|
||||||
:keys keys
|
|
||||||
:texfile (org-preview-latex--create-tex-file
|
:texfile (org-preview-latex--create-tex-file
|
||||||
processing-info preview-strings))))
|
processing-info preview-strings))))
|
||||||
(tex-compile-async
|
(tex-compile-async
|
||||||
|
@ -736,27 +741,36 @@ The path of the created LaTeX file is returned."
|
||||||
(image-output-type (intern (plist-get extended-info :image-output-type)))
|
(image-output-type (intern (plist-get extended-info :image-output-type)))
|
||||||
(images
|
(images
|
||||||
(file-expand-wildcards
|
(file-expand-wildcards
|
||||||
(concat basename "*." (symbol-name image-output-type))
|
(concat basename "*." (plist-get extended-info :image-output-type))
|
||||||
'full))
|
'full))
|
||||||
(clean-exts
|
(clean-exts
|
||||||
(or (plist-get extended-info :post-clean)
|
(or (plist-get extended-info :post-clean)
|
||||||
'(".dvi" ".xdv" ".pdf" ".tex" ".aux" ".log"
|
'(".dvi" ".xdv" ".pdf" ".tex" ".aux" ".log"
|
||||||
".svg" ".png" ".jpg" ".jpeg" ".out")))
|
".svg" ".png" ".jpg" ".jpeg" ".out"))))
|
||||||
(locations (plist-get extended-info :locations))
|
|
||||||
(keys (plist-get extended-info :keys)))
|
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(cl-loop
|
(cl-loop
|
||||||
for (beg . end) in locations
|
for fragment-info in (plist-get extended-info :fragments)
|
||||||
for image-file in images
|
for image-file in images
|
||||||
for key in keys
|
do
|
||||||
do (org-place-latex-image
|
(org-place-latex-image
|
||||||
beg end
|
(car (plist-get fragment-info :buffer-location))
|
||||||
(org-latex-preview--cache-image
|
(cdr (plist-get fragment-info :buffer-location))
|
||||||
key image-file (list :image-type image-output-type)))))
|
(org-latex-preview--cache-image
|
||||||
|
(plist-get fragment-info :key)
|
||||||
|
image-file
|
||||||
|
(org-latex-preview--display-info
|
||||||
|
extended-info fragment-info)))))
|
||||||
(dolist (ext clean-exts)
|
(dolist (ext clean-exts)
|
||||||
(when (file-exists-p (concat basename ext))
|
(when (file-exists-p (concat basename ext))
|
||||||
(delete-file (concat basename ext))))))
|
(delete-file (concat basename ext))))))
|
||||||
|
|
||||||
|
(defun org-latex-preview--display-info (extended-info fragment-info)
|
||||||
|
"From FRAGMENT-INFO and EXTENDED-INFO obtain display-relevant information."
|
||||||
|
(let ((image-type (intern (plist-get extended-info :image-output-type)))
|
||||||
|
info)
|
||||||
|
;; FUTURE extract width/height/etc. info
|
||||||
|
(plist-put info :image-type image-type)))
|
||||||
|
|
||||||
(defun org-latex-preview--dvisvgm-callback (_exit-code _stdout extended-info)
|
(defun org-latex-preview--dvisvgm-callback (_exit-code _stdout extended-info)
|
||||||
"TODO"
|
"TODO"
|
||||||
(let* ((basename (file-name-base (plist-get extended-info :texfile)))
|
(let* ((basename (file-name-base (plist-get extended-info :texfile)))
|
||||||
|
|
Loading…
Reference in New Issue