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

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

[elpa] externals/embark b57c947f20: Add a pre-revert hook to export buff


From: ELPA Syncer
Subject: [elpa] externals/embark b57c947f20: Add a pre-revert hook to export buffers, use it for grep
Date: Tue, 5 Apr 2022 00:57:34 -0400 (EDT)

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

    Add a pre-revert hook to export buffers, use it for grep
    
    The current mechanism is to wait until the indicator overlay becomes a
    colon and then wait a bit more. It seems to work, but is probably not
    very reliable. Any suggestions @minad?
---
 embark-consult.el | 11 ++++++++++-
 embark.el         | 27 ++++++++++++++++++---------
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/embark-consult.el b/embark-consult.el
index 5f9f79195c..8c2e6750ac 100644
--- a/embark-consult.el
+++ b/embark-consult.el
@@ -118,6 +118,14 @@
 (setf (alist-get 'consult-location embark-default-action-overrides)
       #'embark-consult-goto-location)
 
+(defun embark-consult--await ()
+  "Wait for a Consult async search commmand to finish."
+  (when-let (((minibufferp))
+             (ov (car (overlays-at (- (minibuffer-prompt-end) 2)))))
+    (while (not (equal (overlay-get ov 'display) ":"))
+      (sit-for 0.3 t))
+    (sit-for 0.3 t)))
+
 (defun embark-consult-export-occur (lines)
   "Create an occur mode buffer listing LINES.
 The elements of LINES are assumed to be values of category `consult-line'."
@@ -182,7 +190,8 @@ This function is meant to be added to 
`embark-collect-mode-hook'."
       (goto-char (point-min))
       (grep-mode)
       (setq-local wgrep-header/footer-parser #'ignore)
-      (when (fboundp 'wgrep-setup) (wgrep-setup)))
+      (when (fboundp 'wgrep-setup) (wgrep-setup))
+      (add-hook 'embark--export-pre-revert-hook #'embark-consult--await nil t))
     (pop-to-buffer buf)))
 
 (defun embark-consult-goto-grep (location)
diff --git a/embark.el b/embark.el
index 58b7cebc22..c7073b2504 100644
--- a/embark.el
+++ b/embark.el
@@ -684,6 +684,9 @@ This function is meant to be added to 
`minibuffer-setup-hook'."
 (defvar-local embark-collect--candidates nil
   "List of candidates in current collect buffer.")
 
+(defvar-local embark--export-pre-revert-hook nil
+  "Hook run before reverting an Embark Export buffer.")
+
 ;;; Core functionality
 
 (defconst embark--verbose-indicator-buffer " *Embark Actions*")
@@ -2939,19 +2942,25 @@ with key \"Embark Live\"."
 
 (defun embark--export-revert-function ()
   "Return an appropriate revert function for an export buffer in this context."
-  ;; TODO Fix this for async commands.
   (let ((buffer (or embark--target-buffer (embark--target-buffer))))
-    (cl-flet ((reverter (action)
+    (cl-flet ((reverter (wrapper)
                 (lambda (&rest _)
-                  (let ((windows (get-buffer-window-list nil nil t)))
-                    (kill-buffer)
-                    (with-current-buffer buffer
-                      (funcall action windows))))))
+                  (let ((windows (get-buffer-window-list nil nil t))
+                        (old (current-buffer))
+                        (hook embark--export-pre-revert-hook))
+                    (kill-buffer old)
+                    (with-current-buffer
+                        (if (buffer-live-p buffer) buffer (current-buffer))
+                      (funcall wrapper
+                               (lambda ()
+                                 (let ((embark--export-pre-revert-hook hook))
+                                   (run-hooks 'embark--export-pre-revert-hook))
+                                 (embark-export windows))))))))
         (if (minibufferp)
           (reverter
            (let ((command embark--command)
                  (input (minibuffer-contents-no-properties)))
-             (lambda (windows)
+             (lambda (export)
                (minibuffer-with-setup-hook
                    (lambda ()
                      (delete-minibuffer-contents)
@@ -2960,10 +2969,10 @@ with key \"Embark Live\"."
                                (lambda ()
                                  (let ((embark--command command)
                                        (embark--target-buffer buffer))
-                                   (embark-export windows)))
+                                   (funcall export)))
                                nil t))
                  (command-execute command)))))
-      (reverter #'embark-export)))))
+          (reverter #'funcall)))))
 
 ;;;###autoload
 (defun embark-export (&optional windows)



reply via email to

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