* Documentation/user/music-glossary.tely: add @omf tags
[lilypond.git] / lilypond-font-lock.el
blobf8518df97c77309d750eea0714d51d29c46d680f
1 ;;; lilypond-font-lock.el --- syntax coloring for LilyPond mode
3 ;; Copyright (C) 1992,1993,1994 Tim Peters
5 ;; Author: 2001-2003: Heikki Junes
6 ;; * Emacs-mode: new keywords, reserved words, identifiers, notenames,
7 ;; some dynamics and brackets are font-lock-keywords
8 ;; * File lilypond.words gives keywords, identifiers and reserved words
9 ;; Author: 1997: Han-Wen Nienhuys
10 ;; Author: 1995-1996 Barry A. Warsaw
11 ;; 1992-1994 Tim Peters
12 ;; Created: Feb 1992
13 ;; Version: 1.7.12
14 ;; Last Modified: 26DEC2003
15 ;; Keywords: lilypond languages music notation
17 ;; This software is provided as-is, without express or implied
18 ;; warranty. Permission to use, copy, modify, distribute or sell this
19 ;; software, without fee, for any purpose and by any individual or
20 ;; organization, is hereby granted, provided that the above copyright
21 ;; notice and this paragraph appear in all copies.
23 ;; This started out as a cannabalised version of python-mode.el, by hwn
24 ;; For changes see the LilyPond ChangeLog
27 ;; TODO:
28 ;; - handle lexer modes (\header, \melodic) etc.
30 (defconst LilyPond-font-lock-keywords
31 (let* ((kwregex (mapconcat (lambda (x) (concat "\\" x)) LilyPond-keywords "\\|"))
32 (iregex (mapconcat (lambda (x) (concat "\\" x)) LilyPond-identifiers "\\|"))
33 (rwregex (mapconcat (lambda (x) (concat "" x)) LilyPond-reserved-words "\\|"))
36 (list
37 ;; Fonts in use (from GNU Emacs Lisp Reference Manual, elisp.ps):
38 ;; font-lock- (c)omment / (s)tring / (k)eyword / (b)uiltin / (f)unction-name /
39 ;; (v)ariable-name / (t)ype / co(n)stant / (w)arning -face
41 ;; The order below is designed so that proofreading would be possible.
43 ;; Fontify...
44 ;; ... (f) identifiers and (k) keywords.
45 ;; ... (n) user defined indetifiers
46 ;; ... (v) the right and the left side of '='-marks.
47 ;; ... (v) reserved words, e.g., FiguredBass.
48 ;; ... (t) notes and rests
49 ;; "on top", ... (s) lyrics-mode
50 ;; "on top", ... (w) horizontal grouping
51 ;; "on top", ... (f) vertical grouping
52 ;; "on top", ... (b) expressional grouping
53 ;; "on top", ... (s) (multiline-)scheme; urgh. one should count the slurs
54 ;; "on top", ... (s) strings
55 ;; "on top", ... (c) (multiline-)comments
57 ;; One should note 'font-lock-multiline' has been possible since Emacs 21.1.
58 ;; See, e.g., text in "http://emacs.kldp.org/emacs-21.1/etc/NEWS".
60 ;; ... identifiers (defined above, see iregex)
61 (cons (concat "\\(\\([_^-]?\\(" iregex "\\)\\)+\\)\\($\\|[] \t(~{}>\\\\_()^*-]\\)") '(1 font-lock-function-name-face))
63 ;; ... keywords (defined above, see kwregex)
64 (cons (concat "\\(\\([_^-]?\\(" kwregex "\\)\\)+\\)\\($\\|[] \t(~{}>\\\\_()^*-]\\)") '(1 font-lock-keyword-face))
66 ;; ... user defined identifiers \[a-zA-Z]+, but not \breve or \longa (durations)
67 '("\\([_^-]?\\\\\\([ac-km-zA-Z]\\|l[a-np-zA-Z]\\|b[a-qs-zA-Z]\\|lo[a-mo-zA-Z]\\|br[a-df-zA-Z]\\|lon[a-fh-zA-Z]\\|bre[a-uw-zA-Z]\\|long[b-zA-Z]\\|brev[a-df-zA-Z]\\|\\(longa\\|breve\\)[a-zA-Z]\\)[a-zA-Z]*\\)" 1 font-lock-constant-face)
69 ;; ... the left side of '=' -mark
70 '("\\([_a-zA-Z.0-9-]+\\)[ \t]*=[ \t]*" 1 font-lock-variable-name-face)
72 ;; ... the right side of '=' -mark
73 '("[ \t]*=[ \t]*\\([_a-zA-Z.0-9-]+\\)" 1 font-lock-variable-name-face)
75 ;; ... reserved words (defined above, see rwregex)
76 (cons (concat "\\(" rwregex "\\)") 'font-lock-variable-name-face)
78 ;; ... note or rest with (an accidental and) a duration (multiplied), e.g., b,?16.*3/4
79 '("\\(^\\|[ <\{[/~(!)\t\\\|]\\)\\(\\(\\(\\(bb\\|as[ae]s\\|eses\\|\\(do\\|re\\|[ms]i\\|[fl]a\\|sol\\)\\(bb?\\|dd?\\|ss?\\)?\\)\\|\\([a-h]\\(\\(flat\\)+\\|\\(sharp\\)+\\|is\\(siss\\|i?s\\)?\\|es\\(sess\\|e?s\\)?\\|ff?\\|ss?\\)?\\)\\)[,']*[?!]?\\|[srR]\\)\\([ \t]*\\(128\\|6?4\\|3?2\\|16?\\|8\\|\\\\\\(breve\\|longa\\)\\)[.]*\\([ \t]*[*][ \t]*[0-9]+\\(/[1-9][0-9]*\\)?\\)?\\)\\)" 2 font-lock-type-face)
80 ;; ... note or rest (with an accidental), e.g., b,? -- allows cis\longaX
81 '("\\(^\\|[ <\{[/~(!)\t\\\|]\\)\\(\\(\\(bb\\|as[ae]s\\|eses\\|\\(do\\|re\\|[ms]i\\|[fl]a\\|sol\\)\\(bb?\\|dd?\\|ss?\\)?\\)\\|\\([a-h]\\(\\(flat\\)+\\|\\(sharp\\)+\\|is\\(siss\\|i?s\\)?\\|es\\(sess\\|e?s\\)?\\|ff?\\|ss?\\)?\\)\\)[,']*[?!]?\\|[srR]\\)" 2 font-lock-type-face)
83 ;; "on top", ... lyrics-mode: fontify everything between '<'...'>' or '{'...'}'
84 ; URGH, does not know anything about inner brackets.
85 ; Multiple lines may need refontifying (C-c f).
86 '("\\(\\\\lyrics[^{<]*\\)\\({[^}]*\\|<[^>]*\\)" 2 font-lock-string-face t)
88 ;; "on top", ... horizontal grouping:
89 ;; - brackets '{[]}'
90 ;; - ties '~'
91 '("\\([][~}{]\\)" 0 font-lock-warning-face t)
93 ;; "on top", ... vertical grouping:
94 ;; - '<>'-chord brackets with '\\'-voice sep., not marcato '->'
95 ;; - '<< a b >>8' -chords
96 '("\\(\\(-.\\)+\\|[^-^_]\\)\\([<>]+\\(\\(128\\|6?4\\|3?2\\|16?\\|8\\|\\\\\\(breve\\|longa\\)\\)[.]*\\([ \t]*[*][ \t]*[0-9]+\\(/[1-9][0-9]*\\)?\\)?\\)?\\|\\\\\\\\\\)" 3 font-lock-function-name-face t)
98 ;; "on top", ... expressional grouping:
99 ;; - slurs ( ), \( \), [-^_][()]
100 ;; - hairpins \<, \>, \!
101 '("\\(\\\\[(<!>)]\\|[-^_]?[()]\\)" 0 font-lock-builtin-face t)
103 ;; "on top", ... (multiline-)scheme: try find slurs up to 7th
104 '("[_^-]?#\\(#[ft]\\|-?[0-9.]+\\|\"[^\"]*\"\\|['`]?[a-zA-Z-:]+\\|['`]?([^()]*\\(([^()]*\\(([^()]*\\(([^()]*\\(([^()]*\\(([^()]*\\(([^)]*)[^()]*\\)*)[^()]*\\)*)[^()]*\\)*)[^()]*\\)*)[^()]*\\)*)[^()]*\\)*[^)]*)\\)" 0 font-lock-string-face t)
106 ;; "on top", ... strings
107 '("\\([_^-]?\"\\([^\"\\\\]\\|\\\\.\\|\\\\\n\\)*\"\\)" 0 font-lock-string-face t)
109 ;; "on top", ... (multiline-)comments
110 '("\\(%\\({[^%]*%\\(}\\|\\([^}][^%]*%\\)+}\\)\\|.*\\)\\)" 0 font-lock-comment-face t)
114 "Additional expressions to fontify in LilyPond mode.")
116 ;; define a mode-specific abbrev table for those who use such things
117 (defvar LilyPond-mode-abbrev-table nil
118 "Abbrev table in use in `LilyPond-mode' buffers.")
120 (define-abbrev-table 'LilyPond-mode-abbrev-table nil)
122 (defvar LilyPond-mode-syntax-table nil
123 "Syntax table used in `LilyPond-mode' buffers.")
126 (if LilyPond-mode-syntax-table
128 (setq LilyPond-mode-syntax-table (make-syntax-table))
129 (mapcar (function
130 (lambda (x) (modify-syntax-entry
131 (car x) (cdr x) LilyPond-mode-syntax-table)))
132 '(( ?\( . "." ) ( ?\) . "." )
133 ( ?\[ . "(]" ) ( ?\] . ")[" ) ;; all the other paren characters are now handled by
134 ( ?\{ . ". 2b" ) ;; lily-specific indenting/matching code in lilypond-indent.el
135 ( ?\} . ". 4b" )
136 ( ?\< . "." )( ?\> . ".")
137 ( ?\$ . "." ) ( ?\& . "." )
138 ( ?\* . "." ) ( ?\+ . "." )
139 ( ?\/ . "." ) ( ?\= . "." )
140 ( ?\| . "." ) (?\\ . "\\" )
141 ( ?\- . "." ) ( ?\_ . "." ) ( ?\^ . "." ) ; accent positioners: puctuation characters
142 ( ?\' . "w") ( ?\, . "w") ; transposing octaves, parts of words (notes)
143 ( ?\" . "\"" ) ; string quote characters
144 ( ?\% . "< 1b3b" ) ; (block-)comment starter (or ender)
145 ( ?\n . ">") ; newline: comment ender
146 ( ?\r . ">") ; formfeed: comment ender