help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Apply faces to string output to mini-buffer


From: Stephen Berman
Subject: Re: Apply faces to string output to mini-buffer
Date: Fri, 24 May 2013 09:40:50 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

On 24 May 2013 06:30:32 GMT Miguel Guedes <miguel.a.guedes@gmail.com> wrote:

> On Fri, 24 May 2013 05:27:15 +0000, Miguel Guedes wrote:
>
> For instance, the following doesn't work:
>
> Eval:
> (message "%s" (propertize "foo" 'face 'font-lock-variable-name-face))
>
> Echoes:
> #("foo" 0 3 (face font-lock-variable-name-face))
>
> Eval:
> (message "%s" (propertize "foo" 'face '(:foreground "red")))
>
> Echoes:
> #("foo" 0 3 (face (:foreground "red")))
>
>
> Also, eldoc seems to also make use of `message' to output propertized 
> strings (eldoc.el:206:0) so it (seems it) can be used for this purpose. 
> Question is what's wrong with my approach above?

The function `message' returns the printed representation of the
message, so when you evaluate it in the minibuffer, this return value
overwrites the propertized message, which is displayed in the echo area
(which coincides with the minibuffer) as a side effect (on my machine I
can see it briefly before it is overwritten).  If you embed the message
sexp in another function, it returns to the caller, so it doesn't
overwrite the propertized message in the echo area.  E.g., if you
evaluate this:

(defun my-foo ()
  (interactive)
  (message "%s" (propertize "foo" 'face '(:foreground "red"))))

and then type `M-x my-foo', you'll see a red "foo" (without quotes) in
the echo area.

Steve Berman




reply via email to

[Prev in Thread] Current Thread [Next in Thread]