From fb30dfd235a7528f77d0e39f737545562e209461 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Mon, 22 Oct 2007 00:20:06 +0000 Subject: [PATCH] Allow minibuffer default to be a list of default values. With empty input use the first element of this list as returned default. (string_to_object): (read_minibuf_noninteractive): If defalt is cons, set val to its car. (read_minibuf): If defalt is cons, set histstring to its car. (Fread_string): If default_value is cons, set val to its car. (Fread_buffer): If def is cons, use its car. (Fcompleting_read): If defalt is cons, set val to its car. --- src/ChangeLog | 11 +++++++++++ src/minibuf.c | 20 +++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 3df88c6f332..1ed1d3a5d38 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2007-10-22 Juri Linkov + + * minibuf.c: Allow minibuffer default to be a list of default values. + With empty input use the first element of this list as returned default. + (string_to_object): + (read_minibuf_noninteractive): If defalt is cons, set val to its car. + (read_minibuf): If defalt is cons, set histstring to its car. + (Fread_string): If default_value is cons, set val to its car. + (Fread_buffer): If def is cons, use its car. + (Fcompleting_read): If defalt is cons, set val to its car. + 2007-10-21 Michael Albinus * fileio.c (Fcopy_file): Call file name handler with preserve_uid_gid. diff --git a/src/minibuf.c b/src/minibuf.c index d3c9eb505b6..377968fab4f 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -257,9 +257,13 @@ string_to_object (val, defalt) GCPRO2 (val, defalt); - if (STRINGP (val) && SCHARS (val) == 0 - && STRINGP (defalt)) - val = defalt; + if (STRINGP (val) && SCHARS (val) == 0) + { + if (STRINGP (defalt)) + val = defalt; + else if (CONSP (defalt) && STRINGP (XCAR (defalt))) + val = XCAR (defalt); + } expr_and_pos = Fread_from_string (val, Qnil, Qnil); pos = XINT (Fcdr (expr_and_pos)); @@ -337,7 +341,7 @@ read_minibuf_noninteractive (map, initial, prompt, backup_n, expflag, /* If Lisp form desired instead of string, parse it. */ if (expflag) - val = string_to_object (val, defalt); + val = string_to_object (val, CONSP (defalt) ? XCAR (defalt) : defalt); return val; } @@ -785,6 +789,8 @@ read_minibuf (map, initial, prompt, backup_n, expflag, histstring = val; else if (STRINGP (defalt)) histstring = defalt; + else if (CONSP (defalt) && STRINGP (XCAR (defalt))) + histstring = XCAR (defalt); else histstring = Qnil; @@ -1102,7 +1108,7 @@ Fifth arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits Qnil, history, default_value, inherit_input_method); if (STRINGP (val) && SCHARS (val) == 0 && ! NILP (default_value)) - val = default_value; + val = CONSP (default_value) ? XCAR (default_value) : default_value; return val; } @@ -1225,7 +1231,7 @@ The argument PROMPT should be a string ending with a colon and a space. */) args[0] = build_string ("%s (default %s): "); args[1] = prompt; - args[2] = def; + args[2] = CONSP (def) ? XCAR (def) : def; prompt = Fformat (3, args); } @@ -1835,7 +1841,7 @@ Completion ignores case if the ambient value of !NILP (inherit_input_method)); if (STRINGP (val) && SCHARS (val) == 0 && ! NILP (def)) - val = def; + val = CONSP (def) ? XCAR (def) : def; RETURN_UNGCPRO (unbind_to (count, val)); } -- 2.39.2