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

Conversation

JasonKDarby
Copy link
Contributor

This addresses #168 by creating inf-clojure--recent-buffer to keep track of the buffer the repl was switched to from. It's set on both inf-clojure and inf-clojure-switch-to-repl which hopefully means it can never be unintentionally nil. If inf-clojure-switch-to-recent-buffer is called and inf-clojure--recent-buffer IS nil the message "inf-clojure: No recent buffer known." is sent.

This only tracks the most recent buffer among all repls, it will not manage multiple references in the case of multiple repls.

I'm by no means an elisp expert, if there are improvements to be made I'm happy to hear them. I'm gonna try to take on more changes, I love having an opportunity to contribute!


Before submitting the PR make sure the following things have been done (and denote this
by checking the relevant checkboxes):

  • The commits are consistent with our contribution guidelines
  • The new code is not generating bytecode or M-x checkdoc warnings
  • You've updated the changelog (if adding/changing user-visible functionality)
  • You've updated the readme (if adding/changing user-visible functionality)

Thanks!

@bbatsov
Copy link
Member

bbatsov commented May 5, 2022

Looks good to me overall. Just mention this in the changelog and I we can merge this.

@JasonKDarby
Copy link
Contributor Author

Thanks! I did already, if I should change it let me know.

I did notice I forgot to update inf-clojure--recent-buffer on inf-clojure-connect, I can add that later.

@JasonKDarby
Copy link
Contributor Author

As far as I know it's good to go, let me know if there's anything else.

@dpsutton
Copy link
Contributor

This attempts to track a buffer you came from. This seems inherently weak as there are only certain times we mark the buffer we came from. Seems like most times it will be nil or stale. Can we do something like what CIDER does and look through the (buffer-list) for the most recent buffer that is in a mode that descends from clojure-mode?

For reference, CIDER's version:

(defun cider-switch-to-last-clojure-buffer ()
  "Switch to the last Clojure buffer.
The default keybinding for this command is
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)
  (if (derived-mode-p 'cider-repl-mode)
      (let* ((a-buf)
             (the-buf (let ((repl-type (cider-repl-type-for-buffer)))
                        (seq-find (lambda (b)
                                    (unless (with-current-buffer b (derived-mode-p 'cider-repl-mode))
                                      (when-let* ((type (cider-repl-type-for-buffer b)))
                                        (unless a-buf
                                          (setq a-buf b))
                                        (or (eq type 'multi)
                                            (eq type repl-type)))))
                                  (buffer-list)))))
        (if-let* ((buf (or the-buf a-buf)))
            (if cider-repl-display-in-current-window
                (pop-to-buffer-same-window buf)
              (pop-to-buffer buf))
          (user-error "No Clojure buffer found")))
    (user-error "Not in a CIDER REPL buffer")))

But the gist is (seq-find clojure-mode-predicate (buffer-list))

@JasonKDarby
Copy link
Contributor Author

@dpsutton I was only intending to update it when it was swapped with C-c C-z / inf-clojure-switch-to-repl, is this to say the last buffer when swapped to by any means (ex C-xo)?

@dpsutton
Copy link
Contributor

@JasonKDarby exactly. The current implementation would take you back to the last buffer that you used C-c C-z in, which might be a while ago, landing you in a strange buffer. It seems to me that the ideal workflow is a quick way to bounce between the repl and a source buffer, regardless of how you got there.

@JasonKDarby
Copy link
Contributor Author

@dpsutton I think this works, I've tried it out with two windows.
Before passing '(display-buffer-reuse-window . ()) to pop-to-buffer I kept having this issue where it would change back to the correct buffer but would always do it in the 'first' window. I'm not sure why that wasn't happening before but it looks like it's fixed now.

Let me know if there's anything else to do on this. I love inf-clojure.

@dpsutton dpsutton merged commit 8f29505 into clojure-emacs:master Jun 3, 2022
@dpsutton
Copy link
Contributor

dpsutton commented Jun 3, 2022

thanks @JasonKDarby . this is a great addition.

@JasonKDarby JasonKDarby deleted the switch-from-repl branch February 15, 2024 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants