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

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

[elpa] externals/embark 43a0dc70f1 3/4: Incomplete implementation of rev


From: ELPA Syncer
Subject: [elpa] externals/embark 43a0dc70f1 3/4: Incomplete implementation of revert in export buffers
Date: Mon, 4 Apr 2022 16:57:38 -0400 (EDT)

branch: externals/embark
commit 43a0dc70f1a19f3c7b0344715ef269231cd9a770
Author: Omar Antolín <omar.antolin@gmail.com>
Commit: Omar Antolín <omar.antolin@gmail.com>

    Incomplete implementation of revert in export buffers
    
    This partially addresses #171.
    
    It has several problems still:
    
    1. It doesn't work for consult-async commands since (1) the target
    buffer is usually some buffer shown by consult preview that is dead
    by then, (2) in inserts the entire minibuffer contents so you wind up
    with double #, (3) it doesn't wait for the candidate generation to
    finish.
    
    2. Since the exporters create *and* display their own buffers, and for
    some this might be hard to avoid, I currently kill the exported buffer
    and generate it anew, which usually displays it somewhere else. :(
    
    3. Some export buffers bind g to something other than revert-buffer so
    the behavior is surprising, for example, grep export buffers seems to
    have g bound to recompile.
    
    4. It should probably be generalized to cover embark-collect buffers
    too.
    
    So this is definitely just a proof of concept. I'm pushing it since it
    just adds invisible functionality, even if that functionality isn't
    what we want in all cases. And hey, it does work for embark export
    from a non-mini buffer, for file export (which is great to update
    after renaming or deleting files!) and for occur export from
    consult-line.
---
 embark.el | 37 +++++++++++++++++++++++++++++--------
 1 file changed, 29 insertions(+), 8 deletions(-)

diff --git a/embark.el b/embark.el
index 08f29b76a4..d1907a73ad 100644
--- a/embark.el
+++ b/embark.el
@@ -2937,6 +2937,30 @@ with key \"Embark Live\"."
     (when (minibufferp)
       (add-hook 'change-major-mode-hook stop-collect nil t))))
 
+(defun embark--export-revert-function ()
+  "Return an appropriate revert function for an export buffer in this context."
+  ;; TODO Display new export buffer in same window as previous.
+  ;; TODO Fix this for async commands.
+  (let ((buffer (or embark--target-buffer (embark--target-buffer))))
+    (if (minibufferp)
+        (let* ((command embark--command)
+               (input (minibuffer-contents-no-properties)))
+          (lambda (&rest _)
+            (kill-buffer)
+            (minibuffer-with-setup-hook
+                (lambda ()
+                  (insert input)
+                  (add-hook 'post-command-hook
+                            (lambda ()
+                              (let ((embark--command command)
+                                    (embark--target-buffer buffer))
+                                (embark-export)))
+                            nil t))
+              (with-current-buffer buffer (command-execute command)))))
+      (lambda (&rest _)
+        (kill-buffer)
+        (with-current-buffer buffer (embark-export))))))
+
 ;;;###autoload
 (defun embark-export ()
   "Create a type-specific buffer to manage current candidates.
@@ -2951,18 +2975,15 @@ buffer for each type of completion."
                         (alist-get t embark-exporters-alist))))
       (if (eq exporter 'embark-collect)
           (embark-collect)
-        (let ((dir (embark--default-directory))
-              (after embark-after-export-hook)
-              (name (embark--descriptive-buffer-name 'export)))
+        (let ((after embark-after-export-hook)
+              (name (embark--descriptive-buffer-name 'export))
+              (revert (embark--export-revert-function)))
           (embark--quit-and-run
            (lambda ()
-             ;; TODO see embark--quit-and-run and embark--run-after-command,
-             ;; there the default-directory is also smuggled to the lambda.
-             ;; This should be fixed properly.
-             (let ((default-directory dir) ;; dired needs this info
-                   (embark-after-export-hook after))
+             (let ((embark-after-export-hook after))
                (funcall exporter candidates)
                (rename-buffer name t)
+               (setq-local revert-buffer-function revert)
                (run-hooks 'embark-after-export-hook)))))))))
 
 (defmacro embark--export-rename (buffer title &rest body)



reply via email to

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