help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: renumbering numeric comments


From: Steven Arntson
Subject: Re: renumbering numeric comments
Date: Tue, 28 Oct 2014 10:11:43 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Yuri Khan <yuri.v.khan@gmail.com> writes:

> 1. Select the part of document you want to renumber in, or go the the
> beginning of the buffer to renumber throughout the whole document.
> 2. Hit C-M-% (for “query-replace-regexp”).
> 3. Compose a regular expression that matches the parts of text you
> want to replace, with some context. I don’t know Lilypond and assume
> that measures end with a vertical bar and by convention it’s the last
> significant character on the line, followed by a single space,
> followed by a percent sign, then the letter m, then a sequence of
> digits until the end of line. A new measure will end at the vertical
> bar, with the space and comment omitted. So the regexp is: “|\(
> %m[0-9]+\)?$”. Enter this as the replace regexp.
> 4. In the replacement string, use the \# marker where you want a
> sequential number inserted: “| %m\#”
>
> This is almost what you want but numbers starting with 0. If you want
> 1-based numbering, you’ll need to surround the \# marker with an
> expression that adds 1: “| %m\,(+ 1 \#)”
>
> The part after “\,” can be any Emacs Lisp expression. The one above
> just happens to add (+) one (1) to the number of replacements done
> (\#) and can be abbreviated as “(1+ \#)”. (If you wanted to renumber
> starting with 200, you would write “(+ 200 \#)”, and for numbering
> starting with 301 and using only odd numbers, “(+ 301 (* 2 \#))”.)
>
> Final recipe:
>
> query-replace-regexp
> |\( %m[0-9]+\)?$
> | %m\,(1+ \#)

Thank you so much for this. I have only the barest conception of how
regexps work, but this seems like as excellent an introduction as I
could have hoped for!

-steven




reply via email to

[Prev in Thread] Current Thread [Next in Thread]