This repository has been archived by the owner on Jul 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
pyenv-mode-auto.el
57 lines (46 loc) · 1.84 KB
/
pyenv-mode-auto.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
;;; pyenv-mode-auto.el --- Automatically activates pyenv version if .python-version file exists.
;; Copyright © 2016 Sviatoslav Bulbakha <mail@ssbb.me>
;; Author: Sviatoslav Bulbakha <mail@ssbb.me>
;; URL: https://github.com/ssbb/pyenv-mode-auto
;; Keywords: python, pyenv
;; Version: 0.1.1
;; Package-Requires: ((pyenv-mode "0.1.0") (s "1.11.0") (f "0.17.0"))
;; This file is NOT part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;;
;; This library provides easy way to automatically activate pyenv
;; with pyenv-mode if .python-version file exists.
;;
;;; Code:
(require 's)
(require 'f)
(require 'pyenv-mode)
(defun pyenv-mode-auto-hook ()
"Automatically activates pyenv version if .python-version file exists."
(f-traverse-upwards
(lambda (path)
(let ((pyenv-version-path (f-expand ".python-version" path)))
(if (f-exists? pyenv-version-path)
(progn
(pyenv-mode-set (car (s-lines (s-trim (f-read-text pyenv-version-path 'utf-8)))))
t))))))
(add-hook 'find-file-hook 'pyenv-mode-auto-hook)
(provide 'pyenv-mode-auto)
;; Local Variables:
;; indent-tabs-mode: nil
;; End:
;;; pyenv-mode-auto.el ends here