diff options
Diffstat (limited to 'src/minibuf.c')
-rw-r--r-- | src/minibuf.c | 117 |
1 files changed, 59 insertions, 58 deletions
diff --git a/src/minibuf.c b/src/minibuf.c index 469776eaaeb..3408bb995c6 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -22,6 +22,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <errno.h> #include <stdio.h> +#include <binary-io.h> + #include "lisp.h" #include "commands.h" #include "character.h" @@ -34,6 +36,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include "intervals.h" #include "keymap.h" #include "termhooks.h" +#include "systty.h" /* List of buffers for use as minibuffers. The first element of the list is used for the outermost minibuffer @@ -51,37 +54,10 @@ static Lisp_Object minibuf_save_list; EMACS_INT minibuf_level; -/* The maximum length of a minibuffer history. */ - -static Lisp_Object Qhistory_length; - /* Fread_minibuffer leaves the input here as a string. */ Lisp_Object last_minibuf_string; -static Lisp_Object Qminibuffer_history, Qbuffer_name_history; - -static Lisp_Object Qread_file_name_internal; - -/* Normal hooks for entry to and exit from minibuffer. */ - -static Lisp_Object Qminibuffer_setup_hook; -static Lisp_Object Qminibuffer_exit_hook; - -Lisp_Object Qcompletion_ignore_case; -static Lisp_Object Qminibuffer_completion_table; -static Lisp_Object Qminibuffer_completion_predicate; -static Lisp_Object Qminibuffer_completion_confirm; -static Lisp_Object Qcustom_variable_p; - -static Lisp_Object Qminibuffer_default; - -static Lisp_Object Qcurrent_input_method, Qactivate_input_method; - -static Lisp_Object Qcase_fold_search; - -static Lisp_Object Qread_expression_history; - /* Prompt to display in front of the mini-buffer contents. */ static Lisp_Object minibuf_prompt; @@ -224,8 +200,24 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial, char *line; Lisp_Object val; int c; + unsigned char hide_char = 0; + struct emacs_tty etty; + bool etty_valid; + + /* Check, whether we need to suppress echoing. */ + if (CHARACTERP (Vread_hide_char)) + hide_char = XFASTINT (Vread_hide_char); + + /* Manipulate tty. */ + if (hide_char) + { + etty_valid = emacs_get_tty (fileno (stdin), &etty) == 0; + if (etty_valid) + set_binary_mode (fileno (stdin), O_BINARY); + suppress_echo_on_tty (fileno (stdin)); + } - fprintf (stdout, "%s", SDATA (prompt)); + fwrite (SDATA (prompt), 1, SBYTES (prompt), stdout); fflush (stdout); val = Qnil; @@ -233,7 +225,7 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial, len = 0; line = xmalloc (size); - while ((c = getchar ()) != '\n') + while ((c = getchar ()) != '\n' && c != '\r') { if (c == EOF) { @@ -242,6 +234,8 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial, } else { + if (hide_char) + fprintf (stdout, "%c", hide_char); if (len == size) { if (STRING_BYTES_BOUND / 2 < size) @@ -253,7 +247,18 @@ read_minibuf_noninteractive (Lisp_Object map, Lisp_Object initial, } } - if (len || c == '\n') + /* Reset tty. */ + if (hide_char) + { + fprintf (stdout, "\n"); + if (etty_valid) + { + emacs_set_tty (fileno (stdin), &etty, 0); + set_binary_mode (fileno (stdin), O_TEXT); + } + } + + if (len || c == '\n' || c == '\r') { val = make_string (line, len); xfree (line); @@ -619,6 +624,7 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt, set_window_buffer (minibuf_window, Fcurrent_buffer (), 0, 0); Fselect_window (minibuf_window, Qnil); XWINDOW (minibuf_window)->hscroll = 0; + XWINDOW (minibuf_window)->suspend_auto_hscroll = 0; Fmake_local_variable (Qprint_escape_newlines); print_escape_newlines = 1; @@ -666,7 +672,7 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt, if (STRINGP (input_method) && !NILP (Ffboundp (Qactivate_input_method))) call1 (Qactivate_input_method, input_method); - Frun_hooks (1, &Qminibuffer_setup_hook); + run_hook (Qminibuffer_setup_hook); /* Don't allow the user to undo past this point. */ bset_undo_list (current_buffer, Qnil); @@ -680,8 +686,8 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt, { XWINDOW (minibuf_window)->cursor.hpos = 0; XWINDOW (minibuf_window)->cursor.x = 0; - XWINDOW (minibuf_window)->must_be_updated_p = 1; - update_frame (XFRAME (selected_frame), 1, 1); + XWINDOW (minibuf_window)->must_be_updated_p = true; + update_frame (XFRAME (selected_frame), true, true); flush_frame (XFRAME (XWINDOW (minibuf_window)->frame)); } @@ -1090,7 +1096,7 @@ If `read-buffer-function' is non-nil, this works by calling it as a function, instead of the usual behavior. */) (Lisp_Object prompt, Lisp_Object def, Lisp_Object require_match) { - Lisp_Object args[4], result; + Lisp_Object result; char *s; ptrdiff_t len; ptrdiff_t count = SPECPDL_INDEX (); @@ -1124,10 +1130,9 @@ function, instead of the usual behavior. */) STRING_MULTIBYTE (prompt)); } - args[0] = build_string ("%s (default %s): "); - args[1] = prompt; - args[2] = CONSP (def) ? XCAR (def) : def; - prompt = Fformat (3, args); + AUTO_STRING (format, "%s (default %s): "); + prompt = CALLN (Fformat, format, prompt, + CONSP (def) ? XCAR (def) : def); } result = Fcompleting_read (prompt, intern ("internal-complete-buffer"), @@ -1135,13 +1140,7 @@ function, instead of the usual behavior. */) Qbuffer_name_history, def, Qnil); } else - { - args[0] = Vread_buffer_function; - args[1] = prompt; - args[2] = def; - args[3] = require_match; - result = Ffuncall (4, args); - } + result = call3 (Vread_buffer_function, prompt, def, require_match); return unbind_to (count, result); } @@ -1661,17 +1660,10 @@ Completion ignores case if the ambient value of 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] = Fsymbol_value (intern ("completing-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); + return CALLN (Ffuncall, + Fsymbol_value (intern ("completing-read-function")), + prompt, collection, predicate, require_match, initial_input, + hist, def, inherit_input_method); } /* Test whether TXT is an exact completion. */ @@ -1793,8 +1785,6 @@ the values STRING, PREDICATE and `lambda'. */) return Qt; } -static Lisp_Object Qmetadata; - DEFUN ("internal-complete-buffer", Finternal_complete_buffer, Sinternal_complete_buffer, 3, 3, 0, doc: /* Perform completion on buffer names. STRING and PREDICATE have the same meanings as in `try-completion', @@ -1928,9 +1918,14 @@ syms_of_minibuf (void) Fset (Qbuffer_name_history, Qnil); DEFSYM (Qcustom_variable_p, "custom-variable-p"); + + /* Normal hooks for entry to and exit from minibuffer. */ DEFSYM (Qminibuffer_setup_hook, "minibuffer-setup-hook"); DEFSYM (Qminibuffer_exit_hook, "minibuffer-exit-hook"); + + /* The maximum length of a minibuffer history. */ DEFSYM (Qhistory_length, "history-length"); + DEFSYM (Qcurrent_input_method, "current-input-method"); DEFSYM (Qactivate_input_method, "activate-input-method"); DEFSYM (Qcase_fold_search, "case-fold-search"); @@ -2079,6 +2074,12 @@ properties. */); initialization-order problems. */ Vminibuffer_prompt_properties = list2 (intern_c_string ("read-only"), Qt); + DEFVAR_LISP ("read-hide-char", Vread_hide_char, + doc: /* Whether to hide input characters in noninteractive mode. +It must be a character, which will be used to mask the input +characters. This variable should never be set globally. */); + Vread_hide_char = Qnil; + defsubr (&Sactive_minibuffer_window); defsubr (&Sset_minibuffer_window); defsubr (&Sread_from_minibuffer); |