-
Notifications
You must be signed in to change notification settings - Fork 41
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 rg-dwim-regexp #28
Conversation
2 similar comments
3 similar comments
1 similar comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for my slow response on this. Looking good in general. I will be quicker from now on.
rg.el
Outdated
@@ -409,12 +409,13 @@ If LITERAL is non nil prompt for literal pattern." | |||
nil default-directory t))) | |||
(list pattern files dir))) | |||
|
|||
(defun rg-read-files (pattern) | |||
(defun rg-read-files (&optional pattern) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pattern isn't really used from anywhere now. That's actually unfortunate since it's quite useful to have that in the prompt, especially in the functions that extract the pattern automatically. I think the code could be arranged to not use the interactive macro for user interactive input and reorder things such that pattern is extracted first.
I don't think this is super important to spend much time on so I am fine if you remove the pattern argument and cleanup the code below according to that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dajva I think the reason I made this change was that I couldn't figure out a way to guarantee that the pattern was always set before the file alias was set without changing the function signatures in some cases, and I wanted to keep the existing api the same. I think if we stopped using the interactive macro to set the pattern, then we'd have to change the way the functions get called in the tests (and this could also possibly impact some user code that relies on the existing functions).
Do you know a way around this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had problems with this as well. I kind of regret the choice of using interactive
for the input but I guess I'll have to live with it for now. This way of incuding the pattern in the prompt is actually a legacy from when I started this based on grep.el
and I am not sure I would have done the same choice now, although it's kind of useful sometimes.
So, just ignore this. If you want to clean up the defun do that, otherwise I can fix later on.
rg.el
Outdated
@@ -1007,67 +1008,124 @@ prefix is not supplied `rg-keymap-prefix' is used." | |||
(message "Global key bindings for `rg' enabled with prefix: %s" | |||
(edmacro-format-keys prefix)))) | |||
|
|||
(defun rg-set-search-defaults (args) | |||
(if (not (plist-get args :pattern)) (plist-put args :pattern 'regexp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting: Put the "then" clause on next line.
rg.el
Outdated
constructed shell command line before it is executed." | ||
(interactive | ||
(progn | ||
(append (rg-read-input 'literal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rg-read-input
is unused now so please remove it.
rg.el
Outdated
(rg-run pattern files dir literal confirm))))) | ||
|
||
;;;###autoload | ||
(rg-define-search rg-project |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you readd all the removed docstrings to the new entries, using the macro?
rg.el
Outdated
|
||
;;;###autoload | ||
(defmacro rg-define-search (name &rest args) | ||
(let* ((body (macroexp-parse-body args)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't use macroexp-parse-body
unfortunately, since this needs to work all the way back to emacs 24.3. :-(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, that's a bummer. i'll probably just end up copying the definition of that function as a helper here then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that's fine.
rg.el
Outdated
iargs)) | ||
|
||
;;;###autoload | ||
(defmacro rg-define-search (name &rest args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The macro itself needs docs
rg.el
Outdated
(defun rg-search-parse-local-bindings (search-cfg) | ||
(let* ((binding-list `((confirm ,(plist-get search-cfg :confirm)))) | ||
(pattern-opt (plist-get search-cfg :pattern)) | ||
(literal (or (eq pattern-opt 'literal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you split the :pattern
key into :pattern = { 'point }
and :type = { 'literal, 'regexp }
? I'd like to keep the interface flexible and splitting this will ease extending this further on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was mid-cleanup when you reviewed this. I had already split the :pattern
key in to :query = {'ask 'point}
and :format = {'regexp 'literal}
. I can change these names to what you suggest if you prefer those though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you did is perfect.
rg.el
Outdated
(setq binding-list (append binding-list `((literal ,literal)))) | ||
|
||
;; pattern binding | ||
(when (not (or (eq pattern-opt 'literal) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use unless
instead of (when (not
. Can you change all such occurances in this pr?
rg.el
Outdated
(rg-dwim-project-dir))) | ||
|
||
;;;###autoload | ||
(rg-define-search rg-dwim-regexp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change the name of this? I want the dwim
entries to be "no-hands", i.e. you shouldn't have any manual input for those. As for a name. rg-project-
prefix seems approriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i decided to remove this function all together. i agree with you that the first name was inappropriate, but i couldn't think of another good name either. more importantly, i don't think this function is necessary in the library anymore since custom search functions are so easy to define with the rg-define-search
macro anyway.
rg.el
Outdated
binding-list)) | ||
|
||
(defun rg-search-parse-interactive-pattern-arg (search-cfg) | ||
(let* ((opt (plist-get search-cfg :pattern)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docstrings for all new defuns. Need that to pass ci tests.
2 similar comments
@dajva I'm not sure what to make of the CI failure. It looks like the style linter doesn't load the definitions of any of the functions referenced in the |
rg.el
Outdated
@@ -409,12 +409,13 @@ If LITERAL is non nil prompt for literal pattern." | |||
nil default-directory t))) | |||
(list pattern files dir))) | |||
|
|||
(defun rg-read-files (pattern) | |||
(defun rg-read-files (&optional pattern) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had problems with this as well. I kind of regret the choice of using interactive
for the input but I guess I'll have to live with it for now. This way of incuding the pattern in the prompt is actually a legacy from when I started this based on grep.el
and I am not sure I would have done the same choice now, although it's kind of useful sometimes.
So, just ignore this. If you want to clean up the defun do that, otherwise I can fix later on.
rg.el
Outdated
(docstring (car body)) | ||
"Define an rg search functions named NAME. | ||
ARGS is a search specification with `:query' (point or ask), | ||
`:format' (literal or regexp), `files' (rg or custom file alias), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The format of the keys and symbolx is inconsistent. Here you use the `:key' form for keys and no quote for the symbols. Above you just write :key and quoted symbols. I am not entirely sure what's common in this area but
I think the backquote-quote format is only for symbols that can be looked up, like vars and defuns etc so that links will be created in the documentation.
For the symbols used as values for the keys I used uppercase in rg-ignore-case
. I am not entirely sure what should be used here. If you don't have more insights into this could you use uppercase as I used before to keep it consistent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I don't know either. I ended up going with uppercase for the symbal definitions, and getting rid of the the backquote-quote for keywords. One thing I don't like about the uppercase form is that it isn't literally what the user should pass when calling the function/macro, but the values have to get differentiated from normal text somehow, and that wouldn't be the literal form either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you might be right that the uppercase is the wrong call. Let's keep this for now and I will see if I can find something about how others do it. Quoted form for the symbols seems to be the easiest one to interpret.
Regarding the CI failure I think you need to wrap the defuns used from the macro in |
1 similar comment
Thanks a lot for your effort on this. Very nice implementation and well structured code. |
thank you for writing this package in the first place! i'm glad i could help. |
Add a new function,
rg-dwim-regexp
to search for a user provided pattern using the default type alias.rg-dwim-regexp
is like a cross betweenrg-project
andrg-dwim
in that it skips the files confirmation but still lets you enter your own pattern.