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
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## 0.2.0

* <kbd>C-c C-z</kbd> will select the clojure buffer based on the current namespace.
* <kbd>C-u C-u C-c C-z</kbd> will select the clojure buffer based on a user directory prompt.

### Bugs fixed

* <kbd>C-c M-s</kbd> (`nrepl-selector`) was bound to non-existing symbol.
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ Keyboard shortcut | Description
<kbd>TAB</kbd> | Complete symbol at point.
<kbd>C-c C-d</kbd> | Display doc string for the symbol at point. If invoked with a prefix argument, or no symbol is found at point, prompt for a symbol
<kbd>C-c C-j</kbd> | Display JavaDoc (in your default browser) for the symbol at point. If invoked with a prefix argument, or no symbol is found at point, prompt for a symbol.
<kbd>C-c C-z</kbd> | Select the last clojure buffer.
<kbd>C-c C-z</kbd> | Select the last clojure buffer. <kbd>C-u C-c C-z</kbd> will switch the clojure buffer to the namespace in the current buffer.
<kbd>C-u C-u C-c C-z</kbd> | Select the clojure buffer based on a user prompt for a directory.

### Macroexpansion buffer commands:

Expand Down
46 changes: 33 additions & 13 deletions nrepl.el
Original file line number Diff line number Diff line change
Expand Up @@ -2581,6 +2581,16 @@ It is set to current buffer when `nrepl' or `nrepl-jack-in' is called.
After the REPL buffer is created, the value of this variable is used
to call `nrepl-remember-clojure-buffer'.")

(defun nrepl-remember-clojure-buffer (buffer)
"Try to remember the BUFFER from which the user jumps.
The BUFFER needs to be a clojure buffer and current major mode needs
to be `nrepl-mode'. The user can use `nrepl-switch-to-last-clojure-buffer'
to jump back to the last clojure source buffer."
(when (and buffer
(eq 'clojure-mode (with-current-buffer buffer major-mode))
(eq 'nrepl-mode major-mode))
(setq nrepl-last-clojure-buffer buffer)))

(defun nrepl-init-repl-buffer (connection buffer &optional noprompt)
"Initialize the repl for CONNECTION in BUFFER.
Insert a banner, unless NOPROMPT is non-nil."
Expand Down Expand Up @@ -2609,34 +2619,44 @@ Insert a banner, unless NOPROMPT is non-nil."

(defun nrepl-switch-to-repl-buffer (arg)
"Select the repl buffer, when possible in an existing window.
The buffer chosen is based on the file open in the current buffer.

Hint: You can use `display-buffer-reuse-frames' and
`special-display-buffer-names' to customize the frame in which
the buffer should appear.

With a prefix ARG sets the name of the repl buffer to the one
of the current source file."
(interactive "P")
of the current source file.

With a second prefix ARG the chosen repl buffer is based on a
supplied project directory."
(interactive "p")
(if (not (get-buffer (nrepl-current-connection-buffer)))
(message "No active nREPL connection.")
(progn
(let ((project-directory
(or (when (eq 16 arg)
(ido-read-directory-name "Project: "))
(nrepl-project-directory-for (nrepl-current-dir)))))
(when project-directory
(lexical-let ((buf (car (cl-remove-if-not
(lambda (conn)
(equal (file-truename project-directory)
(file-truename
(with-current-buffer (get-buffer conn)
nrepl-project-dir))))
nrepl-connection-list))))
(if (not buf)
(message (format "nREPL connection not found for %s." (file-truename project-directory)))
(setq nrepl-connection-list
(cons buf (delq buf nrepl-connection-list)))))))
(let ((buffer (current-buffer)))
(when arg
(when (eq 4 arg)
(nrepl-set-ns (nrepl-current-ns)))
(pop-to-buffer (nrepl-find-or-create-repl-buffer))
(nrepl-remember-clojure-buffer buffer)
(goto-char (point-max))))))

(defun nrepl-remember-clojure-buffer (buffer)
"Try to remember the BUFFER from which the user jumps.
The BUFFER needs to be a clojure buffer and current major mode needs
to be `nrepl-mode'. The user can use `nrepl-switch-to-last-clojure-buffer'
to jump back to the last clojure source buffer."
(when (and buffer
(eq 'clojure-mode (with-current-buffer buffer major-mode))
(eq 'nrepl-mode major-mode))
(setq nrepl-last-clojure-buffer buffer)))

(defun nrepl-switch-to-last-clojure-buffer ()
"Switch to the last clojure buffer.
The default keybinding for this command is
Expand Down