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 rg-dwim-regexp #28

Merged
merged 10 commits into from
Jan 15, 2018
Merged

add rg-dwim-regexp #28

merged 10 commits into from
Jan 15, 2018

Conversation

zonotope
Copy link
Contributor

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 between rg-project and rg-dwim in that it skips the files confirmation but still lets you enter your own pattern.

@zonotope zonotope mentioned this pull request Dec 25, 2017
@coveralls
Copy link

coveralls commented Dec 25, 2017

Coverage Status

Coverage decreased (-0.5%) to 77.957% when pulling e0ba1ba on zonotope:master into 6898409 on dajva:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.5%) to 77.957% when pulling e0ba1ba on zonotope:master into 6898409 on dajva:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.5%) to 77.957% when pulling e0ba1ba on zonotope:master into 6898409 on dajva:master.

@zonotope zonotope closed this Dec 25, 2017
@zonotope zonotope reopened this Dec 25, 2017
@coveralls
Copy link

coveralls commented Dec 25, 2017

Coverage Status

Coverage decreased (-0.5%) to 77.957% when pulling 9ca4eda on zonotope:master into 6898409 on dajva:master.

3 similar comments
@coveralls
Copy link

coveralls commented Dec 25, 2017

Coverage Status

Coverage decreased (-0.5%) to 77.957% when pulling 9ca4eda on zonotope:master into 6898409 on dajva:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.5%) to 77.957% when pulling 9ca4eda on zonotope:master into 6898409 on dajva:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.5%) to 77.957% when pulling 9ca4eda on zonotope:master into 6898409 on dajva:master.

@coveralls
Copy link

coveralls commented Jan 7, 2018

Coverage Status

Coverage increased (+4.3%) to 82.707% when pulling 64d7bf0 on zonotope:master into 6898409 on dajva:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+4.0%) to 82.368% when pulling 9a24e3a on zonotope:master into 6898409 on dajva:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+4.0%) to 82.368% when pulling 9a24e3a on zonotope:master into 6898409 on dajva:master.

Copy link
Owner

@dajva dajva left a 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)
Copy link
Owner

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.

Copy link
Contributor Author

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?

Copy link
Owner

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)
Copy link
Owner

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)
Copy link
Owner

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
Copy link
Owner

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))
Copy link
Owner

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. :-(

Copy link
Contributor Author

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.

Copy link
Owner

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)
Copy link
Owner

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)
Copy link
Owner

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.

Copy link
Contributor Author

@zonotope zonotope Jan 13, 2018

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.

Copy link
Owner

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)
Copy link
Owner

@dajva dajva Jan 11, 2018

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
Copy link
Owner

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.

Copy link
Contributor Author

@zonotope zonotope Jan 14, 2018

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))
Copy link
Owner

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.

@coveralls
Copy link

coveralls commented Jan 14, 2018

Coverage Status

Coverage increased (+6.1%) to 84.541% when pulling a515fcf on zonotope:master into 6898409 on dajva:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+6.1%) to 84.541% when pulling a515fcf on zonotope:master into 6898409 on dajva:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+6.1%) to 84.541% when pulling a515fcf on zonotope:master into 6898409 on dajva:master.

@zonotope
Copy link
Contributor Author

@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-define-search macro. I can't tell what the problem could be from looking through style-check.el, all the tests pass, and I can successfully load rg.el, define a custom search in an emacs instance, and the functions work as I expect. Do you know what the problem could be?

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)
Copy link
Owner

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),
Copy link
Owner

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?

Copy link
Contributor Author

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.

Copy link
Owner

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.

@dajva
Copy link
Owner

dajva commented Jan 14, 2018

Regarding the CI failure I think you need to wrap the defuns used from the macro in eval-when-compile to make those available during compilation (which is what happens in the style-check). At least that works locally for me.

@coveralls
Copy link

coveralls commented Jan 15, 2018

Coverage Status

Coverage increased (+4.7%) to 83.146% when pulling c558a14 on zonotope:master into 6898409 on dajva:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+4.7%) to 83.146% when pulling c558a14 on zonotope:master into 6898409 on dajva:master.

@dajva dajva merged commit 2a3e6ac into dajva:master Jan 15, 2018
@dajva
Copy link
Owner

dajva commented Jan 15, 2018

Thanks a lot for your effort on this. Very nice implementation and well structured code.
This will greatly improve the usability of this package.

@zonotope
Copy link
Contributor Author

thank you for writing this package in the first place! i'm glad i could help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants