]> git.donarmstrong.com Git - lilypond.git/blobdiff - lilypond-mode.el
*** empty log message ***
[lilypond.git] / lilypond-mode.el
index 399055c94696f546320e1c8a56fd260832313eb4..8672c1f239e42d2bc529fc2096ad40929174920c 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"
@@ -88,27 +88,43 @@ Finds file lilypond-words from load-path."
        (LilyPond-add-dictionary-word (list copy)))
       (kill-buffer b)))
 
-(defconst LilyPond-menu-keywords nil
-  "Keywords which can be inserted from the menu.")
+(defvar LilyPond-insert-tag-current ""
+  "The last command selected from the LilyPond-Insert -menu.")
 
-(defconst LilyPond-keywords 
+(defconst LilyPond-menu-keywords 
+  (let ((wordlist '()) ; add syntax entries to lilypond.words
+       (co (all-completions "" (LilyPond-add-dictionary-word ())))
+       (currword ""))
+    (progn
+      (while (> (length co) 0)
+       (setq currword (car co))
+       (if (string-equal "-" (car (setq co (cdr co))))
+           (progn
+             (add-to-list 'wordlist currword)
+             (while (and (> (length co) 0)
+                         (not (string-equal "-" (car (setq co (cdr co))))))))))
+      (reverse wordlist)))
+  "Keywords inserted from LilyPond-Insert-menu.")
+
+(defconst LilyPond-keywords
   (let ((wordlist '("\\score")) ; add \keywords to lilypond.words
        (co (all-completions "" (LilyPond-add-dictionary-word ())))
        (currword ""))
     (progn
-      (setq LilyPond-menu-keywords '())
       (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-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))))
-           (progn
-             (add-to-list 'LilyPond-menu-keywords currword)
-             (while (and (> (length co) 0)
-                         (not (string-equal "-" (car (setq co (cdr co))))))))))
+           (while (and (> (length co) 0)
+                       (not (string-equal "-" (car (setq co (cdr co)))))))))
       wordlist))
   "LilyPond \\keywords")
 
@@ -120,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))))
@@ -129,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)
@@ -356,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"))
@@ -690,6 +726,7 @@ command."
   (define-key LilyPond-mode-map [(control c) (control return)] 'LilyPond-command-all-midi)
   (define-key LilyPond-mode-map "\C-x\C-s" 'LilyPond-save-buffer)
   (define-key LilyPond-mode-map "\C-cf" 'font-lock-fontify-buffer)
+  (define-key LilyPond-mode-map "\C-ci" 'LilyPond-insert-tag-current)
   ;; the following will should be overriden by Lilypond Quick Insert Mode
   (define-key LilyPond-mode-map "\C-cq" 'LilyPond-quick-insert-mode)
   (define-key LilyPond-mode-map "\C-c;" 'LilyPond-comment-region)
@@ -800,10 +837,21 @@ command."
     (LilyPond-info)
     (Info-index str)))
 
-(defun LilyPond-insert-tag (word)
-  "Insert syntax for given word. The definition is in lilypond.words."
+(defun LilyPond-insert-tag-current (&optional word)
+  "Set the current tag to be inserted."
+  (interactive)
+  (if word
+      (setq LilyPond-insert-tag-current word))
+  (if (memq LilyPond-insert-tag-current LilyPond-menu-keywords)
+      (LilyPond-insert-tag)
+    (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."
+  (interactive)
   (setq b (find-file-noselect (LilyPond-words-filename) t t))
-  (let ((found nil)
+  (let ((word LilyPond-insert-tag-current)
+       (found nil)
        (p nil)
        (query nil)
         (m (set-marker (make-marker) 1 (get-buffer b)))
@@ -902,9 +950,32 @@ command."
          '([ "Midi all" LilyPond-command-all-midi t])
          ))
 
-(defun LilyPond-menu-keywords (arg)
-  "Make vector for LilyPond-mode-menu."
-  (vector arg (list 'LilyPond-insert-tag arg)))
+(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
@@ -912,8 +983,10 @@ command."
   "Menu used in LilyPond mode."
   (append '("LilyPond")
          '(["Add index menu" LilyPond-add-imenu-menu])
-         (list (cons "Insert" (mapcar 'LilyPond-menu-keywords 
-                                      (reverse LilyPond-menu-keywords))))
+         (list (cons "Insert tag" 
+                (cons ["Previously selected" LilyPond-insert-tag-current t] 
+                (cons "-----"
+                     (LilyPond-menu-keywords)))))
          '(("Miscellaneous"
             ["Autocompletion"   LilyPond-autocompletion t]
             ["(Un)comment Region" LilyPond-comment-region t]