There’s an entire world of emacs out there that I have yet to explore. Before leaving for Amhurst I took the first step into that world and oh is it wonderful. I’m going to run through a few run of the mill additions to our ~/.emacs which are fairly essential.

(setq backup-by-copying t)

allow for editing files in Transmit or other FTP programs

(add-to-list 'auto-mode-alist '("\\.h\\'" . c-mode))
(add-to-list 'auto-mode-alist '("\\.pyx\\'" . python-mode))
(add-to-list 'auto-mode-alist '("\\.sm\\'" . fortran-mode))

add additional unrecognized file types that will allow for syntax highlighting

(unless window-system
  (xterm-mouse-mode 1)
  (global-set-key [mouse-4] '(lambda ()
                               (interactive)
                               (scroll-down 1)))
  (global-set-key [mouse-5] '(lambda ()
                               (interactive)
                               (scroll-up 1))))

enable mouse interaction in terminal mode

(require 'package)
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
(package-initialize)

Here we add a package repository. This allows for a package management system very similar to Debian’s apt-get (only for Emacs v24+). We can access these packages via open Emacs after adding this line, then hitting M-x (M stands for meta, default key is ESC), and typing ‘package-list-packages’.

Search the list for ‘jedi’, put your cursor next to it and hit ‘i’ for install, you should see a big I come up next to it. Now hit ‘x’ to execute and it will ask if you would like to install jedi - the obvious answer is ‘yes’. Unfortunately we’re not finished, we have to add some commands to our ~/.emacs and setup a python virtual environment:

(autoload 'jedi:setup "jedi" nil t)
(add-hook 'python-mode-hook 'auto-complete-mode)
(add-hook 'python-mode-hook 'jedi:setup)
(setq jedi:setup-keys t)
(setq jedi:complete-on-dot t)

Now we can proceed to the virtual environment, which can be a bit tricky. Navigate to your jedi.el directory, which is most likely located in ~/.emacs.d/elpa/jedi-xxx. In this directory you will find a Makefile. If you are using any python distribution other than CANOPY, then you can probably just run ‘make requirements’ and be set to go. If you are using CANOPY however, a small change must be made to the makefile since virtualenv is not compatible with 64bit CANOPY on osx. Edit the makefile and change the following line:

virtualenv --python=$(PYTHON) --> venv -s python_virtual

Once this is done run ‘make requirements’ and it should download and compile everything else you need for jedi. Open up a new python document and enjoy the auto complete! ref

Next we can add a syntax highlighter called Flycheck. To install in emacs we M-x package-list-packages and search for flycheck, then follow a similar installation procedure above for the initial install of jedi. Next install pylint and pyflakes to your python install via pip (really not sure which one does the trick, but I believe it is pylint):

pip install pylint
pip install pyflakes

Lastly add this line to your ~/.emacs:

(add-hook 'after-init-hook #'global-flycheck-mode)

Finally we can install autopair/smartpar, which automatically closes parentheses, brackets, etc. Follow the routine above for adding packages, and install ‘autopair’. Then add this to your ~/.emacs and you should be set to go:

(require 'autopair)
(autopair-global-mode)
OR
(smartparens-global-mode t)

refs: 1 2 3 4

EDIT 11/7/13:
I forgot to mention color themes! One of the default Emacs24 themes that is pretty decent is ‘deeper-blue’ which can be enabled by modifying your custom-set-variables by:
(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(custom-enabled-themes (quote (deeper-blue)))
 '(inhibit-startup-screen t))

the ‘(custom-enabled-themes (quote (deeper-blue))) does it. BUT, I’m starting to prefer another theme called solarized. The installation is as simple as adding it via marmalade - ‘M-x package-list-packages’, then search for ‘color-theme-solarized’ and install it. Then in your ~/.emacs add the line:

(load-theme 'solarized-[light|dark] t)

and you should be set to go.


Comments

comments powered by Disqus