Skip to content

Commit

Permalink
Include result count in the modeline
Browse files Browse the repository at this point in the history
Fixes #150
  • Loading branch information
Wilfred committed Jun 27, 2024
1 parent eafc642 commit 3113c81
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# v0.13

Deadgrep now includes the result count in the mode line.

**Changed default keybindings**: `n` and `p` are now bound to
`deadgrep-forward-match` and `deadgrep-backward-match` respectively,
so they only move through matches, ignoring buttons and file
Expand Down
16 changes: 15 additions & 1 deletion deadgrep.el
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ We save the last line here, in case we need to append more text to it.")
"If non-nil, don't (re)start searches.")
(defvar-local deadgrep--running nil
"If non-nil, a search is still running.")
(defvar-local deadgrep--result-count nil
"The number of matches found for the current search.")

(defvar-local deadgrep--debug-command nil)
(put 'deadgrep--debug-command 'permanent-local t)
Expand Down Expand Up @@ -271,6 +273,11 @@ It is used to create `imenu' index.")
;; to hide this filename before we finished finding
;; results in it.
(insert pretty-line-num content)

(when (null deadgrep--result-count)
(setq deadgrep--result-count 0))
(cl-incf deadgrep--result-count)

(when truncate-p
(insert
(propertize " ... (truncated)"
Expand Down Expand Up @@ -1024,7 +1031,7 @@ Returns a list ordered by the most recently accessed."
"Keymap for `deadgrep-edit-mode'.")

(define-derived-mode deadgrep-mode special-mode
'("Deadgrep" (:eval (spinner-print deadgrep--spinner)))
'(:eval (deadgrep--mode-line))
"Major mode for deadgrep results buffers."
(remove-hook 'after-change-functions #'deadgrep--propagate-change t))

Expand Down Expand Up @@ -1452,6 +1459,7 @@ matches (if the result line has been truncated)."
"Start a ripgrep search."
(setq deadgrep--spinner (spinner-create 'progress-bar t))
(setq deadgrep--running t)
(setq deadgrep--result-count 0)
(spinner-start deadgrep--spinner)
(let* ((args (deadgrep--arguments
search-term search-type case
Expand Down Expand Up @@ -1618,6 +1626,12 @@ deadgrep is ready but not yet searching."
(format "Press %s to start the search."
(key-description restart-key))))))

(defun deadgrep--mode-line ()
(let ((s (if deadgrep--result-count
(format "Deadgrep:%s" deadgrep--result-count)
"Deadgrep")))
(concat s (spinner-print deadgrep--spinner))))

(defun deadgrep--create-imenu-index ()
"Create `imenu' index for matched files."
(when deadgrep--imenu-alist
Expand Down

0 comments on commit 3113c81

Please sign in to comment.