-
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
Truncated search pattern in header #177
Truncated search pattern in header #177
Conversation
Thanks for the PR. I like the feature, might even be something to consider to be enabled by default for some proper limit. My main concern is that it's hard to discover and hit (with the mouse) the truncation string. I ran this locally and thought there was a bug since I didn't see the full search string when hovering the truncated version. Then I realized I needed to hover the three dots which is part of the same entity visually. The other issue is a keyboard trigger. Since this is emacs we need some way to echo the full search via key binding. I do think it should be possible to get rid of the help function but the header-line-format is tricky so I can't really give any concrete advice before testing a bit myself. See if I can get around to that. |
Those are good points, I'll have another go at it soon, thanks. |
So I just found
Unfortunately, using UPDATE: So this wouldn't really help since setting |
How would you currently do that? For now I just pushed a change to use the built-in function and apply the help echo to then entire text. |
Not sure TBH. I was thinking there was something in the
This is better and good enough I think. |
So what are the style issues you'd like addressed? And what could be a good default limit? I'll check if I can add some tests for the new functions in the meanwhile to not tank the coverage. |
rg-header.el
Outdated
@@ -97,6 +106,31 @@ items that the map will be applied to." | |||
help-echo ,help | |||
keymap ,map))) | |||
|
|||
(defun rg-header--truncate-search-pattern (search) |
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.
Even though the --
convention is kind of nice for private stuff, I have never used it in this package so let's keep it out to be consistent.
Same for the other similar names.
rg-header.el
Outdated
(and (numberp rg-header-max-search-string-length) | ||
(< rg-header-max-search-string-length (length search)))) | ||
|
||
(defun rg-header--search-help (window _object _pos) |
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.
&rest _
instead?
rg-header.el
Outdated
|
||
(defun rg-header--search-help (window _object _pos) | ||
"Get the search help for WINDOW at POS." | ||
(declare-function rg-cur-search-pattern "rg-result.el") |
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'd like this to be a top level declaration, right after the require
statements if possible.
rg-header.el
Outdated
@@ -113,8 +147,8 @@ If FULL-COMMAND specifies if the full command line search was done." | |||
("literal" rg-literal-face) | |||
("regexp" rg-regexp-face)))) | |||
(rg-header-mouse-action | |||
'rg-rerun-change-query "Change search string" | |||
`(:eval (rg-search-pattern ,search))) | |||
'rg-rerun-change-query #'rg-header--search-help |
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.
Personally I would probably evaluate the help string here instead of using a function. I don't mind this though, so you can keep it if you like.
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.
It would just mean that we wouldn't evaluate it lazily. I'm guessing the performance impact is negligible though.
If you prefer it that way I can change it.
test/rg-header.el-test.el
Outdated
;; When predicate is true. | ||
(rg-unit/mock-truncation-predicate (:max 11 :predicate always) | ||
(should (string= | ||
"everything…" |
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 think you need to use the actual ellipsis in these test to ensure they pass in all envrionments. So something like:
(concat "everything" (truncate-string-ellipsis))
In my test runs ellipsis ends up being "..." (three separate dots).
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.
Ah! Good catch.
rg-header.el
Outdated
|
||
;; Customization | ||
(defcustom rg-header-max-search-string-length nil | ||
"The max line length of header line items." |
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.
This doc string seems a bit off target. Could we change this to something like: The max length of header line search string item.
Not exactly sure. 40-50 seems ok to me to have it not being too much in the way. |
I addressed all your points (I hope) in the latest commit. I will rebase everything into a single commit if you're fine with the changes now. |
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.
Looks good. Just one thing before it can be merged.
rg-header.el
Outdated
|
||
;; Customization | ||
(defcustom rg-header-max-search-string-length nil | ||
"The max line length of header line items." | ||
(defcustom rg-header-max-search-string-length 50 |
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 being unclear here. I was supposed communicate that we need a keyboard binding for this to be enabled by default.
So if you either add that or keep this as nil
for now. I suppose binding it to v
(as in verbose) could make sense in case you want to add 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.
You want a binding in rg-mode-map
to toggle this?
I think I'd prefer keeping it at nil
and leave it at the user's discretion to set it to a value they see fit. I think the scenario where they'd run into the search pattern length being an issue is so minute that dedicating a key to truncating it seems a bit big.
One thing that we may want to consider is to call this -string-width
not string-length
. What do you think?
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.
Ok, let's put it as nil
then. I think I prefer length actually. string-width gives me associations to pixel width on screen rather than number of characters in a string.
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.
Alright, pushed (never mind the commit message, I didn't rename after all, just had it ready to go). Let me know if you're fine with it now, then I'll rebase and remove draft status. Thank you.
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.
All seems fine. So you can clean up and then I merge
This adds new variable `rg-header-max-search-string-length`. If the variable is set to a number and the search pattern exceeds that threshold the header item of the result buffer is truncated. Function `truncate-string-to-width` is used. The help echo of the item now displays the full search pattern if truncation was applied.
cfc93ec
to
71df25a
Compare
Thanks a lot. Merged. |
This is an attempt to tackle #164.
It's a bit awkward since it means we need to use a function for the
help-echo
prop that needs to accessrg-cur-search
to access the full search pattern.Maybe you have a better idea.