From e25565e23b6e7a219c594d359495817d7076eff5 Mon Sep 17 00:00:00 2001
From: Julien Rioux <jrioux@physics.utoronto.ca>
Date: Thu, 12 Jan 2012 12:22:32 -0500
Subject: [PATCH] Add a node prefix to snippets, preventing duplicate node
 errors.

---
 Documentation/snippets.tely                            |  9 +++++++--
 Documentation/snippets/ancient-notation-intro.itely    |  1 +
 Documentation/snippets/chords-intro.itely              |  1 +
 .../snippets/contexts-and-engravers-intro.itely        |  1 +
 .../snippets/editorial-annotations-intro.itely         |  1 +
 Documentation/snippets/expressive-marks-intro.itely    |  1 +
 Documentation/snippets/fretted-strings-intro.itely     |  1 +
 Documentation/snippets/keyboards-intro.itely           |  1 +
 Documentation/snippets/midi-intro.itely                |  1 +
 Documentation/snippets/paper-and-layout-intro.itely    |  1 +
 Documentation/snippets/percussion-intro.itely          |  1 +
 Documentation/snippets/pitches-intro.itely             |  1 +
 Documentation/snippets/repeats-intro.itely             |  1 +
 Documentation/snippets/rhythms-intro.itely             |  1 +
 Documentation/snippets/simultaneous-notes-intro.itely  |  1 +
 Documentation/snippets/spacing-intro.itely             |  1 +
 Documentation/snippets/staff-notation-intro.itely      |  1 +
 Documentation/snippets/template-intro.itely            |  1 +
 Documentation/snippets/text-intro.itely                |  1 +
 Documentation/snippets/titles-intro.itely              |  1 +
 .../snippets/tweaks-and-overrides-intro.itely          |  1 +
 Documentation/snippets/unfretted-strings-intro.itely   |  1 +
 Documentation/snippets/vocal-music-intro.itely         |  1 +
 Documentation/snippets/winds-intro.itely               |  1 +
 Documentation/snippets/world-music-intro.itely         |  1 +
 scripts/build/extract_texi_filenames.py                | 10 +++++++++-
 26 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/Documentation/snippets.tely b/Documentation/snippets.tely
index b44f4c5a90..2d30fa92ae 100644
--- a/Documentation/snippets.tely
+++ b/Documentation/snippets.tely
@@ -41,15 +41,20 @@ by the authors.
 @include macros.itexi
 
 @ifnothtml
+@macro nodeprefix{PRE}
+@end macro
 @macro lydoctitle{TEXT}
 @unnumberedsec \TEXT\
 @end macro
 @end ifnothtml
 
 @ifhtml
+@macro nodeprefix{PRE}
+@unmacro lydoctitle
 @macro lydoctitle{TEXT}
-@node \TEXT\
-@unnumberedsec \TEXT\
+@node \PRE\: \\TEXT\\
+@unnumberedsec \\TEXT\\
+@end macro
 @end macro
 @end ifhtml
 
diff --git a/Documentation/snippets/ancient-notation-intro.itely b/Documentation/snippets/ancient-notation-intro.itely
index a6de3f24c6..30b13b9828 100644
--- a/Documentation/snippets/ancient-notation-intro.itely
+++ b/Documentation/snippets/ancient-notation-intro.itely
@@ -1,5 +1,6 @@
 @node Ancient notation
 @unnumbered Ancient notation
+@nodeprefix Ancient notation
 
 @ruser{Ancient notation}
 
diff --git a/Documentation/snippets/chords-intro.itely b/Documentation/snippets/chords-intro.itely
index 83aeaaaf25..1427e49a5b 100644
--- a/Documentation/snippets/chords-intro.itely
+++ b/Documentation/snippets/chords-intro.itely
@@ -1,5 +1,6 @@
 @node Chords
 @unnumbered Chords
+@nodeprefix Chords
 
 @ruser{Chord notation}
 
diff --git a/Documentation/snippets/contexts-and-engravers-intro.itely b/Documentation/snippets/contexts-and-engravers-intro.itely
index ef796b0592..e4e11670cc 100644
--- a/Documentation/snippets/contexts-and-engravers-intro.itely
+++ b/Documentation/snippets/contexts-and-engravers-intro.itely
@@ -1,5 +1,6 @@
 @node Contexts and engravers
 @unnumbered Contexts and engravers
+@nodeprefix Contexts and engravers
 
 @c FIXME make xref more precise when the chapter has been
 @c revised in GDP
diff --git a/Documentation/snippets/editorial-annotations-intro.itely b/Documentation/snippets/editorial-annotations-intro.itely
index 0dd710632a..793c8570b1 100644
--- a/Documentation/snippets/editorial-annotations-intro.itely
+++ b/Documentation/snippets/editorial-annotations-intro.itely
@@ -1,5 +1,6 @@
 @node Editorial annotations
 @unnumbered Editorial annotations
+@nodeprefix Editorial annotations
 
 @ruser{Editorial annotations}
 
diff --git a/Documentation/snippets/expressive-marks-intro.itely b/Documentation/snippets/expressive-marks-intro.itely
index c869a5347c..60598e5420 100644
--- a/Documentation/snippets/expressive-marks-intro.itely
+++ b/Documentation/snippets/expressive-marks-intro.itely
@@ -1,5 +1,6 @@
 @node Expressive marks
 @unnumbered Expressive marks
+@nodeprefix Expressive marks
 
 @ruser{Expressive marks}
 
diff --git a/Documentation/snippets/fretted-strings-intro.itely b/Documentation/snippets/fretted-strings-intro.itely
index 48a1fea65c..308e4694bd 100644
--- a/Documentation/snippets/fretted-strings-intro.itely
+++ b/Documentation/snippets/fretted-strings-intro.itely
@@ -1,5 +1,6 @@
 @node Fretted strings
 @unnumbered Fretted strings
+@nodeprefix Fretted strings
 
 @ruser{Fretted string instruments}
 
diff --git a/Documentation/snippets/keyboards-intro.itely b/Documentation/snippets/keyboards-intro.itely
index 3fd9b07b27..21675bec14 100644
--- a/Documentation/snippets/keyboards-intro.itely
+++ b/Documentation/snippets/keyboards-intro.itely
@@ -1,5 +1,6 @@
 @node Keyboards
 @unnumbered Keyboards
+@nodeprefix Keyboards
 
 @ruser{Keyboard and other multi-staff instruments}
 
diff --git a/Documentation/snippets/midi-intro.itely b/Documentation/snippets/midi-intro.itely
index cfa76077b8..3302e03eab 100644
--- a/Documentation/snippets/midi-intro.itely
+++ b/Documentation/snippets/midi-intro.itely
@@ -1,5 +1,6 @@
 @node MIDI
 @unnumbered MIDI
+@nodeprefix MIDI
 
 @ruser{MIDI output}
 
diff --git a/Documentation/snippets/paper-and-layout-intro.itely b/Documentation/snippets/paper-and-layout-intro.itely
index 5b654b797f..f227ffe80d 100644
--- a/Documentation/snippets/paper-and-layout-intro.itely
+++ b/Documentation/snippets/paper-and-layout-intro.itely
@@ -1,5 +1,6 @@
 @node Paper and layout
 @unnumbered Paper and layout
+@nodeprefix Paper and layout
 
 @c FIXME not precise enough reference?
 @ruser{Spacing issues}
diff --git a/Documentation/snippets/percussion-intro.itely b/Documentation/snippets/percussion-intro.itely
index 68369ab077..01a3cb42c5 100644
--- a/Documentation/snippets/percussion-intro.itely
+++ b/Documentation/snippets/percussion-intro.itely
@@ -1,5 +1,6 @@
 @node Percussion
 @unnumbered Percussion
+@nodeprefix Percussion
 
 @ruser{Percussion}
 
diff --git a/Documentation/snippets/pitches-intro.itely b/Documentation/snippets/pitches-intro.itely
index 7ca94ff7a2..6141af9afc 100644
--- a/Documentation/snippets/pitches-intro.itely
+++ b/Documentation/snippets/pitches-intro.itely
@@ -1,5 +1,6 @@
 @node Pitches
 @unnumbered Pitches
+@nodeprefix Pitches
 
 @ruser{Pitches}
 
diff --git a/Documentation/snippets/repeats-intro.itely b/Documentation/snippets/repeats-intro.itely
index 896f8f8e4e..27556b74a8 100644
--- a/Documentation/snippets/repeats-intro.itely
+++ b/Documentation/snippets/repeats-intro.itely
@@ -1,5 +1,6 @@
 @node Repeats
 @unnumbered Repeats
+@nodeprefix Repeats
 
 @ruser{Repeats}
 
diff --git a/Documentation/snippets/rhythms-intro.itely b/Documentation/snippets/rhythms-intro.itely
index dede3bf13e..ec7b2a923e 100644
--- a/Documentation/snippets/rhythms-intro.itely
+++ b/Documentation/snippets/rhythms-intro.itely
@@ -1,5 +1,6 @@
 @node Rhythms
 @unnumbered Rhythms
+@nodeprefix Rhythms
 
 @ruser{Rhythms}
 
diff --git a/Documentation/snippets/simultaneous-notes-intro.itely b/Documentation/snippets/simultaneous-notes-intro.itely
index 9a4612c2ea..8a2d2a275a 100644
--- a/Documentation/snippets/simultaneous-notes-intro.itely
+++ b/Documentation/snippets/simultaneous-notes-intro.itely
@@ -1,5 +1,6 @@
 @node Simultaneous notes
 @unnumbered Simultaneous notes
+@nodeprefix Simultaneous notes
 
 @ruser{Simultaneous notes}
 
diff --git a/Documentation/snippets/spacing-intro.itely b/Documentation/snippets/spacing-intro.itely
index c19a14091c..b29c9fcb59 100644
--- a/Documentation/snippets/spacing-intro.itely
+++ b/Documentation/snippets/spacing-intro.itely
@@ -1,5 +1,6 @@
 @node Spacing
 @unnumbered Spacing
+@nodeprefix Spacing
 
 @ruser{Spacing issues}
 
diff --git a/Documentation/snippets/staff-notation-intro.itely b/Documentation/snippets/staff-notation-intro.itely
index b78176376a..e71bb4d78f 100644
--- a/Documentation/snippets/staff-notation-intro.itely
+++ b/Documentation/snippets/staff-notation-intro.itely
@@ -1,5 +1,6 @@
 @node Staff notation
 @unnumbered Staff notation
+@nodeprefix Staff notation
 
 @ruser{Staff notation}
 
diff --git a/Documentation/snippets/template-intro.itely b/Documentation/snippets/template-intro.itely
index 22c9952e84..1521e0cd34 100644
--- a/Documentation/snippets/template-intro.itely
+++ b/Documentation/snippets/template-intro.itely
@@ -1,5 +1,6 @@
 @node Templates
 @unnumbered Templates
+@nodeprefix Templates
 
 @lysnippets
 
diff --git a/Documentation/snippets/text-intro.itely b/Documentation/snippets/text-intro.itely
index eb71a4598e..a3c95a403a 100644
--- a/Documentation/snippets/text-intro.itely
+++ b/Documentation/snippets/text-intro.itely
@@ -1,5 +1,6 @@
 @node Text
 @unnumbered Text
+@nodeprefix Text
 
 @ruser{Text}
 
diff --git a/Documentation/snippets/titles-intro.itely b/Documentation/snippets/titles-intro.itely
index 1d4c288f93..9a5f466c75 100644
--- a/Documentation/snippets/titles-intro.itely
+++ b/Documentation/snippets/titles-intro.itely
@@ -1,5 +1,6 @@
 @node Titles
 @unnumbered Titles
+@nodeprefix Titles
 
 @ruser{Titles and headers}
 
diff --git a/Documentation/snippets/tweaks-and-overrides-intro.itely b/Documentation/snippets/tweaks-and-overrides-intro.itely
index d5308b5bf8..7721859f1e 100644
--- a/Documentation/snippets/tweaks-and-overrides-intro.itely
+++ b/Documentation/snippets/tweaks-and-overrides-intro.itely
@@ -1,5 +1,6 @@
 @node Tweaks and overrides
 @unnumbered Tweaks and overrides
+@nodeprefix Tweaks and overrides
 
 @c FIXME make xref more precise when the chapter has been
 @c revised in GDP
diff --git a/Documentation/snippets/unfretted-strings-intro.itely b/Documentation/snippets/unfretted-strings-intro.itely
index 4770fa7bec..959b852013 100644
--- a/Documentation/snippets/unfretted-strings-intro.itely
+++ b/Documentation/snippets/unfretted-strings-intro.itely
@@ -1,5 +1,6 @@
 @node Unfretted strings
 @unnumbered Unfretted strings
+@nodeprefix Unfretted strings
 
 @ruser{Unfretted string instruments}
 
diff --git a/Documentation/snippets/vocal-music-intro.itely b/Documentation/snippets/vocal-music-intro.itely
index fd192ae925..26326831de 100644
--- a/Documentation/snippets/vocal-music-intro.itely
+++ b/Documentation/snippets/vocal-music-intro.itely
@@ -1,5 +1,6 @@
 @node Vocal music
 @unnumbered Vocal music
+@nodeprefix Vocal music
 
 @ruser{Vocal music}
 
diff --git a/Documentation/snippets/winds-intro.itely b/Documentation/snippets/winds-intro.itely
index 01c5671f6f..89e35e20d6 100644
--- a/Documentation/snippets/winds-intro.itely
+++ b/Documentation/snippets/winds-intro.itely
@@ -1,5 +1,6 @@
 @node Winds
 @unnumbered Winds
+@nodeprefix Winds
 
 @ruser{Wind instruments}
 
diff --git a/Documentation/snippets/world-music-intro.itely b/Documentation/snippets/world-music-intro.itely
index 7dc01da4d3..63977c850f 100644
--- a/Documentation/snippets/world-music-intro.itely
+++ b/Documentation/snippets/world-music-intro.itely
@@ -1,5 +1,6 @@
 @node World music
 @unnumbered World music
+@nodeprefix World music
 
 @ruser{World music}
 
diff --git a/scripts/build/extract_texi_filenames.py b/scripts/build/extract_texi_filenames.py
index a3577ae830..37a7547966 100644
--- a/scripts/build/extract_texi_filenames.py
+++ b/scripts/build/extract_texi_filenames.py
@@ -115,7 +115,7 @@ include_re = re.compile (r'@include ((?!../lily-).*?\.i?te(xi|ly))$', re.M)
 whitespaces = re.compile (r'\s+')
 section_translation_re = re.compile ('^@(node|(?:unnumbered|appendix)\
 (?:(?:sub){0,2}sec)?|top|chapter|(?:sub){0,2}section|\
-(?:major|chap|(?:sub){0,2})heading|lydoctitle|translationof) \
+(?:major|chap|(?:sub){0,2})heading|lydoctitle|translationof|nodeprefix) \
 (.+)$', re.MULTILINE)
 external_node_re = re.compile (r'\s+@c\s+external.*')
 
@@ -225,6 +225,7 @@ def process_sections (filename, lang_suffix, page):
         print 'writing:', p
     f = open (p, 'w')
 
+    node_prefix_title = ''
     this_title = ''
     this_filename = 'index'
     this_anchor = ''
@@ -259,6 +260,9 @@ def process_sections (filename, lang_suffix, page):
                 this_filename = anchor
             elif original_node in initial_map:
                 this_filename = initial_map[original_node][2]
+        elif sec[0] == "nodeprefix":
+            node_prefix_title = remove_texinfo (sec[1])
+            node_prefix_anchor = create_texinfo_anchor (sec[1])
         else:
             # Some pages might not use a node for every section, so
             # treat this case here, too: If we already had a section
@@ -270,6 +274,10 @@ def process_sections (filename, lang_suffix, page):
                 this_anchor = create_texinfo_anchor (sec[1])
             had_section = True
 
+            if sec[0] == "lydoctitle" and node_prefix_title:
+                this_title = "%s: %s" % (node_prefix_title, this_title)
+                this_anchor = "%s-%s" % (node_prefix_anchor, this_anchor)
+
             if split == 'custom':
                 # unnumbered nodes use the previously used file name,
                 # only numbered nodes get their own filename! However,
-- 
2.39.5