-
-
Notifications
You must be signed in to change notification settings - Fork 645
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
Limit the maximum string size to be displayed in echo area #3661
Conversation
4d9b205
to
e6613be
Compare
I guess this intersects with #3635 (only spotted it now). While I think that PR solves a more general problem, it may make sense to restrict it here as well. Dunno, let's discuss. |
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.
Seems a good improvement - thanks!
cider-overlays.el
Outdated
:prepend-face (or overlay-face 'cider-result-overlay-face)))) | ||
(max-message-width (* 10 (window-width)))) | ||
(when (> (string-width font-value) max-message-width) | ||
(setq font-value (concat (substring font-value 0 (- max-message-width 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.
Two nits:
- seems better to reuse the
let*
rather than to setq - it's less imperative - string-trim-right seems slightly better performed after the trimming?
@@ -316,7 +316,11 @@ focused." | |||
(cider--make-result-overlay font-value |
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.
cider--make-result-overlay font-value
is using the non-trimmed value
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.
That's because cider--make-result-overlay
performs its own trimming, so I guess it makes sense to pass the full result to it. In case, in the future, it decides to do something else with the result, so we don't obstruct that here.
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, you meant trimming as in string-trim.
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.
No, I didn't mean string-trim, but length trim
That's because cider--make-result-overlay performs its own trimming
Alright then 👍
I've looked through #3635 and now I think that my PR is unnecessary. While with that PR, the echo area would still receive more than it could handle (e.g., 10k characters instead of ~1500 with this PR), the difference in perceived latency is not noticeable. On the plus side, we won't be doing similar work in two places. If we can fast forward #3635 – that will be great. |
I don't mind about having both in place - this can be a last-resource measure. A drawback being that users (/ maintainers) have to understand/tweak more stuff (e.g. let's imagine that each of the solutions has a different defcustom, or in any case, a different algo). Maybe for the sake of containing complexity (i.e. favoring existing tech, namely the "print quotas"), let's go for #3635 . I can polish it later this week or if it feels like a blocker, I'd be OK with you taking over it. |
You beat me to it ^^ as mentioned, I can go back to it soon, else you can take over. |
Actually, let me reopen. I just understood that because an overflowing message in the echo area truncates the beginning: then, after #3635 is applied (which truncates the end), an overflowing message will show the middle of printed value, which is going to be quite ugly and probably quite confusing. Currently, at least, the user gets to see the end of the value and understand the return type (here – a list), but when shown the middle of the message they won't even get that. Also, arguably the beginning of the value is more useful then the end of it. So, I think, we'll still need this PR, and perhaps even more so after #3635. |
If a small enough quota was requested for ops which output goes to the echo area, why would there be truncating in the beginning? |
That implies that different quota is used when the output is going to the minibuffer vs the REPL vs somewhere else. From #3635 I gathered that it isn't going to be the case. Besides, this goes against how |
e6613be
to
ee581a5
Compare
ee581a5
to
2da9dcd
Compare
Addressed the comments.
I don't think we would need a |
You're partially right, but in that PR some parts were intentionally unchanged to not tighten the quota. So indeed the 'overlay' and 'echo area' limits would be coupled. Honestly I believe that it would be a very minor problem / edge case, because:
So my thinking is that the echo area can help as a quick confirmation that evaluation succeeded - its rough value. Because it's 'transient', it only has relative value as it can easily go away with keypresses or other events. So, tldr I don't exactly oppose this PR but it only seems useful for making very specific things like I'd prefer to keep things simple and not add further moving pieces, since they only address edge cases in the less favored of the available UIs. |
I agree with you that the problem is not a huge one. But I'd still prefer to see the beginning of the value in the minibuffer if the value is too large. At least, it will be consistent with how we trim values everywhere else.
|
@@ -316,7 +316,11 @@ focused." | |||
(cider--make-result-overlay font-value |
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.
No, I didn't mean string-trim, but length trim
That's because cider--make-result-overlay performs its own trimming
Alright then 👍
To your point about the UI being less favored – it is true that the default for
So, I think, if we can improve the UX of it with small costs, then it is reasonable to do so. |
Thanks for the review! |
Cheers. Frankly I'd review the default of |
@@ -316,10 +316,15 @@ focused." | |||
(cider--make-result-overlay font-value | |||
:where point | |||
:duration cider-eval-result-duration | |||
:prepend-face (or overlay-face 'cider-result-overlay-face))))) | |||
:prepend-face (or overlay-face 'cider-result-overlay-face)))) | |||
(msg (format "%s%s" cider-eval-result-prefix value)) |
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.
Seems we need to print font-value
instead of value
, otherwise we'd lose the font-locking (if it was done).
@@ -304,10 +304,10 @@ Note that, while POINT can be a number, it's preferable to be a marker, as | |||
that will better handle some corner cases where the original buffer is not | |||
focused." | |||
(cl-assert (symbolp value-type)) ;; We assert because for avoiding confusion with the optional args. | |||
(let* ((font-value (if cider-result-use-clojure-font-lock | |||
(let* ((value (string-trim-right value)) | |||
(font-value (if cider-result-use-clojure-font-lock |
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.
Probably here font-locked-value
would have been a better name, although depending on the config it might not be font-locked. Naming is hard...
Although there is still work to be done (and thoughts to be thought) in cider-nrepl or nREPL regarding how much we want to print, it makes sense to solve such an issue on CIDER side too. Currently, if
cider-use-overlays
is nott
, the standardcider-interactive-eval-handler
will try to display the whole printed result in the minibuffer (echo area). For some reason, pushing huge strings through the echo area is much slower than printing it to the REPL. E.g., doing(println (range 200000))
is almost instant while evaluating(range 200000)
in the source buffer takes ~3 seconds on my machine to display the truncated result. Emacs would obviously still truncate the echo area output but not before printing the whole response to*Messages*
.This PR proposes to truncate the long output ahead of time. We can also add the similar message that we currently show in overlays, something like
"Result truncated. Type M-x cider-inspect-last-result to inspect it.
if it is deemed necessary.Example of how the truncated result would look like: