summaryrefslogtreecommitdiff
path: root/cider-overlays.el
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2015-07-15 16:58:59 +0100
committerArtur Malabarba <bruce.connor.am@gmail.com>2015-07-16 18:45:13 +0100
commit17385d6dfcd3587cb670038e4c8e880e4035b762 (patch)
treedf823d6c0276e9ec15164b874795b6071e72121f /cider-overlays.el
parent2d745c29778e1b0fccf444dd9998428ac78b174b (diff)
Improve usage of the eval result overlays
Change display-eval-result to be smarter when it receives a marker, so it does the right thing when the original buffer was killed before evaluation finished. If the result overlay would be out of view (or in a hidden buffer) it will also display the result as a message regardless of user option. Hiding the message is better handled now. Instead of messaging the result and then messaging nil to hide it, we simply message the result with an invisible property. This means it's not displayed in the echo area, but shows up on the Messages buffer.
Diffstat (limited to 'cider-overlays.el')
-rw-r--r--cider-overlays.el36
1 files changed, 24 insertions, 12 deletions
diff --git a/cider-overlays.el b/cider-overlays.el
index 32cfd3b3..920d600e 100644
--- a/cider-overlays.el
+++ b/cider-overlays.el
@@ -91,6 +91,10 @@ PROPS is a plist of properties and values to add to the overlay."
VALUE is used as the overlay's after-string property, meaning it is
displayed at the end of the overlay. The overlay itself is placed from
beginning to end of current line.
+Return nil if the overlay was not placed or is not visible, and return the
+overlay otherwise.
+
+Return the overlay if it was placed successfully, and nil if it failed.
If WHERE is a number or a marker, it is the character position of the line
to use, otherwise use `point'.
@@ -120,8 +124,10 @@ PROPS are passed to `cider--make-overlay' with a type of result."
(pcase duration
((pred numberp) (run-at-time duration nil #'cider--delete-overlay o))
(`command (add-hook 'post-command-hook #'cider--remove-result-overlay nil 'local)))
- o)))
- (message "%s%s" cider-eval-result-prefix value)))
+ (-when-let (win (get-buffer-window buffer))
+ (when (pos-visible-in-window-p (point) win)
+ o)))))
+ nil))
;;; Displaying eval result
@@ -135,16 +141,22 @@ This function also removes itself from `post-command-hook'."
"Display the result VALUE of an interactive eval operation.
VALUE is syntax-highlighted and displayed in the echo area.
If POINT and `cider-use-overlays' are non-nil, it is also displayed in an
-overlay at point."
- (let ((font-value (cider-font-lock-as-clojure value)))
- (when (and point cider-use-overlays)
- (cider--make-result-overlay font-value point cider-eval-result-duration))
- (message "%s%s" cider-eval-result-prefix font-value)
- ;; Display the message anyway, but quickly erase it if we shouldn't have
- ;; displayed it. This way it's always available in the Messages buffer.
- (when (and cider-use-overlays
- (not (eq cider-use-overlays 'both)))
- (message nil))))
+overlay at the end of the line containing POINT.
+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."
+ (let* ((font-value (cider-font-lock-as-clojure value))
+ (used-overlay
+ (when (and point cider-use-overlays)
+ (cider--make-result-overlay font-value point cider-eval-result-duration))))
+ (message
+ "%s"
+ (propertize (format "%s%s" cider-eval-result-prefix font-value)
+ ;; 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.
+ 'invisible (and used-overlay
+ (not (eq cider-use-overlays 'both)))))))
(provide 'cider-overlays)
;;; cider-overlays.el ends here