From 3ec03f7e4696b4af1af7e1a2fef2a64ccb9224c2 Mon Sep 17 00:00:00 2001 From: Leo Liu Date: Sun, 20 Mar 2011 18:35:27 +0800 Subject: [PATCH] New variable completing-read-function to customize completing-read --- etc/NEWS | 3 +++ lisp/ChangeLog | 5 +++++ lisp/ido.el | 8 ++++---- src/ChangeLog | 6 ++++++ src/minibuf.c | 34 +++++++++++++++++++++++++++++++++- 5 files changed, 51 insertions(+), 5 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index ba33263cf44..a7ec965e3d6 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -81,6 +81,9 @@ error, its exit status is 1. ** Completion can cycle, depending on completion-cycle-threshold. +** `completing-read' can be customized using the new variable +`completing-read-function' + ** auto-mode-case-fold is now enabled by default. +++ diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 4e71d355886..fe45788d888 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2011-03-20 Leo + + * ido.el (ido-read-internal): Use completing-read-default. + (ido-completing-read): Fix compatibility with completing-read. + 2011-03-20 Christian Ohler * emacs-lisp/ert.el (ert-run-tests-batch): Remove unused variable. diff --git a/lisp/ido.el b/lisp/ido.el index 2e67e367a8f..2a5c7cf2f0e 100644 --- a/lisp/ido.el +++ b/lisp/ido.el @@ -1983,7 +1983,7 @@ If INITIAL is non-nil, it specifies the initial input string." (setq ido-exit nil) (setq ido-final-text (catch 'ido - (completing-read + (completing-read-default (ido-make-prompt item prompt) '(("dummy" . 1)) nil nil ; table predicate require-match (prog1 ido-text-init (setq ido-text-init nil)) ;initial-contents @@ -4740,13 +4740,13 @@ See `read-directory-name' for additional parameters." (concat ido-current-directory filename))))) ;;;###autoload -(defun ido-completing-read (prompt choices &optional predicate require-match initial-input hist def) +(defun ido-completing-read (prompt choices &optional predicate require-match initial-input hist def inherit-input-method) "Ido replacement for the built-in `completing-read'. Read a string in the minibuffer with ido-style completion. PROMPT is a string to prompt with; normally it ends in a colon and a space. CHOICES is a list of strings which are the possible completions. -PREDICATE is currently ignored; it is included to be compatible - with `completing-read'. +PREDICATE and INHERIT-INPUT-METHOD is currently ignored; it is included + to be compatible with `completing-read'. If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless the input is (or completes to) an element of CHOICES or is null. If the input is null, `ido-completing-read' returns DEF, or an empty diff --git a/src/ChangeLog b/src/ChangeLog index 5aee468d933..d5d1efebef8 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2011-03-20 Leo + + * minibuf.c (completing-read-function): New variable. + (completing-read-default): Rename from completing-read. + (completing-read): Call completing-read-function. + 2011-03-19 Juanma Barranquero * xfaces.c (Fx_load_color_file): diff --git a/src/minibuf.c b/src/minibuf.c index 8ff861b2403..3fbe14e9da0 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -72,6 +72,8 @@ Lisp_Object Qcompletion_ignore_case; Lisp_Object Qminibuffer_completion_table; Lisp_Object Qminibuffer_completion_predicate; Lisp_Object Qminibuffer_completion_confirm; +Lisp_Object Qcompleting_read_default; +Lisp_Object Vcompleting_read_function; Lisp_Object Quser_variable_p; Lisp_Object Qminibuffer_default; @@ -1674,7 +1676,27 @@ If INHERIT-INPUT-METHOD is non-nil, the minibuffer inherits the current input method and the setting of `enable-multibyte-characters'. Completion ignores case if the ambient value of - `completion-ignore-case' is non-nil. */) + `completion-ignore-case' is non-nil. + +See also `completing-read-function'. */) + (Lisp_Object prompt, Lisp_Object collection, Lisp_Object predicate, Lisp_Object require_match, Lisp_Object initial_input, Lisp_Object hist, Lisp_Object def, Lisp_Object inherit_input_method) +{ + Lisp_Object args[9]; + args[0] = Vcompleting_read_function; + args[1] = prompt; + args[2] = collection; + args[3] = predicate; + args[4] = require_match; + args[5] = initial_input; + args[6] = hist; + args[7] = def; + args[8] = inherit_input_method; + return Ffuncall (9, args); +} + +DEFUN ("completing-read-default", Fcompleting_read_default, Scompleting_read_default, 2, 8, 0, + doc: /* Default method for reading from the minibuffer with completion. +See `completing-read' for the meaning of the arguments. */) (Lisp_Object prompt, Lisp_Object collection, Lisp_Object predicate, Lisp_Object require_match, Lisp_Object initial_input, Lisp_Object hist, Lisp_Object def, Lisp_Object inherit_input_method) { Lisp_Object val, histvar, histpos, position; @@ -1972,6 +1994,9 @@ syms_of_minibuf (void) minibuf_save_list = Qnil; staticpro (&minibuf_save_list); + Qcompleting_read_default = intern_c_string ("completing-read-default"); + staticpro (&Qcompleting_read_default); + Qcompletion_ignore_case = intern_c_string ("completion-ignore-case"); staticpro (&Qcompletion_ignore_case); @@ -2116,6 +2141,12 @@ If the value is `confirm-after-completion', the user may exit with an doc: /* Non-nil means completing file names. */); Vminibuffer_completing_file_name = Qnil; + DEFVAR_LISP ("completing-read-function", + &Vcompleting_read_function, + doc: /* The function called by `completing-read' to do the work. +It should accept the same arguments as `completing-read'. */); + Vcompleting_read_function = Qcompleting_read_default; + DEFVAR_LISP ("minibuffer-help-form", Vminibuffer_help_form, doc: /* Value that `help-form' takes on inside the minibuffer. */); Vminibuffer_help_form = Qnil; @@ -2191,4 +2222,5 @@ properties. */); defsubr (&Stest_completion); defsubr (&Sassoc_string); defsubr (&Scompleting_read); + defsubr (&Scompleting_read_default); } -- 2.39.5