]> code.delx.au - gnu-emacs-elpa/commitdiff
counsel.el (counsel-git-grep-transformer): New defun
authorOleh Krehel <ohwoeowho@gmail.com>
Sat, 27 Feb 2016 08:10:31 +0000 (09:10 +0100)
committerOleh Krehel <ohwoeowho@gmail.com>
Sat, 27 Feb 2016 08:10:31 +0000 (09:10 +0100)
* counsel.el (ivy-set-display-transformer):
  'counsel-git-grep-transformer to 'counsel-git-grep .

Fixes #399

counsel.el

index cf6eb01d843de8e6e6ed42ec237dc7d6ea8fa2b5..e8597a6f8fb90354d7c61050ce13061a5b728024 100644 (file)
@@ -686,6 +686,7 @@ Describe the selected candidate."
     map))
 
 (ivy-set-occur 'counsel-git-grep 'counsel-git-grep-occur)
+(ivy-set-display-transformer 'counsel-git-grep 'counsel-git-grep-transformer)
 
 (defvar counsel-git-grep-cmd "git --no-pager grep --full-name -n --no-color -i -e %S"
   "Store the command for `counsel-git-grep'.")
@@ -753,6 +754,19 @@ Describe the selected candidate."
                  candidates))
         (setq ivy--old-re regexp))))
 
+(defun counsel-git-grep-transformer (str)
+  "Higlight file and line number in STR."
+  (when (string-match "\\`\\([^:]+\\):\\([^:]+\\):" str)
+    (set-text-properties (match-beginning 1)
+                         (match-end 1)
+                         '(face compilation-info)
+                         str)
+    (set-text-properties (match-beginning 2)
+                         (match-end 2)
+                         '(face compilation-line-number)
+                         str))
+  str)
+
 ;;;###autoload
 (defun counsel-git-grep (&optional cmd initial-input)
   "Grep for a string in the current git repository.