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

Add support for opening counsel-git-grep in other window #3044

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

flooose
Copy link

@flooose flooose commented Apr 25, 2024

Adds functionality described in related issue

Copy link
Collaborator

@basil-conto basil-conto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Works nicely.

See some minor style/logic suggestions below.

counsel.el Outdated Show resolved Hide resolved
counsel.el Outdated Show resolved Hide resolved
counsel.el Outdated Show resolved Hide resolved
counsel.el Outdated Show resolved Hide resolved
counsel.el Outdated Show resolved Hide resolved
@basil-conto basil-conto added the waiting-for-ca Waiting for author's copyright assignment label Apr 27, 2024
New regex:"\\`\\(.*\\):\\([[:digit:]]+\\):\\(.*\\)\\'"

Old regex: "\\`\\(.*?\\):\\([0-9]+\\):\\(.*\\)\\'"
Copy link
Collaborator

@basil-conto basil-conto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, we're almost there! The only real issue is the use of rx-define, which is not sufficiently backward compatible (one day we'll bump Counsel's minimum Emacs version, but not today :).

counsel.el Outdated Show resolved Hide resolved
counsel.el Outdated
(defun counsel--git-grep-file-and-line-number (x)
"Returns a cons cell of file-name and line number"
(when (string-match (rx grouped-regex-matches) x)
(cons (match-string-no-properties 1 x) (match-string-no-properties 2 x))))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is meant to return a file name and a line number: file names are usually strings, and line numbers are usually numbers, so I still think it would be cleaner to parse the second match group as a number here, instead of passing around a string to be parsed as a number later. Then counsel--git-grep-go-to-location won't need to know that its argument is actually a string that has to first be parsed.

counsel.el Outdated
(cons (match-string-no-properties 1 x) (match-string-no-properties 2 x))))

(defun counsel--git-grep-go-to-location (line-number)
"Go to line-number within current buffer"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first line of a docstring is a short but complete sentence (ending in a full stop), and argument names are written in all-caps. If you're interested in the full details of Elisp docstring conventions, feel free to look through (elisp) Documentation Tips.

So in this case, the docstring could be something like:

"Go to LINE-NUMBER in current buffer for `counsel-git-grep'."

Similarly counsel--git-grep-file-and-line-number above could be something like:

  "Extract file name and line number from `counsel-git-grep' line X.
Return a pair (FILE . LINE) on success; nil otherwise."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement waiting-for-ca Waiting for author's copyright assignment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants