Refactor load-path & loaded-files search commands
Follow up to 0df480bf8
This commit is contained in:
parent
2fb76b3ba0
commit
b38501a67b
1 changed files with 37 additions and 36 deletions
|
@ -618,50 +618,51 @@ config blocks in your private config."
|
||||||
(interactive (list (doom--package-list)))
|
(interactive (list (doom--package-list)))
|
||||||
(browse-url (doom--package-url package)))
|
(browse-url (doom--package-url package)))
|
||||||
|
|
||||||
|
|
||||||
|
(defun doom--help-search-prompt (prompt)
|
||||||
|
(let ((query
|
||||||
|
(if (use-region-p)
|
||||||
|
(buffer-substring-no-properties (region-beginning) (region-end))
|
||||||
|
(or (thing-at-point 'symbol t) ""))))
|
||||||
|
(if (featurep 'counsel)
|
||||||
|
query
|
||||||
|
(read-string prompt query 'git-grep query))))
|
||||||
|
|
||||||
|
(defvar counsel-rg-base-command)
|
||||||
|
(defun doom--help-search (dirs query prompt)
|
||||||
|
;; REVIEW Replace with deadgrep
|
||||||
|
(unless (executable-find "rg")
|
||||||
|
(user-error "Can't find ripgrep on your system"))
|
||||||
|
(if (fboundp 'counsel-rg)
|
||||||
|
(let ((counsel-rg-base-command
|
||||||
|
(concat counsel-rg-base-command " "
|
||||||
|
(mapconcat #'shell-quote-argument dirs " "))))
|
||||||
|
(counsel-rg query nil "-Lz" prompt))
|
||||||
|
;; TODO Add helm support?
|
||||||
|
(grep-find
|
||||||
|
(string-join
|
||||||
|
(append (list "rg" "-L" "--search-zip" "--no-heading" "--color=never"
|
||||||
|
(shell-quote-argument query))
|
||||||
|
(mapcar #'shell-quote-argument dirs))
|
||||||
|
" "))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/help-search-load-path (query)
|
(defun doom/help-search-load-path (query)
|
||||||
"Perform a text search on your `load-path'.
|
"Perform a text search on your `load-path'.
|
||||||
Uses the symbol at point or the current selection, if available."
|
Uses the symbol at point or the current selection, if available."
|
||||||
(interactive
|
(interactive
|
||||||
(let ((query
|
(list (doom--help-search-prompt "Search load-path: ")))
|
||||||
;; TODO Generalize this later; into something the lookup module and
|
(doom--help-search (cl-remove-if-not #'file-directory-p load-path)
|
||||||
;; project search commands could as well
|
query "Search load-path: "))
|
||||||
(if (use-region-p)
|
|
||||||
(buffer-substring-no-properties (region-beginning) (region-end))
|
|
||||||
(or (symbol-name (symbol-at-point)) ""))))
|
|
||||||
(list (read-string
|
|
||||||
(format "Search load-path (default: %s): " query)
|
|
||||||
nil 'git-grep query))))
|
|
||||||
;; REVIEW Replace with deadgrep
|
|
||||||
(grep-find
|
|
||||||
(mapconcat
|
|
||||||
#'shell-quote-argument
|
|
||||||
(append (list "rg" "-L" "--search-zip" "--no-heading" "--color=never" query)
|
|
||||||
(cl-remove-if-not #'file-directory-p load-path))
|
|
||||||
" ")))
|
|
||||||
|
|
||||||
;; TODO factor our the duplicate code between this and the above
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/help-search-loaded-files (query)
|
(defun doom/help-search-loaded-files (query)
|
||||||
"Perform a text search on your `load-path'.
|
"Perform a text search on your `load-path'.
|
||||||
Uses the symbol at point or the current selection, if available."
|
Uses the symbol at point or the current selection, if available."
|
||||||
(interactive
|
(interactive
|
||||||
(let ((query
|
(list (doom--help-search-prompt "Search loaded files: ")))
|
||||||
;; TODO Generalize this later; into something the lookup module and
|
(let ((paths (cl-loop for (file . _) in load-history
|
||||||
;; project search commands could as well.
|
for filebase = (file-name-sans-extension file)
|
||||||
(if (use-region-p)
|
if (file-exists-p! (format "%s.el" filebase))
|
||||||
(buffer-substring-no-properties (region-beginning) (region-end))
|
collect it)))
|
||||||
(or (symbol-name (symbol-at-point)) ""))))
|
(doom--help-search paths query "Search loaded files: ")))
|
||||||
(list (read-string
|
|
||||||
(format "Search load-path (default: %s): " query)
|
|
||||||
nil 'git-grep query))))
|
|
||||||
(unless (executable-find "rg")
|
|
||||||
(user-error "Can't find ripgrep on your system"))
|
|
||||||
(require 'elisp-refs)
|
|
||||||
;; REVIEW Replace with deadgrep
|
|
||||||
(grep-find
|
|
||||||
(mapconcat
|
|
||||||
#'shell-quote-argument
|
|
||||||
(append (list "rg" "-L" "--search-zip" "--no-heading" "--color=never" query)
|
|
||||||
(cl-remove-if-not #'file-directory-p (elisp-refs--loaded-paths)))
|
|
||||||
" ")))
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue