*** empty log message ***
[lilypond.git] / lilypond-font-lock.el
blob2ed452e8717f353115013fc480857031c8149cd0
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: 13DEC2003
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", ... (w) horizontal grouping
50 ;; "on top", ... (f) vertical grouping
51 ;; "on top", ... (b) expressional grouping
52 ;; "on top", ... (s) lyrics-mode
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", ... horizontal grouping:
84 ;; - brackets '{[]}'
85 ;; - ties '~'
86 '("\\([][~}{]\\)" 0 font-lock-warning-face t)
88 ;; "on top", ... vertical grouping:
89 ;; - '<>'-chord brackets with '\\'-voice sep., not marcato '->'
90 ;; - '<< a b >>8' -chords
91 '("\\(\\(-.\\)+\\|[^-^_]\\)\\([<>]+\\(\\(128\\|6?4\\|3?2\\|16?\\|8\\|\\\\\\(breve\\|longa\\)\\)[.]*\\([ \t]*[*][ \t]*[0-9]+\\(/[1-9][0-9]*\\)?\\)?\\)?\\|\\\\\\\\\\)" 3 font-lock-function-name-face t)
93 ;; "on top", ... expressional grouping:
94 ;; - slurs ( ), \( \), -( -)
95 ;; - hairpins \<, \>, \!
96 '("\\(\\\\[(<!>)]\\|-?[()]\\)" 0 font-lock-builtin-face t)
98 ;; "on top", ... lyrics-mode: fontify everything between '{' and '}'
99 '("\\(\\\\lyrics[^{]*{\\)\\([^}]*\\)" 2 font-lock-string-face t)
101 ;; "on top", ... (multiline-)scheme: try find slurs up to 7th
102 '("[_^-]?#\\(#[ft]\\|-?[0-9.]+\\|\"[^\"]*\"\\|['`]?[a-zA-Z-:]+\\|['`]?([^()]*\\(([^()]*\\(([^()]*\\(([^()]*\\(([^()]*\\(([^()]*\\(([^)]*)[^()]*\\)*)[^()]*\\)*)[^()]*\\)*)[^()]*\\)*)[^()]*\\)*)[^()]*\\)*[^)]*)\\)" 0 font-lock-string-face t)
104 ;; "on top", ... strings
105 '("\\([_^-]?\"\\([^\"\\\\]\\|\\\\.\\|\\\\\n\\)*\"\\)" 0 font-lock-string-face t)
107 ;; "on top", ... (multiline-)comments
108 '("\\(%\\({[^%]*%\\(}\\|\\([^}][^%]*%\\)+}\\)\\|.*\\)\\)" 0 font-lock-comment-face t)
112 "Additional expressions to fontify in LilyPond mode.")
114 ;; define a mode-specific abbrev table for those who use such things
115 (defvar LilyPond-mode-abbrev-table nil
116 "Abbrev table in use in `LilyPond-mode' buffers.")
118 (define-abbrev-table 'LilyPond-mode-abbrev-table nil)
120 (defvar LilyPond-mode-syntax-table nil
121 "Syntax table used in `LilyPond-mode' buffers.")
124 (if LilyPond-mode-syntax-table
126 (setq LilyPond-mode-syntax-table (make-syntax-table))
127 (mapcar (function
128 (lambda (x) (modify-syntax-entry
129 (car x) (cdr x) LilyPond-mode-syntax-table)))
130 '(( ?\( . "." ) ( ?\) . "." )
131 ( ?\[ . "(]" ) ( ?\] . ")[" ) ;; all the other paren characters are now handled by
132 ( ?\{ . ". 2b" ) ;; lily-specific indenting/matching code in lilypond-indent.el
133 ( ?\} . ". 4b" )
134 ( ?\< . "." )( ?\> . ".")
135 ( ?\$ . "." ) ( ?\& . "." )
136 ( ?\* . "." ) ( ?\+ . "." )
137 ( ?\/ . "." ) ( ?\= . "." )
138 ( ?\| . "." ) (?\\ . "\\" )
139 ( ?\- . "." ) ( ?\_ . "." ) ( ?\^ . "." ) ; accent positioners: puctuation characters
140 ( ?\' . "w") ( ?\, . "w") ; transposing octaves, parts of words (notes)
141 ( ?\" . "\"" ) ; string quote characters
142 ( ?\% . "< 1b3b" ) ; (block-)comment starter (or ender)
143 ( ?\n . ">") ; newline: comment ender
144 ( ?\r . ">") ; formfeed: comment ender