]> git.donarmstrong.com Git - lilypond.git/blob - lilypond-font-lock.el
drum fixes
[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-2002: 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.8
14 ;; Last Modified: 23NOV2002
15 ;; Keywords: lilypond languages music notation
16
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.
22
23 ;; This started out as a cannabalised version of python-mode.el, by hwn
24 ;; For changes see the LilyPond ChangeLog
25 ;;
26
27 ;; TODO:
28 ;;   - handle lexer modes (\header, \melodic, \lyric) etc.
29
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 "\\|"))
34 )
35
36     (list 
37 ;; Fonts in use (from GNU Emacs Lisp Reference Manual, elisp.ps):
38 ;; font-lock- comment / string / keyword / builtin / function-name / 
39 ;;            variable-name / type / constant / warning -face
40
41 ;; The order below is designed so that proofreading would be possible.
42
43 ;; Fontify...
44 ;; ... first identifiers and keywords.
45 ;; ... then other expressions having '\'-mark in the beginning.
46 ;; ... the right and the left side of '='-marks.
47 ;; ... reserved words, e.g., FiguredBass.
48 ;; ... notes and rests
49 ;; "on top", 6) ... '<{[]}>'-brackets
50 ;; "on top", 7) ... ties, slurs and hairpins
51 ;; "on top", 8) ... (multiline-)scheme; urgh. one should count the slurs
52 ;; "on top", 9) ... strings
53 ;; "on top", 10) ... (multiline-)comments
54
55 ;; One should note 'font-lock-multiline' has been possible since Emacs 21.1.
56 ;; See, e.g., text in "http://emacs.kldp.org/emacs-21.1/etc/NEWS".
57
58 ;; ... identifiers (defined above, see iregex)
59       (cons (concat "\\(\\([_^-]?\\(" iregex "\\)\\)+\\)\\($\\|[] \t(~{}>\\\\_()^*-]\\)") '(1 font-lock-function-name-face))
60
61 ;; ... keywords (defined above, see kwregex)
62       (cons (concat "\\(\\([_^-]?\\(" kwregex "\\)\\)+\\)\\($\\|[] \t(~{}>\\\\_()^*-]\\)") '(1 font-lock-keyword-face))
63
64 ;; ... user defined identifiers \[a-zA-Z]+, but not \breve or \longa (durations)
65       '("\\([_^-]?\\\\\\([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)
66
67 ;; ... the left side of '=' -mark
68       '("\\([_a-zA-Z.0-9-]+\\)[ \t]*=[ \t]*" 1 font-lock-variable-name-face)
69
70 ;; ... the right side of '=' -mark
71       '("[ \t]*=[ \t]*\\([_a-zA-Z.0-9-]+\\)" 1 font-lock-variable-name-face)
72
73 ;; ... reserved words (defined above, see rwregex)
74       (cons (concat "\\(" rwregex "\\)") 'font-lock-variable-name-face)
75
76 ;; ... note or rest with (an accidental and) a duration (multiplied), e.g., b,?16.*3/4
77       '("\\(^\\|[ <\{[~(!)\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)
78 ;; ... note or rest (with an accidental), e.g., b,? -- allows cis\longaX
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]\\)" 2 font-lock-type-face)
80
81 ;; "on top", ... '{[]}'-brackets
82       '("\\([][}{]\\)" 0 font-lock-warning-face t)
83
84 ;; "on top", ... '<>'-brackets, not marcato '->'
85       '("\\(\\(-.\\)+\\|[^-^_]\\)\\([[<>]+\\)" 3 font-lock-warning-face t) 
86
87 ;; "on top", ... ties ~, slurs \( () \), hairpins \<, \>, \! 
88       '("\\(\\\\[(<!>)]\\|[(~)]\\)" 0 font-lock-builtin-face t)
89
90 ;; "on top", ... (multiline-)scheme: try find slurs up to 7th
91       '("[_^-]?#\\(#[ft]\\|-?[0-9.]+\\|\"[^\"]*\"\\|['`]?[a-zA-Z-:]+\\|['`]?([^()]*\\(([^()]*\\(([^()]*\\(([^()]*\\(([^()]*\\(([^()]*\\(([^)]*)[^()]*\\)*)[^()]*\\)*)[^()]*\\)*)[^()]*\\)*)[^()]*\\)*)[^()]*\\)*[^)]*)\\)" 0 font-lock-string-face t)
92
93 ;; "on top", ... strings
94       '("\\([_^-]?\"\\([^\"\\\\]\\|\\\\.\\|\\\\\n\\)*\"\\)" 0 font-lock-string-face t)
95
96 ;; "on top", ... (multiline-)comments
97       '("\\(%\\({[^%]*%\\(}\\|\\([^}][^%]*%\\)+}\\)\\|.*\\)\\)" 0 font-lock-comment-face t)
98
99       )
100     )
101   "Additional expressions to fontify in LilyPond mode.")
102
103 ;; define a mode-specific abbrev table for those who use such things
104 (defvar LilyPond-mode-abbrev-table nil
105   "Abbrev table in use in `LilyPond-mode' buffers.")
106
107 (define-abbrev-table 'LilyPond-mode-abbrev-table nil)
108
109 (defvar LilyPond-mode-syntax-table nil
110   "Syntax table used in `LilyPond-mode' buffers.")
111
112 ;;
113 (if LilyPond-mode-syntax-table
114     ()
115   (setq LilyPond-mode-syntax-table (make-syntax-table))
116   (mapcar (function
117            (lambda (x) (modify-syntax-entry
118                         (car x) (cdr x) LilyPond-mode-syntax-table)))
119           '(( ?\( . "." ) ( ?\) . "." ) 
120             ( ?\[ . "(]" ) ( ?\] . ")[" ) ;; all the other paren characters are now handled by          
121             ( ?\{  .  ". 2b" )             ;; lily-specific indenting/matching code in lilypond-indent.el 
122             ( ?\}  .  ". 4b" )              
123             ( ?\< . "." )( ?\> . ".") 
124             ( ?\$ . "." ) ( ?\& . "." )
125             ( ?\* . "." ) ( ?\+ . "." )
126             ( ?\/ . "." )  ( ?\= . "." )
127             ( ?\| . "." ) (?\\ . "\\" )
128             ( ?\- . "." ) ( ?\_ . "." ) ( ?\^ . "." ) ; accent positioners: puctuation characters
129             ( ?\' . "w") ( ?\, . "w") ; transposing octaves, parts of words (notes)
130             ( ?\" . "\"" ) ; string quote characters 
131             ( ?\%  .  "< 1b3b" ) ; (block-)comment starter (or ender)
132             ( ?\n . ">") ; newline: comment ender
133             ( ?\r . ">") ; formfeed: comment ender
134             ))
135   )
136