From 701c651092d026f3d31016eefc6101f5118562dd Mon Sep 17 00:00:00 2001 From: Chris Mann Date: Wed, 29 Jul 2009 20:28:12 +0930 Subject: [PATCH] Add support for alternate completion functions. Ido now supported. * wesnoth-mode.el (wesnoth-use-alternate-completion): New customisable variable. (wesnoth-completion-method): New macro. (wesnoth-element-completion, wesnoth-insert-tag): Use it. --- wesnoth-mode.el | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/wesnoth-mode.el b/wesnoth-mode.el index d31b880..9e63f28 100644 --- a/wesnoth-mode.el +++ b/wesnoth-mode.el @@ -213,6 +213,19 @@ :type 'boolean :group 'wesnoth-mode) +(defcustom wesnoth-use-alternate-completion 'guess + "Use the specified completion method if it is available. +Possible values are `guess', `ido' and nil. `guess' +checks for packages which provide completion functions, and uses +when available; `ido' will try to use `ido-completing-read'; and +nil will use the built-in `completing-read' function. +Currently ido is the only alternate completion method available. +Patches for other completion functions are welcome." + :type '(choice (const :tag "ido completion" guess) + (const :tag "ido completion" ido) + (const :tag "standard completion" nil)) + :group 'wesnoth-mode) + (defcustom wesnoth-indent-savefile t "Non-nil means to use the current indentation conventions. If nil, use the old convention for indentation. @@ -536,6 +549,21 @@ BOUND is the limit to search backwards." ;;; Insertion and completion +(defmacro wesnoth-completion-method (prompt completions) + "Determine a suitable completion method for use. +See `wesnoth-use-alternate-completion' for more information." + (cond + ((and (featurep 'ido) + (or (eq wesnoth-use-alternate-completion 'ido) + (eq wesnoth-use-alternate-completion 'guess))) + `(ido-completing-read ,prompt ,completions + nil nil element + 'wesnoth-history-list)) + (t + `(completing-read ,prompt ,completions + nil nil element + 'wesnoth-history-list)))) + (defmacro wesnoth-element-completion (completions prompt partial &optional completep) "Process completion of COMPLETIONS, displaying PROMPT. @@ -549,9 +577,7 @@ If COMPLETEP is non-nil, do not prompt if no completion is found." ((and element (eq (try-completion element ,completions) t)) element) ((> (length (all-completions (or element "") ,completions)) 1) - (completing-read ,prompt ,completions - nil nil element - 'wesnoth-history-list)) + (wesnoth-completion-method ,prompt ,completions)) ((= (length ,completions) 1) (car ,completions)) (t @@ -881,8 +907,8 @@ tag should wrap around. TAGNAME is the name of the tag to be inserted." (interactive "Ps") (unless tagname - (setq tagname (completing-read "Tag: " (wesnoth-build-completion 0) - nil nil nil 'wesnoth-history-list))) + (setq tagname (wesnoth-completion-method "Tag: " + (wesnoth-build-completion 0)))) (when (or (not elements) (looking-at (concat "[\t ]*\\(:?\\[/\\|" wesnoth-preprocessor-regexp "\\)"))) -- 2.11.4.GIT