From 7399bccbbf6a75303060f32223d706e82d5e0fb1 Mon Sep 17 00:00:00 2001 From: dan sutton Date: Sat, 16 Feb 2019 15:43:39 -0600 Subject: [PATCH 1/5] Scroll buffer after using cider-insert-X-in-repl As it stood, buffer would not scroll, even if you included a `(goto-char (point-max))` call at the end. Using solution from https://stackoverflow.com/questions/13530025/emacs-scroll-automatically-when-inserting-text Have to watch out if the buffer is visible or not. If it is, we can scroll it with `with-selected-window`. Otherwise, the best we can do is the current behavior. Note `get-buffer-window` returns nil if something is not visible which is why we need to branch on it. --- cider-mode.el | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/cider-mode.el b/cider-mode.el index 8c5c4dd92..bfbc687b9 100644 --- a/cider-mode.el +++ b/cider-mode.el @@ -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) @@ -234,18 +234,23 @@ 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))) + (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))) + (when (if cider-invert-insert-eval-p + (not eval) + eval) + (cider-repl-return)) + (goto-char (point-max))))) (when cider-switch-to-repl-after-insert-p (cider-switch-to-repl-buffer))) From 8bcfd0e71303ee5842fd68b41e46e68561096725 Mon Sep 17 00:00:00 2001 From: dan sutton Date: Sat, 16 Feb 2019 18:25:57 -0600 Subject: [PATCH 2/5] Switch to repl buffer before inserting into repl makes it a bit nicer with scrolling if the buffer is visible. Possibly need to rename the var `cider-switch-to-repl-after-insert-p` --- cider-mode.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cider-mode.el b/cider-mode.el index bfbc687b9..3114a0cf8 100644 --- a/cider-mode.el +++ b/cider-mode.el @@ -238,6 +238,8 @@ 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))) + (when cider-switch-to-repl-after-insert-p + (cider-switch-to-repl-buffer)) (let ((repl (cider-current-repl))) (with-selected-window (or (get-buffer-window repl) (selected-window)) @@ -250,9 +252,7 @@ If EVAL is non-nil the form will also be evaluated. Use (not eval) eval) (cider-repl-return)) - (goto-char (point-max))))) - (when cider-switch-to-repl-after-insert-p - (cider-switch-to-repl-buffer))) + (goto-char (point-max)))))) (defun cider-insert-last-sexp-in-repl (&optional arg) "Insert the expression preceding point in the REPL buffer. From 88eebcffb3b4537ae9b6429569165dec067d94f4 Mon Sep 17 00:00:00 2001 From: dan sutton Date: Sat, 16 Feb 2019 18:49:38 -0600 Subject: [PATCH 3/5] Deprecate `cider-switch-to-repl-after-insert-p` in favor of on-insert To prevent this in the future we can just leave this var as "on-insert" rather than constrain ourselves to before or after. The remedy here is almost certainly more painful than the disease. --- CHANGELOG.md | 1 + cider-mode.el | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 391e8ec74..53e34b681 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ ### Changes +* * Add new defcustom `cider-switch-to-repl-on-insert-p`: 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. diff --git a/cider-mode.el b/cider-mode.el index 3114a0cf8..db45f2084 100644 --- a/cider-mode.el +++ b/cider-mode.el @@ -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-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") + (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 @@ -238,7 +249,7 @@ 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))) - (when cider-switch-to-repl-after-insert-p + (when cider-switch-to-repl-on-insert-p (cider-switch-to-repl-buffer)) (let ((repl (cider-current-repl))) (with-selected-window (or (get-buffer-window repl) From 4949c85714d896af35d18410e08bfefe975f5642 Mon Sep 17 00:00:00 2001 From: dan sutton Date: Sat, 16 Feb 2019 18:57:11 -0600 Subject: [PATCH 4/5] Font lock inserted text in repl --- cider-mode.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cider-mode.el b/cider-mode.el index db45f2084..6efdd9241 100644 --- a/cider-mode.el +++ b/cider-mode.el @@ -258,7 +258,8 @@ If EVAL is non-nil the form will also be evaluated. Use (goto-char (point-max)) (let ((beg (point))) (insert form) - (indent-region beg (point))) + (indent-region beg (point)) + (cider--font-lock-ensure beg (point))) (when (if cider-invert-insert-eval-p (not eval) eval) From 8605901ecadf61cf44d76449296e615e2bd78b6c Mon Sep 17 00:00:00 2001 From: dan sutton Date: Mon, 18 Feb 2019 10:54:56 -0600 Subject: [PATCH 5/5] Rename `cider-switch-to-repl-on-insert` without -p suffix --- CHANGELOG.md | 2 +- cider-mode.el | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53e34b681..63f87eb10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ ### Changes -* * Add new defcustom `cider-switch-to-repl-on-insert-p`: 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` +* * 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. diff --git a/cider-mode.el b/cider-mode.el index 6efdd9241..7addce079 100644 --- a/cider-mode.el +++ b/cider-mode.el @@ -223,7 +223,7 @@ 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-p t +(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 @@ -231,7 +231,7 @@ With a prefix argument, prompt for function to run instead of -main." (define-obsolete-variable-alias 'cider-switch-to-repl-after-insert-p - 'cider-switch-to-repl-on-insert-p + 'cider-switch-to-repl-on-insert "0.21.0") (defcustom cider-invert-insert-eval-p nil @@ -249,7 +249,7 @@ 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))) - (when cider-switch-to-repl-on-insert-p + (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)