um-grep
This commit is contained in:
parent
3dcf437d3e
commit
e27b62f038
1 changed files with 33 additions and 4 deletions
37
um.el
37
um.el
|
|
@ -34,11 +34,13 @@
|
||||||
;; current project, falling back to a source directory.
|
;; current project, falling back to a source directory.
|
||||||
;; `um-target-file-at-point-advice' via `embark-dwim': open file under point in all
|
;; `um-target-file-at-point-advice' via `embark-dwim': open file under point in all
|
||||||
;; known projects, falling back to a source directory.
|
;; known projects, falling back to a source directory.
|
||||||
;; `um-tag-grep': search files with some tag
|
;; `um-tag-xref': find files with some tag
|
||||||
;; `um-tag-dwim': insert or delete a tag in dired and other contexts.
|
;; `um-tag-dwim': insert or delete a tag in dired and other contexts.
|
||||||
|
;; `um-grep': grep limited to a filelist obtained dynamically.
|
||||||
|
|
||||||
(require 'project)
|
(require 'project)
|
||||||
(require 'dired)
|
(require 'dired)
|
||||||
|
(require 'grep)
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;; defcustom
|
;;; defcustom
|
||||||
|
|
@ -203,7 +205,7 @@
|
||||||
(match-string 1))))
|
(match-string 1))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun um-tag-grep ()
|
(defun um-tag-xref ()
|
||||||
"Run `project-find-regexp' on a selection made from `um-tags-history' via
|
"Run `project-find-regexp' on a selection made from `um-tags-history' via
|
||||||
`completing-read'.
|
`completing-read'.
|
||||||
|
|
||||||
|
|
@ -219,7 +221,7 @@ Ultimately this relies on `xref-matches-in-files', which calls
|
||||||
"
|
"
|
||||||
(interactive)
|
(interactive)
|
||||||
(project-find-regexp (concat "^\\+ "
|
(project-find-regexp (concat "^\\+ "
|
||||||
(completing-read "um tag: " um-tags-history nil
|
(completing-read "um-tag-xref: " um-tags-history nil
|
||||||
nil nil
|
nil nil
|
||||||
;; NOTE: this means searches
|
;; NOTE: this means searches
|
||||||
;; will add to the history:
|
;; will add to the history:
|
||||||
|
|
@ -306,6 +308,31 @@ Negative prefix arg is handled by `um--tag-do', which see.
|
||||||
(save-buffer)))
|
(save-buffer)))
|
||||||
))
|
))
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;;; grep
|
||||||
|
|
||||||
|
(defvar um-grep-history nil)
|
||||||
|
|
||||||
|
(defun um-grep (ARG)
|
||||||
|
"Run `grep' restricted to the files provided by `um--filelist-dwim' and
|
||||||
|
relative to `um--root-path'.
|
||||||
|
|
||||||
|
Prefix arg prompts for the directory instead.
|
||||||
|
"
|
||||||
|
(interactive "P")
|
||||||
|
(grep-compute-defaults)
|
||||||
|
(when-let* (
|
||||||
|
(default-directory (if ARG (read-string "directory: ") (um--root-path)))
|
||||||
|
(query (shell-quote-argument (read-string "um-grep: " nil 'um-grep-history)))
|
||||||
|
;; resolve to relative paths to keep the grep buffer sane:
|
||||||
|
(files (mapcar (lambda (f) (file-relative-name (expand-file-name f) default-directory))
|
||||||
|
(um--filelist-dwim)))
|
||||||
|
(file-string (string-join files " "))
|
||||||
|
(cmd (concat grep-command query " " file-string))
|
||||||
|
)
|
||||||
|
(grep cmd)
|
||||||
|
))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;; ispell
|
;;; ispell
|
||||||
|
|
||||||
|
|
@ -520,7 +547,7 @@ A negative prefix argument moves it backward.
|
||||||
|
|
||||||
(defvar-keymap um-minor-mode-map
|
(defvar-keymap um-minor-mode-map
|
||||||
:doc "Keymap for `um-minor-mode'."
|
:doc "Keymap for `um-minor-mode'."
|
||||||
"M-s t" #'um-tag-grep
|
"M-s t" #'um-tag-xref
|
||||||
;; M-r is not exactly right, but can't think of a better binding:
|
;; M-r is not exactly right, but can't think of a better binding:
|
||||||
"M-r t" #'um-tag-dwim
|
"M-r t" #'um-tag-dwim
|
||||||
;; TODO: find a better default binding?
|
;; TODO: find a better default binding?
|
||||||
|
|
@ -612,6 +639,8 @@ A negative prefix argument moves it backward.
|
||||||
"w" 'um-copy-line-as-kill
|
"w" 'um-copy-line-as-kill
|
||||||
"C-y" 'um-yank
|
"C-y" 'um-yank
|
||||||
"t" 'um-tag-dwim-iro
|
"t" 'um-tag-dwim-iro
|
||||||
|
;; g is sidebar-revert-resize to parallel dired:
|
||||||
|
"M-s g" #'um-grep
|
||||||
)
|
)
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue