aboutsummaryrefslogtreecommitdiff
path: root/Emacs
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2024-10-01 16:24:48 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2024-10-01 16:26:00 +0100
commita4411b989a01f3215743a045ac2e3376be16bdda (patch)
treefa077393d981952d4476a8bcd478e5f60159b5db /Emacs
parent79da47fd51f10d540f1ba52b4534d4167229f1cb (diff)
downloaddotfiles-a4411b989a01f3215743a045ac2e3376be16bdda.tar.gz
dotfiles-a4411b989a01f3215743a045ac2e3376be16bdda.tar.bz2
dotfiles-a4411b989a01f3215743a045ac2e3376be16bdda.zip
Added better grepping utilities, per file or for the configuration file
Better than (counsel-rg-or-swiper), provides a buffer of results that I can deal with as I want.
Diffstat (limited to 'Emacs')
-rw-r--r--Emacs/.config/emacs/config.org22
1 files changed, 21 insertions, 1 deletions
diff --git a/Emacs/.config/emacs/config.org b/Emacs/.config/emacs/config.org
index 96a98a2..d966f54 100644
--- a/Emacs/.config/emacs/config.org
+++ b/Emacs/.config/emacs/config.org
@@ -1439,6 +1439,8 @@ thing faster and within Emacs lisp. ~rgrep~ is useful though.
(reusable-frames . t))
:general
(search-leader
+ "g" #'grep-this-file
+ "c" #'grep-config-file
"d" #'rgrep)
(nmmap
:keymaps 'grep-mode-map
@@ -1453,7 +1455,25 @@ thing faster and within Emacs lisp. ~rgrep~ is useful though.
"ZQ" #'wgrep-abort-changes)
:config
;; Without this wgrep doesn't work properly
- (evil-set-initial-state 'grep-mode 'normal))
+ (evil-set-initial-state 'grep-mode 'normal)
+
+ (defun grep-file (query filename)
+ (grep (format "grep --color=auto -nIiHZEe \"%s\" -- %s"
+ query filename)))
+
+ (defun grep-this-file ()
+ (interactive)
+ (let ((query (read-string "Search for: ")))
+ (if (buffer-file-name (current-buffer))
+ (grep-file query (buffer-file-name (current-buffer)))
+ (let ((temp-file (make-temp-file "temp-grep")))
+ (write-region (point-min) (point-max) temp-file)
+ (grep-file query temp-file)))))
+
+ (defun grep-config-file ()
+ (interactive)
+ (let ((query (read-string "Search for: " "^[*]+ .*")))
+ (grep-file query (concat user-emacs-directory "config.org")))))
#+end_src
*** rg
#+begin_src emacs-lisp