]> git.donarmstrong.com Git - lilypond.git/blob - lilypond-font-lock.el
4a09294c56a41af73aff863feb981ee13ed92500
[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:       0.0
13 ;; Last Modified: 14SEP2001
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 "accepts" "accompany" "addlyrics" "aeolian" "alias" "alternative"
34 "apply" "arpeggio" "autochange" "bar" "break" "breathe" "breve"
35 "beamintervals" "broken" "blend" "bcincipit" "char" "ch" "cg"
36 "chord\\(s\\|stest\\|chordmodifiers\\)?"
37 "clef \\(bass\\|treble\\|violin\\|tenor\\)?"
38 "clipping" "cm" "coda" "complex" "commandspanrequest" "consists\\(end\\)?"
39 "context" "contrabasso" "decr" "default" "denies" "different" "dirs"
40 "down\\(bow\\|prall\\)?" "dorian" "duration" "dynamicscript"
41 "eccentric" "eg" "embeddedps" "endincipit" "elementdescriptions"
42 "ex\\(treme\\)?" "fermata" "f+" "font" "flageolet" "fp" "fragment" "fz"
43 "gliss\\(ando\\)?" "global" "gg" "gmsus" "grace" "gr\\(and\\)?staff"
44 "header" "hsize" "in\\(clude\\|versions\\|visible\\)?" "ionian"
45 "key\\(s\\(ignature\\)?\\)?" "lag" "lheel" "line\\(break\\|prall\\)"
46 "locrian" "longa" "lower" "ltoe" "lydian" "lyrics"
47 "maintainer" "mark" "maxima" "mel\\(isma\\|ody\\)?" "midi" "major"
48 "minor" "mixolydian" "mordent" "monstrous" "multipart" "music"
49 "musicalpitch" "m\\(p\\|f\\|m\\)?" "name" "newpage" "noise\\(beat\\)?"
50 "normal\\(key\\|size\\)" "note\\(name\\)?s" "nt?"
51 "one\\(staff\\)?" "open" "outputproperty" "over\\(ride\\)?"
52 "paper" "partcombine" "partial" "penalty" "phrygian" "pitch" "p+"
53 "property" "pt" "prall\\(mordent\\|prall\\|up\\)?" "quickmeasure"
54 "relative" "remove" "repeat" "rever\\(t\\|seturn\\)" "rf" "rheel" "rhythm"
55 "right" "rtoe" "scales?" "scheme" "score" "scpaper" "script" "scscore" "sd"
56 "segno" "sequential" "set\\(tings\\)?" "sf\\(f\\|z\\)?" "shortlong"
57 "simultaneous" "singlepart" "skip" "small" "smarttranspose" "spanrequest"
58 "staccato" "staff\\(height\\|space\\)" "start" "stop\\(ped\\)?"
59 "st\\(paper\\|score\\)" "stuff" "stylesheet" "su" "tab" "tempo" "tenuto" 
60 "textscript" "thenotes" "thrd" "threevoice" "thumb" "tilt\\(down\\|up\\)" 
61 "timb" "times?" "timpani" "tiny" "toeters" "touch" "trans\\(lator\\|pose\\)" 
62 "trill" "trombe" "turn" "type" "t\\(wo\\(voice\\(steminvert\\)?\\)?\\)?" 
63 "un\\(der\\|set\\)" "up\\(bow\\|per\\|prall\\)?" "version" 
64 "viol\\(a\\|in\\(incipit\\)?\\|oncello\\)" "visible" "voicedefault" "vsize"
65 "x" "zagers?" "z\\(eu\\|o\\)ger"
66
67                       ))
68
69   (identifiers '( 
70
71 ;; in principle, have one or more uppercase letters
72 "\\(\\(BarNumbering\\|Choir\\|Grand\\|HaraKiri\\|OrchestralPart\\|Piano\\|Rhythmic\\)Staff\\|\\(Cue\\|Lyrics\\)?Voice\\|\\(Orchestral\\)?Score\\|ChordNames\\|Grace\\|Lyrics\\|StaffGroup\\|Thread\\)Context" ; *Context
73 "\\(script\\|dots\\|dynamic\\|slur\\|stem\\|sustain\\|sostenuto\\|unaCorda\\|treCorde\\|tie\\|tuplet\\)\\(Both\\|Down\\|Up\\)" ; *(Both/Down/Up)
74 "\\(slur\\|tie\\)\\(Dotted\\|Solid\\)" ; *(Dotted/Solid)
75 "\\(autoBeam\\|cadenza\\|impro\\|turn\\)\\(Off\\|On\\)" ; *(On/Off)
76 "\\(empty\\|fat\\)Text" ; *Text
77 "shift\\(On+\\|Off\\|I\\|II\\|III\\|IV\\|V\\)" ; shift*
78 "EasyNotation"
79 "\\(hide\\|show\\)StaffSwitch"
80 "\\(lower\\|upper\\)Voice"
81 "voice\\(One\\|Two\\|Three\\|Four\\|B\\|C\\|D\\|E\\)" ; voice*
82 "paper\\(Eleven\\|Sixteen\\|Thirteen\\|TwentySix\\)" ; paper*
83 "\\(lower\\|upper\\)\\(Octave\\|One\\)" ; (lower/upper)*
84 "hairyChord"
85 "\\(Piano\\|Rhythmic\\)\\(Staff\\)?"
86 "\\(clarinetti\\|fagotti\\|flauti\\|melodic\\|oboi\\|\\(quite\\|rather\\|somewhat\\)LongLyrics\\|violinoII?\\)?\\(Staff\\)?" ; *Staff
87 "\\(archi\\|bassi\\|legni\\|ottoni\\|timpani\\|viole\\|violini\\)\\(Group\\)" ; *Group
88 "melisma\\(End\\)?" "staff\\(One\\|Two\\)?" "rests\\(II\\)?" "specialKey"
89 "noBreak" "paperTwentysix" "endHorizScript" "FontBody" "text(I)+"
90
91                       ))
92
93   (reservedwords '(
94
95 ;; Other words which look nicer when colored
96 "Accidentals" "autoBeamSettings" "BarLine" "Beam"
97 "ChordName\\([s]?\\|s.[a-zA-Z]*\\)" "Grace\\(.[a-zA-Z]*\\)?"
98 "\\(Grand\\|Piano\\)Staff" "Lyrics\\(.[a-zA-Z]*\\)?" "NoteHead" 
99 "Score\\(.[a-zA-Z]*\\)" "Stem" "Staff\\(Symbol\\)?" "TextScript" 
100 "TimeSignature" "Voice\\(.[a-zA-Z]*\\)?"
101
102                       ))
103
104        (kwregex (mapconcat (lambda (x) (concat "\\\\" x))  keywords "\\|"))
105        (iregex (mapconcat (lambda (x) (concat "\\\\" x))  identifiers "\\|"))
106        (rwregex (mapconcat (lambda (x) (concat "" x))  reservedwords "\\|"))
107 )
108
109     (list 
110 ;; Fonts in use (from GNU Emacs Lisp Reference Manual, elisp.ps):
111 ;; font-lock- comment / string / keyword / builtin / function-name / 
112 ;;            variable-name / type / constant / warning -face
113
114       '("\\([_^]?\\\\[a-zA-Z][a-zA-Z]*\\)" 1 font-lock-constant-face)
115       '("\\(\\(#'\\)?[a-zA-Z][_a-zA-Z.\-]*[ \t]*=[ \t]*#\\)" 1 font-lock-variable-name-face)
116       '("\\([a-zA-Z][_a-zA-Z.\-]*\\)[ \t]*=[ \t]*" 1 font-lock-variable-name-face)
117       '("[ \t]*=[ \t]*\\([a-zA-Z][_a-zA-Z]*\\)" 1 font-lock-variable-name-face)
118
119
120 ;; other reserved words
121       (cons (concat "\\(" rwregex "\\)") 'font-lock-variable-name-face)
122
123 ;; highlight note names; separate notes from (other than ')'-type) brackets
124       '("[ <\{[~()\t]\\(\\(\\(\\(do\\|re\\|mi\\|fa\\|sol\\|la\\|si\\)\\(bb?\\|dd?\\|ss?\\)?\\)\\|\\([a-hsr]\\(flat\\(flat\\)?\\|sharp\\(sharp\\)?\\|ff?\\|ss?\\|is\\(siss\\|s\\|is\\)?\\|es\\(sess\\|s\\|es\\)?\\)?\\)\\|\\(as\\(as\\|es\\)?\\)\\|\\(es\\(es\\)?\\)\\|\\(bb\\)\\)[,']*\\(64\\|32\\|16\\|8\\|4\\|2\\|1\\)?[.]*\\)" 1 font-lock-type-face)
125
126 ;; highlight identifiers
127       (cons (concat "\\([_^]?\\(" iregex "\\)\\)+\\($\\|[] \t(~{}>\\\\]\\)") '(0 font-lock-function-name-face t))
128
129 ;; highlight keywords
130       (cons (concat "\\([_^]?\\(" kwregex "\\)\\)+\\($\\|[] \t(~{}>\\\\]\\)") '(0 font-lock-keyword-face t))
131
132 ;; highlight bracketing constructs
133       '("\\([][}{]\\)" 0 font-lock-warning-face t)
134 ;; these regexps allow angle-brackets to be highlighted,
135 ;; but leave accented notes, e.g. a b c->, alone
136       '("[^\\]\\(<\\)" 1 font-lock-warning-face t)
137       '("[_^-]\\s-*[-^]\\s-*\\(>\\)" 1 font-lock-warning-face t)
138       '("[^\\t\\n _^-]\\s-*\\(>\\)" 1 font-lock-warning-face t)
139
140       '("\\([(~)]\\|\\\\<\\|\\\\!\\|\\\\>\\)" 0 font-lock-builtin-face t)
141
142 ;; highlight comments (again)
143       '("\\(%.*\\)" 0 font-lock-comment-face t)
144
145       )
146     )
147   "Additional expressions to highlight in LilyPond mode.")
148
149 ;; define a mode-specific abbrev table for those who use such things
150 (defvar LilyPond-mode-abbrev-table nil
151   "Abbrev table in use in `LilyPond-mode' buffers.")
152
153 (define-abbrev-table 'LilyPond-mode-abbrev-table nil)
154
155 (defvar LilyPond-mode-syntax-table nil
156   "Syntax table used in `LilyPond-mode' buffers.")
157
158 ;;
159 (if LilyPond-mode-syntax-table
160     ()
161   (setq LilyPond-mode-syntax-table (make-syntax-table))
162   (mapcar (function
163            (lambda (x) (modify-syntax-entry
164                         (car x) (cdr x) LilyPond-mode-syntax-table)))
165           '(( ?\( . "." ) ( ?\) . "." ) 
166             ( ?\[ . "." ) ( ?\] . "." )
167             ( ?\{  .  "(}2b" )
168             ( ?\}  .  "){4b" )
169             ( ?\< . "." )( ?\> . ".") 
170             ( ?\$ . "." ) ( ?\% . "." ) ( ?\& . "." )
171             ( ?\* . "." ) ( ?\+ . "." )
172             ( ?\/ . "." )  ( ?\= . "." )
173             ( ?\| . "." ) (?\\ . "\\" )
174             ( ?\- . "." ) ( ?\_ . "." ) ( ?\^ . "." )
175             ( ?\' . "w")        
176             ( ?\" . "\"" )
177             ( ?\%  .  ". 1b3b" )
178             ( ?\n . ">")
179             ( ?\r . ">")
180             ))
181   )
182