]> git.donarmstrong.com Git - lilypond.git/blob - lilypond-font-lock.el
(Running LilyPond): Separate
[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.50
13 ;; Last Modified: 6APR2002
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\\|\\(chord\\)?modifiers\\)?"
38 "clef[ \t]*\\(F\\|G\\|alto\\|baritone\\|bass\\|\\(mezzo\\)?soprano\\|treble\\|violin\\|tenor\\)?"
39 "clipping" "[cm]m" "coda" "complex" 
40 "\\(command\\)?spanrequest" "consists\\(end\\)?"
41 "context" "contrabasso" "\\(de\\)?cr" "default" "denies" "different" "dirs"
42 "down\\(bow\\|prall\\)?" "duration" "\\(dynamic\\|text\\)?script"
43 "eccentric" "eg" "embeddedps" "elementdescriptions"
44 "ex\\(treme\\)?" "fermata" "f+" "figures" "font" "flageolet" "fp" "fragment" 
45 "s?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\\|pitch\\)?names" "notes" "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" "rfz?" "rhythm"
58 "right" "scales?" "scheme" "\\(sc\\)?paper" "\\(sc\\)?score" "sd"
59 "segno" "sequential" "set\\(tings\\)?" "shortlong"
60 "simultaneous" "singlepart" "skip" "small" "\\(smart\\)?transpose"
61 "s[pf]+" "staccat\\(issim\\)?o" "staff\\(height\\|space\\)" "start" 
62 "stop\\(ped\\)?"
63 "st\\(paper\\|score\\)" "stuff" "stylesheet" "su" "tab" "tempo" "tenuto" 
64 "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 when and only when they delimit simultaneous music
141       ;; fontify open < but leave crescendos \< alone
142       '("[^\\]\\(<\\)" 1 font-lock-warning-face t)
143       ;; fontify the close-brackets in <a b c--> (tenuto) and <a b c-^> (marcato)
144       '("[_^-]\\s-*[-^]\\s-*\\(>\\)" 1 font-lock-warning-face t) 
145       ;; but leave a b c-> (accent) alone, accounting for whitespace
146       '("\\([^\\t\\n _^-]\\|^\\)\\s-*\\(>\\)" 2 font-lock-warning-face t)
147       ;; ties ~, slurs (), hairpins \<,  \>, end-of-hairpin \!, 
148       '("\\([(~)]\\|\\\\<\\|\\\\!\\|\\\\>\\)" 0 font-lock-builtin-face t)
149
150 ;; highlight comments (again)
151       '("\\(%.*\\)" 0 font-lock-comment-face t)
152
153       )
154     )
155   "Additional expressions to highlight in LilyPond mode.")
156
157 ;; define a mode-specific abbrev table for those who use such things
158 (defvar LilyPond-mode-abbrev-table nil
159   "Abbrev table in use in `LilyPond-mode' buffers.")
160
161 (define-abbrev-table 'LilyPond-mode-abbrev-table nil)
162
163 (defvar LilyPond-mode-syntax-table nil
164   "Syntax table used in `LilyPond-mode' buffers.")
165
166 ;;
167 (if LilyPond-mode-syntax-table
168     ()
169   (setq LilyPond-mode-syntax-table (make-syntax-table))
170   (mapcar (function
171            (lambda (x) (modify-syntax-entry
172                         (car x) (cdr x) LilyPond-mode-syntax-table)))
173           '(( ?\( . "." ) ( ?\) . "." ) 
174             ( ?\[ . "(]" ) ( ?\] . ")[" ) ;; all the other paren characters are now handled by          
175             ( ?\{  .  ".2b" )             ;; lily-specific indenting/matching code in lilypond-indent.el 
176             ( ?\}  .  ".4b" )              
177             ( ?\< . "." )( ?\> . ".") 
178             ( ?\$ . "." ) ( ?\% . "." ) ( ?\& . "." )
179             ( ?\* . "." ) ( ?\+ . "." )
180             ( ?\/ . "." )  ( ?\= . "." )
181             ( ?\| . "." ) (?\\ . "\\" )
182             ( ?\- . "." ) ( ?\_ . "." ) ( ?\^ . "." )
183             ( ?\' . "w")        
184             ( ?\" . "\"" )
185             ( ?\%  .  ". 1b3b" )
186             ( ?\n . ">")
187             ( ?\r . ">")
188             ))
189   )
190