Skip to content

Commit

Permalink
Use null-device
Browse files Browse the repository at this point in the history
* counsel.el (counsel--null-device): New function.
(counsel-locate-cmd-mdfind, counsel-grep-occur): Use it.
  • Loading branch information
basil-conto committed Mar 31, 2024
1 parent 5ca9d7d commit ee56399
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions counsel.el
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ Return a list or string depending on input."
formatter)))
(t (apply #'format formatter args))))

(defalias 'counsel--null-device
(if (fboundp 'null-device) #'null-device (lambda () null-device))
"Compatibility shim for Emacs 28 function `null-device'.")

;;* Async Utility
(defvar counsel--async-time nil
"Store the time when a new process was started.
Expand Down Expand Up @@ -2651,7 +2655,9 @@ library, which see."
(defun counsel-locate-cmd-mdfind (input)
"Return a `mdfind' shell command based on INPUT."
(counsel-require-program "mdfind")
(format "mdfind -name %s 2> /dev/null" (shell-quote-argument input)))
(format "mdfind -name %s 2>%s"
(shell-quote-argument input)
(shell-quote-argument (counsel--null-device))))

(defun counsel-locate-cmd-es (input)
"Return a `es' shell command based on INPUT."
Expand Down Expand Up @@ -3368,14 +3374,12 @@ relative to the last position stored here.")
(swiper--add-overlays (ivy--regex ivy-text))))))))

(defun counsel-grep-occur (&optional _cands)
"Generate a custom occur buffer for `counsel-grep'."
(counsel-grep-like-occur
(format
"grep -niE %%s %s /dev/null"
(shell-quote-argument
(file-name-nondirectory
(buffer-file-name
(ivy-state-buffer ivy-last)))))))
"Generate a custom Occur buffer for `counsel-grep'."
(let ((file (buffer-file-name (ivy-state-buffer ivy-last))))
(counsel-grep-like-occur
(format "grep -niE %%s %s %s"
(if file (shell-quote-argument (file-name-nondirectory file)) "")
(shell-quote-argument (counsel--null-device))))))

(defvar counsel-grep-history nil
"History for `counsel-grep'.")
Expand Down

0 comments on commit ee56399

Please sign in to comment.