Skip to content

Fix `nrepl-switch-to-repl-buffer' to work with all connections #361

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 1 commit into from
Aug 21, 2013
Merged

Fix `nrepl-switch-to-repl-buffer' to work with all connections #361

merged 1 commit into from
Aug 21, 2013

Conversation

vedang
Copy link
Contributor

@vedang vedang commented Aug 18, 2013

Commit 12558e8 breaks nrepl-switch-to-repl-buffer functionality by
assuming that all nrepl connections will be made using
nrepl-jack-in.

Using nrepl-jack-in sets the variable nrepl-project-dir to the
correct value, but this information cannot be retrieved when we
connect to an existing nRepl server using nrepl-connect. Since
nrepl-project-dir is unbound, the function file-truename throws a
null value exception.

This commit checks if nrepl-project-dir is set before calling
file-truename. Further, the message "nREPL connection not found"
does not make sense and thus should not be displayed.

@vedang
Copy link
Contributor Author

vedang commented Aug 18, 2013

Hi @bbatsov,

While my commit fixes the obvious breakage of not being able to switch to nrepl buffer, it exposes a more subtle bug that was introduced in 12558e8:

Suppose I have used nrepl-jack-in to connect to my project. Now I want to work on the production env (for the same project), so I connect to the production repl using M-x nrepl. Now, I go back to work in my clojure file, knowing that my production repl is my active repl. I punch C-c C-z. nrepl-switch-to-repl-buffer will detect that I have a local repl belonging to this project, it will mark that connection as active and will switch to my local repl.

This is absolutely the wrong thing to do, IMHO. People who are connected to multiple repls know that they are connected to multiple repls, and don't need nrepl to switch to the correct repl for them. Please consider rolling back this entire functionality and going back to the way nrepl-switch-to-repl-buffer worked in 0.1.8

@jonpither
Copy link
Contributor

One option is to keep the functionality as a separate function.

The functionality is there for convenience sake.

@vedang
Copy link
Contributor Author

vedang commented Aug 18, 2013

Yes, +1. Keep this as a separate function that can be bound to a separate key and used as per requirement.

@vedang
Copy link
Contributor Author

vedang commented Aug 18, 2013

I have changed the nrepl-switch-to-repl-buffer function back to the one found in 0.1.8 - 12558e8~1 to be precise. In addition, I've added the new functionality in the function nrepl-switch-to-relevant-buffer as proposed in the original pull request #350.

If this change is acceptable, we can add a new key binding for nrepl-switch-to-relevant-buffer in the nrepl-interaction-mode-map. (I propose C-c C-v)

@jonpither
Copy link
Contributor

Other options are having a flag to turn on/off the behaviour in the single function, or to think harder about how the 'magic' should be applied, i.e. if there is a connection present not based off a project and there is some level of ambiguity then don't do it.

@vedang
Copy link
Contributor Author

vedang commented Aug 18, 2013

I'm against 'magic' code in general. Since this is a convenience function, keeping it separate is the right thing to do.

@jonpither
Copy link
Contributor

Yes I agree, just throwing up the other options.

@bbatsov
Copy link
Member

bbatsov commented Aug 20, 2013

Fair enough. Separate function it is. I'd suggest C-c C-Z as the binding for it. Add the new function to the menus as well. Since I generally keep a REPL per project I didn't properly assess the situation originally.

@vedang
Copy link
Contributor Author

vedang commented Aug 21, 2013

I've added the documentation changes and tests for nrepl-switch-to-relevant-buffer. If this is okay to merge, then I'll squash everything into a single commit.

(nrepl-remember-clojure-buffer buffer)
(goto-char (point-max))))))

(defun nrepl-switch-to-relevant-buffer (arg)
Copy link
Member

Choose a reason for hiding this comment

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

I think we should name this nrepl-switch-to-relevant-repl(-buffer).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay.

@bbatsov
Copy link
Member

bbatsov commented Aug 21, 2013

I've added my comments. As soon as you've addressed them we'll be good to merge this.

@vedang
Copy link
Contributor Author

vedang commented Aug 21, 2013

Alright, I'll make the changes and push the commit.

Commit 12558e8 breaks `nrepl-switch-to-repl-buffer' functionality by
assuming that all nrepl connections will be made using
`nrepl-jack-in'.

This commit reverts to old `nrepl-switch-to-repl-buffer'. A new
function `nrepl-switch-to-relevant-repl-buffer' is added as a
convenience function to switch to the correct nrepl buffer from a
given clojure buffer.
@vedang
Copy link
Contributor Author

vedang commented Aug 21, 2013

Done. Rebased on top of master and good to merge.

bbatsov added a commit that referenced this pull request Aug 21, 2013
Fix `nrepl-switch-to-repl-buffer' to work with all connections
@bbatsov bbatsov merged commit db63bf2 into clojure-emacs:master Aug 21, 2013
@vedang vedang deleted the fix-switch-to-repl-buffer branch August 21, 2013 20:20
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