Skip to content

Instantly share code, notes, and snippets.

@aronwc
Last active December 20, 2015 00:59
Show Gist options
  • Save aronwc/6045966 to your computer and use it in GitHub Desktop.
Save aronwc/6045966 to your computer and use it in GitHub Desktop.
Writing Python with Emacs
Here are the steps I took to make Emacs have code-completion and PEP8 checking:
1. Install [Marmalade](http://marmalade-repo.org) by putting this in your .emacs
(require 'package)
(add-to-list 'package-archives
'("marmalade" .
"http://marmalade-repo.org/packages/"))
(package-initialize)
2. In emacs, M-x package-install flymake
3. Add this to .emacs
;; flymake + pep8
(when (load "flymake" t)
(defun flymake-pylint-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "pep8" (list "--repeat" local-file))))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.py\\'" flymake-pylint-init)))
(defun my-flymake-show-help ()
(when (get-char-property (point) 'flymake-overlay)
(let ((help (get-char-property (point) 'help-echo)))
(if help (message "%s" help)))))
(add-hook 'post-command-hook 'my-flymake-show-help)
(add-hook 'find-file-hook 'flymake-find-file-hook)
4. Now, real-time PEP8 checking should happen. Hover over line to see error message.
5. To install [Jedi](https://github.com/davidhalter/jedi) (auto-complete):
pip install jedi
pip install epc
6. In emacs, M-x package-install jedi
7. Add the following to your .emacs
(add-hook 'python-mode-hook
(lambda ()
(auto-complete-mode 1)))
(add-hook 'python-mode-hook 'jedi:setup)
(setq jedi:setup-keys t) ; optional
(setq jedi:complete-on-dot t) ; optional
8. Now, auto-completion should happen as you type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment