module-python.el (2696B)
1 ;;; module-python.el 2 3 ;; Author: Mark Feller <mark.feller@member.fsf.org> 4 5 ;; This file is not part of GNU Emacs. 6 7 ;; This file is free software; you can redistribute it and/or modify 8 ;; it under the terms of the GNU General Public License as published by 9 ;; the Free Software Foundation; either version 3, or (at your option) 10 ;; any later version. 11 12 ;; This file is distributed in the hope that it will be useful, 13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 ;; GNU General Public License for more details. 16 17 ;; You should have received a copy of the GNU General Public License 18 ;; along with this file. If not, see <http://www.gnu.org/licenses/>. 19 20 ;;; Commentary: 21 22 ;;; Code: 23 24 (defun pyenv-init() 25 (setq global-pyenv (replace-regexp-in-string "\n" "" (shell-command-to-string "pyenv global"))) 26 (message (concat "Setting pyenv version to " global-pyenv)) 27 (pyenv-mode-set global-pyenv) 28 (defvar pyenv-current-version nil global-pyenv)) 29 30 (defun mjf/pyenv-activate-current-project () 31 "Automatically activates pyenv version if .python-version file exists." 32 (interactive) 33 (f-traverse-upwards 34 (lambda (path) 35 (message path) 36 (let ((pyenv-version-path (f-expand ".python-version" path))) 37 (if (f-exists? pyenv-version-path) 38 (progn 39 (setq pyenv-current-version (s-trim (f-read-text pyenv-version-path 'utf-8))) 40 (pyenv-mode-set pyenv-current-version) 41 (pyvenv-workon pyenv-current-version) 42 (message (concat "Setting virtualenv to " pyenv-current-version)))))))) 43 44 (use-package python 45 :config 46 (setq python-shell-interpreter "ipython") 47 (setq python-shell-interpreter-args "-i --simple-prompt") 48 49 ;; Enable hideshow minor mode in python for folding and unfolding 50 (add-hook 'python-mode-hook 'hs-minor-mode) 51 (add-hook 'python-mode-hook 'subword-mode) 52 53 (add-hook 54 'python-mode-hook 55 (lambda () 56 (setq pretty-symbols-alist '()) 57 (mapc (lambda (pair) (push pair prettify-symbols-alist)) 58 '(;; Syntax 59 ("lambda" . ?λ) 60 (">=" . ?≥) 61 ("<=" . ?≤) 62 ("->" . ?➜)))))) 63 64 (use-package elpy 65 :bind 66 (:map elpy-mode-map 67 ("C-c C-j" . elpy-goto-definition) 68 ("M-," . pop-tag-mark)) 69 70 :config 71 (setq elpy-rpc-backend "jedi") 72 (setq elpy-rpc-python-command "python3") 73 (setq elpy-shell-echo-output nil) 74 75 (elpy-enable)) 76 77 (use-package pip-requirements 78 :config 79 (add-hook 'pip-requirements-mode-hook #'pip-requirements-auto-complete-setup)) 80 81 (use-package py-autopep8) 82 83 (provide 'module-python) 84 85 ;;; module-python.el ends here