[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/shell-command+ 062576e26a 1/3: Use closures to generate
From: |
ELPA Syncer |
Subject: |
[elpa] externals/shell-command+ 062576e26a 1/3: Use closures to generate the command instead of s-expressions |
Date: |
Wed, 24 Aug 2022 17:57:56 -0400 (EDT) |
branch: externals/shell-command+
commit 062576e26ad6aad26f0d65ae2454b22dd7d3143b
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>
Use closures to generate the command instead of s-expressions
---
shell-command+.el | 65 ++++++++++++++++++++++---------------------------------
1 file changed, 26 insertions(+), 39 deletions(-)
diff --git a/shell-command+.el b/shell-command+.el
index dfae52cc6b..1e2e876fa1 100644
--- a/shell-command+.el
+++ b/shell-command+.el
@@ -108,15 +108,6 @@ is specified."
:type '(choice (const :tag "Entire buffer" nil)
(symbol :tag "Thing")))
-(defvar shell-command+-region nil
- "Cons-cell defining the region to operate on.")
-
-(defconst shell-command+--context-hole (make-symbol "context-hole")
- "Symbol to be replaced by the form in the context.")
-
-(defconst shell-command+--command-hole (make-symbol "command-hole")
- "Symbol to be replaced by the command string.")
-
;;; Modular feature support
@@ -143,25 +134,24 @@ returns the modified command, form and context in a list."
(defun shell-command+-redirect-output (parse form context)
"Replace form with a command that redirects input and output.
For PARSE, FORM and CONTEXT see `shell-command+-features'."
- (pcase-let* ((`(,_ ,mode ,_ ,_) parse)
- (beg (car shell-command+-region))
- (end (cdr shell-command+-region)))
+ (pcase-let ((`(,_ ,mode ,_ ,_) parse))
(list parse
(cond ((if shell-command+-flip-redirection
(eq mode 'output) (eq mode 'input))
- (exchange-point-and-mark)
- `(progn
- (delete-region ,beg ,end)
- (shell-command ,shell-command+--command-hole t
shell-command-default-error-buffer)))
+ (lambda (input beg end)
+ (delete-region beg end)
+ (shell-command input t shell-command-default-error-buffer)))
((if shell-command+-flip-redirection
(eq mode 'input) (eq mode 'output))
- `(shell-command-on-region
- ,beg ,end ,shell-command+--command-hole nil nil
- shell-command-default-error-buffer t))
+ (lambda (input beg end)
+ (shell-command-on-region
+ beg end input nil nil
+ shell-command-default-error-buffer t)))
((eq mode 'pipe)
- `(shell-command-on-region
- ,beg ,end ,shell-command+--command-hole t t
- shell-command-default-error-buffer t))
+ (lambda (input beg end)
+ (shell-command-on-region
+ beg end input t t
+ shell-command-default-error-buffer t)))
(t form))
context)))
@@ -215,8 +205,9 @@ For PARSE, FORM and CONTEXT see `shell-command+-features'."
(pcase-let* ((`(,dir ,_ ,_ ,_) parse))
(list parse form
(if dir
- `(let ((default-directory ,(shell-command+-expand-path dir)))
- ,context)
+ (lambda (fn input beg end)
+ (let ((default-directory (shell-command+-expand-path dir)))
+ (funcall fn input beg end)))
context))))
@@ -307,11 +298,12 @@ this option to nil."
"Check if FORM can be replaced by some other function call.
This is done by querying `shell-command+-substitute-alist'. FORM
PARSE, FORM and CONTEXT see `shell-command+-features'."
- (pcase-let* ((`(,_ ,mode ,command ,all) parse))
+ (pcase-let ((`(,_ ,mode ,name ,_) parse))
(list parse
- (let ((fn (assoc command shell-command+-substitute-alist)))
+ (let ((fn (assoc name shell-command+-substitute-alist)))
(if (and fn (not (eq mode 'literal)))
- `(,(cdr fn) ,all) form))
+ (apply-partially fn)
+ form))
context)))
@@ -469,12 +461,12 @@ between BEG and END. Otherwise the whole buffer is
processed."
(with-current-buffer shell-command-buffer
(cd def-dir))))
(let ((shell-command+-features shell-command+-features)
- (shell-command+-region (cons beg end))
- (form `(shell-command
- ,shell-command+--command-hole
- (and current-prefix-arg t)
- shell-command-default-error-buffer))
- (context shell-command+--context-hole)
+ (form (lambda (input _beg _end)
+ (shell-command
+ input
+ (and current-prefix-arg t)
+ shell-command-default-error-buffer)))
+ (context #'funcall)
(parse (shell-command+-parse command)))
(while shell-command+-features
(let ((step (funcall (pop shell-command+-features)
@@ -485,12 +477,7 @@ between BEG and END. Otherwise the whole buffer is
processed."
(save-excursion
;; CHANGEME: Have the functions generate functions that are
;; funcalled instead of a lisp term that is evaluated?
- (eval (cl-subst (cl-subst (nth 3 parse)
- shell-command+--command-hole
- form)
- shell-command+--context-hole
- context)
- t))))
+ (funcall context form (nth 3 parse) beg end))))
(provide 'shell-command+)