[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/urgrep 266965a0a2 024/115: Add support for intelligent
From: |
ELPA Syncer |
Subject: |
[elpa] externals/urgrep 266965a0a2 024/115: Add support for intelligent editing of previous search commands |
Date: |
Wed, 10 May 2023 03:00:39 -0400 (EDT) |
branch: externals/urgrep
commit 266965a0a263f86675bd0883a9c0306ed97bc1e4
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Jim Porter <jporterbugs@gmail.com>
Add support for intelligent editing of previous search commands
---
urgrep.el | 62 ++++++++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 46 insertions(+), 16 deletions(-)
diff --git a/urgrep.el b/urgrep.el
index dfe2200a54..5cf59e4dd4 100644
--- a/urgrep.el
+++ b/urgrep.el
@@ -259,7 +259,6 @@ for MS shells."
;; urgrep-mode
-(defvar urgrep-search-history nil "History list for urgrep.")
(defvar urgrep-num-matches-found 0
"Running total of matches found. This will be set buffer-locally.")
@@ -268,6 +267,23 @@ for MS shells."
;; number explicitly in the output.
(defvar urgrep-first-column 0)
+(defvar-local urgrep-last-query nil
+ "The last search query run in this buffer.")
+
+(defun urgrep-search-again (&optional edit-command)
+ "Re-run the previous search.
+If EDIT-COMMAND is non-nil, the search can be edited."
+ (interactive "P")
+ (let* ((query (cond ((not edit-command) urgrep-last-query)
+ ((listp urgrep-last-query)
+ (apply #'urgrep--read-query urgrep-last-query))
+ (t (urgrep--read-command urgrep-last-query))))
+ (command (if (listp query)
+ (apply #'urgrep-to-command query)
+ query)))
+ (with-current-buffer (compilation-start command 'urgrep-mode)
+ (setq urgrep-last-query query))))
+
(defvar urgrep-mode-map
(let ((map (make-sparse-keymap)))
;; Don't inherit from `compilation-minor-mode-map',
@@ -289,7 +305,7 @@ for MS shells."
(define-key map "}" 'compilation-next-file)
(define-key map "\t" 'compilation-next-error)
(define-key map [backtab] 'compilation-previous-error)
- (define-key map "g" 'recompile)
+ (define-key map "g" 'urgrep-search-again)
map)
"Keymap for urgrep buffers.")
@@ -495,6 +511,9 @@ This function is called from `compilation-filter-hook'."
;; Minibuffer configuration
+(defvar urgrep-search-history nil "History list for urgrep search queries.")
+(defvar urgrep-command-history nil "History list for urgrep commands.")
+
(defun urgrep--search-default ()
"Return the default thing to search for.
If the region is active, return that. Otherwise, return the symbol at point."
@@ -562,24 +581,34 @@ future searches."
(define-key map "\C-c\C-c" #'urgrep-set-context)
map))
-(cl-defun urgrep--read-query (&key (regexp urgrep-search-regexp)
- (context urgrep-context-lines))
+(cl-defun urgrep--read-query (initial &key (regexp urgrep-search-regexp)
+ (context urgrep-context-lines))
"Prompt the user for a search query.
Return a list that can be passed to `urgrep-command' to turn into a shell
command."
(let* ((urgrep-search-regexp regexp)
(urgrep-context-lines context)
- (default (urgrep--search-default))
+ (default (and (not initial) (urgrep--search-default)))
(prompt (urgrep--search-prompt default))
(query (minibuffer-with-setup-hook
(lambda () (setq-local urgrep--search-default default))
- (read-from-minibuffer prompt nil urgrep-minibuffer-map nil
+ (read-from-minibuffer prompt initial urgrep-minibuffer-map
nil
'urgrep-search-history default)))
(query (if (equal query "") default query)))
- (list query :group urgrep-group-matches
- :regexp-syntax (and urgrep-search-regexp urgrep-regexp-syntax)
+ (list query :regexp urgrep-search-regexp
:context urgrep-context-lines)))
+(defun urgrep--read-command (command)
+ (read-shell-command "Search command: " command
+ (if (equal (car urgrep-command-history) command)
+ '(urgrep-command-history . 1)
+ 'urgrep-command-history)))
+
+(cl-defun urgrep--to-command (query &key regexp context)
+ (urgrep-command query :group urgrep-group-matches
+ :regexp-syntax (and regexp urgrep-regexp-syntax)
+ :context context))
+
;; User-facing functions (and supporting helpers)
@@ -591,7 +620,7 @@ command."
(t (read-directory-name "In directory: " nil nil t))))
;;;###autoload
-(cl-defun urgrep (query directory &rest rest &key command &allow-other-keys)
+(cl-defun urgrep (query directory &rest rest &key commandp &allow-other-keys)
"Recursively search in DIRECTORY for a given QUERY.
When called interactively, search in the project's root directory, or
@@ -611,14 +640,15 @@ Type \\[urgrep-set-context] to set the number of context
lines.
;; Wrap the command in a list so that we can tell it's a real command, not
;; just a query. This gets around some limitations with mixing optional and
;; keyword arguments.
- (list (apply #'urgrep-command (urgrep--read-query)))
+ (urgrep--read-query nil)
(urgrep--read-directory current-prefix-arg)))
- (setq query (cond
- (command query)
- ((listp query) (car query))
- (t (apply #'urgrep-command query rest))))
- (let ((default-directory (or directory default-directory)))
- (compilation-start query 'urgrep-mode)))
+ (let ((command (cond ((listp query) (apply #'urgrep--to-command query))
+ (commandp query)
+ (t (apply #'urgrep-command query rest))))
+ (default-directory (or directory default-directory)))
+ (with-current-buffer (compilation-start command 'urgrep-mode)
+ (setq urgrep-last-query (if (listp query) query command))
+ (current-buffer))))
(provide 'urgrep)
- [elpa] externals/urgrep ccd6fe0d4c 002/115: Add a basic keymap, (continued)
- [elpa] externals/urgrep ccd6fe0d4c 002/115: Add a basic keymap, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 8832dc103f 003/115: Add support for find/grep by delegating to Emacs' built-in `rgrep', ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 133d308eec 004/115: Don't add `-face' to face names, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 4ec9d9febd 010/115: Fix behavior of temporarily overriding `urgrep-search-regexp', ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 7780887977 005/115: Add initial support for git grep, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep d965e6b848 007/115: Add the ability to toggle regexp mode when entering a search, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 764742fd14 006/115: Recurse submodules with git grep, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 6d9217c344 013/115: Rename urgrep-test.el to urgrep-tests.el, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep aba02cc3f9 017/115: Add support for ripgrep and ack, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 53d72fe09c 023/115: Don't cache tool results for hosts which can use VC-specific tools, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 266965a0a2 024/115: Add support for intelligent editing of previous search commands,
ELPA Syncer <=
- [elpa] externals/urgrep 350d6d1889 027/115: Add support for regexp-syntax and context with the grep backend, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 887114113c 001/115: Initial revision, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep b578b0f857 009/115: Add a README and more-detailed docstrings, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 026c54d11e 012/115: Add support for setting context, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep ca67ad1f4d 030/115: Use isearch-like bindings in the urgrep minibuffer, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 8bb469a526 036/115: Add some details about our buffer-local variables, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 9ff22a4481 041/115: Minor fixes to defcustoms, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep c879c02558 040/115: Add some docs and clean up spacing, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 5b792fe0de 045/115: Use symbols instead of strings for `urgrep-tools' keys, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 3dde21c501 047/115: Add `urgrep-setup-hook', ELPA Syncer, 2023/05/10