]> git.donarmstrong.com Git - lilypond.git/blobdiff - lilypond-mode.el
rename generated file lilypond.words to lilypond.words.el.
[lilypond.git] / lilypond-mode.el
index bfdf571b45e73434b69b9f08c6c1d69d4a3de8b8..60e4e6ebb1192c25809c427a7527129350ddd05a 100644 (file)
@@ -19,7 +19,7 @@
 (require 'easymenu)
 (require 'compile)
 
-(defconst LilyPond-version "1.7.30"
+(defconst LilyPond-version "1.8.0"
   "`LilyPond-mode' version number.")
 
 (defconst LilyPond-help-address "bug-lilypond@gnu.org"
 
 (defun LilyPond-words-filename ()
   "The file containing LilyPond \keywords \Identifiers and ReservedWords.
-Finds file lilypond-words from load-path."
+Finds file lilypond-words.el from load-path."
   (let ((fn nil)
        (lp load-path)
-       (words-file "lilypond.words"))
+       (words-file "lilypond.words.el"))
     (while (and (> (length lp) 0) (not fn))
       (setq fn (concat (car lp) "/" words-file))
       (if (not (file-readable-p fn)) 
          (progn (setq fn nil) (setq lp (cdr lp)))))
     (if (not fn)
-       (progn (message "Warning: `lilypond.words' not found in `load-path'. See `lilypond-init.el'.")
+       (progn (message "Warning: `lilypond.words.el' not found in `load-path'. See `lilypond-init.el'.")
               (sit-for 5 0)))
     fn))
 
@@ -92,7 +92,7 @@ Finds file lilypond-words from load-path."
   "The last command selected from the LilyPond-Insert -menu.")
 
 (defconst LilyPond-menu-keywords 
-  (let ((wordlist '()) ; add syntax entries to lilypond.words
+  (let ((wordlist '())
        (co (all-completions "" (LilyPond-add-dictionary-word ())))
        (currword ""))
     (progn
@@ -103,11 +103,11 @@ Finds file lilypond-words from load-path."
              (add-to-list 'wordlist currword)
              (while (and (> (length co) 0)
                          (not (string-equal "-" (car (setq co (cdr co))))))))))
-      wordlist))
+      (reverse wordlist)))
   "Keywords inserted from LilyPond-Insert-menu.")
 
 (defconst LilyPond-keywords
-  (let ((wordlist '("\\score")) ; add \keywords to lilypond.words
+  (let ((wordlist '("\\score"))
        (co (all-completions "" (LilyPond-add-dictionary-word ())))
        (currword ""))
     (progn
@@ -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))))
@@ -125,14 +129,15 @@ Finds file lilypond-words from load-path."
   "LilyPond \\keywords")
 
 (defconst LilyPond-identifiers 
-  (let ((wordlist '("\\voiceOne")) ; add \Identifiers to lilypond.words
+  (let ((wordlist '("\\voiceOne"))
        (co (all-completions "" (LilyPond-add-dictionary-word ()))))
     (progn
       (while (> (length co) 0)
        (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 
-  (let ((wordlist '("Staff")) ; add ReservedWords to lilypond.words
+(defconst LilyPond-Capitalized-Reserved-Words 
+  (let ((wordlist '("Staff"))
+       (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-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"))
        (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-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)
@@ -368,11 +392,11 @@ in LilyPond-include-path."
   ;; Should expand this to include possible keyboard shortcuts which
   ;; could then be mapped to define-key and menu.
   `(
-    ("LilyPond" . ("lilypond %s" . "LaTeX"))
+    ("Raw LilyPond" . ("lilypond-bin %s" . "LaTeX"))
     ("TeX" . ("tex '\\nonstopmode\\input %t'" . "View"))
 
-    ("2Dvi" . ("ly2dvi %s" . "View"))
-    ("2PS" . ("ly2dvi -P %s" . "ViewPS"))
+    ("2Dvi" . ("lilypond %s" . "View"))
+    ("2PS" . ("lilypond -P %s" . "ViewPS"))
     ("2Midi" . ("lilypond -m %s" . "View"))
 
     ("Book" . ("lilypond-book %x" . "LaTeX"))
@@ -823,7 +847,7 @@ command."
     (message "No tag was selected from LilyPond->Insert tag-menu.")))
 
 (defun LilyPond-insert-tag ()
-  "Insert syntax for given tag. The definitions are in lilypond.words."
+  "Insert syntax for given tag. The definitions are in LilyPond-words-filename."
   (interactive)
   (setq b (find-file-noselect (LilyPond-words-filename) t t))
   (let ((word LilyPond-insert-tag-current)
@@ -926,10 +950,33 @@ command."
          '([ "Midi all" LilyPond-command-all-midi t])
          ))
 
-(defun LilyPond-menu-keywords (arg)
-  "Make vector for LilyPond-mode-menu."
+(defun LilyPond-menu-keywords-item (arg)
+  "Make vector for LilyPond-mode-keywords."
   (vector arg (list 'LilyPond-insert-tag-current arg) :style 'radio :selected (list 'eq 'LilyPond-insert-tag-current arg)))
 
+(defun LilyPond-menu-keywords ()
+  "Make Insert Tag menu. 
+
+The Insert Tag -menu is splitted into parts if it is long enough."
+
+  (let ((li (mapcar 'LilyPond-menu-keywords-item LilyPond-menu-keywords))
+       (w (round (sqrt (length LilyPond-menu-keywords))))
+       (splitted '())
+       (imin 0) imax lw rw)
+    (while (< imin (length LilyPond-menu-keywords))
+      (setq imax (- (min (+ imin w) (length LilyPond-menu-keywords)) 1))
+      (setq lw (nth imin LilyPond-menu-keywords)) 
+      (setq rw (nth imax LilyPond-menu-keywords))
+      (add-to-list 'splitted
+         (let ((l (list (concat (substring lw 0 (min 7 (length lw))) 
+                               " ... " 
+                               (substring rw 0 (min 7 (length rw)))))))
+          (while (<= imin imax)
+            (add-to-list 'l (nth imin li))
+            (setq imin (1+ imin)))
+          (reverse l))))
+    (if (> (length LilyPond-menu-keywords) 12) (reverse splitted) li)))
+
 ;;; LilyPond-mode-menu should not be interactive, via "M-x LilyPond-<Tab>"
 (easy-menu-define LilyPond-mode-menu
   LilyPond-mode-map
@@ -939,8 +986,7 @@ command."
          (list (cons "Insert tag" 
                 (cons ["Previously selected" LilyPond-insert-tag-current t] 
                 (cons "-----"
-                     (mapcar 'LilyPond-menu-keywords 
-                             (reverse LilyPond-menu-keywords))))))
+                     (LilyPond-menu-keywords)))))
          '(("Miscellaneous"
             ["Autocompletion"   LilyPond-autocompletion t]
             ["(Un)comment Region" LilyPond-comment-region t]