-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfzfa-grep.el
More file actions
75 lines (60 loc) · 2.35 KB
/
Copy pathfzfa-grep.el
File metadata and controls
75 lines (60 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
;;; fzfa-grep.el --- POSIX grep integration for `fzfa' -*- lexical-binding: t; -*-
;; Copyright (C) 2026 James Nguyen
;; Author: James Nguyen <james@jojojames.com>
;; Version: 1.0
;; Package-Requires: ((emacs "29.1"))
;; Homepage: https://github.com/jojojames/fzfa
;; Assisted-by: Claude:claude-opus-4-7
;; SPDX-License-Identifier: GPL-3.0-or-later
;;; Commentary:
;; POSIX `grep' integration for fzfa.
;;
;; Loaded automatically when `grep' is in `fzfa-extensions' and
;; `fzfa-setup' has been called. No setup function is registered —
;; the commands are usable immediately.
;;
;; Commands:
;; `fzfa-grep' Search file contents under `default-directory'
;; `fzfa-grep-current-file' Search the current buffer's file with grep
;;; Code:
(require 'fzfa)
(defcustom fzfa-grep-command "grep -Rn ''"
"Shell command used by `fzfa-grep' for content search.
Output must be FILE:LINE:CONTENT."
:type 'string
:group 'fzfa)
(defcustom fzfa-grep-current-file-command "grep -vnH '^[[:space:]]*$' %s"
"Shell command used by `fzfa-grep-current-file'.
A `%s' placeholder is filled with the shell-quoted current file path.
Output must be FILE:LINE:CONTENT."
:type 'string
:group 'fzfa)
;;;###autoload
(defun fzfa-grep ()
"Search file contents under `default-directory' with grep.
Streams all file contents as FILE:LINE:CONTENT; type
to fuzzy-filter across them.
Selecting a candidate opens the file at that line.
The command is configurable via `fzfa-grep-command'."
(interactive)
(when-let* ((r (fzfa-completing-read
:command fzfa-grep-command
:category 'fzfa-grep
:group #'fzfa--grep-group)))
(fzfa-visit-grep r)))
;;;###autoload
(defun fzfa-grep-current-file ()
"Search the current buffer's file with grep.
Streams non-blank lines as FILE:LINE:CONTENT; type to fuzzy-filter across them.
Selecting a candidate jumps to that line in the file.
The command is configurable via `fzfa-grep-current-file-command'."
(interactive)
(unless buffer-file-name
(user-error "Buffer is not visiting a file"))
(when-let* ((r (fzfa-completing-read
:command (format fzfa-grep-current-file-command
(shell-quote-argument buffer-file-name))
:category 'fzfa-grep)))
(fzfa-visit-grep r)))
(provide 'fzfa-grep)
;;; fzfa-grep.el ends here