branch: externals/ivy-hydra
commit fb6db466915a058139e2ea2c427474930fe6788d
Author: Rudi Grinberg <[email protected]>
Commit: Oleh Krehel <[email protected]>
counsel.el (counsel-flycheck-occur): Add
Fixes #2404
---
counsel.el | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/counsel.el b/counsel.el
index ea1374a..3553dbe 100644
--- a/counsel.el
+++ b/counsel.el
@@ -6334,9 +6334,36 @@ Local bindings (`counsel-mode-map'):
(flycheck-error-message error)) 'error error))
flycheck-current-errors))
+(defun counsel-flycheck-occur (cands)
+ "Generate a custom occur buffer for `counsel-flycheck'."
+ (require 'thingatpt)
+ (unless cands
+ (message "need to handle empty cands"))
+ (unless (eq major-mode 'ivy-occur-grep-mode)
+ (ivy-occur-grep-mode)
+ (setq default-directory (ivy-state-directory ivy-last)))
+ (swiper--occur-insert-lines
+ (mapcar
+ (lambda (cand)
+ (let ((err (get-text-property 0 'error cand)))
+ (propertize
+ (format
+ "%s:%d:%s"
+ (flycheck-error-filename err)
+ (flycheck-error-line err)
+ (save-excursion
+ (with-current-buffer (flycheck-error-buffer err)
+ (goto-line (flycheck-error-line err))
+ (string-trim (thing-at-point 'line)))))
+ 'error err)))
+ cands)))
+
(defun counsel-flycheck-errors-action (error)
(flycheck-jump-to-error (get-text-property 0 'error error)))
+(ivy-configure 'counsel-flycheck
+ :occur #'counsel-flycheck-occur)
+
;;;###autoload
(defun counsel-flycheck ()
"Flycheck errors."