[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/shell-command+ ac582b21ab 3/4: Add shell-command+-expan
From: |
ELPA Syncer |
Subject: |
[elpa] externals/shell-command+ ac582b21ab 3/4: Add shell-command+-expand-%-fmt as an optional feature |
Date: |
Sat, 27 Aug 2022 13:57:58 -0400 (EDT) |
branch: externals/shell-command+
commit ac582b21abe7807be4ed55b2e0cdf66b76c9e321
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>
Add shell-command+-expand-%-fmt as an optional feature
---
shell-command+.el | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/shell-command+.el b/shell-command+.el
index 519d8e6763..22d0cd5484 100644
--- a/shell-command+.el
+++ b/shell-command+.el
@@ -67,6 +67,7 @@
;; - Allow adding or removing features using
;; `shell-command+-features'.
;; - Add `shell-command+-default-region' user option.
+;; - Add optional alternative to %-expansion (`shell-command+-expand-%-fmt')
;; - Remove `shell-command+-use-eshell'.
;; - Deprecate `shell-command+-enable-file-substitution'.
;; - Minor bug fixes and stability improvements.
@@ -199,6 +200,39 @@ For PARSE, FORM and CONTEXT see `shell-command+-features'."
insert a literal % quote it using a backslash.")
+;;;; generic %-sequence expansion
+
+(defun shell-command+-expand-%-fmt-spec ()
+ "Return a `format-spec' specification for `shell-command+-expand-%-fmt'."
+ `((?f . ,(buffer-file-name))
+ (?o . ,(buffer-file-name (other-buffer)))
+ (?b . ,(and (buffer-file-name) (file-name-base (buffer-file-name))))
+ (?e . ,(and (buffer-file-name) (file-name-extension (buffer-file-name))))
+ (?y . ,(current-kill 0))))
+
+(defun shell-command+-expand-%-fmt (parse form context)
+ "Generalised version of `shell-command+-expand-%'.
+For PARSE, FORM and CONTEXT see `shell-command+-features'."
+ ;; Idea stolen from Alvaro Ramirez' "dwim-shell-command"
+ (setf (nth 3 parse)
+ (format-spec
+ (nth 3 parse)
+ (shell-command+-expand-%-fmt-spec)))
+ (list parse form context))
+
+(put 'shell-command+-expand-%-fmt
+ 'shell-command+-docstring
+ "Inside COMMAND, replace the following %-sequences:
+
+- %f with the result of `buffer-file-name'
+- %o with the result of `buffer-file-name' of `other-buffer'
+- %b with the base of `buffer-file-name'
+- %e with the file extension of `buffer-file-name'
+- %y with the head of the kill ring
+
+See `format-spec' for details on how %-sequences are handled.")
+
+
;;;; Implicit cd
(defun shell-command+-expand-path (path)