Tmpq5a39env Using Emacs As A Python Ide
Tmpq5a39env Using Emacs As A Python Ide
Drew Werner
May 5, 2014
Roadmap
I Motivating demo
I Installation guide
I Customization tips
Try it out: github.com/wernerandrew/jedi-starter
An Emacs IDE
I You’ll need:
I Some unix-y CLI environment (OS X, Linux)
I The jedi-starter repo (on Github)
I Vagrant (tested with 1.4.3)
I VirtualBox (tested with 4.2.16)
I After cloning, from a terminal:
I cd jedi-starter
I vagrant up
I vagrant ssh
I Initialization code is in jedi-starter.el
Structure of jedi-starter.el
(add-hook
’after-init-hook
’(lambda ()
;; Package specific initialization goes here
))
Installation
I You’ll need:
I projectile
I auto-complete
I epc
I jedi
I Manual installation is possible, but annoying
I package.el is much better
Package Management
(require ’package)
(package-initialize)
(add-to-list
’package-archives
’("melpa" . "http://melpa.milkbox.net/packages/"))
(let ((need-to-install
(uninstalled-packages local-packages)))
(when need-to-install
(progn
(package-refresh-contents)
(dolist (p need-to-install)
(package-install p)))))
Working with Projectile
(require ’projectile)
(projectile-global-mode)
;; Emacs 23 hack
(when (not (boundp ’remote-file-name-inhibit-cache))
(setq remote-file-name-inhibit-cache t))
Package Config
(require ’auto-complete-config)
(ac-config-default)
comple;ons,%
naviga;on%info,%
func;on%info%
via%EPC%
jediepcserver.py% jedi.el%
imports% typing,%commands,%etc.%
jedi%Library% Your%Emacs%Session%
Jedi Dependencies
(require ’jedi)
;; Hook up to autocomplete
(add-to-list ’ac-sources ’ac-source-jedi-direct)
;; Enable for python-mode
(add-hook ’python-mode-hook ’jedi:setup)
Jedi Server Options
(defvar jedi-config:use-system-python t)
(defun jedi-config:set-python-executable ()
(set-exec-path-from-shell-PATH) ;; for OS X
(make-local-variable ’jedi:server-command)
(set ’jedi:server-command
(list (executable-find "python")
(cadr default-jedi-server-command))))
Putting everything together
(add-hook ’python-mode-hook
’jedi-config:setup-server-args)
(when jedi-config:use-system-python
(add-hook ’python-mode-hook
’jedi-config:set-python-executable))
Some useful commands
C-c , M-,
jedi:goto-definition-pop-marker
Move to previous location of point
C-c ? M-?
jedi:show-doc
Show docstring for symbol at point in
new window
None M-/
jedi:get-in-function-call
Pop up signature for function at point
Local Jedi keybindings
(defun jedi-config:setup-keys ()
(local-set-key (kbd "M-.") ’jedi:goto-definition)
(local-set-key (kbd "M-,") ’jedi:goto-definition-pop-marker)
(local-set-key (kbd "M-?") ’jedi:show-doc)
(local-set-key (kbd "M-/") ’jedi:get-in-function-call))
Happy editing!
github.com/wernerdrew/jedi-starter
@wernerdrew