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

Limit the maximum string size to be displayed in echo area #3661

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [#3626](https://github.com/clojure-emacs/cider/issues/3626): `cider-ns-refresh`: jump to the relevant file/line on errors.
- [#3628](https://github.com/clojure-emacs/cider/issues/3628): `cider-ns-refresh`: summarize errors as an overlay.
- [#3660](https://github.com/clojure-emacs/cider/issues/3660): Fix `cider-inspector-def-current-val` always defining in `user` namespace.
- [#3661](https://github.com/clojure-emacs/cider/issues/3661): Truncate echo area output ahead of time.
- Bump the injected `enrich-classpath` to [1.19.3](https://github.com/clojure-emacs/enrich-classpath/compare/v1.19.0...v1.19.3).
- Bump the injected nREPL to [1.1.1](https://github.com/nrepl/nrepl/blob/v1.1.1/CHANGELOG.md#111-2024-02-20).
- Bump the injected `cider-nrepl` to [0.47.0](https://github.com/clojure-emacs/cider-nrepl/blob/v0.47.0/CHANGELOG.md#0470-2024-03-10).
Expand Down
13 changes: 9 additions & 4 deletions cider-overlays.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

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

(cider-font-lock-as-clojure value)
value))
(font-value (string-trim-right font-value))
(used-overlay (when (and point
cider-use-overlays
(if (equal 'error value-type)
Expand All @@ -316,10 +316,15 @@ focused."
(cider--make-result-overlay font-value
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member

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 👍

: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))
Copy link
Member

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).

(max-msg-length (* (floor (max-mini-window-lines)) (frame-width)))
(msg (if (> (string-width msg) max-msg-length)
(format "%s..." (substring msg 0 (- max-msg-length 3)))
msg)))
(message
"%s"
(propertize (format "%s%s" cider-eval-result-prefix font-value)
(propertize msg
;; The following hides the message from the echo-area, but
;; displays it in the Messages buffer. We only hide the message
;; if the user wants to AND if the overlay succeeded.
Expand Down
Loading