aboutsummaryrefslogtreecommitdiff
path: root/Emacs/.config/emacs
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2025-02-15 21:45:36 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2025-02-15 21:47:22 +0000
commit36af4e163c460680fe94fce510aa55972f329a19 (patch)
tree7139152a243f49a5b96a82fcc2b185d7e558222a /Emacs/.config/emacs
parent9a4760068fd891869a7d39f1d57706600c48e515 (diff)
downloaddotfiles-36af4e163c460680fe94fce510aa55972f329a19.tar.gz
dotfiles-36af4e163c460680fe94fce510aa55972f329a19.tar.bz2
dotfiles-36af4e163c460680fe94fce510aa55972f329a19.zip
Refactor search.el for cleanliness
Remove useless newlines and try to utilise thread-last where possible to make transformations clearer to the reader.
Diffstat (limited to 'Emacs/.config/emacs')
-rw-r--r--Emacs/.config/emacs/elisp/search.el36
1 files changed, 16 insertions, 20 deletions
diff --git a/Emacs/.config/emacs/elisp/search.el b/Emacs/.config/emacs/elisp/search.el
index 1dcfafb..7522d6f 100644
--- a/Emacs/.config/emacs/elisp/search.el
+++ b/Emacs/.config/emacs/elisp/search.el
@@ -24,6 +24,9 @@
;;; Code:
+(autoload #'grep "grep")
+(autoload #'thread-last "subr-x")
+
(defvar +search/directories
'("~/Dotfiles/" "~/Text/" "~/.local/src/dwm/" "~/.local/src/dwmblocks/"
"~/.local/src/st/" "~/.local/src/dmenu/" "~/Website/")
@@ -33,39 +36,32 @@
"Get files from DIRECTORY using `git ls-files`.
Returns a list of files with the directory preprended to them."
(let* ((default-directory directory)
- (names (split-string
- (shell-command-to-string "git ls-files -z --full-name --")
- "\0")))
- (mapcar #'(lambda (name)
- (concat directory name))
- names)))
+ (git-files (shell-command-to-string "git ls-files -z --full-name --"))
+ (names (split-string git-files "\0")))
+ (mapcar #'(lambda (name) (concat directory name)) names)))
(defun +search/get-all-candidates ()
- (cl-reduce
- #'(lambda (x y) (append x y))
- (mapcar #'(lambda (directory)
- (+search/get-candidates (expand-file-name directory)))
- +search/directories)))
+ (thread-last (mapcar #'(lambda (directory) (expand-file-name directory)) +search/directories)
+ (mapcar #'(lambda (directory) (+search/get-candidates directory)))
+ (cl-reduce #'(lambda (x y) (append x y)))))
(defun +search/find-file ()
(interactive)
(find-file (completing-read "Find file: " (+search/get-all-candidates) nil t)))
(defun +search/-format-grep-candidates ()
- (string-join
- (mapcar
- #'(lambda (x) (concat "\"" x "\" "))
- (cl-remove-if #'directory-name-p (+search/get-all-candidates)))))
-
-(autoload #'grep "grep")
+ (thread-last (+search/get-all-candidates)
+ (cl-remove-if #'directory-name-p)
+ (mapcar #'(lambda (x) (concat "\"" x "\" ")))
+ (string-join)))
(defun +search/search-all ()
(interactive)
(let ((term (read-string "Search for: " (thing-at-point 'symbol)))
(candidates (+search/-format-grep-candidates)))
- (grep
- (format "grep --color=auto -nIHZe \"%s\" -- %s"
- term candidates))
+ (thread-last candidates
+ (format "grep --color=auto -nIHZe \"%s\" -- %s" term)
+ (grep))
(next-error)))
(provide 'search)