Skip to content

Commit

Permalink
Send the complete ns form in interactive eval requests
Browse files Browse the repository at this point in the history
Fixes #1026.
  • Loading branch information
cichli committed Mar 19, 2015
1 parent b0dab07 commit 1b35703
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ when in buffer that's not visiting a file (e.g. a REPL buffer).
* [#981](https://github.com/clojure-emacs/cider/issues/981): Updated `cider-find-file` to use `find-buffer-visiting` instead of `get-file-buffer`.
* [#1004](https://github.com/clojure-emacs/cider/issues/1004): `:repl-env` key is now filtered from exception causes, as it contains unprintably large strings of compiled javascript when using ClojureScript.
* Tunneled ssh connection now deals correctly with the ssh password request.
* [#1026](https://github.com/clojure-emacs/cider/issues/1026): The full `(ns ...)` form for the current buffer is now sent with all source-tracking eval requests, to fix ClojureScript compatibility.

## 0.8.2 / 2014-12-21

Expand Down
60 changes: 35 additions & 25 deletions cider-interaction.el
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,40 @@ otherwise fall back to \"user\"."
(defvar-local cider--cached-ns-form nil
"Cached ns form in the current buffer.")

(defun cider--ns-form-for-dummy-file (form)
"Construct a `(ns ...)` form for `cider--dummy-file-contents'.
If FORM is a ns form itself, or there is no current ns form, returns an
empty string. If the current ns form has not yet been evaluated, returns
the current ns form. Otherwise, returns the current ns form with
all :reload and :reload-all directives removed."
(let ((current-ns-form (cider-ns-form)))
(cond
((cider-ns-form-p form) "")
((null current-ns-form) "")
((null cider--cached-ns-form) current-ns-form)
;; previously, we were sending a truncated version of
;; the current ns form if it was equal to the cached ns
;; form, but this causes problems with ClojureScript,
;; where evaluating ns forms is not additive - see #1026
(:default (replace-regexp-in-string ":reload\\(-all\\)?\\>"
""
current-ns-form)))))

(defun cider--dummy-file-contents (form start-pos)
"Wrap FORM to make it suitable for `cider-request:load-file'.
START-POS is a starting position of the form in the original context."
(let* ((ns-form (cider--ns-form-for-dummy-file form))
(ns-form-lines (length (split-string ns-form "\n")))
(start-pos (or start-pos 1))
(start-line (line-number-at-pos start-pos))
(start-column (save-excursion (goto-char start-pos) (current-column))))
(concat
ns-form
(make-string (max 0 (- start-line ns-form-lines)) ?\n)
(make-string start-column ? )
form)))

(defun cider-interactive-source-tracking-eval (form &optional start-pos callback)
"Evaluate FORM and dispatch the response to CALLBACK.
START-POS is a starting position of the form in the original context.
Expand All @@ -1385,6 +1419,7 @@ definitions. If CALLBACK
is nil use `cider-interactive-eval-handler'."
(cider--clear-compilation-highlights)
(cider--quit-error-window)
(setq cider--cached-ns-form (cider-ns-form))
(let ((filename (or (buffer-file-name)
(buffer-name))))
(cider-request:load-file
Expand Down Expand Up @@ -1439,31 +1474,6 @@ the printed result, and defaults to `fill-column'."
nil
(or right-margin fill-column)))

(defun cider--dummy-file-contents (form start-pos)
"Wrap FORM to make it suitable for `cider-request:load-file'.
START-POS is a starting position of the form in the original context."
(let* ((cur-ns-form (cider-ns-form))
(ns-form (cond
((or (null cur-ns-form)
(cider-ns-form-p form))
"")
((string= cur-ns-form cider--cached-ns-form)
(format "(ns %s)" (cider-current-ns)))
((null cider--cached-ns-form)
cur-ns-form)
(t
(replace-regexp-in-string ":reload\\(-all\\)?\\>" "" cur-ns-form))))
(ns-form-lines (length (split-string ns-form "\n")))
(start-pos (or start-pos 1))
(start-line (line-number-at-pos start-pos))
(start-column (save-excursion (goto-char start-pos) (current-column))))
(setq cider--cached-ns-form cur-ns-form)
(concat
ns-form
(make-string (max 0 (- start-line ns-form-lines)) ?\n)
(make-string start-column ? )
form)))

(defun cider-eval-region (start end)
"Evaluate the region between START and END."
(interactive "r")
Expand Down

0 comments on commit 1b35703

Please sign in to comment.