From 7ed22dee4f254d7af4223213dd8c05b00ca8429d Mon Sep 17 00:00:00 2001 From: Florian Ragwitz Date: Tue, 28 Sep 2010 21:24:45 +0200 Subject: [PATCH] Make completing-read function configurable Also provide some default implementations using completing-read, iswitchb, and ido-completing-read. --- lisp/ChangeLog | 11 ++++++++++ lisp/gnus-util.el | 56 +++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d5546f9..f3e5a54 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,14 @@ +2010-09-28 Florian Ragwitz + + * gnus-util.el (gnus-use-ido): Removed. + (gnus-std-completing-read): Add wrapper around completing-read. + (gnus-icompleting-read): Add wrapper around ibuffer-read-buffer. + (gnus-ido-completing-read): Add wrapper around ido-completing-read. + (gnus-completing-read-function): Add to chose from the above completion + functions or to provide a custom one. + (gnus-completing-read): Use the completing-read function configured + with gnus-completing-read-function. + 2010-09-28 Katsumi Yamaoka * mail-source.el (mail-source-report-new-mail) diff --git a/lisp/gnus-util.el b/lisp/gnus-util.el index d188eba..1c390c7 100644 --- a/lisp/gnus-util.el +++ b/lisp/gnus-util.el @@ -44,11 +44,18 @@ (defmacro with-no-warnings (&rest body) `(progn ,@body)))) -(defcustom gnus-use-ido nil - "Whether to use `ido' for `completing-read'." - :version "24.1" +(defcustom gnus-completing-read-function + #'gnus-std-completing-read + "Function to do a completing read." :group 'gnus-meta - :type 'boolean) + :type '(radio (function-item + :doc "Use Emacs' standard `completing-read' function." + gnus-std-completing-read) + (function-item :doc "Use iswitchb's completing-read function." + gnus-icompleting-read) + (function-item :doc "Use ido's completing-read function." + gnus-ido-completing-read) + (function))) (defcustom gnus-completion-styles (if (and (boundp 'completion-styles-alist) @@ -1583,19 +1590,48 @@ SPEC is a predicate specifier that contains stuff like `or', `and', `(,(car spec) ,@(mapcar 'gnus-make-predicate-1 (cdr spec))) (error "Invalid predicate specifier: %s" spec))))) +(defun gnus-std-completing-read (prompt collection &optional require-match + initial-input history def) + (completing-read prompt collection nil require-match + initial-input history def)) + +(defun gnus-icompleting-read (prompt collection &optional require-match + initial-input history def) + (let ((iswitchb-make-buflist-hook + (lambda () + (setq iswitchb-temp-buflist + (let ((choices (append (list) + (when initial-input (list initial-input)) + history collection)) + filtered-choices) + (while choices + (when (and (car choices) (not (member (car choices) filtered-choices))) + (setq filtered-choices (cons (car choices) filtered-choices))) + (setq choices (cdr choices))) + (nreverse filtered-choices)))))) + (unwind-protect + (progn + (when (not iswitchb-mode) + (add-hook 'minibuffer-setup-hook 'iswitchb-minibuffer-setup)) + (iswitchb-read-buffer prompt def require-match)) + (when (not iswitchb-mode) + (remove-hook 'minibuffer-setup-hook 'iswitchb-minibuffer-setup))))) + +(defun gnus-ido-completing-read (prompt collection &optional require-match + initial-input history def) + (ido-completing-read prompt collection nil require-match + initial-input history def)) + (defun gnus-completing-read (prompt collection &optional require-match initial-input history def) - "Call `completing-read' or `ido-completing-read'. -Depends on `gnus-use-ido'." + "Do a completing read with the configured `gnus-completing-read-function'." (let ((completion-styles gnus-completion-styles)) (funcall - (if gnus-use-ido - 'ido-completing-read - 'completing-read) + gnus-completing-read-function (concat prompt (when def (concat " (default " def ")")) ": ") - collection nil require-match initial-input history def))) + collection require-match initial-input history def))) (defun gnus-graphic-display-p () (if (featurep 'xemacs) -- 1.7.1