Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
marvel
GitHub Repository: marvel/qnf
Path: blob/master/elisp/emacs-for-python/plugins/virtualenv.el
990 views
1
;; This module defines the workon command for using virtualenv inside
2
;; emacs
3
(setq workon-home (getenv "WORKON_HOME"))
4
5
(defun add-to-PATH (dir)
6
"Add the specified path element to the Emacs PATH"
7
(interactive "DEnter directory to be added to PATH: ")
8
(if (file-directory-p dir)
9
(setenv "PATH"
10
(concat (expand-file-name dir)
11
path-separator
12
(getenv "PATH")))))
13
14
(defun activate-virtualenv (dir)
15
(setenv "VIRTUAL_ENV" dir)
16
(add-to-PATH (concat dir "/bin"))
17
(add-to-list 'exec-path (concat dir "/bin")))
18
19
(defun is_virtualenv (dir)
20
"Check if a directory is a virtualenv"
21
(file-exists-p (concat dir "/bin/activate"))
22
)
23
24
(defun filter (condp lst)
25
(delq nil
26
(mapcar (lambda (x) (and (funcall condp x) x)) lst)))
27
28
29
(defun workon-complete ()
30
"return available completions for workon"
31
(let
32
;;Varlist
33
((filelist (directory-files workon-home t))) ;; List directory
34
;; Let Body
35
(mapcar 'file-name-nondirectory
36
(filter 'is_virtualenv ;; select virtualenvs
37
(filter 'file-directory-p filelist))) ;; select directories
38
)
39
)
40
41
(defun workon (name)
42
"Issue a virtualenvwrapper-like workon command"
43
(interactive (list (completing-read "Virtualenv: " (workon-complete))))
44
(activate-virtualenv (concat (getenv "WORKON_HOME") "/" name))
45
)
46
47
48
(provide 'virtualenv)
49