[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/shell-command+ 253d4bc 14/36: removed history code
From: |
Stefan Monnier |
Subject: |
[elpa] externals/shell-command+ 253d4bc 14/36: removed history code |
Date: |
Fri, 25 Sep 2020 11:01:24 -0400 (EDT) |
branch: externals/shell-command+
commit 253d4bc87ec6beb12e5c6f5569a354907adb8679
Author: Philip K <philip@warpmail.net>
Commit: Philip K <philip@warpmail.net>
removed history code
---
bang.el | 97 ++++++++++-------------------------------------------------------
1 file changed, 15 insertions(+), 82 deletions(-)
diff --git a/bang.el b/bang.el
index 8713526..40bcd38 100644
--- a/bang.el
+++ b/bang.el
@@ -1,9 +1,9 @@
;;; bang.el --- A more intelligent shell-command -*- lexical-binding: t -*-
;; Author: Philip K. <philip@warpmail.net>
-;; Version: 0.1.0
+;; Version: 0.2.0
;; Keywords: unix, processes, convenience
-;; Package-Requires: ((emacs "24.1") (seq "2.20"))
+;; Package-Requires: ((emacs "24.1"))
;; URL: https://git.sr.ht/~zge/bang
;; This file is NOT part of Emacs.
@@ -29,69 +29,9 @@
;; https://leahneukirchen.org/dotfiles/.emacs
(require 'rx)
-(require 'seq)
;;; Code:
-(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)
- "Regular expression to parse input to `bang'.")
-
-(defvar bang--last-commands '()
- "List of non-history commands last executed by `bang'.")
-
-(defvar bang-history-size 80
- "Number of commands to save in `bang--last-commands'.")
-
-(defun bang--remember-command (command)
- "Helper function to save COMMAND in bang's history."
- (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)))))
-
-(defun bang--find-last-command (prefix)
- "Helper function to find last command that started with PREFIX."
- (or (seq-find (apply-partially #'string-prefix-p prefix)
- bang--last-commands)
- (error "No such command in history")))
-
-(defun bang--get-command-number (arg rest)
- "Helper function to find ARG'th last command.
-
-Second argument REST will be concatenated to what was found."
- (let* ((num (string-to-number arg))
- (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)))
-
(defun bang (command beg end)
"Intelligently execute string COMMAND in inferior shell.
@@ -99,8 +39,6 @@ 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
- ! executes the last command that started with COMMAND,
- or if a number, re-execute nth last command
Without any argument, `bang' will behave like `shell-command'.
@@ -113,26 +51,23 @@ between BEG and END. Otherwise the whole buffer is
processed."
(if (use-region-p) (region-beginning) (point-min))
(if (use-region-p) (region-end) (point-max))))
(save-match-data
- (unless (string-match bang--command-regexp command)
+ (unless (string-match (rx bos (* space)
+ (or (group "<") (group ">") (group "|") "")
+ (group (* not-newline))
+ eos)
+ 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))
+ (let ((has-< (match-string-no-properties 1 command))
+ (has-> (match-string-no-properties 2 command))
+ (has-| (match-string-no-properties 3 command))
(rest (condition-case nil
(replace-regexp-in-string
(rx (* ?\\ ?\\) (or ?\\ (group "%")))
buffer-file-name
- (match-string-no-properties 7 command)
+ (match-string-no-properties 4 command)
nil nil 1)
- (error (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)
+ (error (match-string-no-properties 4 command)))))
+ (cond (has-< (delete-region beg end)
(shell-command rest t shell-command-default-error-buffer)
(exchange-point-and-mark))
(has-> (shell-command-on-region
@@ -142,11 +77,9 @@ between BEG and END. Otherwise the whole buffer is
processed."
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->)
+ (when has->
(with-current-buffer "*Shell Command Output*"
- (delete-region (point-min) (point-max))))
- (unless (or num-! arg-!)
- (bang--remember-command command)))))
+ (delete-region (point-min) (point-max)))))))
(provide 'bang)
- [elpa] branch externals/shell-command+ created (now 339931d), Stefan Monnier, 2020/09/25
- [elpa] externals/shell-command+ 57afacb 01/36: initial export, Stefan Monnier, 2020/09/25
- [elpa] externals/shell-command+ 3eed583 10/36: fixed typo on the first line, Stefan Monnier, 2020/09/25
- [elpa] externals/shell-command+ ac4ec3c 07/36: added initial readme, Stefan Monnier, 2020/09/25
- [elpa] externals/shell-command+ bed12c8 11/36: minor code cleanup, Stefan Monnier, 2020/09/25
- [elpa] externals/shell-command+ 0931b93 03/36: added cc0 as license, Stefan Monnier, 2020/09/25
- [elpa] externals/shell-command+ c0129cc 02/36: converted all tabs to spaced, Stefan Monnier, 2020/09/25
- [elpa] externals/shell-command+ aecad16 13/36: added link to public inbox, Stefan Monnier, 2020/09/25
- [elpa] externals/shell-command+ 64c0fcf 06/36: delete shell output instead of killing it, Stefan Monnier, 2020/09/25
- [elpa] externals/shell-command+ 253d4bc 14/36: removed history code,
Stefan Monnier <=
- [elpa] externals/shell-command+ ee9e3e6 17/36: added `.' command, Stefan Monnier, 2020/09/25
- [elpa] externals/shell-command+ 11e121a 25/36: added support for bang--command-regexp to start with ~, Stefan Monnier, 2020/09/25
- [elpa] externals/shell-command+ a47986d 32/36: updated commentary section, Stefan Monnier, 2020/09/25
- [elpa] externals/shell-command+ f004dfb 23/36: require at least one non-whitespace character in command, Stefan Monnier, 2020/09/25
- [elpa] externals/shell-command+ 55f3e2a 16/36: emulated insert-into-buffer feature from shell-command, Stefan Monnier, 2020/09/25
- [elpa] externals/shell-command+ f80c7c3 29/36: autoload bang command, Stefan Monnier, 2020/09/25
- [elpa] externals/shell-command+ 8758933 24/36: removed trailing whitespace, Stefan Monnier, 2020/09/25
- [elpa] externals/shell-command+ ab6bb0e 18/36: reworked `.' command, Stefan Monnier, 2020/09/25
- [elpa] externals/shell-command+ 87b5ad3 21/36: version bump, Stefan Monnier, 2020/09/25
- [elpa] externals/shell-command+ 339931d 36/36: rename bang to shell-command+, Stefan Monnier, 2020/09/25