Skip to content

switch-to-relevant buffer #350

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 11, 2013
Merged

switch-to-relevant buffer #350

merged 1 commit into from
Aug 11, 2013

Conversation

jonpither
Copy link
Contributor

Hi I added this function 'nrepl-switch-to-relevant-buffer'. It switches the user to the right nrepl buffer based on the current buffer. So if you have 2 nrepls open for project x and project y, if you open a project x file and run the function (key mapped of course) then you land on the right nrepl buffer. I couldn't see anything that caters for this in nrepl.el hence the pull request.

TBH I'm new to elisp so you might want to make sure it looks sane. Unfortunately since I moved this fn into nrepl.el, I can't seem to use it without eval'ling the nrepl.el in emacs. Not sure why this is? I get:

Symbol's function definition is void: nrepl-switch-to-relevant-buffer. I've tried byte-recompiling my emacs dir to no avail.

Not sure what the issue is.

@@ -2649,6 +2649,23 @@ clojure buffer and the REPL buffer."
(pop-to-buffer nrepl-last-clojure-buffer)
(message "Don't know the original clojure buffer")))

(defun nrepl-switch-to-relevant-buffer ()
"Switch to relevant nrepl buffer based on the current buffer"
Copy link
Member

Choose a reason for hiding this comment

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

This docstring is missing an ending dot.

@bbatsov
Copy link
Member

bbatsov commented Aug 8, 2013

I think that this behaviour should be integrated into the existing switch to REPL buffer command - it's pretty sensible to assume people would won't to go to proper REPL buffer using that command.

@jonpither
Copy link
Contributor Author

Thanks - I've made all the changes bar using cl-remove-if-not and merging into the existing switch command.

I couldn't find cl-remove-if-not... I played around but couldn't improve upon remove-if-not.

As commented in http://stackoverflow.com/questions/2234860/lisp-filter-out-results-from-list-not-matching-predicate, I tried using remove-if, but complement isn't present in elisp.

WRT to merging into the existing switch-command I'm happy to do this. Might be worth a second pull-request as it's changing existing behaviour? But whatever I'll work on it.

@bbatsov
Copy link
Member

bbatsov commented Aug 8, 2013

cl-remove-if-not is part of cl-lib for sure. Seems pretty odd that you don't have it. The problem with remove-if is that it's also part of the now deprecated cl module (as is remove-if-not).

The problem with having this functionality in a separate command is that probably nobody will notice and as I already said - I cannot imagine why I'll want to jump to a REPL that's not connected to my current project so I'd rather us change the existing (and widely used command).

@hugoduncan @purcell @technomancy @samaaron Thoughts?

@jonpither
Copy link
Contributor Author

I've merged the two fns. I'm running with emacs 24.2 which is why I can't seem to get cl-remove-if-not and friends:

http://williamjohnbert.com/2013/05/emacs-cl-lib-madness/

I'll upgrade.

@jonpither
Copy link
Contributor Author

Might it be an issue with users on older Emacs versions though?

@hugoduncan
Copy link
Member

What happens when there are multiple REPLs for a single project? I assume it would just pick the "first", which should be the most recently used, iirc.

Building it into jump to repl should be fine, but should be overridable with a prefix, since it is not impossible that you have REPLs for a project and a subproject open, and want to work with the top level project REPL when changing subproject files. Not sure if checkout dependencies complicate anything further here - I don't think so.

@jonpither
Copy link
Contributor Author

Have used cl-remove-if-not as discussed (after emacs upgrade)

I moved nrepl-remember-clojure-buffer up as it was being used before it was defined.

@hugoduncan it does pick the first match if you were to have multiple nrepl sessions open in the same project dir.

TBH - not sure how the prefix would function? Like a global flag to turn off the extra behaviour?

@bbatsov
Copy link
Member

bbatsov commented Aug 9, 2013

@jonpither A prefix argument means that when the function is invoked like this C-u C-c C-z it will behave differently from the normal invocation C-c C-z. Have a look at the source of nrepl-jack-in for details. I think @hugoduncan is right and that we should add prefix argument support to C-c C-z. More details can be found here - http://www.emacswiki.org/emacs/PrefixArgument

@jonpither
Copy link
Contributor Author

Thanks @bbatsov. I understand the prefix behaviour now :-) The same ido-read-directory-name approach could be taken as for nrepl-jack-in.

There is though already an arg taken by nrepl-switch-to-repl-buffer to put the user into the namespace of the file they are on... thoughts?

@bbatsov
Copy link
Member

bbatsov commented Aug 11, 2013

@jonpither Pretty simple - we have C-u C-c C-z behave like it currently does and make C-u C-u C-c C-z trigger the new special behavior. Basically the number of prefix arguments will control the behavior. This is a pretty common practice in Emacs land.

@jonpither
Copy link
Contributor Author

@bbatsov I've added the second prefix arg that prompts for a directory in the last commit.

The only issue is that if you want the new behaviour of specifying the directory of the repl session you want to jump to through C-u C-u C-c C-z, then the first arg is still also activated, meaning the NS will be changed to whatever the current buffer is (or user if the current buffer does not have a ns open).

This is probably fine, but it may annoy if you want to change to a specific repl but not switch ns.

If there's an easy way of having the second behaviour but not the first, it may be worth doing.

of the current source file.

With a second prefix ARG the chosen repl buffer is based on a
supplied project directory."
(interactive "P")
Copy link
Member

Choose a reason for hiding this comment

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

You can make this interactive "p" to receive directly a numeric prefix argument. For C-u C-c C-z it would be 4 and for C-u C-c C-z it would be 16.

@bbatsov
Copy link
Member

bbatsov commented Aug 11, 2013

I've commented on the relevant bit of code - basically (interactive "p") and comparisons whether arg is 4 or 16 is what you want to do.

@jonpither
Copy link
Contributor Author

Have added as per your comment, the two behaviours are triggered separately. Have added to the docs.

@bbatsov
Copy link
Member

bbatsov commented Aug 11, 2013

OK. Now just update the Changelog and squash all the commits into one and we're good to merge this.

@jonpither
Copy link
Contributor Author

Should be good to go

bbatsov added a commit that referenced this pull request Aug 11, 2013
switch-to-relevant buffer
@bbatsov bbatsov merged commit adcb533 into clojure-emacs:master Aug 11, 2013
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