Skip to content

Scroll buffer after using cider-insert-X-in-repl #2590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

### Changes

* * Add new defcustom `cider-switch-to-repl-on-insert`: Set to prevent cursor from going to the repl when inserting a form in the repl with the insert-to-repl commands. Replaces obsoleted `cider-switch-to-repl-after-insert-p`
* **(Breaking)** Upgrade to nREPL 0.6.0. This is now the minimum required version.
* **(Breaking)** Upgrade to piggieback 0.4.0. This is now the minimum required version.
* **(Breaking)** Remove `cider.nrepl.middleware.pprint`. All functionality has been replaced by the built-in printing support in nREPL 0.6.
Expand Down
43 changes: 30 additions & 13 deletions cider-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Clojure buffer."
(defun cider-switch-to-last-clojure-buffer ()
"Switch to the last Clojure buffer.
The default keybinding for this command is
the same as `cider-switch-to-repl-buffer',
the same as variable `cider-switch-to-repl-buffer',
so that it is very convenient to jump between a
Clojure buffer and the REPL buffer."
(interactive)
Expand Down Expand Up @@ -223,6 +223,17 @@ With a prefix argument, prompt for function to run instead of -main."
:group 'cider
:package-version '(cider . "0.18.0"))

(defcustom cider-switch-to-repl-on-insert t
"Whether to switch to the repl when inserting a form into the repl."
:type 'boolean
:group 'cider
:package-version '(cider . "0.21.0"))

(define-obsolete-variable-alias
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t see the var that was made obsolete anywhere, so I guess that’s not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the var is right above the new one.

(defcustom cider-switch-to-repl-after-insert-p t
  "Whether to switch to the repl after inserting a form into the repl."
  :type 'boolean
  :group 'cider
  :package-version '(cider . "0.18.0"))

(defcustom cider-switch-to-repl-on-insert-p t
  "Whether to switch to the repl when inserting a form into the repl."
  :type 'boolean
  :group 'cider
  :package-version '(cider . "0.21.0"))

(define-obsolete-variable-alias
  'cider-switch-to-repl-after-insert-p
  'cider-switch-to-repl-on-insert-p
  "0.21.0")

The original had a -p so I mimic'ed it. I'll remove that from the new one.

'cider-switch-to-repl-after-insert-p
'cider-switch-to-repl-on-insert
"0.21.0")

(defcustom cider-invert-insert-eval-p nil
"Whether to invert the behavior of evaling.
Default behavior when inserting is to NOT eval the form and only eval with
Expand All @@ -234,20 +245,26 @@ and eval and the prefix is required to prevent evaluation."

(defun cider-insert-in-repl (form eval)
"Insert FORM in the REPL buffer and switch to it.
If EVAL is non-nil the form will also be evaluated."
If EVAL is non-nil the form will also be evaluated. Use
`cider-invert-insert-eval-p' to invert this behavior."
(while (string-match "\\`[ \t\n\r]+\\|[ \t\n\r]+\\'" form)
(setq form (replace-match "" t t form)))
(with-current-buffer (cider-current-repl)
(goto-char (point-max))
(let ((beg (point)))
(insert form)
(indent-region beg (point)))
(when (if cider-invert-insert-eval-p
(not eval)
eval)
(cider-repl-return)))
(when cider-switch-to-repl-after-insert-p
(cider-switch-to-repl-buffer)))
(when cider-switch-to-repl-on-insert
(cider-switch-to-repl-buffer))
(let ((repl (cider-current-repl)))
(with-selected-window (or (get-buffer-window repl)
(selected-window))
(with-current-buffer repl
(goto-char (point-max))
(let ((beg (point)))
(insert form)
(indent-region beg (point))
(cider--font-lock-ensure beg (point)))
(when (if cider-invert-insert-eval-p
(not eval)
eval)
(cider-repl-return))
(goto-char (point-max))))))

(defun cider-insert-last-sexp-in-repl (&optional arg)
"Insert the expression preceding point in the REPL buffer.
Expand Down