emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/dired-preview 8f23847768 17/67: Remove the advice syste


From: ELPA Syncer
Subject: [elpa] externals/dired-preview 8f23847768 17/67: Remove the advice system to restore buffer-local mode
Date: Sat, 8 Jul 2023 15:57:52 -0400 (EDT)

branch: externals/dired-preview
commit 8f238477686ad94ad8978e634a6f3d690ca4017c
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Remove the advice system to restore buffer-local mode
    
    This commit changes the approach that was followed for commit 3304286.
    The intention is to still get the same result, but do it in a way that
    preserves the original design of a buffer-local minor mode.
    
    This follows from the discussion with Christian Tietze:
    
<https://lists.sr.ht/~protesilaos/general-issues/%3Cm1zg4noej2.fsf%40christiantietze.de%3E>.
---
 dired-preview.el | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/dired-preview.el b/dired-preview.el
index 5171596ce2..cea218a573 100644
--- a/dired-preview.el
+++ b/dired-preview.el
@@ -263,37 +263,38 @@ Only do it with the current major mode is Dired."
         (run-with-timer dired-preview-delay nil
                         #'dired-preview--display-buffer buffer)))
 
-(defun dired-preview-display-file (&rest _)
+(defun dired-preview-display-file ()
   "Display preview of `dired-file-name-at-point' if appropriate.
-Return buffer object of displayed buffer.  Ignore any arguments.
-
-Use this as advice after relevant Dired commands (see
-`dired-preview-enable-preview', `dired-preview-disable-preview')."
+Return buffer object of displayed buffer."
   (if-let* ((file (dired-file-name-at-point))
             (buffer (dired-preview--return-preview-buffer file)))
         (dired-preview--display-buffer-with-delay buffer)
     (dired-preview--close-previews)))
 
+(defvar dired-preview-trigger-commands
+  '(dired-next-line dired-previous-line dired-mark dired-goto-file)
+  "List of Dired commands that trigger a preview.")
+
+(defun dired-preview-trigger ()
+  "Trigger display of file at point after `dired-preview-trigger-commands'."
+  (when (memq last-command dired-preview-trigger-commands)
+    (dired-preview-display-file)))
+
 (defun dired-preview-disable-preview ()
   "Disable Dired preview."
   (unless (eq major-mode 'dired-mode)
     (error "Can only use `dired-preview' in Dired"))
-  (dolist (command '(dired-next-line dired-previous-line dired-mark 
dired-goto-file))
-    (advice-remove command #'dired-preview-display-file))
+  (remove-hook 'post-command-hook #'dired-preview-trigger :local)
   (dired-preview--close-previews))
 
 (defun dired-preview-enable-preview ()
   "Enable Dired preview."
   (unless (eq major-mode 'dired-mode)
     (error "Can only use `dired-preview' in Dired"))
-  (dolist (command '(dired-next-line dired-previous-line dired-mark 
dired-goto-file))
-    (advice-add command :after #'dired-preview-display-file))
+  (add-hook 'post-command-hook #'dired-preview-trigger nil :local)
   (add-hook 'post-command-hook #'dired-preview--close-previews-outside-dired 
nil :local)
   (dired-preview-display-file))
 
-;; FIXME 2023-06-28: The :global nil and the `advice-add' contradict
-;; each other.  I still prefer a buffer-local mode and must thus
-;; arrange for the same job via the `post-command-hook'.
 ;;;###autoload
 (define-minor-mode dired-preview-mode
   "Buffer-local mode to preview file at point in Dired."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]