diff --git a/CHANGELOG.md b/CHANGELOG.md index feeb5fdd8..bb788499a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/cider-repl.el b/cider-repl.el index fbcd6bf6c..f72858028 100644 --- a/cider-repl.el +++ b/cider-repl.el @@ -823,37 +823,38 @@ 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))) + (unless (string-empty-p input) ; don't evaluate an empty string + (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. diff --git a/doc/using_the_repl.md b/doc/using_the_repl.md index 306168773..ddd47f63f 100644 --- a/doc/using_the_repl.md +++ b/doc/using_the_repl.md @@ -13,7 +13,7 @@ Here's a list of the keybindings that are available in CIDER's REPL: Keyboard shortcut | Description -------------------------------------|------------------------------ -RET | 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. +RET | 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. C-RET | Close any unmatched parenthesis and then evaluate the current input in Clojure. C-j | Open a new line and indent. C-c C-o | 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.