Skip to content

Commit

Permalink
Add elpy-shell-set-local-shell function
Browse files Browse the repository at this point in the history
  • Loading branch information
galaunay committed Dec 8, 2017
1 parent 7809117 commit 6fa8cc4
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion elpy-shell.el
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,38 @@ if ARG is negative or 0, disable the use of a dedicated shell."
(if (<= arg 0)
(kill-local-variable 'python-shell-buffer-name)
(setq-local python-shell-buffer-name
(format "Python[%s]" (buffer-name))))))
(format "Python[%s]L" (buffer-name))))))

(defun elpy-shell-set-local-shell (&optional shell-name)
;; Todo: doc need rewriting
"Associate the current buffer to a given shell.
This means that the code from the current buffer will be sent to this shell.
If SHELL-NAME is not specified, ask with completion for a name.
If SHELL-NAME is \"Global\", associate the current buffer to the main python
shell (often \"*Python*\" shell)."
(interactive)
(let* ((current-shell-name (if (local-variable-p 'python-shell-buffer-name)
(progn
(string-match "Python\\[\\(.*?\\)\\]"
python-shell-buffer-name)
(match-string 1 python-shell-buffer-name))
"Global"))
(shell-names (cl-loop
for buffer in (buffer-list)
for buffer-name = (substring-no-properties (buffer-name buffer))
if (string-match "\\*Python\\[\\(.*?\\)\\]\\*" buffer-name)
collect (match-string 1 buffer-name)))
(candidates (remove current-shell-name
(delete-dups
(append (list (buffer-name) "Global") shell-names))))
(prompt (format "Shell name (current: %s): " current-shell-name))
(shell-name (or shell-name (completing-read prompt candidates))))
(if (string= shell-name "Global")
(kill-local-variable 'python-shell-buffer-name)
(setq-local python-shell-buffer-name (format "Python[%s]" shell-name)))))

(defun elpy-shell-change-global-shell-name (name)
"Tell Elpy to use another python shell named NAME.
Expand Down

0 comments on commit 6fa8cc4

Please sign in to comment.