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

[Fix #1659] Add fringe indicators for evaluated forms #1691

Merged
merged 1 commit into from
Apr 21, 2016
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### New Features

* Fringe indicators highlight which sexps have been loaded. Disable it with `cider-use-fringe-indicators`.

### Changes

* Signal an error sooner if the user misconfigured `cider-known-endpoints`.
Expand Down
11 changes: 9 additions & 2 deletions cider-interaction.el
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ can be used to display the evaluation result."
(point (when point (copy-marker point))))
(nrepl-make-response-handler (or buffer eval-buffer)
(lambda (_buffer value)
(cider--make-fringe-overlay point)
(cider--display-interactive-eval-result value point))
(lambda (_buffer out)
(cider-emit-interactive-eval-output out))
Expand All @@ -663,8 +664,14 @@ can be used to display the evaluation result."
(nrepl-make-response-handler (or buffer eval-buffer)
(lambda (buffer value)
(cider--display-interactive-eval-result value)
(with-current-buffer buffer
(run-hooks 'cider-file-loaded-hook)))
(when (buffer-live-p buffer)
(with-current-buffer buffer
(save-excursion
(goto-char (point-min))
(while (progn (clojure-forward-logical-sexp)
(not (eobp)))
(cider--make-fringe-overlay (point))))
(run-hooks 'cider-file-loaded-hook))))
(lambda (_buffer value)
(cider-emit-interactive-eval-output value))
(lambda (_buffer err)
Expand Down
39 changes: 36 additions & 3 deletions cider-overlays.el
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,42 @@ This function also removes itself from `post-command-hook'."
(remove-hook 'post-command-hook #'cider--remove-result-overlay-after-command 'local)
(add-hook 'post-command-hook #'cider--remove-result-overlay nil 'local))

(defface cider-fringe-good-face
'((((class color) (background light)) :foreground "lightgreen")
(((class color) (background dark)) :foreground "darkgreen"))
"Face used on the fringe indicator for successful evaluation."
:group 'cider)

(defconst cider--fringe-overlay-good
(propertize " " 'display '(left-fringe empty-line cider-fringe-good-face))
"The before-string property that adds a green indicator on the fringe.")

(defcustom cider-use-fringe-indicators t
"Whether to display evaluation indicators on the left fringe."
:safe #'boolean
:group 'cider
:type 'boolean)

(defun cider--make-fringe-overlay (&optional end)
"Place an eval indicator at the fringe before a sexp.
END is the position where the sexp ends, and defaults to point."
(when cider-use-fringe-indicators
(with-current-buffer (if (markerp end)
(marker-buffer end)
(current-buffer))
(save-excursion
(if end
(goto-char end)
(setq end (point)))
(clojure-forward-logical-sexp -1)
;; Create the green-circle overlay.
(cider--make-overlay (point) end 'cider-fringe-indicator
'before-string cider--fringe-overlay-good)))))

(cl-defun cider--make-result-overlay (value &rest props &key where duration (type 'result)
(format (concat " " cider-eval-result-prefix "%s "))
(prepend-face 'cider-result-overlay-face)
&allow-other-keys)
(format (concat " " cider-eval-result-prefix "%s "))
(prepend-face 'cider-result-overlay-face)
&allow-other-keys)
"Place an overlay displaying VALUE at the end of line.
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
Expand Down Expand Up @@ -185,6 +217,7 @@ overlay."
;; Put the cursor property only once we're done manipulating the
;; string, since we want it to be at the first char.
(put-text-property 0 1 'cursor 0 display-string)
;; Create the result overlay.
(setq o (apply #'cider--make-overlay
beg end type
'after-string display-string
Expand Down