From 4a112fd7a6f0dcbd1b99b811b324123f5699bdfb Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 8 Mar 2021 03:29:42 +0100 Subject: Add new face 'help-key-binding' for keybindings in help * lisp/faces.el (help-key-binding): New face. * lisp/help.el (help-for-help): Rename from 'help-for-help-internal'. Use 'substitute-command-keys' syntax. (help): Make into alias for 'help-for-help'. (help-for-help-internal): Make into obsolete alias for 'help-for-help'. (help--key-description-fontified): New function to add the 'help-key-binding' face. (help-key-description, substitute-command-keys) (describe-map-tree, help--describe-command) (help--describe-translation, describe-map): * lisp/help-fns.el (help-fns--key-bindings, describe-mode): Use above new function. * lisp/isearch.el (isearch-help-for-help-internal): Use `substitute-command-keys' syntax. * lisp/help-macro.el (make-help-screen): Use 'substitute-command-keys' and 'help--key-description-fontified'. Simplify. * src/keymap.c (describe_key_maybe_fontify): New function to add the 'help-key-binding' face to keybindings. (describe_vector): Use above new keybinding. (syms_of_keymap) : New DEFSYMs. (fontify_key_properties): New static variable. * lisp/tooltip.el (tooltip-show): Avoid overriding faces in specified tooltip text. * test/lisp/help-tests.el (with-substitute-command-keys-test): Don't test for text properties. (help-tests-substitute-command-keys/add-key-face) (help-tests-substitute-command-keys/add-key-face-listing): New tests. --- src/keymap.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/keymap.c') diff --git a/src/keymap.c b/src/keymap.c index 782931fadff..bb26b6389d4 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -2846,6 +2846,21 @@ DESCRIBER is the output function used; nil means use `princ'. */) return unbind_to (count, Qnil); } +static Lisp_Object fontify_key_properties; + +static Lisp_Object +describe_key_maybe_fontify (Lisp_Object str, Lisp_Object prefix, + bool keymap_p) +{ + Lisp_Object key_desc = Fkey_description (str, prefix); + if (keymap_p) + Fadd_text_properties (make_fixnum (0), + make_fixnum (SCHARS (key_desc)), + fontify_key_properties, + key_desc); + return key_desc; +} + DEFUN ("help--describe-vector", Fhelp__describe_vector, Shelp__describe_vector, 7, 7, 0, doc: /* Insert in the current buffer a description of the contents of VECTOR. Call DESCRIBER to insert the description of one value found in VECTOR. @@ -3021,7 +3036,7 @@ describe_vector (Lisp_Object vector, Lisp_Object prefix, Lisp_Object args, if (!NILP (elt_prefix)) insert1 (elt_prefix); - insert1 (Fkey_description (kludge, prefix)); + insert1 (describe_key_maybe_fontify (kludge, prefix, keymap_p)); /* Find all consecutive characters or rows that have the same definition. But, if VECTOR is a char-table, we had better @@ -3071,7 +3086,7 @@ describe_vector (Lisp_Object vector, Lisp_Object prefix, Lisp_Object args, if (!NILP (elt_prefix)) insert1 (elt_prefix); - insert1 (Fkey_description (kludge, prefix)); + insert1 (describe_key_maybe_fontify (kludge, prefix, keymap_p)); } /* Print a description of the definition of this character. @@ -3200,6 +3215,12 @@ be preferred. */); staticpro (&where_is_cache); staticpro (&where_is_cache_keymaps); + DEFSYM (Qfont_lock_face, "font-lock-face"); + DEFSYM (Qhelp_key_binding, "help-key-binding"); + staticpro (&fontify_key_properties); + fontify_key_properties = Fcons (Qfont_lock_face, + Fcons (Qhelp_key_binding, Qnil)); + defsubr (&Skeymapp); defsubr (&Skeymap_parent); defsubr (&Skeymap_prompt); -- cgit v1.2.3 From 3e93c2e5ae48e8595e80b1fb69955c2e051ca004 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Tue, 20 Apr 2021 10:36:48 -0400 Subject: * src/minibuf.c (Fread_no_blanks_input): Move to `minibuffer.el` * src/keymap.c (syms_of_keymap): * lisp/minibuffer.el (minibuffer-local-ns-map): Move declaration to initialization. (read-no-blanks-input): Move from `minibuf.c`. --- lisp/minibuffer.el | 31 +++++++++++++++++++++++++++---- src/keymap.c | 6 ------ src/minibuf.c | 25 ------------------------- 3 files changed, 27 insertions(+), 35 deletions(-) (limited to 'src/keymap.c') diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 55af95a9604..7da3c39e6b9 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -2469,10 +2469,33 @@ with `minibuffer-local-must-match-map'.") (defvar minibuffer-local-filename-must-match-map (make-sparse-keymap)) (make-obsolete-variable 'minibuffer-local-filename-must-match-map nil "24.1") -(let ((map minibuffer-local-ns-map)) - (define-key map " " 'exit-minibuffer) - (define-key map "\t" 'exit-minibuffer) - (define-key map "?" 'self-insert-and-exit)) +(defvar minibuffer-local-ns-map + (let ((map (make-sparse-keymap))) + (set-keymap-parent map minibuffer-local-map) + (define-key map " " #'exit-minibuffer) + (define-key map "\t" #'exit-minibuffer) + (define-key map "?" #'self-insert-and-exit) + map) + "Local keymap for the minibuffer when spaces are not allowed.") + +(defun read-no-blanks-input (prompt &optional initial inherit-input-method) + "Read a string from the terminal, not allowing blanks. +Prompt with PROMPT. Whitespace terminates the input. If INITIAL is +non-nil, it should be a string, which is used as initial input, with +point positioned at the end, so that SPACE will accept the input. +\(Actually, INITIAL can also be a cons of a string and an integer. +Such values are treated as in `read-from-minibuffer', but are normally +not useful in this function.) + +Third arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits +the current input method and the setting of`enable-multibyte-characters'. + +If `inhibit-interaction' is non-nil, this function will signal an +`inhibited-interaction' error." + (read-from-minibuffer prompt initial minibuffer-local-ns-map + nil minibuffer-history nil inherit-input-method)) + +;;; Major modes for the minibuffer (defvar minibuffer-inactive-mode-map (let ((map (make-keymap))) diff --git a/src/keymap.c b/src/keymap.c index bb26b6389d4..fb8eceaec18 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -3148,12 +3148,6 @@ syms_of_keymap (void) doc: /* Default keymap to use when reading from the minibuffer. */); Vminibuffer_local_map = Fmake_sparse_keymap (Qnil); - DEFVAR_LISP ("minibuffer-local-ns-map", Vminibuffer_local_ns_map, - doc: /* Local keymap for the minibuffer when spaces are not allowed. */); - Vminibuffer_local_ns_map = Fmake_sparse_keymap (Qnil); - Fset_keymap_parent (Vminibuffer_local_ns_map, Vminibuffer_local_map); - - DEFVAR_LISP ("minor-mode-map-alist", Vminor_mode_map_alist, doc: /* Alist of keymaps to use for minor modes. Each element looks like (VARIABLE . KEYMAP); KEYMAP is used to read diff --git a/src/minibuf.c b/src/minibuf.c index 89d9357b4ed..1a637c86ade 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -1360,30 +1360,6 @@ Fifth arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits return unbind_to (count, val); } -DEFUN ("read-no-blanks-input", Fread_no_blanks_input, Sread_no_blanks_input, 1, 3, 0, - doc: /* Read a string from the terminal, not allowing blanks. -Prompt with PROMPT. Whitespace terminates the input. If INITIAL is -non-nil, it should be a string, which is used as initial input, with -point positioned at the end, so that SPACE will accept the input. -\(Actually, INITIAL can also be a cons of a string and an integer. -Such values are treated as in `read-from-minibuffer', but are normally -not useful in this function.) - -Third arg INHERIT-INPUT-METHOD, if non-nil, means the minibuffer inherits -the current input method and the setting of`enable-multibyte-characters'. - -If `inhibit-interaction' is non-nil, this function will signal an -`inhibited-interaction' error. */) - (Lisp_Object prompt, Lisp_Object initial, Lisp_Object inherit_input_method) -{ - CHECK_STRING (prompt); - barf_if_interaction_inhibited (); - - return read_minibuf (Vminibuffer_local_ns_map, initial, prompt, - 0, Qminibuffer_history, make_fixnum (0), Qnil, 0, - !NILP (inherit_input_method)); -} - DEFUN ("read-command", Fread_command, Sread_command, 1, 2, 0, doc: /* Read the name of a command and return as a symbol. Prompt with PROMPT. By default, return DEFAULT-VALUE or its first element @@ -2517,7 +2493,6 @@ instead. */); defsubr (&Sread_variable); defsubr (&Sinternal_complete_buffer); defsubr (&Sread_buffer); - defsubr (&Sread_no_blanks_input); defsubr (&Sminibuffer_depth); defsubr (&Sminibuffer_prompt); -- cgit v1.2.3