Skip to content
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

Added function for switching back from an inf-clojure buffer #200

Merged
merged 4 commits into from
Jun 3, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### New features

* [#168](https://github.com/clojure-emacs/inf-clojure/pull/197): Helper function `inf-clojure-switch-to-recent-buffer` to select the last buffer an inf-clojure process buffer was swapped to from.
* [#187](https://github.com/clojure-emacs/inf-clojure/pull/197): Defcustom `inf-clojure-enable-eldoc` to disable eldoc interaction.

## 3.1.0 (2021-07-23)
Expand Down
27 changes: 21 additions & 6 deletions inf-clojure.el
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ Either \"no process\" or \"buffer-name(repl-type)\""
(define-key map (kbd "C-c C-S-a") #'inf-clojure-apropos)
(define-key map (kbd "C-c M-o") #'inf-clojure-clear-repl-buffer)
(define-key map (kbd "C-c C-q") #'inf-clojure-quit)
(define-key map (kbd "C-c C-z") #'inf-clojure-switch-to-recent-buffer)
(easy-menu-define inf-clojure-mode-menu map
"Inferior Clojure REPL Menu"
'("Inf-Clojure REPL"
Expand Down Expand Up @@ -694,22 +695,36 @@ to continue it."
(let ((comint-buffer-maximum-size 0))
(comint-truncate-buffer))))

(defun inf-clojure--swap-to-buffer-window (to-buffer)
"Switch to `TO-BUFFER''s window."
(let ((pop-up-frames
;; Be willing to use another frame
;; that already has the window in it.
(or pop-up-frames
(get-buffer-window to-buffer t))))
(pop-to-buffer to-buffer '(display-buffer-reuse-window . ()))))

(defun inf-clojure-switch-to-repl (eob-p)
"Switch to the inferior Clojure process buffer.
With prefix argument EOB-P, positions cursor at end of buffer."
(interactive "P")
(if (get-buffer-process inf-clojure-buffer)
(let ((pop-up-frames
;; Be willing to use another frame
;; that already has the window in it.
(or pop-up-frames
(get-buffer-window inf-clojure-buffer t))))
(pop-to-buffer inf-clojure-buffer))
(inf-clojure--swap-to-buffer-window inf-clojure-buffer)
(call-interactively #'inf-clojure))
(when eob-p
(push-mark)
(goto-char (point-max))))

(defun inf-clojure-switch-to-recent-buffer ()
"Switch to the most recently used `inf-clojure-minor-mode' buffer."
(interactive)
(let ((recent-inf-clojure-minor-mode-buffer (seq-find (lambda (buf)
(with-current-buffer buf (bound-and-true-p inf-clojure-minor-mode)))
(buffer-list))))
(if recent-inf-clojure-minor-mode-buffer
(inf-clojure--swap-to-buffer-window recent-inf-clojure-minor-mode-buffer)
(message "inf-clojure: No recent buffer known."))))

(defun inf-clojure-quit (&optional buffer)
"Kill the REPL buffer and its underlying process.

Expand Down