]> git.donarmstrong.com Git - lilypond.git/blobdiff - lilypond-mode.el
* scm/chord-name.scm: remove new-chord-name-brew-molecule ; use
[lilypond.git] / lilypond-mode.el
index 399055c94696f546320e1c8a56fd260832313eb4..bc10329dde7ec7043ee55bc58343248d7cc9920d 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,15 +88,29 @@ 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)
@@ -105,10 +119,8 @@ Finds file lilypond-words from load-path."
                     (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")
 
@@ -690,6 +702,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 +813,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 +926,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 +959,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]