Hello both, On 17/03/2026, Paul D. Nelson wrote:
> Hi Al and Arash, > >> Hi Al, >> >> Al Haji-Ali <[email protected]> writes: >> >>> If we want to lazily load buframe (only when needed rather than when >>> setting `preview-at-point-placement`), then we can consider the attached >>> patch. >> >> Thanks for the update. I'd let Paul comment, he is more familiar with >> the code. > > Looks good to me. > > Nitpicking: > >>> + ;; Don't load buframe if not already loaded > > If I recall correctly, this and similar comments should be complete > sentences and end with a period. > I've correct this and added package-version as Arash suggested in the attached. I also made a small modification to dvisvgm call to pass currentcolor so that the output inherits the face-color instead of being hardcoded in svg files. Best regards, -- Al
>From 2b527d17ef501e5de41dfbe85ceb7ada11fe22c2 Mon Sep 17 00:00:00 2001 From: Al Haji-Ali <[email protected]> Date: Fri, 20 Mar 2026 22:44:42 +0000 Subject: [PATCH] Lazily require buframe before use. * preview.el (preview--buframe-error): New variable. (preview--update-buframe): Require buframe before use. (preview-visibility-style, preview-keep-stale-images, preview-at-point-placement): add package-version. (preview-dvisvgm-command): Pass currentcolor by default. --- preview.el | 130 +++++++++++++++++++++++++++++------------------------ 1 file changed, 72 insertions(+), 58 deletions(-) diff --git a/preview.el b/preview.el index b253ef889c..4d7817d12d 100644 --- a/preview.el +++ b/preview.el @@ -478,7 +478,8 @@ sync with the preview." :type '(choice (const :tag "Only at point with source" at-point) (const :tag "Only away from point, hiding source" off-point) - (const :tag "Both" always))) + (const :tag "Both" always)) + :package-version '(auctex . "14.2.0")) (defcustom preview-keep-stale-images nil "Keep the last preview image visible even when the source changes. @@ -489,7 +490,8 @@ icon. When nil, the icon appears until the refreshed image arrives. The value of this variable is ignored when `preview-visibility-style' is `off-point'. In that case, stale images are never retained." :group 'preview-appearance - :type 'boolean) + :type 'boolean + :package-version '(auctex . "14.2.0")) (defcustom preview-at-point-placement 'before-string "Placement of the at-point preview or icon relative to its source. @@ -520,7 +522,8 @@ where: (const :tag "Default" nil) (function :tag "Position function")) (alist :tag "Frame parameters") - (alist :tag "Buffer parameters")))) + (alist :tag "Buffer parameters"))) + :package-version '(auctex . "14.2.0")) (defun preview-string-expand (arg &optional separator) "Expand ARG as a string. @@ -644,7 +647,8 @@ You may set the variable `preview-dvi*-command' to (concat (TeX-command-expand (or cmd - "dvisvgm --no-fonts %d --page=- --output=\"%m/prev%%3p.svg\"")) + "dvisvgm --no-fonts --currentcolor --page=- %d \ + --output=\"%m/prev%%3p.svg\"")) (format " --scale=%g " scale))))) (defcustom preview-dvips-command @@ -4571,10 +4575,7 @@ If not a regular release, the date of the last change.") (insert "\n"))) (error nil))) -;;; buframe specific - -;; Buframe functions, it will be assumed that buframe is installed so -;; that it can be required. +;;; buframe-specific functions. (declare-function buframe-position-right-of-overlay "ext:buframe" (frame ov &optional location)) (declare-function buframe-make-buffer "ext:buframe" (name &optional locals)) @@ -4586,61 +4587,74 @@ If not a regular release, the date of the last change.") (declare-function buframe-find "ext:buframe" (&optional frame-or-name buffer parent noerror)) +(defvar preview--buframe-error t + "When non-nil, issue a one-time error if loading buframe fails.") + (defun preview--update-buframe (&optional force) "Show or hide a buframe popup depending on overlays at point. The frame is not updated if the `buframe' property has not changed, unless FORCE is non-nil." - (when (featurep 'buframe) - (let* ((frame-name "auctex-preview") - (buf-name " *auctex-preview-buffer*") - (old-frame (buframe-find frame-name nil nil t))) - (if-let* ((ov (cl-find-if - (lambda (ov) (when (overlay-get ov 'buframe) ov)) - (overlays-at (point)))) - (str (overlay-get ov 'buframe))) - (unless (and (not force) - old-frame - (pcase (frame-parameter old-frame 'auctex-preview) - (`(,o . ,s) (and (eq o ov) (eq s str))))) - (let* ((buf (buframe-make-buffer buf-name - (car-safe - (cddr (cdr-safe - preview-at-point-placement))))) - (max-image-size - (if (integerp max-image-size) - max-image-size - ;; Set the size max-image-size using the current frame - ;; since the popup frame will be small to begin with - (* max-image-size (frame-width))))) - (with-current-buffer buf - (let (buffer-read-only) - (with-silent-modifications - (erase-buffer) - (insert (propertize str - ;; Remove unnecessary properties - 'help-echo nil - 'keymap nil - 'mouse-face nil)) - (goto-char (point-min))))) - (setq old-frame - (buframe-make - frame-name - (lambda (frame) - (funcall - (or (car-safe (cdr-safe preview-at-point-placement)) - #'buframe-position-right-of-overlay) - frame - ov)) - buf - (overlay-buffer ov) - (window-frame) - (car-safe (cdr (cdr-safe preview-at-point-placement))))) - (set-frame-parameter old-frame 'auctex-preview - (cons ov str)))) - (when old-frame - (set-frame-parameter old-frame 'auctex-preview nil) - (buframe-disable old-frame)))))) + (let* ((frame-name "auctex-preview") + (buf-name " *auctex-preview-buffer*") + (old-frame (and (featurep 'buframe) + ;; Do not autoload buframe if it is not already + ;; loaded. + (buframe-find frame-name nil nil t)))) + (if-let* ((ov (cl-find-if + (lambda (ov) (when (overlay-get ov 'buframe) ov)) + (overlays-at (point)))) + (str (overlay-get ov 'buframe))) + (unless (and (not force) + old-frame + (pcase (frame-parameter old-frame 'auctex-preview) + (`(,o . ,s) (and (eq o ov) (eq s str))))) + (if (require 'buframe nil t) + (let* ((buf (buframe-make-buffer + buf-name + (car-safe + (cddr (cdr-safe + preview-at-point-placement))))) + (max-image-size + (if (integerp max-image-size) + max-image-size + ;; Set the size max-image-size using the current + ;; frame, since the popup frame will be small to + ;; begin with. + (* max-image-size (frame-width))))) + (with-current-buffer buf + (let (buffer-read-only) + (with-silent-modifications + (erase-buffer) + (insert (propertize str + ;; Remove unnecessary properties + 'help-echo nil + 'keymap nil + 'mouse-face nil)) + (goto-char (point-min))))) + (setq old-frame + (buframe-make + frame-name + (lambda (frame) + (funcall + (or (car-safe (cdr-safe preview-at-point-placement)) + #'buframe-position-right-of-overlay) + frame + ov)) + buf + (overlay-buffer ov) + (window-frame) + (car-safe (cdr (cdr-safe + preview-at-point-placement))))) + (set-frame-parameter old-frame 'auctex-preview + (cons ov str))) + (when preview--buframe-error + (setq preview--buframe-error nil) + (error "buframe is unavailable for use with preview. \ +See `preview-at-point-placement'.")))) + (when old-frame + (set-frame-parameter old-frame 'auctex-preview nil) + (buframe-disable old-frame))))) ;;;###autoload (defun preview-report-bug () "Report a bug in the preview-latex package." -- 2.50.1 (Apple Git-155)
_______________________________________________ bug-auctex mailing list [email protected] https://lists.gnu.org/mailman/listinfo/bug-auctex
