Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

counsel--grep-mode-occur: remove column indicators for wgrep. #1835

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion counsel.el
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,16 @@ If NO-ASYNC is non-nil, do it synchronously instead."
nil))))

(defun counsel--normalize-grep-match (str)
(if (string-match-p "\\`\\.[/\\]" str) str (concat "./" str)))
;; Prepend ./ if necessary:
(unless (string-match-p "\\`\\.[/\\]" str)
(setq str (concat "./" str)))
;; Remove column info if any:
(save-match-data
(when (string-match
"[^\n:]+?[^\n/:]:[\t ]*[1-9][0-9]*[\t ]*:\\([1-9][0-9]*:\\)"
str)
(setq str (replace-match "" t t str 1))))
str)

(defun counsel-git-grep-occur ()
"Generate a custom occur buffer for `counsel-git-grep'.
Expand Down
24 changes: 24 additions & 0 deletions ivy-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,30 @@ a buffer visiting a file."
(should (not (ivy--starts-with-dotslash "t\\est5")))
(should (not (ivy--starts-with-dotslash "tes./t6"))))

(ert-deftest counsel--normalize-grep-match ()
(with-temp-buffer
(let ((match-data-orig
(progn
(insert "abcd\nefgh")
(goto-char (point-min))
(re-search-forward "\\(ab\\)\\(cd\\)")
(match-data)))
input expected out)
(dolist (test '(("./FILENAME:1234:32: TEXT MORETEXT" .
"./FILENAME:1234: TEXT MORETEXT")
("FILENAME:1234: TEXT MORETEXT" .
"./FILENAME:1234: TEXT MORETEXT")
))
(setq input (car test))
(setq expected (cdr test))
(setq out (counsel--normalize-grep-match input))
(should (equal out expected))
(should (equal match-data-orig (match-data)))
(print (list :out out :expected expected))
(setq out (counsel--normalize-grep-match out))
(should (equal out expected))
(should (equal match-data-orig (match-data)))))))

(provide 'ivy-test)

;;; ivy-test.el ends here