From bf7b0be7b00cb50950ebc3a7d33e17cf68e5cbe7 Mon Sep 17 00:00:00 2001
From: Heikki Junes <heikki.junes@hut.fi>
Date: Sat, 2 Aug 2003 09:31:50 +0000
Subject: [PATCH] repeating last tag insertion.

---
 ChangeLog        |  7 ++++++-
 lilypond-mode.el | 30 ++++++++++++++++++++++++------
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index daf2d919e6..a0969db0fc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2003-08-02  Heikki Junes <hjunes@cc.hut.fi>
+
+	* lilypond-mode.el (LilyPond-insert-tag-current): new function,
+	which repeats the tag insertion selected from "Insert tag" menu.
+
 2003-08-02  Han-Wen Nienhuys  <hanwen@cs.uu.nl>
 
 	* input/trip.ly: remove
@@ -14,7 +19,7 @@
 
 2003-08-01  Heikki Junes <hjunes@cc.hut.fi>
 
-        * lilypond-mode.el: Add each word to regexps only once.
+	* lilypond-mode.el: Add each word to regexps only once.
 
 	* lilypond-mode.el (LilyPond-insert-tag): add new function, which 
 	is based on the syntax definitions in lilypond.words. Remove all 
diff --git a/lilypond-mode.el b/lilypond-mode.el
index 278afe01cf..bfdf571b45 100644
--- a/lilypond-mode.el
+++ b/lilypond-mode.el
@@ -88,6 +88,9 @@ Finds file lilypond-words from load-path."
 	(LilyPond-add-dictionary-word (list copy)))
       (kill-buffer b)))
 
+(defvar LilyPond-insert-tag-current ""
+  "The last command selected from the LilyPond-Insert -menu.")
+
 (defconst LilyPond-menu-keywords 
   (let ((wordlist '()) ; add syntax entries to lilypond.words
 	(co (all-completions "" (LilyPond-add-dictionary-word ())))
@@ -699,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)
@@ -809,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)))
@@ -913,7 +928,7 @@ command."
 
 (defun LilyPond-menu-keywords (arg)
   "Make vector for LilyPond-mode-menu."
-  (vector arg (list 'LilyPond-insert-tag arg)))
+  (vector arg (list 'LilyPond-insert-tag-current arg) :style 'radio :selected (list 'eq 'LilyPond-insert-tag-current arg)))
 
 ;;; LilyPond-mode-menu should not be interactive, via "M-x LilyPond-<Tab>"
 (easy-menu-define LilyPond-mode-menu
@@ -921,8 +936,11 @@ 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 "-----"
+		      (mapcar 'LilyPond-menu-keywords 
+			      (reverse LilyPond-menu-keywords))))))
 	  '(("Miscellaneous"
 	     ["Autocompletion"   LilyPond-autocompletion t]
 	     ["(Un)comment Region" LilyPond-comment-region t]
-- 
2.39.5