From 1f27aa54a0fcb956de0d7d8371c487d7790ebe3f Mon Sep 17 00:00:00 2001 From: Heikki Junes Date: Thu, 18 Sep 2003 20:48:44 +0000 Subject: [PATCH] * buildscripts/lilypond.words.py: extract note names. * lilypond-mode.el: take note names from lilypond.words -file. small fix in the use of string-match. * lilypond-font-lock.el: use lilypond.words for note names, add maxima to note a duration. --- ChangeLog | 10 ++++++++ buildscripts/lilypond.words.py | 47 ++++++++++++++++++++++++++++++++++ lilypond-font-lock.el | 27 +++++++++++-------- lilypond-mode.el | 32 ++++++++++++++++++++--- 4 files changed, 101 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3fd2b92780..bad9fb76a4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2003-09-18 Heikki Junes + + * buildscripts/lilypond.words.py: extract note names. + + * lilypond-mode.el: take note names from lilypond.words -file. + small fix in the use of string-match. + + * lilypond-font-lock.el: use lilypond.words for note names, add + maxima to note a duration. + 2003-09-18 Han-Wen Nienhuys * debian/rules: small corrections in the (Pedro K) diff --git a/buildscripts/lilypond.words.py b/buildscripts/lilypond.words.py index 32fcbf2f4d..c21202b051 100755 --- a/buildscripts/lilypond.words.py +++ b/buildscripts/lilypond.words.py @@ -74,6 +74,53 @@ for name in [ outlines = outlines + [prekw + m.group(2)] F.close() +# more identifiers +for name in [ +'ly/declarations-init.ly', +'ly/paper11-init.ly', +'ly/paper13-init.ly', +'ly/paper16-init.ly', +'ly/paper19-init.ly', +'ly/paper20-init.ly', +'ly/paper23-init.ly', +'ly/paper26-init.ly', +'ly/paper-as5-init.ly', +'ly/paper-as9-init.ly', +'ly/paper-init.ly', +'ly/params-init.ly', +'ly/params-as-init.ly', +]: + F = open(name, 'r') + for line in F.readlines(): + m = re.search(r"^(\s*)([a-zA-Z]+)(\s*=)",line) + if m: + outlines = outlines + [prekw + m.group(2)] + F.close() + +# note names +for name in [ +'ly/catalan.ly', +'ly/deutsch.ly', +'ly/drumpitch-init.ly', +'ly/english.ly', +'ly/espanol.ly', +'ly/italiano.ly', +'ly/nederlands.ly', +'ly/norsk.ly', +'ly/suomi.ly', +'ly/svenska.ly', +]: + F = open(name, 'r') + for line in F.readlines(): + for pattern in [ + r"^(\s*\()([a-z]+)([^l]+ly:make-pitch)", + ]: + m = re.search(pattern,line) + if m: + print(m.group(2)) + outlines = outlines + ['' + m.group(2)] + F.close() + # reserved words for name in [ 'ly/engraver-init.ly', diff --git a/lilypond-font-lock.el b/lilypond-font-lock.el index cb07b331d7..511db9e388 100644 --- a/lilypond-font-lock.el +++ b/lilypond-font-lock.el @@ -5,14 +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.25 -;; Last Modified: 20JUL2003 +;; Version: 1.9.7 +;; Last Modified: 18SEP2003 ;; Keywords: lilypond languages music notation ;; This software is provided as-is, without express or implied @@ -31,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 @@ -64,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) @@ -76,10 +80,11 @@ ;; ... 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. @@ -95,7 +100,7 @@ ;; "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, also as postfix syntax '-*': ;; - slurs ( ), \( \), [-^_][()] diff --git a/lilypond-mode.el b/lilypond-mode.el index 2a55aece08..8672c1f239 100644 --- a/lilypond-mode.el +++ b/lilypond-mode.el @@ -115,7 +115,11 @@ Finds file lilypond-words from load-path." (setq currword (car co)) (if (> (length currword) 1) (if (and (string-equal "\\" (substring currword 0 1)) - (not (string-match "[^a-zA-Z-]" (substring currword 1))) + (progn (string-match "[a-z-]+" currword) + (= (match-end 0) (length currword))) + (not (string-equal "\\longa" currword)) + (not (string-equal "\\breve" currword)) + (not (string-equal "\\maxima" currword)) (string-equal (downcase currword) currword)) (add-to-list 'wordlist currword))) (if (string-equal "-" (car (setq co (cdr co)))) @@ -132,7 +136,8 @@ Finds file lilypond-words from load-path." (setq currword (car co)) (if (> (length currword) 1) (if (and (string-equal "\\" (substring currword 0 1)) - (not (string-match "[^a-zA-Z-]" (substring currword 1))) + (progn (string-match "[a-zA-Z-]+" currword) + (= (match-end 0) (length currword))) (not (string-equal (downcase currword) currword))) (add-to-list 'wordlist currword))) (if (string-equal "-" (car (setq co (cdr co)))) @@ -141,14 +146,33 @@ Finds file lilypond-words from load-path." wordlist)) "LilyPond \\Identifiers") -(defconst LilyPond-reserved-words +(defconst LilyPond-Capitalized-Reserved-Words (let ((wordlist '("Staff")) ; add ReservedWords to lilypond.words (co (all-completions "" (LilyPond-add-dictionary-word ())))) (progn (while (> (length co) 0) (setq currword (car co)) (if (> (length currword) 0) - (if (not (string-match "[^a-zA-Z]" currword)) + (if (and (progn (string-match "[a-zA-Z_]+" currword) + (= (match-end 0) (length currword))) + (not (string-equal (downcase currword) currword))) + (add-to-list 'wordlist currword))) + (if (string-equal "-" (car (setq co (cdr co)))) + (while (and (> (length co) 0) + (not (string-equal "-" (car (setq co (cdr co))))))))) + wordlist)) + "LilyPond ReservedWords") + +(defconst LilyPond-non-capitalized-reserved-words + (let ((wordlist '("c")) ; add note names lilypond.words + (co (all-completions "" (LilyPond-add-dictionary-word ())))) + (progn + (while (> (length co) 0) + (setq currword (car co)) + (if (> (length currword) 0) + (if (and (progn (string-match "[a-z]+" currword) + (= (match-end 0) (length currword))) + (string-equal (downcase currword) currword)) (add-to-list 'wordlist currword))) (if (string-equal "-" (car (setq co (cdr co)))) (while (and (> (length co) 0) -- 2.39.2