* renumbering numeric comments
@ 2014-10-28 1:59 Steven Arntson
2014-10-28 3:53 ` Yuri Khan
0 siblings, 1 reply; 5+ messages in thread
From: Steven Arntson @ 2014-10-28 1:59 UTC (permalink / raw)
To: help-gnu-emacs
Greetings! I'm very curious what more knowledgeable souls would do in
the following situation. I'm writing music using emacs' lilypond
mode. In Lilypond, measure numbers are usually (so far in my experience)
entered as comments at the end of a line in the form `%m__':
\tempo 4=100
e4 d e8 f | %m1
\tempo 4=130
<c a>2. | %m2
<d e,>2 ~ <d e,>8 e | %m3
...
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. I have limited technical expertise, but would love
ideas about better methods than "by hand!" Thank you!
Steven Arntson
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: renumbering numeric comments
2014-10-28 1:59 renumbering numeric comments Steven Arntson
@ 2014-10-28 3:53 ` Yuri Khan
2014-10-28 17:11 ` Steven Arntson
0 siblings, 1 reply; 5+ messages in thread
From: Yuri Khan @ 2014-10-28 3:53 UTC (permalink / raw)
To: Steven Arntson; +Cc: help-gnu-emacs@gnu.org
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+ \#)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: renumbering numeric comments
[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
0 siblings, 1 reply; 5+ messages in thread
From: Pascal J. Bourguignon @ 2014-10-28 8:12 UTC (permalink / raw)
To: help-gnu-emacs
Steven Arntson <steven@stevenarntson.com> writes:
> Greetings! I'm very curious what more knowledgeable souls would do in
> the following situation. I'm writing music using emacs' lilypond
> mode. In Lilypond, measure numbers are usually (so far in my experience)
> entered as comments at the end of a line in the form `%m__':
>
> \tempo 4=100
> e4 d e8 f | %m1
> \tempo 4=130
> <c a>2. | %m2
> <d e,>2 ~ <d e,>8 e | %m3
> ...
>
> 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. I have limited technical expertise, but would love
> ideas about better methods than "by hand!" Thank you!
Write yourself a numbering/renumbering command.
For an example, have a look at:
https://gitorious.org/nasium-lse/nasium-lse/source/028c064543abf8ad4043897d8b9029beab18db15:lse-mode.el#L321
In your case, it is even easier, because you don't have GOTOs.
--
__Pascal Bourguignon__ http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: renumbering numeric comments
2014-10-28 3:53 ` Yuri Khan
@ 2014-10-28 17:11 ` Steven Arntson
0 siblings, 0 replies; 5+ messages in thread
From: Steven Arntson @ 2014-10-28 17:11 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: renumbering numeric comments
2014-10-28 8:12 ` Pascal J. Bourguignon
@ 2014-10-28 17:13 ` Steven Arntson
0 siblings, 0 replies; 5+ messages in thread
From: Steven Arntson @ 2014-10-28 17:13 UTC (permalink / raw)
To: help-gnu-emacs
"Pascal J. Bourguignon" <pjb@informatimago.com> writes:
> Write yourself a numbering/renumbering command.
>
> For an example, have a look at:
>
> https://gitorious.org/nasium-lse/nasium-lse/source/028c064543abf8ad4043897d8b9029beab18db15:lse-mode.el#L321
>
> In your case, it is even easier, because you don't have GOTOs.
I've just this week started going through emacs' on-board Lisp
tutorial. This seems like a perfect project! I'll start working on it.
Best! steven
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-10-28 17:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-28 1:59 renumbering numeric comments Steven Arntson
2014-10-28 3:53 ` Yuri Khan
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
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.