Productivity, a year on.

Posted by Chris Ball Mon, 15 Oct 2007 19:44:00 GMT

It's been a year and a half since I wrote a blog post about productivity tools — I mentioned some of the shell and editor tools I use, and it was fun and people gave me useful comments. Here's another post, with some new lessons learned.

Emacs


python-mode flymake

Flymake is mostly the reason I'm writing this blog post. It does incremental compiling/code checking for emacs — when you make a source code change, it passes your input to an external program, and then shows (by highlighting lines in different colours) where the external program thinks that warnings or errors are.

I use it with Python, and pylint: after a code change, pylint is run on the buffer, and emacs parses the output and shows a display like the following:

This seems like a basic thing to do, but it's making me enjoy programming more than I ever have. My Python code almost always runs correctly first time now, as I wait for the pylint warnings to go away before trying it, and I get cheered up (and, frankly, shocked!) every time I write another fifty lines of code and it works straight away. I totally recommend it. The setup's documented on emacswiki.

find-tag-at-point

I often work on the kernel or Xorg, and I would be totally ridiculously lost with both if I wasn't using "tags" support in my editor. Here's how it works: you run etags over your .[ch] files (or make tags in a kernel source dir), and it generates a TAGS index. You load that in emacs with M-x visit-tags-table, and with the below keybinding, pressing F10 will take you to the original definition of whichever symbol the cursor is on, no matter where it appears in the source tree. Within a few presses of F10, you've escaped macro hell and found where the code that actually defines the function you're interested in is.

(defun find-tag-at-point ()
  "*Find tag whose name contains TAGNAME.
  Identical to `find-tag' but does not prompt for 
  tag when called interactively;  instead, uses 
  tag around or before point."
    (interactive)
      (find-tag (if current-prefix-arg
                    (find-tag-tag "Find tag: "))
                (find-tag (find-tag-default))))

(global-set-key [f10] 'find-tag-at-point)

git.el

Also, there's fairly good GIT support in emacs, which mostly consists of turning each GIT shell script into an emacs command you can run with M-x. I use this, but it's not particularly exciting.

M-x gdb

emacs22 has a new graphical GDB mode. It is awesome. Here's a screenshot from Phil Sung.

org-mode

I'm trying to get the hang of emacs org-mode, but I'm not quite there yet. I mostly want something to manage my TODOs that don't have hard deadlines and my diary/appointment entries that do. If anyone feels like bragging about their great org-mode setup and sharing code, go right ahead.

GIT


All of the hosted projects at OLPC use GIT, for better or worse. I thought it was for worse for a while, especially when GIT 1.4 came out and made me hate branches all over again, but there are a few new features that are making me like GIT more:

git rebase --interactive

Pierre Habouzit has already written plenty about this. Solves the "wait how do I revert this one commit I made twenty commits ago" problem, and some other ones too.

git stash

git stash lets you temporarily store changes away while you get your tree in a different state; examples are in the man page.

git add --interactive

"Anonymous" commented on this post:

Don't forget `git add --interactive` (in newer git). It allows you to commit only certain hunks of a patch.

Misc


iprint/i

While working on a kernel driver, I was wishing for a way to take a hex number (that represented a bitfield) and print its binary decoding without having to do so in my head. The command /usr/bin/i (available as iprint in Debian/Ubuntu) does this. For example:

pullcord:cjb~ % i 0x4F
79 0x4F 0117 0b1001111 'O'

(The order there is: decimal, hex, octal, bitstring, ASCII.)

Even though this solves my problem well, I'd still like the kernel printk() to get a formatting string for "binary string" itself. I wonder if a patch would be accepted.

rpmbuild --short-circuit

I'm used to Debian's make-kpkg, which lets you hack on a kernel source tree and then build a package out of it. rpmbuild instead wants you to supply a tarball and patches for a source tree for it to unpack, patch and build with all at once. You can get around that with the --short-circuit option, which skips steps before the one you're after. So, rpmbuild --short-circuit -bc goes through the build and install phases, skipping the prep stage.

zsh share_history

setopt share_history lets each of my shells use the same history file, and the file is updated after every command is run, so I no longer have to flick through each shell window wondering which one in particular contains the shell with a copy of the long command I ran in its history.

Tags , , ,  | 12 comments | 8 trackbacks

Productivity

Posted by Chris Ball Tue, 21 Mar 2006 23:12:00 GMT

The main purpose of this post is to show off a link I found documenting some of the under-used features of emacs — Effective Emacs. (Thanks to Edward O'Connor's blog for the link.)

I've been on an optimisation binge recently, making sure that I'm getting the best out of my editor and shell. I decided to document some of the features I'm using:

zsh:

  • Hostname completion based on the contents of your ~/.ssh/known_hosts file. This requires you to turn off HashKnownHosts (see below), and add the following to your ~/.zshrc:
       hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\*}%%,*})
       zstyle ':completion:*:hosts' hosts $hosts
  • Remote filename completion over ssh, which works wonderfully with public key auth, remote host completion, and the ssh ControlMaster tip below. This is enabled by default; an example use is below, with the bold characters written by tab presses rather than by my keyboard directly:

    % scp foo.html printf.net:public_html/index.html

  • Colour matches in grep results (in green):

    export GREP_COLOR='01;32'
    alias grep='grep --color'
    
  • pushd: Few people seem to use directory stacks in their shell. After enabling auto_pushd as below, you can quickly popd back to the last directory you were in (and popd again for the directory before that, etc), or use dirs to see the stack of past directories that you can cd to using cd ~n, where n is the number given for that directory. To enable:

    setopt auto_pushd
    
  • The <() construct lets you avoid having to use temporary files as arguments to commands, like so:

    diff -y <(wc -l 1/*) <(wc -l 2/*)
    
  • zsh's cd has a useful three-argument syntax where the third argument is treated as a replacement for the portion of the current directory given in the second argument:

    ~/dir % ls
    foo1  foo2  foo3  foo4  foo5  foo6
    ~/dir % cd foo5
    ~/dir/foo5 % cd 5 6
    ~/dir/foo6 %
    

ssh:

  • By default, modern ssh hashes the known_hosts file so that someone who hacks access to your account doesn't have a list of where they might be able to go next. This is sensible, but breaks the hostname completion above, so I turn it off in ~/.ssh/config:

    HashKnownHosts no
    
  • New (4.0+) versions of OpenSSH have support for multiplexing several shells over a single ssh connection; this means that the second time you type ssh host, the first (already established) connection is used and told to spawn a new shell, making your new shell appear immediately instead of in a few seconds. This cuts login time for a new shell from 1.891s to 0.267s on my work machine. It also speeds up anything that uses a single ssh session per file such as bash/zsh remote filename completion (see above), or rsync/darcs/svn/etc over ssh. To enable, in ~/.ssh/config:

    ControlMaster auto
    ControlPath /tmp/%r@%h:%p
    

I have a few annoyances with ControlMaster — let me know if you know of a clean way to have the first connection for each host be created as a background process without a tty so that it can't easily be killed by accident.

emacs:

  • I use tramp to edit files remotely — this has the same host and filename completion as zsh, and is insanely useful for me; some of the machines I use at work are an ssh tunnel away (meaning high latency) and don't have emacs or vim installed (only vi, meaning no syntax highlighting). Setting up tramp is easy:

    (require 'tramp)
    C-x C-f /somehost:some/dir/and/file RET
    
  • I use gnus (see also my.gnus.org) for mail, news and RSS reading, and think it's the best mailer ever.

  • I use ERC as an IRC client.


My dotfiles are available online.

Tags  | 7 comments | 5 trackbacks