branch: externals/shell-command+ commit ee9e3e684920004c8258d91ac2c30f3d157c34ff Author: Philip K <phi...@warpmail.net> Commit: Philip K <phi...@warpmail.net>
added `.' command --- README.md | 7 +------ bang.el | 13 ++++++++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index f001a4b..7036bc5 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,7 @@ `bang` is a `shell-command` substitute that makes it easier to run commands on regions or whole buffers. This is done by potentially interpreting the first character differently, as the `bang` docstring -explains: - - When COMMAND starts with - < the output of COMMAND replaces the current selection - > COMMAND is run with the current selection as input - | the current selection is filtered through COMMAND +explains. Bang has been based on a function of the same name by [Leah Neukirchen][leah]. diff --git a/bang.el b/bang.el index 2be0b25..8907f37 100644 --- a/bang.el +++ b/bang.el @@ -39,6 +39,7 @@ When COMMAND starts with < the output of COMMAND replaces the current selection > COMMAND is run with the current selection as input | the current selection is filtered through COMMAND + . COMMAND executes in the relative path following the dot Without any argument, `bang' will behave like `shell-command'. @@ -52,7 +53,9 @@ between BEG and END. Otherwise the whole buffer is processed." (if (use-region-p) (region-end) (point-max)))) (save-match-data (unless (string-match (rx bos (* space) - (or (group "<") (group ">") (group "|") "") + (or (group "<") (group ">") (group "|") + (group "." (* (not space))) "") + (* space) (group (* not-newline)) eos) command) @@ -60,13 +63,14 @@ between BEG and END. Otherwise the whole buffer is processed." (let ((has-< (match-string-no-properties 1 command)) (has-> (match-string-no-properties 2 command)) (has-| (match-string-no-properties 3 command)) + (has-. (match-string-no-properties 4 command)) (rest (condition-case nil (replace-regexp-in-string (rx (* ?\\ ?\\) (or ?\\ (group "%"))) buffer-file-name - (match-string-no-properties 4 command) + (match-string-no-properties 5 command) nil nil 1) - (error (match-string-no-properties 4 command))))) + (error (match-string-no-properties 5 command))))) (cond (has-< (delete-region beg end) (shell-command rest t shell-command-default-error-buffer) (exchange-point-and-mark)) @@ -76,6 +80,9 @@ between BEG and END. Otherwise the whole buffer is processed." (has-| (shell-command-on-region beg end rest t t shell-command-default-error-buffer t)) + (has-. (let ((default-directory (expand-file-name has-.))) + (shell-command rest (if current-prefix-arg t nil) + shell-command-default-error-buffer))) (t (shell-command command (if current-prefix-arg t nil) shell-command-default-error-buffer))) (when has->