From bf0b6fab032bd35fae36f7371b7cd1fe3bfaaac7 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sun, 1 May 2016 16:53:38 +0200 Subject: [PATCH] Allow minibuffer prompts to use faces * doc/lispref/minibuf.texi (Text from Minibuffer): Document `minibuffer-prompt-properties' and explain how faces work in the minibuffer prompt. * src/minibuf.c (read_minibuf): If `face' is in `minibuffer-prompt-properties', apply it to the end of the face list to allow users to have their own faces on the prompts (bug#16136). --- doc/lispref/minibuf.texi | 17 +++++++++++++++++ etc/NEWS | 6 ++++++ src/minibuf.c | 27 +++++++++++++++++++++++++-- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi index 6f41090ebe..88662aba08 100644 --- a/doc/lispref/minibuf.texi +++ b/doc/lispref/minibuf.texi @@ -170,6 +170,23 @@ non-@code{nil}, then the string that is returned includes whatever text properties were present in the minibuffer. Otherwise all the text properties are stripped when the value is returned. +@cvindex minibuffer-prompt-properties +The text properties in @code{minibuffer-prompt-properties} are applied +to the prompt. By default, this property list defines a face to use +for the prompt. This face, if present, is applied to the end of the +face list and merged before display. + +If the user wants to completely control the look of the prompt, the +most convenient way to do that is to specify the @code{default} face +at the end of all face lists. For instance: + +@lisp +(read-from-minibuffer + (concat + (propertize "Bold" 'face '(bold default)) + (propertize " and normal: " 'face '(default)))) +@end lisp + If the argument @var{inherit-input-method} is non-@code{nil}, then the minibuffer inherits the current input method (@pxref{Input Methods}) and the setting of @code{enable-multibyte-characters} (@pxref{Text diff --git a/etc/NEWS b/etc/NEWS index ed4810b298..cf360a329a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -56,6 +56,12 @@ affected by this, as SGI stopped supporting IRIX in December 2013. * Changes in Emacs 25.2 ++++ +** Faces in `minibuffer-prompt-properties' no longer overwrite properties +in the text in functions like `read-from-minibuffer', but instead are +added to the end of the face list. This allows users to say things +like `(read-from-minibuffer (propertize "Enter something: " 'face 'bold))'. + +++ ** The new variable `extended-command-suggest-shorter' has been added to control whether to suggest shorter `M-x' commands or not. diff --git a/src/minibuf.c b/src/minibuf.c index 0b8b00ce2c..d2a4c9b953 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -630,8 +630,31 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt, Qrear_nonsticky, Qt, Qnil); Fput_text_property (make_number (BEG), make_number (PT), Qfield, Qt, Qnil); - Fadd_text_properties (make_number (BEG), make_number (PT), - Vminibuffer_prompt_properties, Qnil); + if (Fconsp (Vminibuffer_prompt_properties)) + { + /* We want to apply all properties from + `minibuffer-prompt-properties' to the region normally, + but if the `face' property is present, add that + property to the end of the face properties to avoid + overwriting faces. */ + Lisp_Object list = Vminibuffer_prompt_properties; + while (CONSP (list)) + { + Lisp_Object key = XCAR (list); + list = XCDR (list); + if (CONSP (list)) + { + Lisp_Object val = XCAR (list); + list = XCDR (list); + if (EQ (key, Qface)) + Fadd_face_text_property (make_number (BEG), + make_number (PT), val, Qt, Qnil); + else + Fput_text_property (make_number (BEG), make_number (PT), + key, val, Qnil); + } + } + } } unbind_to (count1, Qnil); } -- 2.39.2