unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Yuri Khan <yuri.v.khan@gmail.com>
To: Steven Arntson <steven@stevenarntson.com>
Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Re: renumbering numeric comments
Date: Tue, 28 Oct 2014 10:53:35 +0700	[thread overview]
Message-ID: <CAP_d_8VAm8J+dV=bkxK_2ZT3+099tGQFhSgxBoj+mzdf15p7Fg@mail.gmail.com> (raw)
In-Reply-To: <878uk17y4k.fsf@stevenarntson.com>

On Tue, Oct 28, 2014 at 7:59 AM, Steven Arntson
<steven@stevenarntson.com> wrote:

> In Lilypond, measure numbers are usually (so far in my experience)
> entered as comments at the end of a line in the form `%m__':
>
> These "%m_" numbers are very useful in debugging when the "code" is
> compiled. However, in the above case I later inserted two new measures:
>
>          \tempo 4=100
>          e4 d e8 f | %m1
>          \tempo 4=130
> ----->   g8 f e d e f |
> ----->   e d c b c d |
>          <c a>2. | %m2
>          <d e,>2 ~ <d e,>8 e | %m3
>          ...
>
> Renumbering everything by hand is a lot of work, because the piece is
> many measures long.

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+ \#)



  reply	other threads:[~2014-10-28  3:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-28  1:59 renumbering numeric comments Steven Arntson
2014-10-28  3:53 ` Yuri Khan [this message]
2014-10-28 17:11   ` Steven Arntson
     [not found] <mailman.12210.1414461603.1147.help-gnu-emacs@gnu.org>
2014-10-28  8:12 ` Pascal J. Bourguignon
2014-10-28 17:13   ` Steven Arntson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAP_d_8VAm8J+dV=bkxK_2ZT3+099tGQFhSgxBoj+mzdf15p7Fg@mail.gmail.com' \
    --to=yuri.v.khan@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=steven@stevenarntson.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).