Skip to content

Ensure repl scrolls on insert #204

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 3 commits into from
Aug 7, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## master (unreleased)
* [#202](https://github.com/clojure-emacs/inf-clojure/issues/202): Add ClojureCLR support.
* [#204](https://github.com/clojure-emacs/inf-clojure/issues/204): Scroll repl buffer on insert commands


## 3.2.1 (2022-07-22)

Expand Down
25 changes: 15 additions & 10 deletions inf-clojure.el
Original file line number Diff line number Diff line change
Expand Up @@ -920,16 +920,21 @@ Prefix argument AND-GO means switch to the Clojure buffer afterwards."
"Insert FORM into process and evaluate.
Indent FORM. FORM is expected to have been trimmed."
(let ((clojure-process (inf-clojure-proc)))
(with-current-buffer (process-buffer clojure-process)
(comint-goto-process-mark)
(let ((beginning (point)))
(insert (format "%s" form))
(let ((end (point)))
(goto-char beginning)
(indent-sexp end)
;; font-lock the inserted code
(font-lock-ensure beginning end)))
(comint-send-input t t))))
;; ensure the repl buffer scrolls. See similar fix in CIDER:
;; https://github.com/clojure-emacs/cider/pull/2590
(with-selected-window (or (get-buffer-window inf-clojure-buffer)
Copy link
Member

Choose a reason for hiding this comment

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

What is this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I linked the CIDER PR that does the same thing. That points to https://stackoverflow.com/questions/13530025/emacs-scroll-automatically-when-inserting-text . If the point is not visible the (goto (point-max)) code won't actually scroll the buffer.

This change ensures that inserting into the repl will scroll the repl so you can see what you inserted and the result. Before this it only worked if the point was at the end and visible.

Copy link
Member

Choose a reason for hiding this comment

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

Got it - admittedly I didn't read the PRs description, only the title. :D Might be good to mention this in some comment as well.

Copy link
Contributor Author

@dpsutton dpsutton Aug 7, 2022

Choose a reason for hiding this comment

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

on it! thanks! EDIT: done

(selected-window))
(with-current-buffer (process-buffer clojure-process)
(comint-goto-process-mark)
(let ((beginning (point)))
(insert form)
(let ((end (point)))
(goto-char beginning)
(indent-sexp end)
;; font-lock the inserted code
(font-lock-ensure beginning end)
(goto-char end)))
(comint-send-input t t)))))

(defun inf-clojure-insert-defun ()
"Send current defun to process."
Expand Down