summaryrefslogtreecommitdiffstats
path: root/lisp/ravi-init-python.el
diff options
context:
space:
mode:
authorRavi R Kiran <aine.marina@gmail.com>2015-10-23 18:57:59 (GMT)
committerRavi R Kiran <aine.marina@gmail.com>2015-10-23 18:57:59 (GMT)
commitcd1924466152177ea06b17c843f256463c1b91b8 (patch)
treeaf90afe028e5e392f242a3ea36302aafe1c1769d /lisp/ravi-init-python.el
parent5561df232cfa49822f322196d98170f95aa1139e (diff)
parent74c319ef12dd3130f6afc17abc59404b59d601d1 (diff)
downloaddotemacs-cd1924466152177ea06b17c843f256463c1b91b8.zip
dotemacs-cd1924466152177ea06b17c843f256463c1b91b8.tar.gz
dotemacs-cd1924466152177ea06b17c843f256463c1b91b8.tar.bz2
Merge branch 'master' into rtags-attempt
* master: (139 commits) Add pdf-tools as a nicer replacement for doc-view Add pdf-tools submodule Fix maildir data with correct path Add desktop notifications for email Potential use for modes without repls Attach files more easily in mu Update to newest version of mu Please remove tooltips after a while, please ace-window gets confused when tooltips are present Sometimes the dispatch list does come in handy Pre-populate searches Succumb to muscle memory of control keys Remove ropemacs due to disuse Do not let company-quickhelp steal a global key Manage word navigation Use proper helm function to replace completing-read Electric operators on python mode Use which-key in preference to guide-key Navigate easier Simplify config with magit 2.1.0 ...
Diffstat (limited to 'lisp/ravi-init-python.el')
-rw-r--r--lisp/ravi-init-python.el164
1 files changed, 164 insertions, 0 deletions
diff --git a/lisp/ravi-init-python.el b/lisp/ravi-init-python.el
new file mode 100644
index 0000000..7993092
--- /dev/null
+++ b/lisp/ravi-init-python.el
@@ -0,0 +1,164 @@
+;;; ravi-init-python.el --- python support
+
+;; Copyright (C) 2013
+
+;; Author: <ravi@nero.lan>
+;; Keywords:
+
+;; 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 of the License, 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 this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Python programming setup
+
+;;; Code:
+
+(use-package python
+ :mode ("\\.py\\'" . python-mode)
+ :commands python-shell-switch-to-shell
+ :config
+ (progn
+
+ (add-hook 'python-mode-hook 'ravi/python-mode-hook)
+ (defun ravi/python-mode-hook()
+ ;; Set ipython as our interpreter
+ (setq python-shell-interpreter "ipython"
+ python-shell-interpreter-args "--pylab"
+ python-shell-prompt-regexp "In \\[[0-9]+\\]: "
+ python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: "
+ python-shell-completion-setup-code
+ "from IPython.core.completerlib import module_completion"
+ python-shell-completion-module-string-code
+ "';'.join(module_completion('''%s'''))\n"
+ python-shell-completion-string-code
+ "';'.join(get_ipython().Completer.all_completions('''%s'''))\n"
+ )
+
+ ;; For ipython 0.10, uncomment the following:
+ ;; (setq python-shell-completion-string-code
+ ;; "';'.join(__IP.complete('''%s'''))\n"
+ ;; python-shell-completion-module-string-code ""
+ ;; )
+
+ (when (functionp 'helm-dash)
+ (setq-local helm-dash-docsets '("Python 2" "NumPy")))
+
+ ;; I'd really prefer indentation by 2 spaces, but have too much existing
+ ;; python code with indentation at 4 spaces.
+ (setq python-indent-offset 4)
+ )
+
+ (bind-key "<return>" 'newline-and-indent python-mode-map)
+
+ ;; We no longer use smart-tab-mode
+ ;(add-to-list 'smart-tab-disabled-major-modes 'inferior-python-mode)
+
+ (define-auto-insert "\\.py\\'" 'ravi/auto-insert-py)
+ (defun ravi/auto-insert-py ()
+ (progn
+ (insert "#!/usr/bin/env python\n\n")
+ )
+ )
+
+ (use-package virtualenvwrapper
+ :config
+ (progn
+ (venv-initialize-interactive-shells)
+ (venv-initialize-eshell)
+ (setq venv-location (expand-file-name "~/usr/local/venv/"))
+ )
+
+ :ensure t
+ )
+
+ ;; Use jedi.el for code completion plus documentation browsing.
+ ;; The main issue is that this requires both python-side and emacs-side
+ ;; support, but the python-side support cannot be installed as a package
+ ;; from MELPA. Fedora does not provide python-epc as an RPM either. We
+ ;; work around it by adding sexpdata, jedi and python-epc as git submodules.
+ (use-package jedi-core
+ :config
+ (progn
+ (defun ravi/jedi-setup ()
+ (let ((basic-server-args (list
+ "--sys-path" (ravi/emacs-file "site-lisp/python-epc")
+ "--sys-path" (ravi/emacs-file "site-lisp/sexpdata")
+ "--sys-path" (ravi/emacs-file "site-lisp/jedi"))
+ ))
+ (set (make-local-variable 'jedi:server-args)
+ (if (and (boundp 'extra-jedi-args)
+ (listp extra-jedi-args))
+ (append basic-server-args extra-jedi-args)
+ basic-server-args))
+ (jedi:setup)))
+
+ ;; Override pos-tip support to automatically delete tooltip
+ (defun ravi/jedi:tooltip-show (string)
+ (cond
+ ((and (memq 'pos-tip jedi:tooltip-method) window-system
+ (featurep 'pos-tip))
+ (pos-tip-show (jedi:string-fill-paragraph string)
+ 'popup-tip-face nil nil 5))
+ ((and (memq 'popup jedi:tooltip-method)
+ (featurep 'popup))
+ (popup-tip string))
+ (t (when (stringp string)
+ (let ((message-log-max nil))
+ (message string))))))
+ (fset 'jedi:tooltip-show 'ravi/jedi:tooltip-show)
+
+ (defun ravi/python-jedi-hook-installer ()
+ ;; (setq jedi:complete-on-dot t) ; needs auto-complete
+ (add-hook 'hack-local-variables-hook 'ravi/jedi-setup nil t))
+ (add-hook 'python-mode-hook 'ravi/python-jedi-hook-installer)
+ )
+ :ensure t
+ )
+
+ (use-package company-jedi
+ :config
+ (progn
+ (add-to-list 'company-backends 'company-jedi))
+ :ensure t)
+
+ (use-package sphinx-doc
+ :config
+ (progn
+ (defun ravi/sphinx-doc-setup ()
+ (sphinx-doc-mode 1))
+ (add-hook 'python-mode-hook 'ravi/sphinx-doc-setup)
+ )
+ :diminish sphinx-doc-mode
+ :ensure t)
+
+ (use-package python-docstring
+ :config
+ (progn
+ (defun ravi/python-docstring-mode-setup ()
+ (python-docstring-mode 1))
+ (add-hook 'python-mode-hook 'ravi/python-docstring-mode-setup))
+ :diminish python-docstring-mode
+ :ensure t)
+
+ (use-package electric-operator
+ :config
+ (progn
+ (add-hook 'python-mode-hook #'electric-operator-mode))
+ ;; :diminish electric-operator
+ :ensure t)
+ )
+ )
+
+(provide 'ravi-init-python)
+