I have a bibtex file, and would like to have indentation as follows.
@book{moon70:trees,
AUTHOR = {John W. Moon},
TITLE = {Counting labelled trees},
YEAR = 1970,
SERIES = {Canadian Mathematical Monographs},
NUMBER = 1,
PUBLISHER = {Canadian Mathematical Congress}
}
I am thinking of creating a indent-bibtex-entry
command,
but I am stuck in steps 4 and 5.
- Save current position, jump to the previous ocurrence of the
regular expression
^[ \t]*@
, then to the next{
and then to the next,
. - While next nonblank is not
}
- Capture the next field with the regular expression
[ \t\n]*\([^ \t=]+\)=
. - Replace by
\n \1 =
where the number of spaces must make the total length of this expression equal to, say, 15. - Capture the entry's content (see caveats below), removing line-breaks and spaces before and after.
- Goto 2.
- Restore cursor's position.
Caveats
The content of an entry is somewhat tex-aware.
The entries are text between quotes "like this"
or between matching braces {like this}
.
However, you may have braces (as long as they're balanced)
inside, and escaped quotes as well {na\"ive {example}}
.
Simplier, but also nice
If that is too difficult, an alternative is to define a command
indent-field
, assuming that the line contains a single field.
The problem is similar to the previous step 4 (but here it is step 3).
- Save current position, jump to the beginning of the line.
- Capture the next field with the regular expression
[ \t\n]*\([^ \t=]+\)=[ \t\n*]*
. - Replace by
\n \1 =
where the number of spaces must make the total length of this expression equal to, say, 15. - Restore cursor's position.
Any suggestions? I am still working on the code for the items I "know" how to do. This is my first time with elisp.