views:

53

answers:

1

In the emacsclient documentation, an example EDITOR setting is:

EDITOR="emacsclient --alternate-editor emacs +%d %s"

How can the %d and %s be used? I understand that + starts at the specified line and the %s is the file name to edit, but what program replaces %d and %s the values?

For example, if subversion tried to kick of $EDITOR, emacs will edit 3 files: +%d, %s, and the target file. Is there any program that replaces these %d and %s with the next two arguments? Is the emacs documentation just incorrect? Why wouldn't you just set EDITOR to `emacsclient --alternate-editor emacs?

+2  A: 

The syntax mimics the one used by the printf function in C and languages inspired by it: %d is intended to be replaced by an integer in decimal notation, and %s is intended to be replaced by a string. However, I don't know of any program that will perform such a replacement on the value of $EDITOR. This may well qualify as a bug in the Emacs manual.

There are programs that interpret $EDITOR as the path to an executable file (a few don't even look up in $PATH), and others that interpret it as a shell snippet that starts the editor (allowing passing extra arguments to the executable the way you did). So it's safest to set EDITOR to just the full path to an executable, not containing special characters. Use a relay script if you want to pass options, e.g. EDITOR=~/bin/EDITOR where the contents of ~/bin/EDITOR are something like

#!/bin/sh
exec emacsclient --alternate-editor emacs
Gilles