Skip to content

Commit

Permalink
[Fix #1139] Correct the handling of ns forms and forms with unevalute…
Browse files Browse the repository at this point in the history
…d ns

Ns forms should always be evaluated in the "user" namespace. We have introduced
a regression in 0.9.0 after which they started being evaluated in their own
namespace, which doesn't exist originally. This commit also fixes a problem
with the auto-evaluation of ns forms, when a form from their ns gets evaluated
before the ns form.
  • Loading branch information
bbatsov committed Jun 19, 2015
1 parent 11859d1 commit de23b4d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
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)

### Bugs fixed

* [#1139](https://github.com/clojure-emacs/cider/issues/1139): Fix evaluation of ns forms and of forms with unevaluated namespaces.

## 0.9.0 / 2015-06-16

### New features
Expand Down
23 changes: 12 additions & 11 deletions cider-interaction.el
Original file line number Diff line number Diff line change
Expand Up @@ -1582,17 +1582,14 @@ evaluated (so that the ns containing FORM exists).
Clears any compilation highlights and kills the error window."
(cider--clear-compilation-highlights)
(cider--quit-error-window)
;; always eval ns forms in the user namespace
;; otherwise trying to eval ns form for the first time will produce an error
(let ((ns (if (cider-ns-form-p form)
"user"
(cider-current-ns)))
(cur-ns-form (cider-ns-form)))
(let ((cur-ns-form (cider-ns-form)))
(when (and cur-ns-form
(not (string= cur-ns-form cider--cached-ns-form))
(not (string= ns "user")))
(cider-eval-ns-form))
(setq cider--cached-ns-form cur-ns-form)))
(not (cider-ns-form-p form)))
;; this should probably be done synchronously
;; otherwise an errors in the ns form will go unnoticed
(cider-eval-ns-form)
(setq cider--cached-ns-form cur-ns-form))))

(defun cider-interactive-eval (form &optional callback)
"Evaluate FORM and dispatch the response to CALLBACK.
Expand All @@ -1603,7 +1600,9 @@ If CALLBACK is nil use `cider-interactive-eval-handler'."
(nrepl-request:eval
form
(or callback (cider-interactive-eval-handler))
(cider-current-ns)))
;; always eval ns forms in the user namespace
;; otherwise trying to eval ns form for the first time will produce an error
(if (cider-ns-form-p form) "user" (cider-current-ns))))

(defun cider-interactive-pprint-eval (form &optional callback right-margin)
"Evaluate FORM and dispatch the response to CALLBACK.
Expand All @@ -1614,7 +1613,9 @@ the printed result, and defaults to `fill-column'."
(nrepl-request:pprint-eval
form
(or callback (cider-interactive-eval-handler))
(cider-current-ns)
;; always eval ns forms in the user namespace
;; otherwise trying to eval ns form for the first time will produce an error
(if (cider-ns-form-p form) "user" (cider-current-ns))
nil
(or right-margin fill-column)))

Expand Down

0 comments on commit de23b4d

Please sign in to comment.