Posts tagged ‘emacs’

Getting emacs to behave more like vim

Although the viper mode does not provide a lot of vim’s motions e.g diw and similar. The vimpulse plugin ( does extends viper to provide several of these.

Supported commands in include

diw, ciw, yiw, di”, da”, ci”, ca”, yi”, ya”,
di(, da(, ci(, ca(, yi(, ya(,
di’, da’, ci’, ca’, yi’, ya’,

(take that google)

I find these vim text objects fairly useful.


November 22, 2009 at 6:13 pm Leave a comment

Making viper mode in emacs use C-[ for escape rather than escape

Pressing the actual escape button is far too much effort, so my brain seems to have decided to learn to us C-[ in vim in preference to escape.

To get this working in viper add the following line:

(setq viper-ESC-key “\C-[“)

To your emacs init file before you have required viper. Note that this variable cannot be set in your .viper file or changed after you have loaded viper, or rather it can but it has no effect.

November 18, 2009 at 2:59 pm 1 comment

viper-want-ctl-h broken when set in .viper

This happens in the emacs viper vim emulation mode shipped with ubuntu 9.10 in November 2009.

There is a work around by setting viper-want-ctl-help-h in your emacs init file after viper has been imported.

This bug occurs because viper-set-expert-level which is called as part of loading viper tramples on various viper settings. However it does need to set those settings which have not been overwritten in your .viper file.

As a workaround in viper one could do one of the following:

i) Make viper-set-expert-level only set those settings which are not already set if dont-change… is set to true
ii) Load the .viper file twice once after calling set-expert-level (hackish but it works)
iii) Do something crazy so as to have shadowed variables, where the set-expert-level only sets the value that is shadowed.

However, I am not going to change any of this at the moment.

November 18, 2009 at 1:15 pm Leave a comment

Using flymake in emacs to validate xml as you type


  • Seeing mistakes earlier can make them easier to correct
  • Many programs will simply die with little logging if given broken xml files
  • Remembering to run a validator takes effort


  • Install rxp (this is available under cygwin on windows, and using apt under most linuxes)
  • Create this perl scripts, make it executable and place it on your path [1] call it xmlparse
    open(HA, "rxp $ARGV[0] 2>&1|");
    while (){
        /^Error/ && chomp;
  • Add the following code to your .emacs file
  • (defun flymake-xml-init ()
      (let* ((temp-file (flymake-init-create-temp-buffer-copy
    	 (local-file (file-relative-name
    		      (file-name-directory buffer-file-name))))
        (list "xmlparse" (list local-file))))
    (add-to-list 'flymake-allowed-file-name-masks
    	     '("\\.xml\\'" flymake-xml-init)) 
    (add-to-list 'flymake-err-line-patterns
    	     '("\\(.*\\) at line \\([0-9]+\\) char \\([0-9]+\\) of file://\\(.*\\)"
    	      4 2 3 1))
  • Also, ensure that you have the following command somewhere in your .emacs file
     (add-hook 'find-file-hook 'flymake-find-file-hook)

This should then work. You might like to change the face used to show errors with M-x customize-face flymake-errline. Hovering over an error will show you a description of the error


The behavior for unclosed tags is not what I want. The error is reported where the parent tag closes – which can be quite some distance from the opening tag. However at least the message is informative.

There is an existing emacs host, nxhtml, which has some of these things built in together with other editing tools – but it looks a little monolithic.

[1] This ensures that each error is written on only one line. Flymake appears to only be able deal with output in this form.

February 23, 2009 at 11:44 pm Leave a comment

Emacs version control

I discovered how emacs version control worked today… and was duelly impressed. (Having previously thought that it didn’t work at all well – guess this means I should learn to read manuals).[1]

Regardless, emacs comes with a unified version control front-end which supports back-ends for most version control systems : I believe this includes git, svn and bzr).  This can do most of the things that one wants to do.

One of my only irritations is that one can’t revert individual lines of the diffs that it shows.

Summary for the impatient

Emacs version control is wonderful, I’m dim for not realising this earlier. To make it work do the following:

C-x v = in a file for a diff

To submit:

C-x v d <TOP LEVEL DIR> to get a list of all modifed files, then mark everything (hold down m) and press C-x v v.

If you want to see diffs for individual files press v=.

[1] As an aside, one of the reasons I hadn’t found this out earlier was because I was under the false impression the mode help (C-h m) would show all relevant keybindings… I’m not quite sure why, C-h b is (strangely!) better for this purpose.

July 30, 2008 at 10:33 pm 3 comments

Searching multiple buffers emacs

FSF has two magic functions for searching multiple buffers:

multi-occur: – Search specified buffers to a string

multi-occur-in-matching-buffers: Allows one to search a subset of one’s open buffers or files specified as a regexp:

Given .* as its first argument, this allows one to search all currently open files for a given regular expression.

Given a prefix argument and .* as its first argument, this allows one to search all currently open buffers for a regular expression.

Also (occur-1 regexp nil buffer-list) can be usefully adapted to search for other things.

July 27, 2008 at 6:43 pm 5 comments

Emacs buttons – an introduction for the somewhat impatient

Working out how to make buttons work in emacs took rather too much effort – I suspect I was just being slow. However, I thought I’d write a tiny how-to for anyone else who tries to do this:

Below is a prototypical emacs lisp function call to create a new button in your text between characters beg and end is:

(defun f (button)
    (call-interactively 'find-file))

(make-button beg end 'action 'f 'follow-link t)

Note the following:

  • The properties are defined via a variable number of arguments . It does does not take a list.
  • Removing the follow-link property would cause left mouse-clicks on the link to have no effects
  • f must take a single argument otherwise this will fail.

For more on emacs buttons see:

If you want to make your button more anonymous (so that changing the function value associated with f has no deleterious results) you can use the following

(make-button beg end 'action
    (lambda (button) (call-interactively 'find-file))
    'follow-link t)

May 14, 2008 at 7:08 pm 3 comments

Older Posts

June 2019
« Nov