浏览代码

Update

master
10sr 7 年前
父节点
当前提交
9d774fa960
签署人:: 10sr GPG 密钥 ID: 7BEC428194130EB2
共有 1 个文件被更改,包括 35 次插入10 次删除
  1. +35
    -10
      emacs.el

+ 35
- 10
emacs.el 查看文件

@@ -2020,7 +2020,11 @@ initializing."
"Execute BODY with venv enabled. "Execute BODY with venv enabled.


This function tries to find suitable venv dir, or raise error when none found." This function tries to find suitable venv dir, or raise error when none found."
`(with-venv-dir ,(with-venv-find-venv-dir) ,@body))
`(with-venv-dir
;; If set explicitly use it
,(or with-venv-venv-dir
with-venv-find-venv-dir)
,@body))


(defvar-local with-venv-venv-dir (defvar-local with-venv-venv-dir
nil nil
@@ -2032,17 +2036,38 @@ This function tries to find suitable venv dir, or raise error when none found."
(when dir (when dir
(cd dir)) (cd dir))
(or (or
;; If set explicitly use it
with-venv-venv-dir
;; Check pipenv ;; Check pipenv
(let ((status (call-process "pipenv" nil t nil "--venv")))
(goto-char (point-min))
(and (eq status 0)
(buffer-substring-no-properties (point-at-bol)
(point-at-eol))))
(with-venv--find-venv-dir-pipenv)
;; Check poetry
(with-venv--find-venv-dir-poetry)
;; Search for .venv dir ;; Search for .venv dir
(locate-dominating-file default-directory
".venv"))))
(with-venv--find-venv-dir-by-name))))

(defun with-venv--find-venv-dir-pipenv ()
"Try to find venv dir via pipenv."
(with-temp-buffer
(let ((status (call-process "pipenv" nil t nil "--venv")))
(when (eq status 0)
(goto-char (point-min))
(buffer-substring-no-properties (point-at-bol)
(point-at-eol))))))

(defun with-venv--find-venv-dir-poetry ()
"Try to find venv dir via poetry."
(with-temp-buffer
;; TODO: Use poetry env info --path
(let ((status (call-process "poetry" nil t nil "debug:info")))
(when (eq status 0)
(goto-char (point-min))
(save-match-data
(when (re-search-forward "^ \\* Path: *\\(.*\\)$")
(match-string 1)))))))

(defun with-venv--find-venv-dir-by-name ()
"Try to find venv dir by its name."
(expand-file-name ".venv"
(locate-dominating-file default-directory
".venv")))




;; (with-venv (:dir default-directory) (message "a")) ;; (with-venv (:dir default-directory) (message "a"))


正在加载...
取消
保存