Skip to content

Commit

Permalink
[#2235] Make repl ignore a blank string rather than evaluating it
Browse files Browse the repository at this point in the history
  • Loading branch information
gonewest818 committed Mar 11, 2018
1 parent 6b86f1a commit 9e28777
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* New interactive command `cider-cheatsheet` allows you to browse the Clojure Cheatsheet with an Emacs interface.
* [#2191](https://github.com/clojure-emacs/cider/issues/2191): Add support for jacking-in just with the `clojure` command-line tool and `tools.deps`.
* Make it possible to start a Nashorn ClojureScript REPL.
* [#2235](https://github.com/clojure-emacs/cider/pull/2235): REPL should ignore empty input rather than needlessly evaluating "".

### Bugs Fixed

Expand Down
69 changes: 38 additions & 31 deletions cider-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -823,37 +823,44 @@ the symbol."
If NEWLINE is true then add a newline at the end of the input."
(unless (cider-repl--in-input-area-p)
(error "No input at point"))
(goto-char (point-max))
(let ((end (point))) ; end of input, without the newline
(cider-repl--add-to-input-history (buffer-substring cider-repl-input-start-mark end))
(when newline
(insert "\n")
(cider-repl--show-maximum-output))
(let ((inhibit-modification-hooks t))
(add-text-properties cider-repl-input-start-mark
(point)
`(cider-old-input
,(cl-incf cider-repl-old-input-counter))))
(unless cider-repl-use-clojure-font-lock
(let ((overlay (make-overlay cider-repl-input-start-mark end)))
;; These properties are on an overlay so that they won't be taken
;; by kill/yank.
(overlay-put overlay 'read-only t)
(overlay-put overlay 'font-lock-face 'cider-repl-input-face))))
(let ((input (cider-repl--current-input))
(input-start (save-excursion (cider-repl-beginning-of-defun) (point))))
(goto-char (point-max))
(cider-repl--mark-input-start)
(cider-repl--mark-output-start)
(cider-nrepl-request:eval
input
(cider-repl-handler (current-buffer))
(cider-current-ns)
(line-number-at-pos input-start)
(cider-column-number-at-pos input-start)
(unless (or (not cider-repl-use-pretty-printing)
(string-match-p "\\`[ \t\r\n]*\\'" input))
(cider--nrepl-pprint-request-plist (cider--pretty-print-width))))))
(let ((input (cider-repl--current-input)))
(if (string-blank-p input)
;; don't evaluate a blank string, but erase it and emit
;; a fresh prompt to acknowledge to the user.
(progn
(cider-repl--replace-input "")
(cider-repl-emit-prompt (current-buffer)))
;; otherwise evaluate the input
(goto-char (point-max))
(let ((end (point))) ; end of input, without the newline
(cider-repl--add-to-input-history input)
(when newline
(insert "\n")
(cider-repl--show-maximum-output))
(let ((inhibit-modification-hooks t))
(add-text-properties cider-repl-input-start-mark
(point)
`(cider-old-input
,(cl-incf cider-repl-old-input-counter))))
(unless cider-repl-use-clojure-font-lock
(let ((overlay (make-overlay cider-repl-input-start-mark end)))
;; These properties are on an overlay so that they won't be taken
;; by kill/yank.
(overlay-put overlay 'read-only t)
(overlay-put overlay 'font-lock-face 'cider-repl-input-face))))
(let ((input-start (save-excursion (cider-repl-beginning-of-defun) (point))))
(goto-char (point-max))
(cider-repl--mark-input-start)
(cider-repl--mark-output-start)
(cider-nrepl-request:eval
input
(cider-repl-handler (current-buffer))
(cider-current-ns)
(line-number-at-pos input-start)
(cider-column-number-at-pos input-start)
(unless (or (not cider-repl-use-pretty-printing)
(string-match-p "\\`[ \t\r\n]*\\'" input))
(cider--nrepl-pprint-request-plist (cider--pretty-print-width))))))))

(defun cider-repl-return (&optional end-of-input)
"Evaluate the current input string, or insert a newline.
Expand Down
2 changes: 1 addition & 1 deletion doc/using_the_repl.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Here's a list of the keybindings that are available in CIDER's REPL:

Keyboard shortcut | Description
-------------------------------------|------------------------------
<kbd>RET</kbd> | Evaluate the current input in Clojure if it is complete. If incomplete, open a new line and indent. If invoked with a prefix argument is given then the input is evaluated without checking for completeness.
<kbd>RET</kbd> | Evaluate the current input in Clojure if it is complete. If incomplete, open a new line and indent. If the current input is the empty string then do nothing. If invoked with a prefix argument is given then the input is evaluated without checking for completeness.
<kbd>C-RET</kbd> | Close any unmatched parenthesis and then evaluate the current input in Clojure.
<kbd>C-j</kbd> | Open a new line and indent.
<kbd>C-c C-o</kbd> | Remove the output of the previous evaluation from the REPL buffer. With a prefix argument it will clear the entire REPL buffer, leaving only a prompt.
Expand Down

0 comments on commit 9e28777

Please sign in to comment.