Browse Source

Fix some bugs

master
10sr 6 years ago
parent
commit
04ef1fadc4
Signed by: 10sr GPG Key ID: 7BEC428194130EB2
1 changed files with 22 additions and 20 deletions
  1. +22
    -20
      emacs.el

+ 22
- 20
emacs.el View File

@@ -2018,7 +2018,9 @@ initializing."
"Venv directory path. "Venv directory path.


This variable is intended to be explicitly set by user. This variable is intended to be explicitly set by user.
When nil, `with-venv' tries to find suitable venv dir.")
When nil, `with-venv' tries to find suitable venv dir.
When this variable is set , use this value without checking if it is a valid
python environment.")


(defmacro with-venv-dir (dir &rest body) (defmacro with-venv-dir (dir &rest body)
"Set python environment to DIR and execute BODY. "Set python environment to DIR and execute BODY.
@@ -2029,7 +2031,7 @@ If dir is nil, execute BODY as usual."
(--with-venv-exec-path-orig (cl-copy-list exec-path))) (--with-venv-exec-path-orig (cl-copy-list exec-path)))
(unwind-protect (unwind-protect
(progn (progn
(when dir
(when ,dir
;; Do the same thing that bin/activate does ;; Do the same thing that bin/activate does
(setq exec-path (setq exec-path
(cons (concat ,dir "/bin") (cons (concat ,dir "/bin")
@@ -2043,6 +2045,9 @@ If dir is nil, execute BODY as usual."
(setq exec-path (setq exec-path
--with-venv-exec-path-orig)))) --with-venv-exec-path-orig))))



(defvar-local with-venv-previously-used nil
"Previously used venv dir path.")
(defmacro with-venv (&rest body) (defmacro with-venv (&rest body)
"Execute BODY with venv enabled. "Execute BODY with venv enabled.


@@ -2051,32 +2056,29 @@ suitable environment was found."
`(with-venv-dir `(with-venv-dir
;; If set explicitly use it ;; If set explicitly use it
,(or with-venv-venv-dir ,(or with-venv-venv-dir
(with-venv-find-venv-dir))
(with-venv-check-exists with-venv-previously-used)
(setq with-venv-previously-used (with-venv-find-venv-dir)))
,@body)) ,@body))


(defvar-local with-venv-previously-used nil
"Previously used venv dir path.")
(defun with-venv-find-venv-dir (&optional dir) (defun with-venv-find-venv-dir (&optional dir)
"Try to find venv dir for DIR. "Try to find venv dir for DIR.
If none found return nil." If none found return nil."
(with-temp-buffer (with-temp-buffer
(when dir (when dir
(cd dir)) (cd dir))
(let ((result (or
;; Check used previously
(with-venv-check-exists
with-venv-previously-used)
;; Check pipenv
(with-venv-check-exists
(with-venv--find-venv-dir-pipenv))
;; Check poetry
(with-venv-check-exists
(with-venv--find-venv-dir-poetry))
;; Search for .venv dir
(with-venv-check-exists
(with-venv--find-venv-dir-by-name)))))
(setq with-venv-previously-used
result))))
(or
;; Check used previously
(with-venv-check-exists
with-venv-previously-used)
;; Check pipenv
(with-venv-check-exists
(with-venv--find-venv-dir-pipenv))
;; Check poetry
(with-venv-check-exists
(with-venv--find-venv-dir-poetry))
;; Search for .venv dir
(with-venv-check-exists
(with-venv--find-venv-dir-by-name)))))


(defun with-venv--find-venv-dir-pipenv () (defun with-venv--find-venv-dir-pipenv ()
"Try to find venv dir via pipenv." "Try to find venv dir via pipenv."


Loading…
Cancel
Save