From 837aa14695cf84b58b60e7a25c63056406f99b42 Mon Sep 17 00:00:00 2001
From: Heikki Junes <heikki.junes@hut.fi>
Date: Fri, 22 Nov 2002 01:45:19 +0000
Subject: [PATCH] Lilypond-mode.el (LilyPond-words-filename): find
 lilypond.words from load-path.

---
 ChangeLog        |  5 +++++
 lilypond-mode.el | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index dbd238a0f3..ff63924c90 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2002-11-22  Heikki Junes <hjunes@cc.hut.fi>
+
+	* lilypond-mode.el (LilyPond-words-filename): find lilypond.words
+	from load-path.
+	
 2002-11-21  Han-Wen Nienhuys  <hanwen@cs.uu.nl>
 
 	* lily/parser.yy (tempo_event): use tempo-unit for \tempo
diff --git a/lilypond-mode.el b/lilypond-mode.el
index 0240d93553..22165e0c45 100644
--- a/lilypond-mode.el
+++ b/lilypond-mode.el
@@ -48,6 +48,17 @@
   :type 'string
   :group 'LilyPond)
 
+(defun LilyPond-words-filename ()
+  "The file containing LilyPond \keywords \Identifiers and ReservedWords.
+Finds file lilypond-words from load-path."
+  (let ((fn nil)
+	(lp load-path)
+	(words-file "lilypond.words"))
+    (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)))))
+    fn))
 
 (defun LilyPond-check-files (derived originals extensions)
   "Check that DERIVED is newer than any of the ORIGINALS.
@@ -523,6 +534,7 @@ command."
   (define-key LilyPond-mode-map ")" 'LilyPond-electric-close-paren)
   (define-key LilyPond-mode-map ">" 'LilyPond-electric-close-paren)
   (define-key LilyPond-mode-map "}" 'LilyPond-electric-close-paren)
+  (define-key LilyPond-mode-map "\C-x\C-t" 'LilyPond-autocompletion)
   )
 
 ;;; Menu Support
@@ -624,6 +636,31 @@ command."
 	     (message "Remember to add all other details as well.") (sit-for 5 0 1)))
     )))
 
+(defun LilyPond-autocompletion ()
+  "Show completions in mini-buffer for the given word."
+  (interactive)
+  (setq fn (LilyPond-words-filename))
+  (setq b (find-file-noselect fn))
+  (setq m (set-marker (make-marker) 1 (get-buffer b)))
+  (defun add-dictionary-word (x)
+    (nconc '(("" . 1)) x))
+  (setq i 1)
+  (while (> (buffer-size b) (marker-position m))
+    (setq i (+ i 1))
+    (setq copy (copy-alist (list (eval (symbol-name (read m))))))
+    (setcdr copy i)
+    (add-dictionary-word (list copy))
+    )
+  (setq ch (preceding-char))
+;  (if (or (and (>= ch 65) (<= ch 90)) 
+;	  (and (>= ch 97) (<= ch 122))) ; A-Z,a-z
+;      (message "yes") (message "no"))
+  (setq co (all-completions (char-to-string ch) (add-dictionary-word ())))
+  (while (> (length co) 0)
+    (message (car co)) 
+    (sit-for 0 500 1)
+    (setq co (cdr co))))
+
 (defun LilyPond-insert-string (pre)
   "Insert text to the buffer."
   (interactive)
-- 
2.39.5