summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Zheng <zcaudate@users.noreply.github.com>2018-06-22 13:04:06 +0800
committerBozhidar Batsov <bozhidar.batsov@gmail.com>2018-06-22 08:04:06 +0300
commit0bca1d16eec90d2c3aaeac74b87852977a79fe6c (patch)
treed919e8a51252b88c52525f686d2913a287d00b04
parent37bf7534b3b7913be29196882a6370f42213d228 (diff)
[Fix #2328] Add new interactive command cider-eval-sexp-to-point (#2339)
It's similar in nature to cider-eval-defun-to-point, but operates on the current sexp.
-rw-r--r--CHANGELOG.md1
-rw-r--r--cider-interaction.el20
-rw-r--r--cider-mode.el1
3 files changed, 22 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fc9abb45..6b4f6db9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@
### Bugs fixed
+* [#2328](https://github.com/clojure-emacs/cider/issues/2328): Added `cider-eval-sexp-to-point`.
* [#2310](https://github.com/clojure-emacs/cider/issues/2310): `cider-format-edn-last-sexp` will format the last sexp.
* [#2294](https://github.com/clojure-emacs/cider/issues/2294): Fix setting default stacktrace filters.
* [#2286](https://github.com/clojure-emacs/cider/issues/2286): Fix eldoc issue with images in the REPL.
diff --git a/cider-interaction.el b/cider-interaction.el
index 1de3cede..83469294 100644
--- a/cider-interaction.el
+++ b/cider-interaction.el
@@ -1443,6 +1443,24 @@ It constructs an expression to eval in the following manner:
code
(when output-to-current-buffer (cider-eval-print-handler)))))
+(defun cider-eval-sexp-to-point (&optional output-to-current-buffer)
+ "Evaluate the current sexp form up to point.
+If invoked with OUTPUT-TO-CURRENT-BUFFER, print the result in the current buffer.
+It constructs an expression to eval in the following manner:
+
+- It finds the code between the point and the start of the sexp expression;
+- It balances this bit of code by closing the expression;
+- It evaluates the resulting code using `cider-interactive-eval'."
+ (interactive "P")
+ (let* ((beg-of-sexp (save-excursion (up-list) (backward-list) (point)))
+ (beg-delimiter (save-excursion (up-list) (backward-list) (char-after)))
+ (beg-set? (save-excursion (up-list) (backward-list) (char-before)))
+ (code (buffer-substring-no-properties beg-of-sexp (point)))
+ (code (if (= beg-set? ?#) (concat (list beg-set?) code) code))
+ (code (concat code (list (cider--matching-delimiter beg-delimiter)))))
+ (cider-interactive-eval code
+ (when output-to-current-buffer (cider-eval-print-handler)))))
+
(defun cider-pprint-eval-defun-at-point (&optional output-to-current-buffer)
"Evaluate the \"top-level\" form at point and pprint its value.
If invoked with OUTPUT-TO-CURRENT-BUFFER, insert as comment in the current
@@ -1494,6 +1512,7 @@ passing arguments."
(define-key map (kbd "r") #'cider-eval-region)
(define-key map (kbd "n") #'cider-eval-ns-form)
(define-key map (kbd "v") #'cider-eval-sexp-at-point)
+ (define-key map (kbd "o") #'cider-eval-sexp-to-point)
(define-key map (kbd ".") #'cider-read-and-eval-defun-at-point)
(define-key map (kbd "z") #'cider-eval-defun-to-point)
(define-key map (kbd "c") #'cider-eval-last-sexp-in-context)
@@ -1504,6 +1523,7 @@ passing arguments."
(define-key map (kbd "C-r") #'cider-eval-region)
(define-key map (kbd "C-n") #'cider-eval-ns-form)
(define-key map (kbd "C-v") #'cider-eval-sexp-at-point)
+ (define-key map (kbd "C-o") #'cider-eval-sexp-to-point)
(define-key map (kbd "C-.") #'cider-read-and-eval-defun-at-point)
(define-key map (kbd "C-z") #'cider-eval-defun-to-point)
(define-key map (kbd "C-c") #'cider-eval-last-sexp-in-context)
diff --git a/cider-mode.el b/cider-mode.el
index 61f03d97..bc330cca 100644
--- a/cider-mode.el
+++ b/cider-mode.el
@@ -215,6 +215,7 @@ the related commands `cider-repl-clear-buffer' and
["Eval top-level sexp" cider-eval-defun-at-point]
["Eval top-level sexp to point" cider-eval-defun-to-point]
["Eval current sexp" cider-eval-sexp-at-point]
+ ["Eval current sexp to point" cider-eval-sexp-to-point]
["Eval current sexp in context" cider-eval-sexp-at-point-in-context]
["Eval last sexp" cider-eval-last-sexp]
["Eval last sexp in context" cider-eval-last-sexp-in-context]