branch: externals/shell-command+
commit c0129cc8113890ac1939168822761b4cf59cf11d
Author: Philip K <[email protected]>
Commit: Philip K <[email protected]>
converted all tabs to spaced
---
.dir-locals.el | 5 +++
bang.el | 122 ++++++++++++++++++++++++++++-----------------------------
2 files changed, 66 insertions(+), 61 deletions(-)
diff --git a/.dir-locals.el b/.dir-locals.el
new file mode 100644
index 0000000..3bcda92
--- /dev/null
+++ b/.dir-locals.el
@@ -0,0 +1,5 @@
+;;; Directory Local Variables
+;;; For more information see (info "(emacs) Directory Variables")
+
+((emacs-lisp-mode
+ (indent-tabs-mode . nil)))
diff --git a/bang.el b/bang.el
index 8658ab6..2c29a76 100644
--- a/bang.el
+++ b/bang.el
@@ -8,15 +8,15 @@
(defconst bang--command-regexp
(rx bos (* space)
- (or (seq (group "!" )
- (or (group (+ digit))
- (group (+ alnum))))
- (group "<") (group ">") (group "|") "")
- (? (* space)
- (group (* not-newline)
- (not space)
- (*? not-newline)))
- eos)
+ (or (seq (group "!" )
+ (or (group (+ digit))
+ (group (+ alnum))))
+ (group "<") (group ">") (group "|") "")
+ (? (* space)
+ (group (* not-newline)
+ (not space)
+ (*? not-newline)))
+ eos)
"Regular expression to parse input to `bang'.")
(defvar bang--last-commands '()
@@ -28,39 +28,39 @@
(defun bang--remember-command (command)
(push command bang--last-commands)
(let ((overflow (- (length bang--last-commands)
- bang-history-size)))
- (when (> overflow 0)
- (setq bang--last-commands
- (nbutlast bang--last-commands overflow)))))
+ bang-history-size)))
+ (when (> overflow 0)
+ (setq bang--last-commands
+ (nbutlast bang--last-commands overflow)))))
(defun bang--find-last-command (prefix)
(catch 'found
- (dolist (cmd bang--last-commands)
- (when (string-prefix-p prefix cmd)
- (throw 'found cmd)))
- (error "no such command in history")))
+ (dolist (cmd bang--last-commands)
+ (when (string-prefix-p prefix cmd)
+ (throw 'found cmd)))
+ (error "no such command in history")))
(defun bang--get-command-number (arg rest)
(let* ((num (string-to-number arg))
- (pos (- (length bang--last-commands)
- (1- num)))
- (cmd (nth pos bang--last-commands)))
- (concat cmd " " rest)))
+ (pos (- (length bang--last-commands)
+ (1- num)))
+ (cmd (nth pos bang--last-commands)))
+ (concat cmd " " rest)))
(defun bang-history ()
"Display a buffer with overview of previous bang commands."
(interactive)
(let ((buf (get-buffer-create "*bang-history*"))
- (i (length bang--last-commands)))
- (with-current-buffer buf
- (setq buffer-read-only nil)
- (delete-region (goto-char (point-min))
- (point-max))
- (dolist (cmd bang--last-commands)
- (insert (format "%d\t%s\n" i cmd))
- (setq i (1- i)))
- (special-mode))
- (pop-to-buffer buf)))
+ (i (length bang--last-commands)))
+ (with-current-buffer buf
+ (setq buffer-read-only nil)
+ (delete-region (goto-char (point-min))
+ (point-max))
+ (dolist (cmd bang--last-commands)
+ (insert (format "%d\t%s\n" i cmd))
+ (setq i (1- i)))
+ (special-mode))
+ (pop-to-buffer buf)))
(defun bang (command beg end)
"Intelligently execute string COMMAND in inferior shell, like
@@ -78,36 +78,36 @@ Without any argument, `bang' will behave like
`shell-command'.
Inside COMMAND, % is replaced with the current file name. To
insert a literal % quote it using a backslash."
(interactive (list (read-shell-command "Bang command: ")
- (if mark-active (region-beginning)
(point-min))
- (if mark-active (region-end)
(point-max))))
+ (if mark-active (region-beginning) (point-min))
+ (if mark-active (region-end) (point-max))))
(save-match-data
- (unless (string-match bang--command-regexp command)
- (error "Invalid command"))
- (let ((has-! (match-string-no-properties 1 command))
- (num-! (match-string-no-properties 2 command))
- (arg-! (match-string-no-properties 3 command))
- (has-< (match-string-no-properties 4 command))
- (has-> (match-string-no-properties 5 command))
- (has-| (match-string-no-properties 6 command))
- (rest (match-string-no-properties 7 command)))
- (cond (arg-! (bang (bang--find-last-command arg-!)
- beg end))
- (num-! (bang (bang--get-command-number num-! rest)
- beg end))
- (has-< (delete-region beg end)
- (shell-command rest t
shell-command-default-error-buffer)
- (exchange-point-and-mark))
- (has-> (shell-command-on-region
- beg end rest nil nil
- shell-command-default-error-buffer t))
- (has-| (shell-command-on-region
- beg end rest t t
- shell-command-default-error-buffer t))
- (t (shell-command command nil
shell-command-default-error-buffer)))
- (when (or has-! has->)
- (with-current-buffer "*Shell Command Output*"
- (kill-ring-save (point-min) (point-max))))
- (unless (or num-! arg-!)
- (bang--remember-command command)))))
+ (unless (string-match bang--command-regexp command)
+ (error "Invalid command"))
+ (let ((has-! (match-string-no-properties 1 command))
+ (num-! (match-string-no-properties 2 command))
+ (arg-! (match-string-no-properties 3 command))
+ (has-< (match-string-no-properties 4 command))
+ (has-> (match-string-no-properties 5 command))
+ (has-| (match-string-no-properties 6 command))
+ (rest (match-string-no-properties 7 command)))
+ (cond (arg-! (bang (bang--find-last-command arg-!)
+ beg end))
+ (num-! (bang (bang--get-command-number num-! rest)
+ beg end))
+ (has-< (delete-region beg end)
+ (shell-command rest t shell-command-default-error-buffer)
+ (exchange-point-and-mark))
+ (has-> (shell-command-on-region
+ beg end rest nil nil
+ shell-command-default-error-buffer t))
+ (has-| (shell-command-on-region
+ beg end rest t t
+ shell-command-default-error-buffer t))
+ (t (shell-command command nil shell-command-default-error-buffer)))
+ (when (or has-! has->)
+ (with-current-buffer "*Shell Command Output*"
+ (kill-ring-save (point-min) (point-max))))
+ (unless (or num-! arg-!)
+ (bang--remember-command command)))))
(provide 'bang)