diff options
| author | Richard M. Stallman | 1997-05-10 21:47:21 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-05-10 21:47:21 +0000 |
| commit | e5d4686b2023aca4e8164151ace591a2451919b6 (patch) | |
| tree | 94202c771f54683484aea1836151ec1a849ff82f | |
| parent | ff9cd111c68f9d939f2bbe4af77a6b0a3376ead1 (diff) | |
| download | emacs-e5d4686b2023aca4e8164151ace591a2451919b6.tar.gz emacs-e5d4686b2023aca4e8164151ace591a2451919b6.zip | |
(Fread_command): New optional arg DEFAULT-VALUE. Callers changed.
(Fread_variable, Fread_string, Fread_from_minibuffer): Likewise.
(read_minibuf): Now static. New arg DEFALT. Callers changed.
Bind minibuffer-default here.
(read_minibuf_unwind): Now static.
(Fcompleting_read): Past DEF to Fread_from_minibuffer;
no need to use it directly here.
(Fcompleting_read): New arg DEF. Callers changed.
(Qminibuffer_default): New variable.
(syms_of_minibuf): Initialize it.
| -rw-r--r-- | src/minibuf.c | 137 |
1 files changed, 80 insertions, 57 deletions
diff --git a/src/minibuf.c b/src/minibuf.c index 249e96f485a..6395860f826 100644 --- a/src/minibuf.c +++ b/src/minibuf.c | |||
| @@ -101,6 +101,8 @@ static Lisp_Object last_exact_completion; | |||
| 101 | 101 | ||
| 102 | Lisp_Object Quser_variable_p; | 102 | Lisp_Object Quser_variable_p; |
| 103 | 103 | ||
| 104 | Lisp_Object Qminibuffer_default; | ||
| 105 | |||
| 104 | /* Non-nil means it is the window for C-M-v to scroll | 106 | /* Non-nil means it is the window for C-M-v to scroll |
| 105 | when the minibuffer is selected. */ | 107 | when the minibuffer is selected. */ |
| 106 | extern Lisp_Object Vminibuf_scroll_window; | 108 | extern Lisp_Object Vminibuf_scroll_window; |
| @@ -162,9 +164,9 @@ without invoking the usual minibuffer commands.") | |||
| 162 | 164 | ||
| 163 | /* Actual minibuffer invocation. */ | 165 | /* Actual minibuffer invocation. */ |
| 164 | 166 | ||
| 165 | void read_minibuf_unwind (); | 167 | static void read_minibuf_unwind (); |
| 166 | Lisp_Object get_minibuffer (); | 168 | Lisp_Object get_minibuffer (); |
| 167 | Lisp_Object read_minibuf (); | 169 | static Lisp_Object read_minibuf (); |
| 168 | 170 | ||
| 169 | /* Read from the minibuffer using keymap MAP, initial contents INITIAL | 171 | /* Read from the minibuffer using keymap MAP, initial contents INITIAL |
| 170 | (a string), putting point minus BACKUP_N chars from the end of INITIAL, | 172 | (a string), putting point minus BACKUP_N chars from the end of INITIAL, |
| @@ -175,10 +177,13 @@ Lisp_Object read_minibuf (); | |||
| 175 | but if EXPFLAG is nonzero, read it and return the object read. | 177 | but if EXPFLAG is nonzero, read it and return the object read. |
| 176 | If HISTVAR is given, save the value read on that history only if it doesn't | 178 | If HISTVAR is given, save the value read on that history only if it doesn't |
| 177 | match the front of that history list exactly. The value is pushed onto | 179 | match the front of that history list exactly. The value is pushed onto |
| 178 | the list as the string that was read. */ | 180 | the list as the string that was read. |
| 179 | 181 | ||
| 180 | Lisp_Object | 182 | DEFALT specifies te default value for the sake of history commands. */ |
| 181 | read_minibuf (map, initial, prompt, backup_n, expflag, histvar, histpos) | 183 | |
| 184 | static Lisp_Object | ||
| 185 | read_minibuf (map, initial, prompt, backup_n, expflag, | ||
| 186 | histvar, histpos, defalt) | ||
| 182 | Lisp_Object map; | 187 | Lisp_Object map; |
| 183 | Lisp_Object initial; | 188 | Lisp_Object initial; |
| 184 | Lisp_Object prompt; | 189 | Lisp_Object prompt; |
| @@ -186,12 +191,15 @@ read_minibuf (map, initial, prompt, backup_n, expflag, histvar, histpos) | |||
| 186 | int expflag; | 191 | int expflag; |
| 187 | Lisp_Object histvar; | 192 | Lisp_Object histvar; |
| 188 | Lisp_Object histpos; | 193 | Lisp_Object histpos; |
| 194 | Lisp_Object defalt; | ||
| 189 | { | 195 | { |
| 190 | Lisp_Object val; | 196 | Lisp_Object val; |
| 191 | int count = specpdl_ptr - specpdl; | 197 | int count = specpdl_ptr - specpdl; |
| 192 | Lisp_Object mini_frame, ambient_dir, minibuffer; | 198 | Lisp_Object mini_frame, ambient_dir, minibuffer; |
| 193 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | 199 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
| 194 | 200 | ||
| 201 | specbind (Qminibuffer_default, defalt); | ||
| 202 | |||
| 195 | single_kboard_state (); | 203 | single_kboard_state (); |
| 196 | 204 | ||
| 197 | val = Qnil; | 205 | val = Qnil; |
| @@ -388,17 +396,18 @@ read_minibuf (map, initial, prompt, backup_n, expflag, histvar, histpos) | |||
| 388 | /* Truncate if requested. */ | 396 | /* Truncate if requested. */ |
| 389 | length = Fget (Vminibuffer_history_variable, Qhistory_length); | 397 | length = Fget (Vminibuffer_history_variable, Qhistory_length); |
| 390 | if (NILP (length)) length = Vhistory_length; | 398 | if (NILP (length)) length = Vhistory_length; |
| 391 | if (INTEGERP (length)) { | 399 | if (INTEGERP (length)) |
| 392 | if (XINT (length) <= 0) | 400 | { |
| 393 | Fset (Vminibuffer_history_variable, Qnil); | 401 | if (XINT (length) <= 0) |
| 394 | else | 402 | Fset (Vminibuffer_history_variable, Qnil); |
| 395 | { | 403 | else |
| 396 | Lisp_Object temp; | 404 | { |
| 397 | 405 | Lisp_Object temp; | |
| 398 | temp = Fnthcdr (Fsub1 (length), histval); | 406 | |
| 399 | if (CONSP (temp)) Fsetcdr (temp, Qnil); | 407 | temp = Fnthcdr (Fsub1 (length), histval); |
| 400 | } | 408 | if (CONSP (temp)) Fsetcdr (temp, Qnil); |
| 401 | } | 409 | } |
| 410 | } | ||
| 402 | } | 411 | } |
| 403 | } | 412 | } |
| 404 | 413 | ||
| @@ -469,7 +478,7 @@ get_minibuffer (depth) | |||
| 469 | /* This function is called on exiting minibuffer, whether normally or not, | 478 | /* This function is called on exiting minibuffer, whether normally or not, |
| 470 | and it restores the current window, buffer, etc. */ | 479 | and it restores the current window, buffer, etc. */ |
| 471 | 480 | ||
| 472 | void | 481 | static void |
| 473 | read_minibuf_unwind (data) | 482 | read_minibuf_unwind (data) |
| 474 | Lisp_Object data; | 483 | Lisp_Object data; |
| 475 | { | 484 | { |
| @@ -557,16 +566,19 @@ Fifth arg HIST, if non-nil, specifies a history list\n\ | |||
| 557 | In that case, HISTVAR is the history list variable to use,\n\ | 566 | In that case, HISTVAR is the history list variable to use,\n\ |
| 558 | and HISTPOS is the initial position (the position in the list\n\ | 567 | and HISTPOS is the initial position (the position in the list\n\ |
| 559 | which INITIAL-CONTENTS corresponds to).\n\ | 568 | which INITIAL-CONTENTS corresponds to).\n\ |
| 560 | Positions are counted starting from 1 at the beginning of the list." | 569 | Positions are counted starting from 1 at the beginning of the list.\n\ |
| 570 | Sixth arg DEFAULT-VALUE is the default value. If non-nil, it is used\n\ | ||
| 571 | for history commands, and as the value to return if the user enters\n\ | ||
| 572 | the empty string.\n\ | ||
| 561 | */ | 573 | */ |
| 562 | 574 | ||
| 563 | DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, 5, 0, | 575 | DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, 6, 0, |
| 564 | 0 /* See immediately above */) | 576 | 0 /* See immediately above */) |
| 565 | (prompt, initial_contents, keymap, read, hist) | 577 | (prompt, initial_contents, keymap, read, hist, default_value) |
| 566 | Lisp_Object prompt, initial_contents, keymap, read, hist; | 578 | Lisp_Object prompt, initial_contents, keymap, read, hist, default_value; |
| 567 | { | 579 | { |
| 568 | int pos = 0; | 580 | int pos = 0; |
| 569 | Lisp_Object histvar, histpos, position; | 581 | Lisp_Object histvar, histpos, position, val; |
| 570 | position = Qnil; | 582 | position = Qnil; |
| 571 | 583 | ||
| 572 | CHECK_STRING (prompt, 0); | 584 | CHECK_STRING (prompt, 0); |
| @@ -610,8 +622,12 @@ DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, | |||
| 610 | if (NILP (histpos)) | 622 | if (NILP (histpos)) |
| 611 | XSETFASTINT (histpos, 0); | 623 | XSETFASTINT (histpos, 0); |
| 612 | 624 | ||
| 613 | return read_minibuf (keymap, initial_contents, prompt, | 625 | val = read_minibuf (keymap, initial_contents, prompt, |
| 614 | make_number (pos), !NILP (read), histvar, histpos); | 626 | make_number (pos), !NILP (read), |
| 627 | histvar, histpos, default_value); | ||
| 628 | if (STRINGP (val) && XSTRING (val)->size == 0 && ! NILP (default_value)) | ||
| 629 | val = default_value; | ||
| 630 | return val; | ||
| 615 | } | 631 | } |
| 616 | 632 | ||
| 617 | DEFUN ("read-minibuffer", Fread_minibuffer, Sread_minibuffer, 1, 2, 0, | 633 | DEFUN ("read-minibuffer", Fread_minibuffer, Sread_minibuffer, 1, 2, 0, |
| @@ -625,7 +641,8 @@ is a string to insert in the minibuffer before reading.") | |||
| 625 | if (!NILP (initial_contents)) | 641 | if (!NILP (initial_contents)) |
| 626 | CHECK_STRING (initial_contents, 1); | 642 | CHECK_STRING (initial_contents, 1); |
| 627 | return read_minibuf (Vminibuffer_local_map, initial_contents, | 643 | return read_minibuf (Vminibuffer_local_map, initial_contents, |
| 628 | prompt, Qnil, 1, Qminibuffer_history, make_number (0)); | 644 | prompt, Qnil, 1, Qminibuffer_history, |
| 645 | make_number (0), Qnil); | ||
| 629 | } | 646 | } |
| 630 | 647 | ||
| 631 | DEFUN ("eval-minibuffer", Feval_minibuffer, Seval_minibuffer, 1, 2, 0, | 648 | DEFUN ("eval-minibuffer", Feval_minibuffer, Seval_minibuffer, 1, 2, 0, |
| @@ -640,16 +657,17 @@ is a string to insert in the minibuffer before reading.") | |||
| 640 | 657 | ||
| 641 | /* Functions that use the minibuffer to read various things. */ | 658 | /* Functions that use the minibuffer to read various things. */ |
| 642 | 659 | ||
| 643 | DEFUN ("read-string", Fread_string, Sread_string, 1, 3, 0, | 660 | DEFUN ("read-string", Fread_string, Sread_string, 1, 4, 0, |
| 644 | "Read a string from the minibuffer, prompting with string PROMPT.\n\ | 661 | "Read a string from the minibuffer, prompting with string PROMPT.\n\ |
| 645 | If non-nil, second arg INITIAL-INPUT is a string to insert before reading.\n\ | 662 | If non-nil, second arg INITIAL-INPUT is a string to insert before reading.\n\ |
| 646 | The third arg HISTORY, if non-nil, specifies a history list\n\ | 663 | The third arg HISTORY, if non-nil, specifies a history list\n\ |
| 647 | and optionally the initial position in the list.\n\ | 664 | and optionally the initial position in the list.\n\ |
| 648 | See `read-from-minibuffer' for details of HISTORY argument.") | 665 | See `read-from-minibuffer' for details of HISTORY argument.") |
| 649 | (prompt, initial_input, history) | 666 | (prompt, initial_input, history, default_value) |
| 650 | Lisp_Object prompt, initial_input, history; | 667 | Lisp_Object prompt, initial_input, history, default_value; |
| 651 | { | 668 | { |
| 652 | return Fread_from_minibuffer (prompt, initial_input, Qnil, Qnil, history); | 669 | return Fread_from_minibuffer (prompt, initial_input, Qnil, |
| 670 | Qnil, history, default_value); | ||
| 653 | } | 671 | } |
| 654 | 672 | ||
| 655 | DEFUN ("read-no-blanks-input", Fread_no_blanks_input, Sread_no_blanks_input, 1, 2, 0, | 673 | DEFUN ("read-no-blanks-input", Fread_no_blanks_input, Sread_no_blanks_input, 1, 2, 0, |
| @@ -662,17 +680,18 @@ Prompt with PROMPT, and provide INIT as an initial value of the input string.") | |||
| 662 | if (! NILP (init)) | 680 | if (! NILP (init)) |
| 663 | CHECK_STRING (init, 1); | 681 | CHECK_STRING (init, 1); |
| 664 | 682 | ||
| 665 | return read_minibuf (Vminibuffer_local_ns_map, init, prompt, Qnil, 0, | 683 | return read_minibuf (Vminibuffer_local_ns_map, init, prompt, Qnil, |
| 666 | Qminibuffer_history, make_number (0)); | 684 | 0, Qminibuffer_history, make_number (0), Qnil); |
| 667 | } | 685 | } |
| 668 | 686 | ||
| 669 | DEFUN ("read-command", Fread_command, Sread_command, 1, 1, 0, | 687 | DEFUN ("read-command", Fread_command, Sread_command, 1, 2, 0, |
| 670 | "One arg PROMPT, a string. Read the name of a command and return as a symbol.\n\ | 688 | "Read the name of a command and return as a symbol.\n\ |
| 671 | Prompts with PROMPT.") | 689 | Prompts with PROMPT. By default, return DEFAULT-VALUE.") |
| 672 | (prompt) | 690 | (prompt, default_value) |
| 673 | Lisp_Object prompt; | 691 | Lisp_Object prompt, default_value; |
| 674 | { | 692 | { |
| 675 | return Fintern (Fcompleting_read (prompt, Vobarray, Qcommandp, Qt, Qnil, Qnil), | 693 | return Fintern (Fcompleting_read (prompt, Vobarray, Qcommandp, Qt, |
| 694 | Qnil, Qnil, default_value), | ||
| 676 | Qnil); | 695 | Qnil); |
| 677 | } | 696 | } |
| 678 | 697 | ||
| @@ -683,34 +702,34 @@ Prompts with PROMPT.") | |||
| 683 | (prompt) | 702 | (prompt) |
| 684 | Lisp_Object prompt; | 703 | Lisp_Object prompt; |
| 685 | { | 704 | { |
| 686 | return Fintern (Fcompleting_read (prompt, Vobarray, Qfboundp, Qt, Qnil, Qnil), | 705 | return Fintern (Fcompleting_read (prompt, Vobarray, Qfboundp, Qt, Qnil, Qnil, Qnil), |
| 687 | Qnil); | 706 | Qnil); |
| 688 | } | 707 | } |
| 689 | #endif /* NOTDEF */ | 708 | #endif /* NOTDEF */ |
| 690 | 709 | ||
| 691 | DEFUN ("read-variable", Fread_variable, Sread_variable, 1, 1, 0, | 710 | DEFUN ("read-variable", Fread_variable, Sread_variable, 1, 2, 0, |
| 692 | "One arg PROMPT, a string. Read the name of a user variable and return\n\ | 711 | "Read the name of a user variable and return it as a symbol.\n\ |
| 693 | it as a symbol. Prompts with PROMPT.\n\ | 712 | Prompts with PROMPT. By default, return DEFAULT-VALUE.\n\ |
| 694 | A user variable is one whose documentation starts with a `*' character.") | 713 | A user variable is one whose documentation starts with a `*' character.") |
| 695 | (prompt) | 714 | (prompt, default_value) |
| 696 | Lisp_Object prompt; | 715 | Lisp_Object prompt, default_value; |
| 697 | { | 716 | { |
| 698 | return Fintern (Fcompleting_read (prompt, Vobarray, | 717 | return Fintern (Fcompleting_read (prompt, Vobarray, |
| 699 | Quser_variable_p, Qt, Qnil, Qnil), | 718 | Quser_variable_p, Qt, |
| 719 | Qnil, Qnil, default_value), | ||
| 700 | Qnil); | 720 | Qnil); |
| 701 | } | 721 | } |
| 702 | 722 | ||
| 703 | DEFUN ("read-buffer", Fread_buffer, Sread_buffer, 1, 3, 0, | 723 | DEFUN ("read-buffer", Fread_buffer, Sread_buffer, 1, 3, 0, |
| 704 | "One arg PROMPT, a string. Read the name of a buffer and return as a string.\n\ | 724 | "One arg PROMPT, a string. Read the name of a buffer and return as a string.\n\ |
| 705 | Prompts with PROMPT.\n\ | 725 | Prompts with PROMPT.\n\ |
| 706 | Optional second arg is value to return if user enters an empty line.\n\ | 726 | Optional second arg DEF is value to return if user enters an empty line.\n\ |
| 707 | If optional third arg REQUIRE-MATCH is non-nil, only existing buffer names are allowed.") | 727 | If optional third arg REQUIRE-MATCH is non-nil, only existing buffer names are allowed.") |
| 708 | (prompt, def, require_match) | 728 | (prompt, def, require_match) |
| 709 | Lisp_Object prompt, def, require_match; | 729 | Lisp_Object prompt, def, require_match; |
| 710 | { | 730 | { |
| 711 | Lisp_Object tem; | 731 | Lisp_Object tem; |
| 712 | Lisp_Object args[3]; | 732 | Lisp_Object args[3]; |
| 713 | struct gcpro gcpro1; | ||
| 714 | 733 | ||
| 715 | if (BUFFERP (def)) | 734 | if (BUFFERP (def)) |
| 716 | def = XBUFFER (def)->name; | 735 | def = XBUFFER (def)->name; |
| @@ -721,12 +740,8 @@ If optional third arg REQUIRE-MATCH is non-nil, only existing buffer names are a | |||
| 721 | args[2] = def; | 740 | args[2] = def; |
| 722 | prompt = Fformat (3, args); | 741 | prompt = Fformat (3, args); |
| 723 | } | 742 | } |
| 724 | GCPRO1 (def); | 743 | return Fcompleting_read (prompt, Vbuffer_alist, Qnil, |
| 725 | tem = Fcompleting_read (prompt, Vbuffer_alist, Qnil, require_match, Qnil, Qnil); | 744 | require_match, Qnil, Qnil, def); |
| 726 | UNGCPRO; | ||
| 727 | if (XSTRING (tem)->size) | ||
| 728 | return tem; | ||
| 729 | return def; | ||
| 730 | } | 745 | } |
| 731 | 746 | ||
| 732 | DEFUN ("try-completion", Ftry_completion, Stry_completion, 2, 3, 0, | 747 | DEFUN ("try-completion", Ftry_completion, Stry_completion, 2, 3, 0, |
| @@ -1091,7 +1106,7 @@ Lisp_Object Vminibuffer_completion_confirm, Qminibuffer_completion_confirm; | |||
| 1091 | for make-docfile to see. We cannot put this in the real DEFUN | 1106 | for make-docfile to see. We cannot put this in the real DEFUN |
| 1092 | due to limits in the Unix cpp. | 1107 | due to limits in the Unix cpp. |
| 1093 | 1108 | ||
| 1094 | DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 6, 0, | 1109 | DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 7, 0, |
| 1095 | "Read a string in the minibuffer, with completion.\n\ | 1110 | "Read a string in the minibuffer, with completion.\n\ |
| 1096 | PROMPT is a string to prompt with; normally it ends in a colon and a space.\n\ | 1111 | PROMPT is a string to prompt with; normally it ends in a colon and a space.\n\ |
| 1097 | TABLE is an alist whose elements' cars are strings, or an obarray.\n\ | 1112 | TABLE is an alist whose elements' cars are strings, or an obarray.\n\ |
| @@ -1116,13 +1131,15 @@ HIST, if non-nil, specifies a history list\n\ | |||
| 1116 | and HISTPOS is the initial position (the position in the list\n\ | 1131 | and HISTPOS is the initial position (the position in the list\n\ |
| 1117 | which INITIAL-CONTENTS corresponds to).\n\ | 1132 | which INITIAL-CONTENTS corresponds to).\n\ |
| 1118 | Positions are counted starting from 1 at the beginning of the list.\n\ | 1133 | Positions are counted starting from 1 at the beginning of the list.\n\ |
| 1134 | DEF, if non-nil, is the default value. | ||
| 1135 | |||
| 1119 | Completion ignores case if the ambient value of\n\ | 1136 | Completion ignores case if the ambient value of\n\ |
| 1120 | `completion-ignore-case' is non-nil." | 1137 | `completion-ignore-case' is non-nil." |
| 1121 | */ | 1138 | */ |
| 1122 | DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 6, 0, | 1139 | DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 7, 0, |
| 1123 | 0 /* See immediately above */) | 1140 | 0 /* See immediately above */) |
| 1124 | (prompt, table, predicate, require_match, init, hist) | 1141 | (prompt, table, predicate, require_match, init, hist, def) |
| 1125 | Lisp_Object prompt, table, predicate, require_match, init, hist; | 1142 | Lisp_Object prompt, table, predicate, require_match, init, hist, def; |
| 1126 | { | 1143 | { |
| 1127 | Lisp_Object val, histvar, histpos, position; | 1144 | Lisp_Object val, histvar, histpos, position; |
| 1128 | int pos = 0; | 1145 | int pos = 0; |
| @@ -1169,7 +1186,9 @@ DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 6, 0, | |||
| 1169 | ? Vminibuffer_local_completion_map | 1186 | ? Vminibuffer_local_completion_map |
| 1170 | : Vminibuffer_local_must_match_map, | 1187 | : Vminibuffer_local_must_match_map, |
| 1171 | init, prompt, make_number (pos), 0, | 1188 | init, prompt, make_number (pos), 0, |
| 1172 | histvar, histpos); | 1189 | histvar, histpos, def); |
| 1190 | if (STRINGP (val) && XSTRING (val)->size == 0 && ! NILP (def)) | ||
| 1191 | val = def; | ||
| 1173 | return unbind_to (count, val); | 1192 | return unbind_to (count, val); |
| 1174 | } | 1193 | } |
| 1175 | 1194 | ||
| @@ -1849,6 +1868,10 @@ syms_of_minibuf () | |||
| 1849 | Qread_file_name_internal = intern ("read-file-name-internal"); | 1868 | Qread_file_name_internal = intern ("read-file-name-internal"); |
| 1850 | staticpro (&Qread_file_name_internal); | 1869 | staticpro (&Qread_file_name_internal); |
| 1851 | 1870 | ||
| 1871 | Qminibuffer_default = intern ("minibuffer-default"); | ||
| 1872 | staticpro (&Qminibuffer_default); | ||
| 1873 | Fset (Qminibuffer_default, Qnil); | ||
| 1874 | |||
| 1852 | Qminibuffer_completion_table = intern ("minibuffer-completion-table"); | 1875 | Qminibuffer_completion_table = intern ("minibuffer-completion-table"); |
| 1853 | staticpro (&Qminibuffer_completion_table); | 1876 | staticpro (&Qminibuffer_completion_table); |
| 1854 | 1877 | ||