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

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

[elpa] externals/embark c40d538709 3/7: DWIM behavior for consult async


From: ELPA Syncer
Subject: [elpa] externals/embark c40d538709 3/7: DWIM behavior for consult async search commands
Date: Wed, 6 Dec 2023 12:58:02 -0500 (EST)

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

    DWIM behavior for consult async search commands
    
    (Except for consult-locate.)
---
 embark-consult.el | 53 ++++++++++++++++-------------------------------------
 1 file changed, 16 insertions(+), 37 deletions(-)

diff --git a/embark-consult.el b/embark-consult.el
index b8e9f873bf..5343237dfd 100644
--- a/embark-consult.el
+++ b/embark-consult.el
@@ -358,47 +358,26 @@ This is intended to be used in 
`embark-target-injection-hooks'."
   (cl-pushnew #'embark-consult--unique-match
               (alist-get cmd embark-target-injection-hooks)))
 
-(cl-defun embark-consult--prep-async (&key type target &allow-other-keys)
-  "Either add Consult's async separator or ignore the TARGET depending on TYPE.
-If the TARGET of the given TYPE has an associated notion of
-directory, we don't want to search for the text of target, but
-rather just start a search in the associated directory.
-
-This is intended to be used in `embark-target-injection-hooks'
-for any action that is a Consult async command."
-  (let* ((style (alist-get consult-async-split-style
-                           consult-async-split-styles-alist))
-         (initial (plist-get style :initial))
-         (separator (plist-get style :separator))
-         (directory (embark--associated-directory target type)))
-    (when directory
-      (delete-minibuffer-contents))
-    (when initial
-      (goto-char (minibuffer-prompt-end))
-      (insert initial)
-      (goto-char (point-max)))
-    (when (and separator (null directory))
-      (goto-char (point-max))
-      (insert separator))))
-
-(cl-defun embark-consult--projectless
-    (&rest rest &key run target type &allow-other-keys)
-  "Run action with nil `consult-project-function', if TARGET has an directory.
-The values of TYPE which are considered to have an associated
-directory are: file, buffer, bookmark and library.  The REST of
-the arguments are also passed to RUN."
-  (if (embark--associated-directory target type)
+(cl-defun embark-consult--async-search-dwim
+    (&key action type target candidates &allow-other-keys)
+  "DWIM when using a Consult async search command as an ACTION.
+If the TYPE of the target(s) has a notion of associated
+file (files, buffers, libraries and some bookmarks do), then run
+the ACTION with `consult-project-function' set to nil, and search
+only the files associated to the TARGET or CANDIDATES.  For other
+types, run the ACTION with TARGET or CANDIDATES as initial input."
+  (if-let ((file-fn (cdr (assq type embark--associated-file-fn-alist))))
       (let (consult-project-function)
-        (apply run :target target :type type rest))
-    (apply run :target target :type type rest)))
+        (funcall action
+                 (delq nil (mapcar file-fn (or candidates (list target))))))
+    (funcall action nil (or target (string-join candidates " ")))))
 
 (map-keymap
  (lambda (_key cmd)
-   (cl-pushnew #'embark--cd (alist-get cmd embark-around-action-hooks))
-   (cl-pushnew #'embark-consult--projectless
-               (alist-get cmd embark-around-action-hooks))
-   (cl-pushnew #'embark-consult--prep-async
-               (alist-get cmd embark-target-injection-hooks)))
+   (unless (eq cmd #'consult-locate)
+     (cl-pushnew cmd embark-multitarget-actions)
+     (cl-pushnew #'embark-consult--async-search-dwim
+                 (alist-get cmd embark-around-action-hooks))))
  embark-consult-async-search-map)
 
 ;;; Tables of contents for buffers: imenu and outline candidate collectors



reply via email to

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