Skip to content

Commit 1dba82f

Browse files
author
Bozhidar Batsov
committed
[Fix #830] Stop using load-file for most interactive evaluation commands
1 parent 8a128dd commit 1dba82f

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* [#883](https://github.com/clojure-emacs/cider/issues/883): Encode properly the javadoc url.
99
* [#824](https://github.com/clojure-emacs/cider/issues/824): Fix REPL font-locking.
1010
* [#888](https://github.com/clojure-emacs/cider/issues/888): Handle comments in `cider-repl-mode`.
11+
* [#830](https://github.com/clojure-emacs/cider/issues/830): Stop using `load-file` for most interactive evaluation commands.
1112

1213
## 0.8.1 / 2014-11-20
1314

cider-interaction.el

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,11 +1244,11 @@ otherwise fall back to \"user\"."
12441244

12451245
;;; Evaluation
12461246

1247-
(defun cider-interactive-eval (form &optional start-pos callback)
1247+
(defun cider-interactive-source-tracking-eval (form &optional start-pos callback)
12481248
"Evaluate FORM and dispatch the response to CALLBACK.
1249-
START-POS is a starting position of the form in the original context. This
1250-
function is the main entry point in CIDER's interactive evaluation API. All
1251-
other interactive eval functions should rely on this function. If CALLBACK
1249+
START-POS is a starting position of the form in the original context.
1250+
Unlike `cider-interactive-eval' this command will set proper metadata for var
1251+
definitions. If CALLBACK
12521252
is nil use `cider-interactive-eval-handler'."
12531253
(cider--clear-compilation-highlights)
12541254
(-when-let (error-win (get-buffer-window cider-error-buffer))
@@ -1261,6 +1261,19 @@ is nil use `cider-interactive-eval-handler'."
12611261
(file-name-nondirectory filename)
12621262
(or callback (cider-interactive-eval-handler)))))
12631263

1264+
(defun cider-interactive-eval (form &optional callback)
1265+
"Evaluate FORM and dispatch the response to CALLBACK.
1266+
This function is the main entry point in CIDER's interactive evaluation
1267+
API. Most other interactive eval functions should rely on this function.
1268+
If CALLBACK is nil use `cider-interactive-eval-handler'."
1269+
(cider--clear-compilation-highlights)
1270+
(-when-let (error-win (get-buffer-window cider-error-buffer))
1271+
(quit-window nil error-win))
1272+
(nrepl-request:eval
1273+
form
1274+
(or callback (cider-interactive-eval-handler))
1275+
(cider-current-ns)))
1276+
12641277
(defun cider--dummy-file-contents (form start-pos)
12651278
"Wrap FORM to make it suitable for `cider-request:load-file'.
12661279
START-POS is a starting position of the form in the original context."
@@ -1283,7 +1296,7 @@ START-POS is a starting position of the form in the original context."
12831296
"Evaluate the region between START and END."
12841297
(interactive "r")
12851298
(let ((code (buffer-substring-no-properties start end)))
1286-
(cider-interactive-eval code start)))
1299+
(cider-interactive-source-tracking-eval code start)))
12871300

12881301
(defun cider-eval-buffer ()
12891302
"Evaluate the current buffer."
@@ -1294,7 +1307,7 @@ START-POS is a starting position of the form in the original context."
12941307
"Evaluate the expression preceding point.
12951308
If invoked with a PREFIX argument, print the result in the current buffer."
12961309
(interactive "P")
1297-
(cider-interactive-eval (cider-last-sexp) (cider-last-sexp-start-pos)
1310+
(cider-interactive-eval (cider-last-sexp)
12981311
(when prefix (cider-eval-print-handler))))
12991312

13001313
(defun cider-eval-last-sexp-and-replace ()
@@ -1306,13 +1319,13 @@ If invoked with a PREFIX argument, print the result in the current buffer."
13061319
(nrepl-sync-request:eval last-sexp)
13071320
;; seems like the sexp is valid, so we can safely kill it
13081321
(backward-kill-sexp)
1309-
(cider-interactive-eval last-sexp start-pos (cider-eval-print-handler))))
1322+
(cider-interactive-eval last-sexp (cider-eval-print-handler))))
13101323

13111324
(defun cider-eval-last-sexp-to-repl (&optional prefix)
13121325
"Evaluate the expression preceding point and insert its result in the REPL.
13131326
If invoked with a PREFIX argument, switch to the REPL buffer."
13141327
(interactive "P")
1315-
(cider-interactive-eval (cider-last-sexp) (cider-last-sexp-start-pos)
1328+
(cider-interactive-eval (cider-last-sexp)
13161329
(cider-insert-eval-handler (cider-current-repl-buffer)))
13171330
(when prefix
13181331
(cider-switch-to-repl-buffer)))
@@ -1321,33 +1334,35 @@ If invoked with a PREFIX argument, switch to the REPL buffer."
13211334
"Evaluate the expression preceding point.
13221335
Print its value into the current buffer."
13231336
(interactive)
1324-
(cider-interactive-eval (cider-last-sexp) (cider-last-sexp-start-pos)
1337+
(cider-interactive-eval (cider-last-sexp)
13251338
(cider-eval-print-handler)))
13261339

1327-
(defun cider--pprint-eval-form (form start-pos)
1328-
"Pretty print FORM starting at START-POS in popup buffer."
1340+
(defun cider--pprint-eval-form (form)
1341+
"Pretty print FORM in popup buffer."
13291342
(let* ((result-buffer (cider-popup-buffer cider-result-buffer nil 'clojure-mode))
13301343
(right-margin (max fill-column
13311344
(1- (window-width (get-buffer-window result-buffer))))))
1332-
(cider-interactive-eval (cider-format-pprint-eval form right-margin) start-pos
1345+
(cider-interactive-eval (cider-format-pprint-eval form right-margin)
13331346
(cider-popup-eval-out-handler result-buffer))))
13341347

13351348
(defun cider-pprint-eval-last-sexp ()
13361349
"Evaluate the sexp preceding point and pprint its value in a popup buffer."
13371350
(interactive)
1338-
(cider--pprint-eval-form (cider-last-sexp) (cider-last-sexp-start-pos)))
1351+
(cider--pprint-eval-form (cider-last-sexp)))
13391352

13401353
(defun cider-eval-defun-at-point (&optional prefix)
13411354
"Evaluate the current toplevel form, and print result in the minibuffer.
13421355
With a PREFIX argument, print the result in the current buffer."
13431356
(interactive "P")
1344-
(cider-interactive-eval (cider-defun-at-point) (cider-defun-at-point-start-pos)
1345-
(when prefix (cider-eval-print-handler))))
1357+
(cider-interactive-source-tracking-eval
1358+
(cider-defun-at-point)
1359+
(cider-defun-at-point-start-pos)
1360+
(when prefix (cider-eval-print-handler))))
13461361

13471362
(defun cider-pprint-eval-defun-at-point ()
13481363
"Evaluate the top-level form at point and pprint its value in a popup buffer."
13491364
(interactive)
1350-
(cider--pprint-eval-form (cider-defun-at-point) (cider-defun-at-point-start-pos)))
1365+
(cider--pprint-eval-form (cider-defun-at-point)))
13511366

13521367
(defun cider-eval-ns-form ()
13531368
"Evaluate the current buffer's namespace form."
@@ -1367,9 +1382,8 @@ With a PREFIX argument, print the result in the current buffer."
13671382
(clojure-mode)
13681383
(unless (string= "" ns-form)
13691384
(insert ns-form "\n\n"))
1370-
(let ((start-pos (point)))
1371-
(insert form)
1372-
(cider-interactive-eval form start-pos)))))
1385+
(insert form)
1386+
(cider-interactive-eval form))))
13731387

13741388

13751389
;; Connection and REPL

0 commit comments

Comments
 (0)