comparison src/minibuf.c @ 19545:a7f1c1acde93

(Qcurrent_input_method, Qactivate_input_method): New variables. (syms_of_minibuf): Intern and staticpro them. (read_minibuf): New argument INHERIT_INPUT_METHOD. If it is nonzero, remember the current input method in INPUT_METHOD, and activate it after switching to the minibuffer. (Fread_from_minibuffer): New argument INHERIT_INPUT_METHOD. (Fread_minibuffer): Call read_minibuf with INHERIT_INPUT_METHOD nil. (Fread_string): New argument INHERIT_INPUT_METHOD. (Fread_no_blanks_input): Likewise. (Fread_command): Call Fcompleting_read with INHERIT_INPUT_METHOD nil. (Fread_function, Fread_variable, Fread_buffer): Likewise (Fcompleting_read): New argument INHERIT_INPUT_METHOD.
author Kenichi Handa <handa@m17n.org>
date Tue, 26 Aug 1997 11:42:33 +0000
parents d87f6112e034
children 7e13891b6f22
comparison
equal deleted inserted replaced
19544:fc0bb24597ba 19545:a7f1c1acde93
110 /* Non-nil means it is the window for C-M-v to scroll 110 /* Non-nil means it is the window for C-M-v to scroll
111 when the minibuffer is selected. */ 111 when the minibuffer is selected. */
112 extern Lisp_Object Vminibuf_scroll_window; 112 extern Lisp_Object Vminibuf_scroll_window;
113 113
114 extern Lisp_Object Voverriding_local_map; 114 extern Lisp_Object Voverriding_local_map;
115
116 Lisp_Object Qcurrent_input_method, Qactivate_input_method;
117
115 118
116 /* Put minibuf on currently selected frame's minibuffer. 119 /* Put minibuf on currently selected frame's minibuffer.
117 We do this whenever the user starts a new minibuffer 120 We do this whenever the user starts a new minibuffer
118 or when a minibuffer exits. */ 121 or when a minibuffer exits. */
119 122
191 match the front of that history list exactly. The value is pushed onto 194 match the front of that history list exactly. The value is pushed onto
192 the list as the string that was read. 195 the list as the string that was read.
193 196
194 DEFALT specifies te default value for the sake of history commands. 197 DEFALT specifies te default value for the sake of history commands.
195 198
196 If ALLOW_PROPS is nonzero, we do not throw away text properties. */ 199 If ALLOW_PROPS is nonzero, we do not throw away text properties.
200
201 if INHERIT_INPUT_METHOD is nonzeor, the minibuffer inherit the
202 current input method. */
197 203
198 static Lisp_Object 204 static Lisp_Object
199 read_minibuf (map, initial, prompt, backup_n, expflag, 205 read_minibuf (map, initial, prompt, backup_n, expflag,
200 histvar, histpos, defalt, allow_props, disable_multibyte) 206 histvar, histpos, defalt, allow_props, inherit_input_method)
201 Lisp_Object map; 207 Lisp_Object map;
202 Lisp_Object initial; 208 Lisp_Object initial;
203 Lisp_Object prompt; 209 Lisp_Object prompt;
204 Lisp_Object backup_n; 210 Lisp_Object backup_n;
205 int expflag; 211 int expflag;
206 Lisp_Object histvar; 212 Lisp_Object histvar;
207 Lisp_Object histpos; 213 Lisp_Object histpos;
208 Lisp_Object defalt; 214 Lisp_Object defalt;
209 int disable_multibyte; 215 int inherit_input_method;
210 { 216 {
211 Lisp_Object val; 217 Lisp_Object val;
212 int count = specpdl_ptr - specpdl; 218 int count = specpdl_ptr - specpdl;
213 Lisp_Object mini_frame, ambient_dir, minibuffer; 219 Lisp_Object mini_frame, ambient_dir, minibuffer, input_method;
214 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 220 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
215 221
216 specbind (Qminibuffer_default, defalt); 222 specbind (Qminibuffer_default, defalt);
217 223
218 single_kboard_state (); 224 single_kboard_state ();
219 225
220 val = Qnil; 226 val = Qnil;
221 ambient_dir = current_buffer->directory; 227 ambient_dir = current_buffer->directory;
228 input_method = Qnil;
222 229
223 /* Don't need to protect PROMPT, HISTVAR, and HISTPOS because we 230 /* Don't need to protect PROMPT, HISTVAR, and HISTPOS because we
224 store them away before we can GC. Don't need to protect 231 store them away before we can GC. Don't need to protect
225 BACKUP_N because we use the value only if it is an integer. */ 232 BACKUP_N because we use the value only if it is an integer. */
226 GCPRO4 (map, initial, val, ambient_dir); 233 GCPRO5 (map, initial, val, ambient_dir, input_method);
227 234
228 if (!STRINGP (prompt)) 235 if (!STRINGP (prompt))
229 prompt = build_string (""); 236 prompt = build_string ("");
230 237
231 if (!enable_recursive_minibuffers 238 if (!enable_recursive_minibuffers
289 minibuf_prompt = Fcopy_sequence (prompt); 296 minibuf_prompt = Fcopy_sequence (prompt);
290 Vminibuffer_history_position = histpos; 297 Vminibuffer_history_position = histpos;
291 Vminibuffer_history_variable = histvar; 298 Vminibuffer_history_variable = histvar;
292 Vhelp_form = Vminibuffer_help_form; 299 Vhelp_form = Vminibuffer_help_form;
293 300
301 if (inherit_input_method)
302 /* `current-input-method' is buffer local. So, remeber it in
303 INPUT_METHOD before changing the current buffer. */
304 input_method = Fsymbol_value (Qcurrent_input_method);
305
294 /* Switch to the minibuffer. */ 306 /* Switch to the minibuffer. */
295 307
296 minibuffer = get_minibuffer (minibuf_level); 308 minibuffer = get_minibuffer (minibuf_level);
297 Fset_buffer (minibuffer); 309 Fset_buffer (minibuffer);
298 310
355 echo_area_glyphs = 0; 367 echo_area_glyphs = 0;
356 /* This is in case the minibuffer-setup-hook calls Fsit_for. */ 368 /* This is in case the minibuffer-setup-hook calls Fsit_for. */
357 previous_echo_glyphs = 0; 369 previous_echo_glyphs = 0;
358 370
359 current_buffer->keymap = map; 371 current_buffer->keymap = map;
372
373 /* Turn on an input method stored in INPUT_METHOD if any. */
374 if (STRINGP (input_method) && Ffboundp (Qactivate_input_method))
375 call1 (Qactivate_input_method, input_method);
360 376
361 /* Run our hook, but not if it is empty. 377 /* Run our hook, but not if it is empty.
362 (run-hooks would do nothing if it is empty, 378 (run-hooks would do nothing if it is empty,
363 but it's important to save time here in the usual case). */ 379 but it's important to save time here in the usual case). */
364 if (!NILP (Vminibuffer_setup_hook) && !EQ (Vminibuffer_setup_hook, Qunbound) 380 if (!NILP (Vminibuffer_setup_hook) && !EQ (Vminibuffer_setup_hook, Qunbound)
559 575
560 /* This comment supplies the doc string for read-from-minibuffer, 576 /* This comment supplies the doc string for read-from-minibuffer,
561 for make-docfile to see. We cannot put this in the real DEFUN 577 for make-docfile to see. We cannot put this in the real DEFUN
562 due to limits in the Unix cpp. 578 due to limits in the Unix cpp.
563 579
564 DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, 6, 0, 580 DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, 7, 0,
565 "Read a string from the minibuffer, prompting with string PROMPT.\n\ 581 "Read a string from the minibuffer, prompting with string PROMPT.\n\
566 If optional second arg INITIAL-CONTENTS is non-nil, it is a string\n\ 582 If optional second arg INITIAL-CONTENTS is non-nil, it is a string\n\
567 to be inserted into the minibuffer before reading input.\n\ 583 to be inserted into the minibuffer before reading input.\n\
568 If INITIAL-CONTENTS is (STRING . POSITION), the initial input\n\ 584 If INITIAL-CONTENTS is (STRING . POSITION), the initial input\n\
569 is STRING, but point is placed at position POSITION in the minibuffer.\n\ 585 is STRING, but point is placed at position POSITION in the minibuffer.\n\
581 which INITIAL-CONTENTS corresponds to).\n\ 597 which INITIAL-CONTENTS corresponds to).\n\
582 Positions are counted starting from 1 at the beginning of the list.\n\ 598 Positions are counted starting from 1 at the beginning of the list.\n\
583 Sixth arg DEFAULT-VALUE is the default value. If non-nil, it is used\n\ 599 Sixth arg DEFAULT-VALUE is the default value. If non-nil, it is used\n\
584 for history commands, and as the value to return if the user enters\n\ 600 for history commands, and as the value to return if the user enters\n\
585 the empty string.\n\ 601 the empty string.\n\
602 Seventh arg INHERIT-INPUT-METHOD non-nil means the minibuffer inherits\n\
603 the current input method.\n\
586 If the variable `minibuffer-allow-text-properties is non-nil,\n\ 604 If the variable `minibuffer-allow-text-properties is non-nil,\n\
587 then the string which is returned includes whatever text properties\n\ 605 then the string which is returned includes whatever text properties\n\
588 were present in the minibuffer. Otherwise the value has no text properties. */ 606 were present in the minibuffer. Otherwise the value has no text properties.")
589 607 (prompt, initial_contents, keymap, read, hist, default_value, inherit_input_method)
590 DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, 6, 0, 608 */
609
610 DEFUN ("read-from-minibuffer", Fread_from_minibuffer, Sread_from_minibuffer, 1, 7, 0,
591 0 /* See immediately above */) 611 0 /* See immediately above */)
592 (prompt, initial_contents, keymap, read, hist, default_value) 612 (prompt, initial_contents, keymap, read, hist, default_value, inherit_input_method)
593 Lisp_Object prompt, initial_contents, keymap, read, hist, default_value; 613 Lisp_Object prompt, initial_contents, keymap, read, hist, default_value;
614 Lisp_Object inherit_input_method;
594 { 615 {
595 int pos = 0; 616 int pos = 0;
596 Lisp_Object histvar, histpos, position, val; 617 Lisp_Object histvar, histpos, position, val;
597 struct gcpro gcpro1; 618 struct gcpro gcpro1;
598 619
641 662
642 GCPRO1 (default_value); 663 GCPRO1 (default_value);
643 val = read_minibuf (keymap, initial_contents, prompt, 664 val = read_minibuf (keymap, initial_contents, prompt,
644 make_number (pos), !NILP (read), 665 make_number (pos), !NILP (read),
645 histvar, histpos, default_value, 666 histvar, histpos, default_value,
646 minibuffer_allow_text_properties, 0); 667 minibuffer_allow_text_properties,
668 !NILP (inherit_input_method));
647 if (STRINGP (val) && XSTRING (val)->size == 0 && ! NILP (default_value)) 669 if (STRINGP (val) && XSTRING (val)->size == 0 && ! NILP (default_value))
648 val = default_value; 670 val = default_value;
649 UNGCPRO; 671 UNGCPRO;
650 return val; 672 return val;
651 } 673 }
675 return Feval (Fread_minibuffer (prompt, initial_contents)); 697 return Feval (Fread_minibuffer (prompt, initial_contents));
676 } 698 }
677 699
678 /* Functions that use the minibuffer to read various things. */ 700 /* Functions that use the minibuffer to read various things. */
679 701
680 DEFUN ("read-string", Fread_string, Sread_string, 1, 4, 0, 702 DEFUN ("read-string", Fread_string, Sread_string, 1, 5, 0,
681 "Read a string from the minibuffer, prompting with string PROMPT.\n\ 703 "Read a string from the minibuffer, prompting with string PROMPT.\n\
682 If non-nil, second arg INITIAL-INPUT is a string to insert before reading.\n\ 704 If non-nil, second arg INITIAL-INPUT is a string to insert before reading.\n\
683 The third arg HISTORY, if non-nil, specifies a history list\n\ 705 The third arg HISTORY, if non-nil, specifies a history list\n\
684 and optionally the initial position in the list.\n\ 706 and optionally the initial position in the list.\n\
685 See `read-from-minibuffer' for details of HISTORY argument.") 707 See `read-from-minibuffer' for details of HISTORY argument.\n\
686 (prompt, initial_input, history, default_value) 708 The forth arg INHERIT-INPUT-METHOD non-nil means the minibuffer inherits\n\
709 the current input method.")
710 (prompt, initial_input, history, default_value, inherit_input_method)
687 Lisp_Object prompt, initial_input, history, default_value; 711 Lisp_Object prompt, initial_input, history, default_value;
712 Lisp_Object inherit_input_method;
688 { 713 {
689 return Fread_from_minibuffer (prompt, initial_input, Qnil, 714 return Fread_from_minibuffer (prompt, initial_input, Qnil,
690 Qnil, history, default_value); 715 Qnil, history, default_value,
691 } 716 inherit_input_method);
692 717 }
693 DEFUN ("read-no-blanks-input", Fread_no_blanks_input, Sread_no_blanks_input, 1, 2, 0, 718
719 DEFUN ("read-no-blanks-input", Fread_no_blanks_input, Sread_no_blanks_input, 1, 3, 0,
694 "Args PROMPT and INIT, strings. Read a string from the terminal, not allowing blanks.\n\ 720 "Args PROMPT and INIT, strings. Read a string from the terminal, not allowing blanks.\n\
695 Prompt with PROMPT, and provide INIT as an initial value of the input string.") 721 Prompt with PROMPT, and provide INIT as an initial value of the input string.\n\
696 (prompt, init) 722 The third optional arg INHERIT-INPUT-METHOD non-nil means the minibuffer\n\
697 Lisp_Object prompt, init; 723 inherits the current input method.")
724 (prompt, init, inherit_input_method)
725 Lisp_Object prompt, init, inherit_input_method;
698 { 726 {
699 CHECK_STRING (prompt, 0); 727 CHECK_STRING (prompt, 0);
700 if (! NILP (init)) 728 if (! NILP (init))
701 CHECK_STRING (init, 1); 729 CHECK_STRING (init, 1);
702 730
703 return read_minibuf (Vminibuffer_local_ns_map, init, prompt, Qnil, 731 return read_minibuf (Vminibuffer_local_ns_map, init, prompt, Qnil,
704 0, Qminibuffer_history, make_number (0), Qnil, 0, 0); 732 0, Qminibuffer_history, make_number (0), Qnil, 0,
733 !NILP (inherit_input_method));
705 } 734 }
706 735
707 DEFUN ("read-command", Fread_command, Sread_command, 1, 2, 0, 736 DEFUN ("read-command", Fread_command, Sread_command, 1, 2, 0,
708 "Read the name of a command and return as a symbol.\n\ 737 "Read the name of a command and return as a symbol.\n\
709 Prompts with PROMPT. By default, return DEFAULT-VALUE.") 738 Prompts with PROMPT. By default, return DEFAULT-VALUE.")
710 (prompt, default_value) 739 (prompt, default_value)
711 Lisp_Object prompt, default_value; 740 Lisp_Object prompt, default_value;
712 { 741 {
713 return Fintern (Fcompleting_read (prompt, Vobarray, Qcommandp, Qt, 742 return Fintern (Fcompleting_read (prompt, Vobarray, Qcommandp, Qt,
714 Qnil, Qnil, default_value), 743 Qnil, Qnil, default_value, Qnil),
715 Qnil); 744 Qnil);
716 } 745 }
717 746
718 #ifdef NOTDEF 747 #ifdef NOTDEF
719 DEFUN ("read-function", Fread_function, Sread_function, 1, 1, 0, 748 DEFUN ("read-function", Fread_function, Sread_function, 1, 1, 0,
720 "One arg PROMPT, a string. Read the name of a function and return as a symbol.\n\ 749 "One arg PROMPT, a string. Read the name of a function and return as a symbol.\n\
721 Prompts with PROMPT.") 750 Prompts with PROMPT.")
722 (prompt) 751 (prompt)
723 Lisp_Object prompt; 752 Lisp_Object prompt;
724 { 753 {
725 return Fintern (Fcompleting_read (prompt, Vobarray, Qfboundp, Qt, Qnil, Qnil, Qnil), 754 return Fintern (Fcompleting_read (prompt, Vobarray, Qfboundp, Qt, Qnil, Qnil, Qnil, Qnil),
726 Qnil); 755 Qnil);
727 } 756 }
728 #endif /* NOTDEF */ 757 #endif /* NOTDEF */
729 758
730 DEFUN ("read-variable", Fread_variable, Sread_variable, 1, 2, 0, 759 DEFUN ("read-variable", Fread_variable, Sread_variable, 1, 2, 0,
734 (prompt, default_value) 763 (prompt, default_value)
735 Lisp_Object prompt, default_value; 764 Lisp_Object prompt, default_value;
736 { 765 {
737 return Fintern (Fcompleting_read (prompt, Vobarray, 766 return Fintern (Fcompleting_read (prompt, Vobarray,
738 Quser_variable_p, Qt, 767 Quser_variable_p, Qt,
739 Qnil, Qnil, default_value), 768 Qnil, Qnil, default_value, Qnil),
740 Qnil); 769 Qnil);
741 } 770 }
742 771
743 DEFUN ("read-buffer", Fread_buffer, Sread_buffer, 1, 3, 0, 772 DEFUN ("read-buffer", Fread_buffer, Sread_buffer, 1, 3, 0,
744 "One arg PROMPT, a string. Read the name of a buffer and return as a string.\n\ 773 "One arg PROMPT, a string. Read the name of a buffer and return as a string.\n\
759 args[1] = prompt; 788 args[1] = prompt;
760 args[2] = def; 789 args[2] = def;
761 prompt = Fformat (3, args); 790 prompt = Fformat (3, args);
762 } 791 }
763 return Fcompleting_read (prompt, Vbuffer_alist, Qnil, 792 return Fcompleting_read (prompt, Vbuffer_alist, Qnil,
764 require_match, Qnil, Qnil, def); 793 require_match, Qnil, Qnil, def, Qnil);
765 } 794 }
766 795
767 DEFUN ("try-completion", Ftry_completion, Stry_completion, 2, 3, 0, 796 DEFUN ("try-completion", Ftry_completion, Stry_completion, 2, 3, 0,
768 "Return common substring of all completions of STRING in ALIST.\n\ 797 "Return common substring of all completions of STRING in ALIST.\n\
769 Each car of each element of ALIST is tested to see if it begins with STRING.\n\ 798 Each car of each element of ALIST is tested to see if it begins with STRING.\n\
1124 1153
1125 /* This comment supplies the doc string for completing-read, 1154 /* This comment supplies the doc string for completing-read,
1126 for make-docfile to see. We cannot put this in the real DEFUN 1155 for make-docfile to see. We cannot put this in the real DEFUN
1127 due to limits in the Unix cpp. 1156 due to limits in the Unix cpp.
1128 1157
1129 DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 7, 0, 1158 DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 8, 0,
1130 "Read a string in the minibuffer, with completion.\n\ 1159 "Read a string in the minibuffer, with completion.\n\
1131 PROMPT is a string to prompt with; normally it ends in a colon and a space.\n\ 1160 PROMPT is a string to prompt with; normally it ends in a colon and a space.\n\
1132 TABLE is an alist whose elements' cars are strings, or an obarray.\n\ 1161 TABLE is an alist whose elements' cars are strings, or an obarray.\n\
1133 PREDICATE limits completion to a subset of TABLE.\n\ 1162 PREDICATE limits completion to a subset of TABLE.\n\
1134 See `try-completion' and `all-completions' for more details 1163 See `try-completion' and `all-completions' for more details
1149 or it can be a cons cell (HISTVAR . HISTPOS).\n\ 1178 or it can be a cons cell (HISTVAR . HISTPOS).\n\
1150 In that case, HISTVAR is the history list variable to use,\n\ 1179 In that case, HISTVAR is the history list variable to use,\n\
1151 and HISTPOS is the initial position (the position in the list\n\ 1180 and HISTPOS is the initial position (the position in the list\n\
1152 which INITIAL-CONTENTS corresponds to).\n\ 1181 which INITIAL-CONTENTS corresponds to).\n\
1153 Positions are counted starting from 1 at the beginning of the list.\n\ 1182 Positions are counted starting from 1 at the beginning of the list.\n\
1154 DEF, if non-nil, is the default value. 1183 DEF, if non-nil, is the default value.\n\
1155 1184 \n\
1185 If INHERIT-INPUT-METHOD is non-nil, the minibuffer inherits\n\
1186 the current input method.\n\
1187 \n\
1156 Completion ignores case if the ambient value of\n\ 1188 Completion ignores case if the ambient value of\n\
1157 `completion-ignore-case' is non-nil." 1189 `completion-ignore-case' is non-nil."
1158 */ 1190 */
1159 DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 7, 0, 1191 DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 8, 0,
1160 0 /* See immediately above */) 1192 0 /* See immediately above */)
1161 (prompt, table, predicate, require_match, init, hist, def) 1193 (prompt, table, predicate, require_match, init, hist, def, inherit_input_method)
1162 Lisp_Object prompt, table, predicate, require_match, init, hist, def; 1194 Lisp_Object prompt, table, predicate, require_match, init, hist, def;
1195 Lisp_Object inherit_input_method;
1163 { 1196 {
1164 Lisp_Object val, histvar, histpos, position; 1197 Lisp_Object val, histvar, histpos, position;
1165 int pos = 0; 1198 int pos = 0;
1166 int count = specpdl_ptr - specpdl; 1199 int count = specpdl_ptr - specpdl;
1167 struct gcpro gcpro1; 1200 struct gcpro gcpro1;
1209 1242
1210 val = read_minibuf (NILP (require_match) 1243 val = read_minibuf (NILP (require_match)
1211 ? Vminibuffer_local_completion_map 1244 ? Vminibuffer_local_completion_map
1212 : Vminibuffer_local_must_match_map, 1245 : Vminibuffer_local_must_match_map,
1213 init, prompt, make_number (pos), 0, 1246 init, prompt, make_number (pos), 0,
1214 histvar, histpos, def, 0, disable_multibyte); 1247 histvar, histpos, def, 0,
1248 !NILP (inherit_input_method));
1215 if (STRINGP (val) && XSTRING (val)->size == 0 && ! NILP (def)) 1249 if (STRINGP (val) && XSTRING (val)->size == 0 && ! NILP (def))
1216 val = def; 1250 val = def;
1217 RETURN_UNGCPRO (unbind_to (count, val)); 1251 RETURN_UNGCPRO (unbind_to (count, val));
1218 } 1252 }
1219 1253
1925 staticpro (&Qminibuffer_exit_hook); 1959 staticpro (&Qminibuffer_exit_hook);
1926 1960
1927 Qhistory_length = intern ("history-length"); 1961 Qhistory_length = intern ("history-length");
1928 staticpro (&Qhistory_length); 1962 staticpro (&Qhistory_length);
1929 1963
1964 Qcurrent_input_method = intern ("current-input-method");
1965 staticpro (&Qcurrent_input_method);
1966
1967 Qactivate_input_method = intern ("activate-input-method");
1968 staticpro (&Qactivate_input_method);
1969
1930 DEFVAR_LISP ("minibuffer-setup-hook", &Vminibuffer_setup_hook, 1970 DEFVAR_LISP ("minibuffer-setup-hook", &Vminibuffer_setup_hook,
1931 "Normal hook run just after entry to minibuffer."); 1971 "Normal hook run just after entry to minibuffer.");
1932 Vminibuffer_setup_hook = Qnil; 1972 Vminibuffer_setup_hook = Qnil;
1933 1973
1934 DEFVAR_LISP ("minibuffer-exit-hook", &Vminibuffer_exit_hook, 1974 DEFVAR_LISP ("minibuffer-exit-hook", &Vminibuffer_exit_hook,