Skip to content

Commit

Permalink
Merge pull request #41 from sambrightman/noearlydeactivate
Browse files Browse the repository at this point in the history
Refactor penv-workon
  • Loading branch information
porterjamesj authored Oct 2, 2016
2 parents 45c2028 + 2099382 commit 5649028
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions virtualenvwrapper.el
Original file line number Diff line number Diff line change
Expand Up @@ -265,25 +265,19 @@ This is useful e.g. when using tox."
"Interactively switch to virtualenv NAME. Prompts for name if called
interactively."
(interactive)
(if name
;; if called with argument, make sure it is valid
(progn
(when (not (venv-is-valid name))
(error "Invalid virtualenv specified!"))
;; then deactivate
(venv-deactivate)
;; then switch
(setq venv-current-name name))
;; if without argument, deactivate first
(let ((old-venv venv-current-name))
(venv-deactivate)
;; then read
(setq
venv-current-name
(venv-read-name
(if old-venv
(format "Choose a virtualenv (currently %s): " old-venv)
"Choose a virtualenv: ")))))
;; if without argument, read from user
(unless name
(setq name (venv-read-name
(if venv-current-name
(format "Choose a virtualenv (currently %s): " venv-current-name)
"Choose a virtualenv: "))))
;; validate name
(when (not (venv-is-valid name))
(error (format "Invalid virtualenv %s specified!" name)))
;; then deactivate
(venv-deactivate)
;; then switch
(setq venv-current-name name)
;; push it onto the history
(add-to-list 'venv-history venv-current-name)
;; actually activate it
Expand Down

0 comments on commit 5649028

Please sign in to comment.