Mercurial > emacs
comparison src/minibuf.c @ 85516:6260015b7802
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.
author | Juri Linkov <juri@jurta.org> |
---|---|
date | Mon, 22 Oct 2007 00:19:51 +0000 |
parents | f7d19cfed7da |
children | a1ea2ab31c31 |
comparison
equal
deleted
inserted
replaced
85515:7fa3f0c5ecbf | 85516:6260015b7802 |
---|---|
255 Lisp_Object expr_and_pos; | 255 Lisp_Object expr_and_pos; |
256 int pos; | 256 int pos; |
257 | 257 |
258 GCPRO2 (val, defalt); | 258 GCPRO2 (val, defalt); |
259 | 259 |
260 if (STRINGP (val) && SCHARS (val) == 0 | 260 if (STRINGP (val) && SCHARS (val) == 0) |
261 && STRINGP (defalt)) | 261 { |
262 val = defalt; | 262 if (STRINGP (defalt)) |
263 val = defalt; | |
264 else if (CONSP (defalt) && STRINGP (XCAR (defalt))) | |
265 val = XCAR (defalt); | |
266 } | |
263 | 267 |
264 expr_and_pos = Fread_from_string (val, Qnil, Qnil); | 268 expr_and_pos = Fread_from_string (val, Qnil, Qnil); |
265 pos = XINT (Fcdr (expr_and_pos)); | 269 pos = XINT (Fcdr (expr_and_pos)); |
266 if (pos != SCHARS (val)) | 270 if (pos != SCHARS (val)) |
267 { | 271 { |
335 error ("Error reading from stdin"); | 339 error ("Error reading from stdin"); |
336 } | 340 } |
337 | 341 |
338 /* If Lisp form desired instead of string, parse it. */ | 342 /* If Lisp form desired instead of string, parse it. */ |
339 if (expflag) | 343 if (expflag) |
340 val = string_to_object (val, defalt); | 344 val = string_to_object (val, CONSP (defalt) ? XCAR (defalt) : defalt); |
341 | 345 |
342 return val; | 346 return val; |
343 } | 347 } |
344 | 348 |
345 DEFUN ("minibufferp", Fminibufferp, | 349 DEFUN ("minibufferp", Fminibufferp, |
783 /* Choose the string to add to the history. */ | 787 /* Choose the string to add to the history. */ |
784 if (SCHARS (val) != 0) | 788 if (SCHARS (val) != 0) |
785 histstring = val; | 789 histstring = val; |
786 else if (STRINGP (defalt)) | 790 else if (STRINGP (defalt)) |
787 histstring = defalt; | 791 histstring = defalt; |
792 else if (CONSP (defalt) && STRINGP (XCAR (defalt))) | |
793 histstring = XCAR (defalt); | |
788 else | 794 else |
789 histstring = Qnil; | 795 histstring = Qnil; |
790 | 796 |
791 /* Add the value to the appropriate history list, if any. */ | 797 /* Add the value to the appropriate history list, if any. */ |
792 if (!NILP (Vhistory_add_new_input) | 798 if (!NILP (Vhistory_add_new_input) |
1100 Lisp_Object val; | 1106 Lisp_Object val; |
1101 val = Fread_from_minibuffer (prompt, initial_input, Qnil, | 1107 val = Fread_from_minibuffer (prompt, initial_input, Qnil, |
1102 Qnil, history, default_value, | 1108 Qnil, history, default_value, |
1103 inherit_input_method); | 1109 inherit_input_method); |
1104 if (STRINGP (val) && SCHARS (val) == 0 && ! NILP (default_value)) | 1110 if (STRINGP (val) && SCHARS (val) == 0 && ! NILP (default_value)) |
1105 val = default_value; | 1111 val = CONSP (default_value) ? XCAR (default_value) : default_value; |
1106 return val; | 1112 return val; |
1107 } | 1113 } |
1108 | 1114 |
1109 DEFUN ("read-no-blanks-input", Fread_no_blanks_input, Sread_no_blanks_input, 1, 3, 0, | 1115 DEFUN ("read-no-blanks-input", Fread_no_blanks_input, Sread_no_blanks_input, 1, 3, 0, |
1110 doc: /* Read a string from the terminal, not allowing blanks. | 1116 doc: /* Read a string from the terminal, not allowing blanks. |
1223 STRING_MULTIBYTE (prompt)); | 1229 STRING_MULTIBYTE (prompt)); |
1224 } | 1230 } |
1225 | 1231 |
1226 args[0] = build_string ("%s (default %s): "); | 1232 args[0] = build_string ("%s (default %s): "); |
1227 args[1] = prompt; | 1233 args[1] = prompt; |
1228 args[2] = def; | 1234 args[2] = CONSP (def) ? XCAR (def) : def; |
1229 prompt = Fformat (3, args); | 1235 prompt = Fformat (3, args); |
1230 } | 1236 } |
1231 | 1237 |
1232 return Fcompleting_read (prompt, intern ("internal-complete-buffer"), | 1238 return Fcompleting_read (prompt, intern ("internal-complete-buffer"), |
1233 Qnil, require_match, Qnil, Qbuffer_name_history, | 1239 Qnil, require_match, Qnil, Qbuffer_name_history, |
1833 init, prompt, make_number (pos), 0, | 1839 init, prompt, make_number (pos), 0, |
1834 histvar, histpos, def, 0, | 1840 histvar, histpos, def, 0, |
1835 !NILP (inherit_input_method)); | 1841 !NILP (inherit_input_method)); |
1836 | 1842 |
1837 if (STRINGP (val) && SCHARS (val) == 0 && ! NILP (def)) | 1843 if (STRINGP (val) && SCHARS (val) == 0 && ! NILP (def)) |
1838 val = def; | 1844 val = CONSP (def) ? XCAR (def) : def; |
1839 | 1845 |
1840 RETURN_UNGCPRO (unbind_to (count, val)); | 1846 RETURN_UNGCPRO (unbind_to (count, val)); |
1841 } | 1847 } |
1842 | 1848 |
1843 Lisp_Object Fminibuffer_completion_help (); | 1849 Lisp_Object Fminibuffer_completion_help (); |