X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lilypond-font-lock.el;h=6e1e6ee91b74015545afca457bbcd445d4f100ab;hb=b9955d706ca6f136b160f0611db85c6bdf0fea9b;hp=1646ad001b158a3c4ec6af5a0fa01a1efd29fcba;hpb=59fa5811ada76ef5b17e1666457e0b63766b598f;p=lilypond.git diff --git a/lilypond-font-lock.el b/lilypond-font-lock.el index 1646ad001b..6e1e6ee91b 100644 --- a/lilypond-font-lock.el +++ b/lilypond-font-lock.el @@ -2,15 +2,16 @@ ;; Copyright (C) 1992,1993,1994 Tim Peters -;; Author: 2001: Heikki Junes -;; * Emacs-mode: new keywords, reserved words, notenames and brackets are -;; font-lock-keywords; implementation encourages spacing/indenting. +;; Author: 2001-2003: Heikki Junes +;; * Emacs-mode: new keywords, reserved words, identifiers, notenames, +;; some dynamics and brackets are font-lock-keywords +;; * File lilypond.words gives keywords, identifiers and reserved words ;; Author: 1997: Han-Wen Nienhuys ;; Author: 1995-1996 Barry A. Warsaw ;; 1992-1994 Tim Peters ;; Created: Feb 1992 -;; Version: 0.0 -;; Last Modified: 1SEP2001 +;; Version: 1.7.20 +;; Last Modified: 9JUN2003 ;; Keywords: lilypond languages music notation ;; This software is provided as-is, without express or implied @@ -24,90 +25,95 @@ ;; ;; TODO: -;; - should handle block comments too. -;; - handle lexer modes (\header, \melodic, \lyric) etc. -;; - indentation +;; - handle lexer modes (\header, \melodic) etc. (defconst LilyPond-font-lock-keywords - (let* ((keywords '( ; need special order due to over[lapping] of words - -"accepts" "addlyrics" "alternative" "apply" "arpeggio" "autoBeamOff" -"autoBeamOn" "autochange" "bar" "BarNumberingStaffContext" "break" -"breathe" "breve" "cadenzaOn" "cadenzaOff" "char" "chord" "chordmodifiers" -"ChordNamesContext" "chordstest" "chords" "clef" "cm" "commandspanrequest" -"consistsend" "consists" "context" "default" "denies" "different" -"dotsBoth" "dotsDown" "dotsUp" "duration" "dynamicscript" "dynamicUp" -"dynamicDown" "dynamicBoth" "EasyNotation" "elementdescriptions" -"emptyText" "extreme" "ex" "fatText" "fermata" "fff" "ff" "f" "font" "foo" -"glissando" "gliss" "grace" "grstaff" "hairyChord" "HaraKiriStaffContext" -"header" "hideStaffSwitch" "include" "in" "key" "linebreak" "longa" -"lyrics" "LyricsContext" "LyricsVoiceContext" "major" "mark" "melismaEnd" -"melisma" "midi" "minor" "mm" "musicalpitch" "m" "name" "newpage" -"noBreak" "noisebeat" "noise" "normalkey" "normalsize" "notenames" "notes" -"n" "onestaff" "oneVoice" "one" "OrchestralScoreContext" "outputproperty" -"override" "paperTwentysix" "paper" "partcombine" "partial" "penalty" -"PianoStaffContext" "pp" "property" "pt" "p" "relative" "remove" "repeat" -"restsII" "rests" "revert" "rhythm" "right" "scales" "scale" "scheme" -"score" "ScoreContext" "scpaper" "scriptBoth" "scriptDown" "scriptUp" -"script" "scscore" "sd" "sequential" "settings" "set" "sfz" "shitfOnnn" -"shitfOnn" "shitfOn" "shitfOff" "showStaffSwitch" "simultaneous" "skip" -"slurBoth" "slurDown" "slurUp" "slurDotted" "slurSolid" "small" -"spanrequest" "specialKey" "staccato" "StaffContext" "staffspace" -"stemBoth" "stemDown" "stemUp" "stpaper" "stscore" "stylesheet" "su" -"tempo" "tenuto" "textII" "textI" "textscript" "thenotes" "ThreadContext" -"threevoice" "tieBoth" "tieDown" "tieDotted" "tieSolid" "tieUp" "times" -"time" "tiny" "touch" "translator" "transpose" "tupletBoth" "tupletDown" -"tupletUp" "twovoicesteminvert" "twovoice" "two" "turnOff" "type" "t" -"unset" "version" "voiceB" "VoiceContext" "voiceC" "voiceD" "voiceE" -"voiceOne" "voiceTwo" "voiceThree" "voiceFour" "zagers" "zager" "zoger" - - )) - - (reservedwords '( - -"bass" "treble" "PianoStaff" - - )) - - (kwregex (mapconcat (lambda (x) (concat "\\\\" x)) keywords "\\|")) - (rwregex (mapconcat (lambda (x) (concat "" x)) reservedwords "\\|")) + (let* ((kwregex (mapconcat (lambda (x) (concat "\\" x)) LilyPond-keywords "\\|")) + (iregex (mapconcat (lambda (x) (concat "\\" x)) LilyPond-identifiers "\\|")) + (rwregex (mapconcat (lambda (x) (concat "" x)) LilyPond-reserved-words "\\|")) ) (list ;; Fonts in use (from GNU Emacs Lisp Reference Manual, elisp.ps): -;; font-lock- comment / string / keyword / builtin / function-name / -;; variable-name / type / constant / warning -face - -;; Using extra spaces was both easier to parse and looks better! -;; highlight note grouping brackets; space around these { [ < brackets > ] } -;; make the text look {less[]erronous} - '("\\([<{[]\\)[ \t]" 1 font-lock-warning-face) - '("\\([\]}>]\\)[ \t]" 1 font-lock-warning-face) - '("^\\([<{[]\\)[ \t]" 1 font-lock-warning-face) - '("^\\([\]}>]\\)[ \t]" 1 font-lock-warning-face) - '("\\([<{[]\\)$" 1 font-lock-warning-face) - '("\\([\]}>]\\)$" 1 font-lock-warning-face) - -;; highlight keywords; space after[ ]these commands /increases/readability - (concat "\\([_^]?\\(" kwregex "\\)\\)[ \t(]") - (concat "\\([_^]?\\(" kwregex "\\)\\)$") - '("\\([_^]?\\\\[a-zA-Z][a-zA-Z]*\\)" 1 font-lock-constant-face) - '("\\([a-zA-Z][_a-zA-Z]*\\)[ \t]*=[ \t]*" 1 font-lock-variable-name-face) - '("[ \t]*=[ \t]*\\([a-zA-Z][_a-zA-Z]*\\)[ \t(]" 1 font-lock-variable-name-face) - '("[ \t]*=[ \t]*\\([a-zA-Z][_a-zA-Z]*\\)$" 1 font-lock-variable-name-face) - -;; other reserved words - (cons (concat "\\(" rwregex "\\) ") 'font-lock-variable-name-face) - (cons (concat "\\(" rwregex "\\)$") 'font-lock-variable-name-face) - -;; highlight note names; separate notes from (other than ')'-type) brackets - '("[ )\t]\\(\\(\\(\\(do\\|re\\|mi\\|fa\\|sol\\|la\\|si\\)\\(b\\|bb\\|d\\|dd\\|s\\|ss\\)?\\)\\|\\([a-hsr]\\(f\\|ff\\|s\\|ss\\|flat\\|flatflat\\|sharp\\|sharpsharp\\|is[s]?\\|is[s]?is[s]?\\|es[s]?\\|es[s]?es[s]?\\)?\\)\\|\\(as\\(as\\|es\\)?\\)\\|\\(es\\(ses\\)?\\)\\|\\(bb\\)\\)[,']*\\(64\\|32\\|16\\|8\\|4\\|2\\|1\\)?[.]*\\)" 1 font-lock-type-face) - - '("\\([(~)]\\)" 1 font-lock-builtin-face) +;; font-lock- (c)omment / (s)tring / (k)eyword / (b)uiltin / (f)unction-name / +;; (v)ariable-name / (t)ype / co(n)stant / (w)arning -face + +;; The order below is designed so that proofreading would be possible. + +;; Fontify... +;; ... (f) identifiers and (k) keywords. +;; ... (n) user defined indetifiers +;; ... (v) the right and the left side of '='-marks. +;; ... (v) reserved words, e.g., FiguredBass. +;; ... (t) notes and rests +;; "on top", ... (s) lyrics-mode +;; "on top", ... (w) horizontal grouping +;; "on top", ... (f) vertical grouping +;; "on top", ... (b) expressional grouping +;; "on top", ... (s) (multiline-)scheme; urgh. one should count the slurs +;; "on top", ... (s) strings +;; "on top", ... (c) (multiline-)comments + +;; One should note 'font-lock-multiline' has been possible since Emacs 21.1. +;; See, e.g., text in "http://emacs.kldp.org/emacs-21.1/etc/NEWS". + +;; ... identifiers (defined above, see iregex) + (cons (concat "\\(\\([_^-]?\\(" iregex "\\)\\)+\\)\\($\\|[] \t(~{}>\\\\_()^*-]\\)") '(1 font-lock-function-name-face)) + +;; ... keywords (defined above, see kwregex) + (cons (concat "\\(\\([_^-]?\\(" kwregex "\\)\\)+\\)\\($\\|[] \t(~{}>\\\\_()^*-]\\)") '(1 font-lock-keyword-face)) + +;; ... user defined identifiers \[a-zA-Z]+, but not \breve or \longa (durations) + '("\\([_^-]?\\\\\\([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) + +;; ... the left side of '=' -mark + '("\\([_a-zA-Z.0-9-]+\\)[ \t]*=[ \t]*" 1 font-lock-variable-name-face) + +;; ... the right side of '=' -mark + '("[ \t]*=[ \t]*\\([_a-zA-Z.0-9-]+\\)" 1 font-lock-variable-name-face) + +;; ... reserved words (defined above, see rwregex) + (cons (concat "\\(" rwregex "\\)") 'font-lock-variable-name-face) + +;; ... note or rest with (an accidental and) a duration (multiplied), e.g., b,?16.*3/4 + '("\\(^\\|[ <\{[/~(!)\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) +;; ... note or rest (with an accidental), e.g., b,? -- allows cis\longaX + '("\\(^\\|[ <\{[/~(!)\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) + +;; "on top", ... lyrics-mode: fontify everything between '<'...'>' or '{'...'}' +; URGH, does not know anything about inner brackets. +; Multiple lines may need refontifying (C-c f). + '("\\(\\\\lyrics[^{<]*\\)\\({[^}]*\\|<[^>]*\\)" 2 font-lock-string-face t) + +;; "on top", ... horizontal grouping, also as postfix syntax '-*': +;; - brackets '{[]}' +;; - ties '~' +;; - ligatures \[, \] + '("\\(-?[][~}{]\\|\\\\[][]\\)" 0 font-lock-warning-face t) + +;; "on top", ... vertical grouping: +;; - '<>'-chord brackets with '\\'-voice sep., not marcato '->' +;; - '<< a b >>8' -chords + '("\\(\\(-.\\)+\\|[^-^_]\\)\\([<>]+\\(\\(128\\|6?4\\|3?2\\|16?\\|8\\|\\\\\\(breve\\|longa\\)\\)[.]*\\([ \t]*[*][ \t]*[0-9]+\\(/[1-9][0-9]*\\)?\\)?\\)?\\|\\\\\\\\\\)" 3 font-lock-function-name-face t) + +;; "on top", ... expressional grouping, also as postfix syntax '-*': +;; - slurs ( ), \( \), [-^_][()] +;; - hairpins \<, \>, \! + '("\\(-?\\\\[()]\\|[-^_]?[()]\\)" 0 font-lock-builtin-face t) + +;; "on top", ... (multiline-)scheme: try find slurs up to 7th + '("[_^-]?#\\(#[ft]\\|-?[0-9.]+\\|\"[^\"]*\"\\|['`]?[a-zA-Z:-]+\\|['`]?([^()]*\\(([^()]*\\(([^()]*\\(([^()]*\\(([^()]*\\(([^()]*\\(([^)]*)[^()]*\\)*)[^()]*\\)*)[^()]*\\)*)[^()]*\\)*)[^()]*\\)*)[^()]*\\)*[^)]*)\\)" 0 font-lock-string-face t) + +;; "on top", ... strings, match also unending strings at eof: +;; if '\n' was not found, it must be '$' which is eof (?). + '("\\([_^-]?\"\\([^\"\\\\]\\|\\\\.\\|\\\\\n\\)*\\(\"\\|$\\)\\)" 0 font-lock-string-face t) + +;; "on top", ... (multiline-)comments + '("\\(%\\({[^%]*%\\(}\\|\\([^}][^%]*%\\)+}\\)\\|.*\\)\\)" 0 font-lock-comment-face t) ) ) - "Additional expressions to highlight in LilyPond mode.") + "Additional expressions to fontify in LilyPond mode.") ;; define a mode-specific abbrev table for those who use such things (defvar LilyPond-mode-abbrev-table nil @@ -118,31 +124,35 @@ (defvar LilyPond-mode-syntax-table nil "Syntax table used in `LilyPond-mode' buffers.") -;; (if LilyPond-mode-syntax-table () (setq LilyPond-mode-syntax-table (make-syntax-table)) + ;; NOTE: Emacs knows only "13"-style (used), XEmacs knows also "1b3b", etc. (mapcar (function (lambda (x) (modify-syntax-entry (car x) (cdr x) LilyPond-mode-syntax-table))) - '(( ?\( . "()" ) ( ?\) . ")(" ) ; need matching parens for inline lisp - ( ?\[ . "." ) ( ?\] . "." ) - ( ?\{ . "(}" ) ( ?\} . "){" ) - ( ?\< . "(>" )( ?\> . ")>") - ( ?\$ . "." ) ( ?\% . "." ) ( ?\& . "." ) - ( ?\* . "." ) ( ?\+ . "." ) ( ?\- . "." ) - ( ?\/ . "." ) ( ?\= . "." ) - ( ?\| . "." ) (?\\ . "\\" ) - ( ?\_ . "." ) - ( ?\' . "w") - ( ?\" . "\"" ) - ( ?\% . "<") - ( ?\n . ">") - -; FIXME -; ( ?% . ". 124b" ) -; ( ?{ . ". 23" ) + '( + ;; all the paren characters are now handled by + ;; lily-specific indenting/matching code in lilypond-indent.el + ;; Emacs' show-paren-function and XEmacs' paren-highlight use + ;; these slur-definitions through Lilypond specific scan-sexps. + ( ?\[ . "(]" ) ( ?\] . ")[" ) + ( ?\( . "()" ) ( ?\) . ")(" ) + ( ?\< . "(>" ) ( ?\> . ")<") + ( ?\{ . "(} 2" ) ; also 2nd char in begin of block-comment + ( ?\} . "){ 4" ) ; also 2nd char in end of block-comment + ( ?\% . "< 13" ) ; comment starter, 1st char in block-comments + ( ?\n . ">") ; newline: comment ender + ( ?\r . ">") ; formfeed: comment ender + ( ?\\ . "\\" ) ; escape characters (as '\n' in strings) + ( ?\" . "\"" ) ; string quote characters + ;; word constituents (e.g., belonging to a note) + ( ?\' . "w") ( ?\, . "w") ; transposing octaves + ;; punctuation characters (separate symbols from another) + ( ?\$ . "." ) ( ?\& . "." ) + ( ?\* . "." ) ( ?\+ . "." ) ( ?\/ . "." ) ( ?\= . "." ) + ( ?\| . "." ) ; bar line + ( ?\- . "." ) ( ?\_ . "." ) ( ?\^ . "." ) ; accent positioners )) - - ) + )