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

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

[elpa] externals/shell-command+ 4bbd5c546e 1/2: Add new option shell-com


From: ELPA Syncer
Subject: [elpa] externals/shell-command+ 4bbd5c546e 1/2: Add new option shell-command+-default-region
Date: Tue, 15 Feb 2022 07:58:12 -0500 (EST)

branch: externals/shell-command+
commit 4bbd5c546e29329b89d765f3759ca50792b7f4b3
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>

    Add new option shell-command+-default-region
---
 shell-command+.el | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/shell-command+.el b/shell-command+.el
index 0f9d7f7e73..be3fffa729 100644
--- a/shell-command+.el
+++ b/shell-command+.el
@@ -78,6 +78,7 @@
 (eval-when-compile (require 'pcase))
 (require 'diff)
 (require 'info)
+(provide 'thingatpt)
 
 (defgroup shell-command+ nil
   "An extended `shell-command'."
@@ -155,6 +156,15 @@ this option to nil."
                 :value-type (function :tag "Substitute"))
   :set-after '(shell-command+-use-eshell))
 
+(defcustom shell-command+-default-region nil
+  "Default thing to apply a command onto.
+The default value nil will apply a buffer to the entire buffer.
+A symbol such as `line', `page', `defun', ... as defined by
+`bounds-of-thing-at-point' will restrict the region to whatever
+is specified."
+  :type '(choice (const :tag "Entire buffer" nil)
+                 (symbol :tag "Thing")))
+
 
 
 (defconst shell-command+-token-regexp
@@ -354,13 +364,20 @@ These extentions can all be combined with one-another.
 
 In case a region is active, `shell-command+' will only work with the region
 between BEG and END.  Otherwise the whole buffer is processed."
-  (interactive (list (read-shell-command
-                      (if (bound-and-true-p shell-command-prompt-show-cwd)
-                          (format shell-command+-prompt
-                                  (abbreviate-file-name default-directory))
-                        shell-command+-prompt))))
-  (unless beg (setq beg (if (use-region-p) (region-beginning) (point-min))))
-  (unless end (setq end (if (use-region-p) (region-end) (point-max))))
+  (interactive (let ((bounds (and shell-command+-default-region
+                                  (bounds-of-thing-at-point
+                                   shell-command+-default-region))))
+                 (list (read-shell-command
+                        (if (bound-and-true-p shell-command-prompt-show-cwd)
+                            (format shell-command+-prompt
+                                    (abbreviate-file-name default-directory))
+                          shell-command+-prompt))
+                       (cond ((use-region-p) (region-beginning))
+                             (bounds (car bounds))
+                             ((point-min)))
+                       (cond ((use-region-p) (region-end))
+                             (bounds (cdr bounds))
+                             ((point-max))))))
   (pcase-let* ((`(,path ,mode ,command ,rest) (shell-command+-parse command))
                (default-directory (shell-command+-expand-path (or path "."))))
     ;; Make sure the previous output buffer was killed, to prevent



reply via email to

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