From dc53cb1865863f38b6f2737c21e70897d525b1ab Mon Sep 17 00:00:00 2001 From: Marc Pohling Date: Sun, 4 Mar 2018 12:41:35 +0100 Subject: [PATCH] anaconda --- config.org | 110 ++++++++++++++++++++++++++++++++++++++++++++--------- init.el | 6 ++- 2 files changed, 96 insertions(+), 20 deletions(-) diff --git a/config.org b/config.org index 2e011d7..466e250 100644 --- a/config.org +++ b/config.org @@ -326,11 +326,11 @@ Activate company and make it react nearly instantly :ensure t :config (add-to-list 'company-backends 'company-elisp) - (setq company-minimum-prefix-length 2 - company-tooltip-align-annotation t - company-tooltop-flip-when-above t - company-show-numbers t) - (setq company-idle-delay 0.1) + (setq-default company-minimum-prefix-length 2 + company-tooltip-align-annotation t + company-tooltop-flip-when-above t + company-show-numbers t + company-idle-delay 0.1) (add-hook 'after-init-hook 'global-company-mode) ;; (global-company-mode t) ) @@ -341,17 +341,18 @@ Addon to sort suggestions by usage #+begin_src emacs-lisp (use-package company-statistics :ensure t + :after company :config (company-statistics-mode 1) ) #+end_src Get a popup with documentation of the completion candidate. -I have to test if it even works. #+begin_src emacs-lisp (use-package company-quickhelp :ensure t + :after company :config (company-quickhelp-mode 1) ) @@ -363,12 +364,23 @@ Maybe add [[https://github.com/hlissner/emacs-company-dict][company-dict]]? It's ** Python Systemwide following packages need to be installed: -- virtualenv +- venv The virtual environments need to have following modules installed: - jedi - epc -- flake8 +- pylint + +#+begin_src emacs-lisp + (use-package flycheck + :ensure t + :init + (add-hook 'after-init-hook #'global-flycheck-mode) + (add-hook 'python-mode-hook (lambda () + (semantic-mode 1) + (setq flycheck-checker 'python-pylint))) + ) +#+end_src Automatically start python-mode when opening a .py-file. Not sure if python.el is better than python-mode.el. @@ -379,6 +391,8 @@ The custom function is to run inferiour processes (do I really need that?), see (use-package python :mode ("\\.py\\'" . python-mode) :interpreter ("python" . python-mode) + :init + (add-hook 'python-mode-hook 'eldoc-mode) :config (setq python-shell-completion-native-enable nil) ;; (defun my/run-python () @@ -389,31 +403,43 @@ The custom function is to run inferiour processes (do I really need that?), see ) #+end_src -~TEST~ ELPY +Anaconda test -begin_src emacs-lisp - (use-package elpy +#+begin_src emacs-lisp + (use-package anaconda-mode :ensure t -;; :pin elpy + :defer t + :init + (add-hook 'python-mode-hook 'anaconda-mode) +;; (add-hook 'python-mode-hook 'anaconda-eldoc-mode) :config - (elpy-enable) - (add-hook 'python-mode-hook 'elpy-mode) - (setq elpy-rpc-backend "jedi") - (pyvenv-mode 1) + (setq anaconda-eldoc-mode 1) ) -end_src +#+end_src +#+begin_src emacs-lisp + (use-package company-anaconda + :ensure t + :defer t + :init + (defun my/company-anaconda-hook() + (add-to-list 'company-backends 'company-anaconda)) + (add-hook 'python-mode-hook 'my/company-anaconda-hook) + ) +#+end_src Jedi is a backend for python autocompletion and needs to be installed on the server: - pip install jedi Code checks need to be installed, too: - pip install flake8 -#+begin_src emacs-lisp +begin_src emacs-lisp (use-package company-jedi :defer t +;; :after company :ensure t :config (setq jedi:environment-virtualenv (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/"))) + (setq jedi:python-environment-directory (list (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/"))) (add-hook 'python-mode-hook 'jedi:setup) (setq jedi:complete-on-dot t) (setq jedi:use-shortcuts t) @@ -425,8 +451,54 @@ Code checks need to be installed, too: A wrapper to handle virtual environments. I strongly recommend to install virtual environments on the terminal, not through this wrapper, but changing venvs is fine. +pyvenv might need virtualenvwrapper, I have to test this. +apt install #+begin_src emacs-lisp + (use-package pyvenv + :ensure t + :init + (setenv "WORKON_HOME" (expand-file-name "~/Archiv/Programmierprojekte/Python/virtualenv/")) + :config + (pyvenv-mode t) + (defun my/post-activate-hook() + (setq jedi:environment-root pyvenv-virtual-env) + (setq jedi:environment-virtualenv pyvenv-virtual-env) + (setq python-shell-virtualenv-root pyvenv-virtual-env) + ;; default traceback, other option M-x jedi:toggle-log-traceback + ;; traceback is in jedi:pop-to-epc-buffer + (jedi:setup) + (setq jedi:server-args '("--log-traceback")) + (add-to-list 'company-backends 'company-jedi) + (add-to-list 'company-backends 'company-anaconda) +;; (setq flycheck-checker 'python-pylint)) + (flycheck-select-checker 'python-pylint)) +;; (setq flycheck-checker 'python-flake8) + (add-hook 'pyvenv-post-activate-hooks 'my/post-activate-hook) + ) +#+end_src + +I want Emacs to automatically start the proper virtual environment. +Required is a .python-version file with, content in the first line being /path/to/virtualenv/ +[[https://github.com/marcwebbie/auto-virtualenv][Github source]] + +Depends on pyvenv + +#+begin_src emacs-lisp + (use-package auto-virtualenv + :ensure t +;; :after pyvenv +;; :defer t + :init + (add-hook 'python-mode-hook 'auto-virtualenv-set-virtualenv) + ;; activate on changing buffers + ;; (add-hook 'window-configuration-change-hook 'auto-virtualenv-set-virtualenv) + ;; activate on focus in + ;; (add-hook 'focus-in-hook 'auto-virtualenv-set-virtualenv) + ) +#+end_src + +begin_src emacs-lisp (use-package virtualenvwrapper :ensure t :init @@ -439,7 +511,7 @@ I strongly recommend to install virtual environments on the terminal, not throug (add-hook 'venv-postactivate-hook 'jedi:stop-server) (add-hook 'venv-postdeactivate-hook 'jedi:stop-server) ) -#+end_src +end_src diff --git a/init.el b/init.el index 0114386..dce9dcf 100644 --- a/init.el +++ b/init.el @@ -18,7 +18,11 @@ ;; Setup package (require 'package) (add-to-list 'package-archives - '("melpa" . "http://melpa.org/packages/") t) + '("melpa" . "https://melpa.org/packages/") t) +(add-to-list 'package-archives + '("melpa-stable" . "https://stable.melpa.org/packages/") t) +(add-to-list 'package-archives + '("gnu" . "https://elpa.gnu.org/packages/") t) (add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t) (when (boundp 'package-pinned-packages)