]> git.donarmstrong.com Git - lilypond.git/blob - lilypond-font-lock.el
release: 1.5.48
[lilypond.git] / lilypond-font-lock.el
1 ;;; lilypond-font-lock.el --- syntax coloring for LilyPond mode
2
3 ;; Copyright (C) 1992,1993,1994  Tim Peters
4
5 ;; Author: 2001: Heikki Junes
6 ;;  * Emacs-mode: new keywords, reserved words, identifiers, notenames, 
7 ;;    some dynamics and brackets are font-lock-keywords
8 ;; Author: 1997: Han-Wen Nienhuys
9 ;; Author: 1995-1996 Barry A. Warsaw
10 ;;         1992-1994 Tim Peters
11 ;; Created:       Feb 1992
12 ;; Version:       1.5.47
13 ;; Last Modified: 26MAR2002
14 ;; Keywords: lilypond languages music notation
15
16 ;; This software is provided as-is, without express or implied
17 ;; warranty.  Permission to use, copy, modify, distribute or sell this
18 ;; software, without fee, for any purpose and by any individual or
19 ;; organization, is hereby granted, provided that the above copyright
20 ;; notice and this paragraph appear in all copies.
21
22 ;; This started out as a cannabalised version of python-mode.el, by hwn
23 ;; For changes see the LilyPond ChangeLog
24 ;;
25
26 ;; TODO:
27 ;;   - handle lexer modes (\header, \melodic, \lyric) etc.
28
29 (defconst LilyPond-font-lock-keywords
30   (let* ((keywords '( ; need special order due to over[lapping] of words
31
32 ;; all letters are lowercase
33 "accent" "accepts" "accompany" "\\(add\\)?lyrics" 
34 "\\(aeol\\|dor\\|ion\\|locr\\|\\(mixo\\)?lyd\\|phryg\\)ian" 
35 "alias" "\\(altern\\|rel\\)ative" "apply" "arpeggio" "autochange" "bar" "break"
36 "breathe" "breve" "beamintervals" "broken" "blend" "\\(bc\\|end\\)incipit" 
37 "ch\\(ar\\)?" "cg" "chord\\(s\\|stest\\|chordmodifiers\\)?"
38 "clef[ \t]*\\(F\\|G\\|alto\\|baritone\\|bass\\|\\(mezzo\\)?soprano\\|treble\\|violin\\|tenor\\)?"
39 "clipping" "cm" "coda" "complex" 
40 "\\(command\\)?spanrequest" "consists\\(end\\)?"
41 "context" "contrabasso" "\\(de\\)?cr" "default" "denies" "different" "dirs"
42 "down\\(bow\\|prall\\)?" "duration" "\\(dynamic\\)?script"
43 "eccentric" "eg" "embeddedps" "elementdescriptions"
44 "ex\\(treme\\)?" "fermata" "f+" "figures" "font" "flageolet" "fp" "fragment" 
45 "fz" "gliss\\(ando\\)?" "gg" "gmsus" "grace" "gr\\(and\\)?staff"
46 "header" "\\(h\\|v\\)size" "in\\(clude\\|versions\\|visible\\)?" 
47 "key\\(s\\(ignature\\)?\\)?" "lag" "\\(l\\|r\\)heel" "line\\(break\\|prall\\)"
48 "longa" "lower" "\\(l\\|r\\)toe"
49 "mark" "marcato" "maxima" "mel\\(isma\\|ody\\)?" "midi" "m\\(aj\\|in\\)or"
50 "\\(up\\|down\\)?mordent" "monstrous" "multipart" "music"
51 "\\(musical\\)?pitch" "m\\(p\\|f\\|m\\)?" "name" "newpage" "noise\\(beat\\)?"
52 "normal\\(key\\|size\\)" "note\\(name\\)?s" "nt?"
53 "one\\(staff\\)?" "open" "\\(output\\)?property" "over\\(ride\\)?"
54 "part\\(combine\\|ial\\)" "penalty" "p+" "pt" 
55 "prall\\(down\\|mordent\\|prall\\|up\\)?" "quickmeasure" "rc\\(ed\\)?" "remove"
56 "repeat[ \t]*\\(\\(un\\)?fold\\|percent\\|\\|tremolo\\|volta\\)?" "rest"
57 "revert" "\\(reverse\\)?turn" "rf\\(z\\)?" "rhythm"
58 "right" "scales?" "scheme" "\\(sc\\)?paper" "\\(sc\\)?score" "sd"
59 "segno" "sequential" "set\\(tings\\)?" "sf\\(f\\|z\\)?" "shortlong"
60 "simultaneous" "singlepart" "skip" "small" "\\(smart\\)?transpose"
61 "sp\\(p\\)?" "staccat\\(issim\\)?o" "staff\\(height\\|space\\)" "start" 
62 "stop\\(ped\\)?"
63 "st\\(paper\\|score\\)" "stuff" "stylesheet" "su" "tab" "tempo" "tenuto" 
64 "textscript" "thenotes" "thrd" "threevoice" "thumb" "tilt\\(down\\|up\\)" 
65 "timb" "times?" "tiny" "toeters" "touch" "translator" 
66 "trill" "type" "t\\(wo\\(voice\\(steminvert\\)?\\)?\\)?" 
67 "un\\(der\\|set\\)" "up\\(bow\\|per\\|prall\\)?" "version" 
68 "visible" "voicedefault" "x"
69
70                       ))
71
72   (identifiers '( 
73
74 ;; in principle, have one or more uppercase letters
75 "\\(\\(BarNumbering\\|Choir\\|Grand\\|HaraKiri\\|OrchestralPart\\|Piano\\|Rhythmic\\)?Staff\\|\\(Cue\\|Lyrics\\)?Voice\\|\\(Orchestral\\)?Score\\|ChordNames\\|Grace\\|Lyrics\\|Staff\\(Group\\)?\\|Thread\\)Context" ; *Context
76 "\\(script\\|dots\\|dynamic\\|slur\\|stem\\|sustain\\|sostenuto\\|unaCorda\\|treCorde\\|tie\\|tuplet\\)\\(Both\\|Down\\|Up\\)" ; *(Both/Down/Up)
77 "\\(slur\\|tie\\)\\(Dotted\\|Solid\\)" ; *(Dotted/Solid)
78 "\\(autoBeam\\|cadenza\\|impro\\|turn\\)\\(Off\\|On\\)" ; *(On/Off)
79 "\\(empty\\|fat\\)Text" ; *Text
80 "shift\\(On+\\|Off\\|I\\|II\\|III\\|IV\\|V\\)" ; shift*
81 "EasyNotation"
82 "\\(hide\\|show\\)StaffSwitch"
83 "\\(lower\\|upper\\)Voice"
84 "voice\\(One\\|Two\\|Three\\|Four\\|B\\|C\\|D\\|E\\)" ; voice*
85 "paper\\(Eleven\\|Sixteen\\|Thirteen\\|TwentySix\\)" ; paper*
86 "\\(lower\\|upper\\)\\(Octave\\|One\\)" ; (lower/upper)*
87 "hairyChord" "\\(Piano\\|Rhythmic\\)\\(Staff\\)?"
88 "\\(clarinetti\\|fagotti\\|flauti\\|melodic\\|oboi\\|\\(quite\\|rather\\|somewhat\\)LongLyrics\\|violinoII?\\)?\\(Staff\\)?" ; *Staff
89 "\\(archi\\|bassi\\|legni\\|ottoni\\|timpani\\|viole\\|violini\\)\\(Group\\)" ; *Group
90 "melisma\\(End\\)?" "staff\\(One\\|Two\\)?" "rests\\(II\\)?" "specialKey"
91 "noBreak" "paperTwentysix" "endHorizScript" "FontBody" "text(I)+"
92 "\\(modern\\|forget\\)Accidentals" ; *Accidentals
93 "noResetKey" "modern\\(Voice\\)?Cautionaries" "unaCorda" "treCorde"
94
95                       ))
96
97   (reservedwords '(
98
99 ;; Other words which look nicer when colored
100 "Accidentals" "autoBeamSettings" "BarLine" "Beam"
101 "ChordName\\([s]?\\|s.[a-zA-Z]*\\)" "DynamicText"
102 "FiguredBass" "Hairpin" "\\(Grand\\|Piano\\)Staff"
103 "Slur" "Stem" "SpacingSpanner" "System\\(StartDelimiter\\)?"
104 "\\(Grace\\|Lyrics\\|Note\\(Head\\|Names\\)\\|Score\\|\\(Rhythmic\\)?Staff\\(Symbol\\)?\\|Thread\\|Voice\\)\\(.[a-zA-Z]*\\)?" ; combine below, if possible
105 "\\(Grace\\|Lyrics\\|Note\\(Head\\|Names\\)\\|Score\\|\\(Rhythmic\\)?Staff\\(Symbol\\)?\\|Thread\\|Voice\\)[ \t]*\\(.[ \t]*[a-zA-Z]*\\)?" 
106 "TextScript" "TimeSignature" "VerticalAlignment"
107
108                       ))
109
110        (kwregex (mapconcat (lambda (x) (concat "\\\\" x))  keywords "\\|"))
111        (iregex (mapconcat (lambda (x) (concat "\\\\" x))  identifiers "\\|"))
112        (rwregex (mapconcat (lambda (x) (concat "" x))  reservedwords "\\|"))
113 )
114
115     (list 
116 ;; Fonts in use (from GNU Emacs Lisp Reference Manual, elisp.ps):
117 ;; font-lock- comment / string / keyword / builtin / function-name / 
118 ;;            variable-name / type / constant / warning -face
119
120       '("\\([_^-]?\\\\[a-zA-Z][a-zA-Z]*\\)" 1 font-lock-constant-face)
121       '("\\(\\(#'\\)?[a-zA-Z][_a-zA-Z.\-]*[ \t]*=[ \t]*#\\(#f\\|#t\\)\\)" 1 font-lock-variable-name-face)
122       '("\\([a-zA-Z][_a-zA-Z.\-]*\\)[ \t]*=[ \t]*" 1 font-lock-variable-name-face)
123       '("[ \t]*=[ \t]*\\([a-zA-Z][_a-zA-Z]*\\)" 1 font-lock-variable-name-face)
124
125
126 ;; other reserved words
127       (cons (concat "\\(" rwregex "\\)") 'font-lock-variable-name-face)
128
129 ;; highlight note names; separate notes from (other than ')'-type) brackets
130       '("[ <\{[~()\t]\\(\\(\\(\\(do\\|re\\|mi\\|fa\\|sol\\|la\\|si\\)\\(bb?\\|dd?\\|ss?\\)?\\)\\|\\([a-hsrR]\\(flat\\(flat\\)?\\|sharp\\(sharp\\)?\\|ff?\\|ss?\\|is\\(siss\\|s\\|is\\)?\\|es\\(sess\\|s\\|es\\)?\\)?\\)\\|\\(as\\(as\\|es\\)?\\)\\|\\(es\\(es\\)?\\)\\|\\(bb\\)\\)[,']*\\(128\\|64\\|32\\|16\\|8\\|4\\|2\\|1\\)?[.]*\\)" 1 font-lock-type-face)
131
132 ;; highlight identifiers
133       (cons (concat "\\([_^-]?\\(" iregex "\\)\\)+\\($\\|[] \t(~{}>\\\\]\\)") '(0 font-lock-function-name-face t))
134
135 ;; highlight keywords
136       (cons (concat "\\([_^-]?\\(" kwregex "\\)\\)+\\($\\|[] \t(~{}>\\\\]\\)") '(0 font-lock-keyword-face t))
137
138 ;; highlight bracketing constructs
139       '("\\([][}{]\\)" 0 font-lock-warning-face t)
140 ;; these regexps allow angle-brackets to be highlighted,
141 ;; but leave accented notes, e.g. a b c->, alone
142       '("[^\\]\\(<\\)" 1 font-lock-warning-face t)
143       '("[_^-]\\s-*[-^]\\s-*\\(>\\)" 1 font-lock-warning-face t)
144       '("[^\\t\\n _^-]\\s-*\\(>\\)" 1 font-lock-warning-face t)
145
146       '("\\([(~)]\\|\\\\<\\|\\\\!\\|\\\\>\\)" 0 font-lock-builtin-face t)
147
148 ;; highlight comments (again)
149       '("\\(%.*\\)" 0 font-lock-comment-face t)
150
151       )
152     )
153   "Additional expressions to highlight in LilyPond mode.")
154
155 ;; define a mode-specific abbrev table for those who use such things
156 (defvar LilyPond-mode-abbrev-table nil
157   "Abbrev table in use in `LilyPond-mode' buffers.")
158
159 (define-abbrev-table 'LilyPond-mode-abbrev-table nil)
160
161 (defvar LilyPond-mode-syntax-table nil
162   "Syntax table used in `LilyPond-mode' buffers.")
163
164 ;;
165 (if LilyPond-mode-syntax-table
166     ()
167   (setq LilyPond-mode-syntax-table (make-syntax-table))
168   (mapcar (function
169            (lambda (x) (modify-syntax-entry
170                         (car x) (cdr x) LilyPond-mode-syntax-table)))
171           '(( ?\( . "." ) ( ?\) . "." ) 
172             ( ?\[ . "(]" ) ( ?\] . ")[" )
173             ( ?\{  .  "(}2b" )
174             ( ?\}  .  "){4b" )
175             ( ?\< . "." )( ?\> . ".") 
176             ( ?\$ . "." ) ( ?\% . "." ) ( ?\& . "." )
177             ( ?\* . "." ) ( ?\+ . "." )
178             ( ?\/ . "." )  ( ?\= . "." )
179             ( ?\| . "." ) (?\\ . "\\" )
180             ( ?\- . "." ) ( ?\_ . "." ) ( ?\^ . "." )
181             ( ?\' . "w")        
182             ( ?\" . "\"" )
183             ( ?\%  .  ". 1b3b" )
184             ( ?\n . ">")
185             ( ?\r . ">")
186             ))
187   )
188