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

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

[elpa] externals/embark 8d0ef3fba0 3/4: Remove embark-eshell, add more g


From: ELPA Syncer
Subject: [elpa] externals/embark 8d0ef3fba0 3/4: Remove embark-eshell, add more general embark--cd
Date: Sun, 17 Apr 2022 20:57:30 -0400 (EDT)

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

    Remove embark-eshell, add more general embark--cd
    
    The new embark--cd pre-action hook will cause the action to run with
    default-directory set to the directory associated to the target, a
    file, buffer, bookmark or library.
    
    Having that allows us to remove embark-eshell, instead using eshell
    directly. It also makes sense know to bind eshell in the buffer and
    bookmark maps as well. In case people prefer shell over eshell, we
    have embark--cd setup it for it too.
---
 README.org  |  5 +++++
 embark.el   | 51 +++++++++++++++++++++++++++++++++++++--------------
 embark.texi |  6 ++++++
 3 files changed, 48 insertions(+), 14 deletions(-)

diff --git a/README.org b/README.org
index 882bfd119e..4f1936b333 100644
--- a/README.org
+++ b/README.org
@@ -556,6 +556,11 @@ For pre-action hooks:
   which you'd like to be able to come back to where you were using
   =xref-pop-marker-stack=. This is used by default for =find-library=.
 
+- =embark--cd= :: Run the action with =default-directory= set to the
+  directory associated to the current target. The target should be of
+  type =file=, =buffer=, =bookmark= or =library=, and the associated directory
+  is what you'd expect in each case.
+
 For post-action hooks:
 
 - =embark--restart= :: Restart the command currently prompting in the
diff --git a/embark.el b/embark.el
index 93786c6b53..27b2289ffd 100644
--- a/embark.el
+++ b/embark.el
@@ -493,7 +493,10 @@ the key :always are executed always."
     (query-replace embark--beginning-of-target embark--unmark-target)
     (query-replace-regexp embark--beginning-of-target embark--unmark-target)
     ;; narrow to target for duration of action
-    (repunctuate-sentences embark--narrow-to-target))
+    (repunctuate-sentences embark--narrow-to-target)
+    ;; use directory of target as default-directory
+    (shell embark--cd embark--universal-argument)
+    (eshell embark--cd embark--universal-argument))
   "Alist associating commands with pre-action hooks.
 The hooks are run right before an action is embarked upon.  See
 `embark-target-injection-hooks' for information about the hook
@@ -3277,15 +3280,6 @@ STRING contains no newlines."
           (ins-string))
       (ins-string))))
 
-(defun embark-eshell (file)
-  "Run eshell in directory of FILE."
-  (interactive "GDirectory: ")
-  (let ((default-directory
-          (file-name-directory
-           (expand-file-name
-            (substitute-in-file-name file)))))
-    (eshell '(4))))
-
 ;; For Emacs 28 dired-jump will be moved to dired.el, but it seems
 ;; that since it already has an autoload in Emacs 28, this next
 ;; autoload is ignored.
@@ -3664,6 +3658,32 @@ The advice is self-removing so it only affects ACTION 
once."
   (unless (y-or-n-p (format "Run %s on %s? " action target))
     (user-error "Cancelled")))
 
+(autoload 'bookmark-location "bookmark")
+(cl-defun embark--cd (&key action target type &allow-other-keys)
+  "Run ACTION with `default-directory' set to the directory of TARGET.
+The supported values of TYPE are file, buffer, bookmark and
+library, which have an obvious notion of associated directory."
+  (when-let (((symbolp action))
+             (directory
+              (pcase type
+                ('file
+                 (file-name-directory target))
+                ('buffer
+                 (buffer-local-value 'default-directory (get-buffer target)))
+                ('bookmark
+                 (file-name-directory (bookmark-location target)))
+                ('library
+                 (file-name-directory (locate-library target))))))
+    (cl-labels ((in-directory (fn &rest args)
+                  (advice-remove action #'in-directory)
+                  (let ((default-directory directory))
+                    (apply fn args))))
+      (advice-add action :around #'in-directory))))
+
+(defun embark--universal-argument (&rest _)
+  "Run action with a universal prefix argument."
+  (setq prefix-arg '(4)))
+
 ;;; keymaps
 
 (embark-define-keymap embark-meta-map
@@ -3800,7 +3820,7 @@ The advice is self-removing so it only affects ACTION 
once."
   ("j" embark-dired-jump)
   ("!" shell-command)
   ("&" async-shell-command)
-  ("$" embark-eshell)
+  ("$" eshell)
   ("<" insert-file)
   ("m" chmod)
   ("=" ediff-files)
@@ -3838,7 +3858,8 @@ The advice is self-removing so it only affects ACTION 
once."
   ("h" finder-commentary)
   ("a" apropos-library)
   ("L" locate-library)
-  ("m" info-display-manual))
+  ("m" info-display-manual)
+  ("$" eshell))
 
 (embark-define-keymap embark-buffer-map
   "Keymap for Embark buffer actions."
@@ -3851,7 +3872,8 @@ The advice is self-removing so it only affects ACTION 
once."
   ("r" embark-rename-buffer)
   ("=" ediff-buffers)
   ("|" embark-shell-command-on-buffer)
-  ("<" insert-buffer))
+  ("<" insert-buffer)
+  ("$" eshell))
 
 (embark-define-keymap embark-tab-map
   "Keymap for actions for tab-bar tabs."
@@ -3999,7 +4021,8 @@ The advice is self-removing so it only affects ACTION 
once."
   ("o" bookmark-jump-other-window)
   ("f" bookmark-jump-other-frame)
   ("a" 'bookmark-show-annotation)
-  ("e" 'bookmark-edit-annotation))
+  ("e" 'bookmark-edit-annotation)
+  ("$" eshell))
 
 (embark-define-keymap embark-unicode-name-map
   "Keymap for Embark unicode name actions."
diff --git a/embark.texi b/embark.texi
index d1b97a3768..9fedef5f1e 100644
--- a/embark.texi
+++ b/embark.texi
@@ -684,6 +684,12 @@ Push the current location on the xref
 marker stack. Use this for commands that take you somewhere and for
 which you'd like to be able to come back to where you were using
 @samp{xref-pop-marker-stack}. This is used by default for @samp{find-library}.
+
+@item @samp{embark--cd}
+Run the action with @samp{default-directory} set to the
+directory associated to the current target. The target should be of
+type @samp{file}, @samp{buffer}, @samp{bookmark} or @samp{library}, and the 
associated directory
+is what you'd expect in each case.
 @end table
 
 For post-action hooks:



reply via email to

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