X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lilypond-font-lock.el;h=511db9e3882d306762476e6499fe2598c494793a;hb=453dee171b167f76530206b484cab6c3a43f5f4d;hp=b60b6579e791495f35a476a55fc81ee8e46a88e5;hpb=5f4c723f182730bd4b82064c9d21c91c4e218bdc;p=lilypond.git diff --git a/lilypond-font-lock.el b/lilypond-font-lock.el index b60b6579e7..511db9e388 100644 --- a/lilypond-font-lock.el +++ b/lilypond-font-lock.el @@ -5,13 +5,15 @@ ;; 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 +;; * File lilypond.words contains \keywords, \Identifiers and +;; ReservedWords notenames. +;; * context-dependent syntax-tables ;; Author: 1997: Han-Wen Nienhuys ;; Author: 1995-1996 Barry A. Warsaw ;; 1992-1994 Tim Peters ;; Created: Feb 1992 -;; Version: 1.7.18 -;; Last Modified: 6MAY2003 +;; Version: 1.9.7 +;; Last Modified: 18SEP2003 ;; Keywords: lilypond languages music notation ;; This software is provided as-is, without express or implied @@ -30,7 +32,10 @@ (defconst LilyPond-font-lock-keywords (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 "\\|")) + (ncrwregex (mapconcat (lambda (x) (concat "" x)) LilyPond-non-capitalized-reserved-words "\\|")) + (rwregex (mapconcat (lambda (x) (concat "" x)) LilyPond-Capitalized-Reserved-Words "\\|")) + (duration "\\([ \t]*\\(\\\\breve\\|128\\|6?4\\|3?2\\|16?\\|8\\)[.]*\\([ \t]*[*][ \t]*[0-9]+\\(/[1-9][0-9]*\\)?\\)?\\)") + (longduration "\\([ \t]*\\(\\\\\\(longa\\|breve\\|maxima\\)\\)[.]*\\([ \t]*[*][ \t]*[0-9]+\\(/[1-9][0-9]*\\)?\\)?\\)") ) (list @@ -63,8 +68,8 @@ ;; ... 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) +;; ... user defined identifiers \[a-zA-Z]+ + '("\\([_^-]?\\\\\\([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) @@ -75,37 +80,39 @@ ;; ... 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) +;; ... note or rest with (an accidental and) a duration, e.g., b,?16.*3/4 + (cons (concat "\\(^\\|[ <\{[/~(!)\t\\\|]\\)\\(\\(\\(" ncrwregex "\\)[,']*[?!]?\\|[srR]\\)" duration "?\\)") '(2 font-lock-type-face)) + +;; "on top", ... notes and rests with a long duration + (cons (concat longduration) '(0 font-lock-type-face t)) ;; "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: +;; "on top", ... horizontal grouping, also as postfix syntax '-*': ;; - brackets '{[]}' ;; - ties '~' ;; - ligatures \[, \] - '("\\([][~}{]\\|\\\\[][]\\)" 0 font-lock-warning-face t) + '("\\(-?[][~}{]\\|\\\\[][]\\)" 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) + (cons (concat "\\(\\(-.\\)+\\|[^-^_]\\)\\([<>]+\\(" duration "\\|" longduration "\\)?\\|\\\\\\\\\\)") '(3 font-lock-function-name-face t)) -;; "on top", ... expressional grouping: +;; "on top", ... expressional grouping, also as postfix syntax '-*': ;; - slurs ( ), \( \), [-^_][()] ;; - hairpins \<, \>, \! - '("\\(\\\\[()]\\|[-^_]?[()]\\)" 0 font-lock-builtin-face t) + '("\\(-?\\\\[()]\\|[-^_]?[()]\\)" 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) + '("[_^-]?#\\(#[ft]\\|-?[0-9.]+\\|\"[^\"]*\"\\|['`]?[a-zA-Z:-]+\\|['`]?([^()]*\\(([^()]*\\(([^()]*\\(([^()]*\\(([^()]*\\(([^()]*\\(([^)]*)[^()]*\\)*)[^()]*\\)*)[^()]*\\)*)[^()]*\\)*)[^()]*\\)*)[^()]*\\)*[^)]*)\\)" 0 font-lock-string-face t) -;; "on top", ... strings - '("\\([_^-]?\"\\([^\"\\\\]\\|\\\\.\\|\\\\\n\\)*\"\\)" 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) @@ -123,24 +130,14 @@ (defvar LilyPond-mode-syntax-table nil "Syntax table used in `LilyPond-mode' buffers.") -(if LilyPond-mode-syntax-table - () +(defun LilyPond-mode-set-syntax-table (&optional not-punct) + "Change syntax table according to the argument `not-punct' which contains characters which are given a context dependent non-punctuation syntax: parentheses may be set to parenthesis syntax and characters `-', `^' and `_' may be set to escape syntax." + (if (not not-punct) (setq not-punct '())) (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))) + (let ((defaults '( - ;; also '['- and ']'-slurs should be handled by lilypond-indent.el - ;; in order to match also '\['- and '\]'-slurs in ligatures - ( ?\[ . "(]" ) ( ?\] . ")[" ) ; handled by the syntax table - ;; all the other paren characters are now handled by - ;; lily-specific indenting/matching code in lilypond-indent.el - ( ?\( . "." ) ( ?\) . "." ) - ( ?\< . "." )( ?\> . ".") - ( ?\{ . ". 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 + ;; NOTE: Emacs knows only "13"-style (used), XEmacs knows also "1b3b", etc. + ( ?\% . "< 13" ) ; comment starter, 1st char in block-comments ( ?\n . ">") ; newline: comment ender ( ?\r . ">") ; formfeed: comment ender ( ?\\ . "\\" ) ; escape characters (as '\n' in strings) @@ -151,7 +148,53 @@ ( ?\$ . "." ) ( ?\& . "." ) ( ?\* . "." ) ( ?\+ . "." ) ( ?\/ . "." ) ( ?\= . "." ) ( ?\| . "." ) ; bar line - ( ?\- . "." ) ( ?\_ . "." ) ( ?\^ . "." ) ; accent positioners - )) - ) - + ))) + ;; all the paren characters are now handled by lily-specific indenting/matching code in lilypond-indent.el + (if (or (memq ?\{ not-punct) (memq ?\} not-punct)) + (setq defaults (cons '( ?\{ . "(} 2" ) (cons '( ?\} . "){ 4" ) defaults))) ; begin and end of a block-comment + (setq defaults (cons '( ?\{ . ". 2" ) (cons '( ?\} . ". 4" ) defaults)))) ; begin and end of a block-comment + (if (or (memq ?\[ not-punct) (memq ?\] not-punct)) + (setq defaults (cons '( ?\[ . "(]" ) (cons '( ?\] . ")[" ) defaults))) + (setq defaults (cons '( ?\[ . "." ) (cons '( ?\] . "." ) defaults)))) + (if (or (memq ?\< not-punct) (memq ?\> not-punct)) + (setq defaults (cons '( ?\< . "(>" ) (cons '( ?\> . ")<" ) defaults))) + (setq defaults (cons '( ?\< . "." ) (cons '( ?\> . "." ) defaults)))) + (if (or (memq ?\( not-punct) (memq ?\) not-punct)) + (setq defaults (cons '( ?\( . "()" ) (cons '( ?\) . ")(" ) defaults))) + (setq defaults (cons '( ?\( . "." ) (cons '( ?\) . "." ) defaults)))) + ;; In LilyPond the following chars serve as escape chars, e.g., c^> d-) e_( , + ;; but they may be set to punctuation chars, since inside strings they should not act as escape chars + (setq defaults (cons (if (memq ?\- not-punct) '( ?\- . "\\" ) '( ?\- . "." ) ) defaults)) + (setq defaults (cons (if (memq ?\^ not-punct) '( ?\^ . "\\" ) '( ?\^ . "." ) ) defaults)) + (setq defaults (cons (if (memq ?\_ not-punct) '( ?\_ . "\\" ) '( ?\_ . "." ) ) defaults)) + (mapcar (function + (lambda (x) (modify-syntax-entry + (car x) (cdr x) LilyPond-mode-syntax-table))) + defaults) + (set-syntax-table LilyPond-mode-syntax-table))) + +(defun LilyPond-mode-context-set-syntax-table () + "Change syntax table according to current context." + (interactive) + ;; default syntax table sets parentheses to punctuation characters + (LilyPond-mode-set-syntax-table) + ;; find current context + (setq context (parse-partial-sexp (point-min) (point))) + (cond ((nth 3 context)) ; inside string + ((nth 4 context)) ; inside a comment + ((eq (char-syntax (char-before (point))) ?\\)) ; found escape-char + ((and (eq (char-syntax (char-before (- (point) 1))) ?\\) + (memq (char-before (point)) '( ?\) ?\] )))) ; found escape-char + ((memq (char-before (point)) '( ?\) )) + (LilyPond-mode-set-syntax-table '( ?\( ?\) ))) + ((memq (char-before (point)) '( ?\] )) + (LilyPond-mode-set-syntax-table '( ?\[ ?\] ))) + ((memq (char-before (point)) '( ?\> ?\} )) + (LilyPond-mode-set-syntax-table '( ?\< ?\> ?\{ ?\} ?\^ ?\- ?\_ ))) + ((memq (char-after (point)) '( ?\( )) + (LilyPond-mode-set-syntax-table '( ?\( ?\) ))) + ((memq (char-after (point)) '( ?\[ )) + (LilyPond-mode-set-syntax-table '( ?\[ ?\] ))) + ((memq (char-after (point)) '( ?\< ?\{ )) + (LilyPond-mode-set-syntax-table '( ?\< ?\> ?\{ ?\} ?\^ ?\- ?\_ ))) + ))