Skip to content

Commit

Permalink
Add helpers to change shell name
Browse files Browse the repository at this point in the history
  • Loading branch information
galaunay committed Dec 7, 2017
1 parent 65df265 commit 7809117
Showing 1 changed file with 36 additions and 30 deletions.
66 changes: 36 additions & 30 deletions elpy-shell.el
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
;;
;;; Code:

(require 'python)

;;;;;;;;;;;;;;;;;;;;;;
;;; User customization

Expand Down Expand Up @@ -324,36 +326,40 @@ If ASK-FOR-EACH-ONE is non-nil, ask before killing each python process.
If SIT is non-nil, sit for that many seconds after creating a
Python process. This allows the process to start up."
(let* ((bufname (format "*%s*" (python-shell-get-process-name nil)))
(dedbufname (format "*%s*" (python-shell-get-process-name t)))
(proc (get-buffer-process bufname))
(dedproc (get-buffer-process dedbufname)))
(if elpy-dedicated-shells
(if dedproc
dedproc
(let ((default-directory (or (and elpy-shell-use-project-root
(elpy-project-root))
default-directory)))
(run-python (python-shell-parse-command) t t))
(when sit
(sit-for sit))
(when (elpy-project-root)
(python-shell-send-string
(format "import sys;sys.path.append('%s')" (elpy-project-root))))
(get-buffer-process dedbufname))
(if dedproc
dedproc
(if proc
proc
(let ((default-directory (or (and elpy-shell-use-project-root
(elpy-project-root))
default-directory)))
(run-python (python-shell-parse-command) nil t))
(when sit
(sit-for sit))
(when (elpy-project-root)
(python-shell-send-string
(format "import sys;sys.path.append('%s')" (elpy-project-root))))
(get-buffer-process bufname))))))
(proc (get-buffer-process bufname)))
(if proc
proc
(let ((default-directory (or (and elpy-shell-use-project-root
(elpy-project-root))
default-directory)))
(run-python (python-shell-parse-command) nil t))
(when sit (sit-for sit))
(when (elpy-project-root)
(python-shell-send-string
(format "import sys;sys.path.append('%s')" (elpy-project-root))))
(get-buffer-process bufname))))

(defun elpy-shell-toggle-dedicated-shell (&optional arg)
"Toggle the use of a dedicated python shell for the current buffer.
if ARG is positive, enable the use of a dedicated shell.
if ARG is negative or 0, disable the use of a dedicated shell."
(interactive)
(let ((arg (or arg
(if (local-variable-p 'python-shell-buffer-name) 0 1))))
(if (<= arg 0)
(kill-local-variable 'python-shell-buffer-name)
(setq-local python-shell-buffer-name
(format "Python[%s]" (buffer-name))))))

(defun elpy-shell-change-global-shell-name (name)
"Tell Elpy to use another python shell named NAME.
This allows to have multiple python shells running in parallel."
(interactive "sPython shell name: ")
(if (string-empty-p name)
(setq-default python-shell-buffer-name "Python")
(setq-default python-shell-buffer-name (format "Python[%s]" name))))

(defun elpy-shell--ensure-shell-running ()
"Ensure that the Python shell for the current buffer is running.
Expand Down

0 comments on commit 7809117

Please sign in to comment.