Skip to content

Commit 8f29505

Browse files
authored
Added function for switching back from an inf-clojure buffer (#200)
* Added function for switching back from an inf-clojure buffer * set inf-clojure--recent-buffer on inf-clojure-connect * use most recent buffer instead of 'last swapped from' buffer * provide display-buffer-reuse-window one day I'll learn how to read and pass args in emacs
1 parent abeab8d commit 8f29505

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### New features
66

7+
* [#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.
78
* [#187](https://github.com/clojure-emacs/inf-clojure/pull/197): Defcustom `inf-clojure-enable-eldoc` to disable eldoc interaction.
89

910
## 3.1.0 (2021-07-23)

inf-clojure.el

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ Either \"no process\" or \"buffer-name(repl-type)\""
330330
(define-key map (kbd "C-c C-S-a") #'inf-clojure-apropos)
331331
(define-key map (kbd "C-c M-o") #'inf-clojure-clear-repl-buffer)
332332
(define-key map (kbd "C-c C-q") #'inf-clojure-quit)
333+
(define-key map (kbd "C-c C-z") #'inf-clojure-switch-to-recent-buffer)
333334
(easy-menu-define inf-clojure-mode-menu map
334335
"Inferior Clojure REPL Menu"
335336
'("Inf-Clojure REPL"
@@ -694,22 +695,36 @@ to continue it."
694695
(let ((comint-buffer-maximum-size 0))
695696
(comint-truncate-buffer))))
696697

698+
(defun inf-clojure--swap-to-buffer-window (to-buffer)
699+
"Switch to `TO-BUFFER''s window."
700+
(let ((pop-up-frames
701+
;; Be willing to use another frame
702+
;; that already has the window in it.
703+
(or pop-up-frames
704+
(get-buffer-window to-buffer t))))
705+
(pop-to-buffer to-buffer '(display-buffer-reuse-window . ()))))
706+
697707
(defun inf-clojure-switch-to-repl (eob-p)
698708
"Switch to the inferior Clojure process buffer.
699709
With prefix argument EOB-P, positions cursor at end of buffer."
700710
(interactive "P")
701711
(if (get-buffer-process inf-clojure-buffer)
702-
(let ((pop-up-frames
703-
;; Be willing to use another frame
704-
;; that already has the window in it.
705-
(or pop-up-frames
706-
(get-buffer-window inf-clojure-buffer t))))
707-
(pop-to-buffer inf-clojure-buffer))
712+
(inf-clojure--swap-to-buffer-window inf-clojure-buffer)
708713
(call-interactively #'inf-clojure))
709714
(when eob-p
710715
(push-mark)
711716
(goto-char (point-max))))
712717

718+
(defun inf-clojure-switch-to-recent-buffer ()
719+
"Switch to the most recently used `inf-clojure-minor-mode' buffer."
720+
(interactive)
721+
(let ((recent-inf-clojure-minor-mode-buffer (seq-find (lambda (buf)
722+
(with-current-buffer buf (bound-and-true-p inf-clojure-minor-mode)))
723+
(buffer-list))))
724+
(if recent-inf-clojure-minor-mode-buffer
725+
(inf-clojure--swap-to-buffer-window recent-inf-clojure-minor-mode-buffer)
726+
(message "inf-clojure: No recent buffer known."))))
727+
713728
(defun inf-clojure-quit (&optional buffer)
714729
"Kill the REPL buffer and its underlying process.
715730

0 commit comments

Comments
 (0)