From 63fef2690828e4a74b9b80fe09a85b9f88cd1f99 Mon Sep 17 00:00:00 2001 From: Heikki Junes Date: Sat, 23 Nov 2002 11:42:17 +0000 Subject: [PATCH] * autocompletion: deletes end-of-word, inserts try-completion and shows all-completions. --- ChangeLog | 5 +++++ lilypond-mode.el | 45 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index eace566172..c4fc9f3d9e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2002-11-23 Heikki Junes + + * lilypond-mode.el (LilyPond-autocompletion): deletes end-of-word, + inserts try-completion and shows all-completions. + 2002-11-22 Heikki Junes * lilypond-mode.el (LilyPond-words-filename): find lilypond.words diff --git a/lilypond-mode.el b/lilypond-mode.el index 21b6911f46..1cf8b3742c 100644 --- a/lilypond-mode.el +++ b/lilypond-mode.el @@ -641,7 +641,8 @@ command." (interactive) (defun add-dictionary-word (x) (nconc '(("" . 1)) x)) - (if (eq (length (add-dictionary-word ())) 1) ; does not recreate the dict + ; creates dictionary if empty + (if (eq (length (add-dictionary-word ())) 1) (progn (setq fn (LilyPond-words-filename)) (setq b (find-file-noselect fn t t)) @@ -654,25 +655,50 @@ command." (add-dictionary-word (list copy)) ) (kill-buffer b))) - (setq i 0) + + ; search the begin of word (setq beg "") - (setq ch (preceding-char)) + (setq i 0) + (setq ch (char-before (- (point) i))) (while (or (and (>= ch 65) (<= ch 90)) (and (>= ch 97) (<= ch 122))) ; add [A-Z,a-z] until non-alpha (setq beg (concat (char-to-string ch) beg)) (setq i (+ i 1)) (setq ch (char-before (- (point) i))) ) + + ; search the end of word + (setq end "") + (setq j 0) + (setq ch (char-after (+ (point) j))) + (while (or (and (>= ch 65) (<= ch 90)) + (and (>= ch 97) (<= ch 122))) ; add [A-Z,a-z] until non-alpha + (setq end (concat end (char-to-string ch))) + (setq j (+ j 1)) + (setq ch (char-after (+ (point) j)))) + + ; insert try-completion and show all-completions (if (> i 0) (progn + (setq tryc (try-completion beg (add-dictionary-word ()))) + (if (char-or-string-p tryc) + (if (string-equal (concat beg end) tryc) + (goto-char (+ (point) (length end))) + (progn + (delete-region (point) (+ (point) (length end))) + (insert (substring tryc (length beg) nil)))) + (progn + (delete-region (point) (+ (point) (length end))) + (font-lock-fontify-buffer))) + + (setq others "") (setq co (all-completions beg (add-dictionary-word ()))) - ; the completions are known already co, currently only show them - ; later, one of them could be interactively added (while (> (length co) 0) - (sit-for 0 500 1) - (message (car co)) - (setq co (cdr co)))))) - + (setq others (concat others "\"" (car co) "\" ")) + (setq co (cdr co))) + (message others) + (sit-for 0 100 1)))) + (defun LilyPond-insert-string (pre) "Insert text to the buffer." (interactive) @@ -784,6 +810,7 @@ command." [ "\\notes..." LilyPond-insert-tag-notes t] [ "\\score..." LilyPond-insert-tag-score t] ["Quick Notes" LilyPond-quick-note-insert t] + ["Autocompletion" LilyPond-autocompletion t] )) '(("Miscellaneous" ["Uncomment Region" LilyPond-un-comment-region t] -- 2.39.5