Friday, 29 November 2013

Ready for Python development with Emacs in just 60 seconds

This post demonstrates how you can configure a very decent environment for Python development with Emacs, in just 60 seconds.

A dream is now true: The first time you start Emacs, it automagically downloads and configures all plugins you need.  Emacs is then just ready to work and you can start typing code immediately. 

For the impatient


1. Save configuration files you eventually have!

  $ cd $HOME 
  $ tar cpf dot-emacs.ORIGINAL.tar.gz .emacs .emacs.d
  $ mv .emacs   dot-emacs.ORIGINAL
  $ mv .emacs.d dot-emacs.d.ORIGINAL

2. Remove any Emacs configuration files you eventually have.

  $ rm -r -f .emacs .emacs.d

3. Install Python libraries

This should be done preferably inside a virtual environment.

   $ workon py276 #-- py276 is a virtualenv I'm using
   $ pip install epc
   $ pip install jedi
   $ pip install elpy

4. Download my .emacs file onto your home folder.

  $ cd $HOME 
  $ wget https://raw.github.com/frgomes/dot-emacs/master/dot-emacs.el
  $ ln -s dot-emacs.el .emacs

4. Start emacs. It will configure itself when it first run!

  $ emacs test.py

Features in a nutshell

  • python-mode, cython-mode and nxml-mode: ditto
  • jedi: provides auto completion
  • flymake: highlight syntax errors as you type

Contribute


Please let me know if you find issues. In particular, I don't have Windoze boxes, so the automagic configuration thing was never tested on it.

This script was designed to run on Emacs 23 onwards but only tested on Emacs 24. Please let me know if you find issues.

Please point out typos and bad English.

You can also suggest plugins or tools I missed. This is very much appreciated and may benefit my workflow as well :)
So... thanks a lot for your suggestion!

Known Issues

If you are behind firewall, you may (or may not) face download problems which involves HTTPS protocol. As far as I know, this is a bug on a third party library which Emacs depends on.

If Emacs opens the message window and vomits hundreds of errors coming from file cython-mode.el ... that's because your proxy server refused the https request and returned an error message in HTML. It's easy to fix this issue:

  $ cd $HOME/.emacs.d/plugins
  $ rm cython-mode.el
  $ wget https://raw.github.com/cython/cython/master/Tools/cython-mode.el

Chances are that now cython-mode.el is OK, since wget performs the request the way it needs to be in order to work properly.


That's it: ready for coding in 60 seconds :)

Cheers

-- Richard Gomes

Versioning your /etc under Bazaar in Debian Wheezy

Suppose you've installed some packages on your Linux box, made some configurations and messed your system. Pretty bad! You would like to revert all changes to a previous working state, isn't it? This post explains how you can employ Bazaar in Debian boxes to do that.

The idea is pretty simple: put your /etc into some sort of source control system, like git, bzr, hg or darcs. There's a tool which does just that: etckeeper.

We will also create two other repositories, for high availability purposes: one in the same computer and another remotely.

Let's start: install etckeeper. You will see that /etc/.git is created, because git is the default choice for etckeeper.

Install etckeeper

    $ apt-get etckeeper -y
    $ ls -ald /etc/.git

I prefer Bazaar. So, let's get rid of this .git repository:

    $ etckeeper uninit
    $ ls -ald /etc/.git

Using bzr instead of git

Now it's time to reconfigure etckeeper so that it will user Bazaar instead. Simply edit /etc/etckeeper/etckeeper.conf in order to look like below:

    $ head -5 /etc/etckeeper/etckeeper.conf
    # The VCS to use.
    #VCS="hg"
    #VCS="git"
    VCS="bzr"
    #VCS="darcs"

Let's now install Bazaar and create the repository again, this time using Bazaar.

    $ apt-get install bzr -y
    $ etckeepet init
    $ ls -ald /etc/.bzr

Your first commit

Review what was done and perform your first commit.

    $ cd /etc
    $ bzr status | less
    $ bzr commit -m 'first commit'
    $ bzr status

Create a second repository on a separate hard drive

It's now time to create a copy on the same computer, preferably on a separate hard drive:

    $ cd /srv
    $ bzr init --no-tree etckeeper
    $ cd /etc
    $ bzr config push_location=/srv/etckeeper
    $ bzr push

Create a third repository on a server box

It's also a good idea to create a remote repository, like the example below:

    $ ssh myself@server
    $ COMPUTER=penguim
    $ mkdir -p /srv/bzr/etckeeper
    $ bzr init --no-tree /srv/bzr/etckeeper/${COMPUTER}
    $ exit


Back to your local computer, push a copy from your second repository (the one on your second hard drive) onto the remote server:

    $ cd /srv/etckeeper
    $ COMPUTER=$( hostname )
    $ bzr config push_location=bzr+ssh://myself@server/srv/bzr/etckeeper/${COMPUTER}
    $ bzr push


That's it :)

-- Richard Gomes