all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Apply faces to string output to mini-buffer
@ 2013-05-23 10:50 Miguel Guedes
  2013-05-23 16:26 ` Eli Zaretskii
       [not found] ` <mailman.259.1369326384.22516.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 7+ messages in thread
From: Miguel Guedes @ 2013-05-23 10:50 UTC (permalink / raw)
  To: help-gnu-emacs

Hello List,

How can faces be applied to strings output to the minibuffer?

An elisp client I'm writing receives data asynchronously from a server 
and I would very much like to apply faces to it. So the following string 
should have the appropriate faces applied to type, variable and function 
name, and so on:

boost::shared_ptr<const PrecompiledHeader> get(unsigned int index)


-- 
Miguel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Apply faces to string output to mini-buffer
  2013-05-23 10:50 Apply faces to string output to mini-buffer Miguel Guedes
@ 2013-05-23 16:26 ` Eli Zaretskii
       [not found] ` <mailman.259.1369326384.22516.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2013-05-23 16:26 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Miguel Guedes <miguel.a.guedes@gmail.com>
> Date: 23 May 2013 10:50:56 GMT
> 
> How can faces be applied to strings output to the minibuffer?

Use 'propertize'.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Apply faces to string output to mini-buffer
       [not found] ` <mailman.259.1369326384.22516.help-gnu-emacs@gnu.org>
@ 2013-05-24  5:27   ` Miguel Guedes
  2013-05-24  6:30     ` Miguel Guedes
  2013-05-24  6:40     ` Eli Zaretskii
  0 siblings, 2 replies; 7+ messages in thread
From: Miguel Guedes @ 2013-05-24  5:27 UTC (permalink / raw)
  To: help-gnu-emacs

On Thu, 23 May 2013 19:26:09 +0300, Eli Zaretskii wrote:

> 
> Use 'propertize'.

I did do, Eli, and while it works as expected with normal buffers it 
doesn't so when it comes to the minibuffer.  Your answer, though, has 
forced me to consider the approach I've been taking, which was to use the 
built in C function `message' to output propertized strings?  Your reply 
seems to imply my approach is wrong and I should instead look for a 
different one - perhaps I shouldn't be using `message' at all?

-- 
Miguel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Apply faces to string output to mini-buffer
  2013-05-24  5:27   ` Miguel Guedes
@ 2013-05-24  6:30     ` Miguel Guedes
  2013-05-24  7:40       ` Stephen Berman
       [not found]       ` <mailman.301.1369381272.22516.help-gnu-emacs@gnu.org>
  2013-05-24  6:40     ` Eli Zaretskii
  1 sibling, 2 replies; 7+ messages in thread
From: Miguel Guedes @ 2013-05-24  6:30 UTC (permalink / raw)
  To: help-gnu-emacs

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?


-- 
Miguel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Apply faces to string output to mini-buffer
  2013-05-24  5:27   ` Miguel Guedes
  2013-05-24  6:30     ` Miguel Guedes
@ 2013-05-24  6:40     ` Eli Zaretskii
  1 sibling, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2013-05-24  6:40 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Miguel Guedes <miguel.a.guedes@gmail.com>
> Date: 24 May 2013 05:27:15 GMT
> 
> On Thu, 23 May 2013 19:26:09 +0300, Eli Zaretskii wrote:
> 
> > Use 'propertize'.
> 
> I did do, Eli, and while it works as expected with normal buffers it 
> doesn't so when it comes to the minibuffer.

Then please show a simplified version of your code that could be used
to see the issues.  Your original question was too general, and
suggested that you didn't know about 'propertize' at all.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Apply faces to string output to mini-buffer
  2013-05-24  6:30     ` Miguel Guedes
@ 2013-05-24  7:40       ` Stephen Berman
       [not found]       ` <mailman.301.1369381272.22516.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 7+ messages in thread
From: Stephen Berman @ 2013-05-24  7:40 UTC (permalink / raw)
  To: help-gnu-emacs

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




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Apply faces to string output to mini-buffer
       [not found]       ` <mailman.301.1369381272.22516.help-gnu-emacs@gnu.org>
@ 2013-05-24  8:38         ` Miguel Guedes
  0 siblings, 0 replies; 7+ messages in thread
From: Miguel Guedes @ 2013-05-24  8:38 UTC (permalink / raw)
  To: help-gnu-emacs

On Fri, 24 May 2013 09:40:50 +0200, Stephen Berman wrote:
> 
> 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.

I would never have got that.  Thank you for the explanation & solution, 
Stephen!

-- 
Miguel


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-05-24  8:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-23 10:50 Apply faces to string output to mini-buffer Miguel Guedes
2013-05-23 16:26 ` Eli Zaretskii
     [not found] ` <mailman.259.1369326384.22516.help-gnu-emacs@gnu.org>
2013-05-24  5:27   ` Miguel Guedes
2013-05-24  6:30     ` Miguel Guedes
2013-05-24  7:40       ` Stephen Berman
     [not found]       ` <mailman.301.1369381272.22516.help-gnu-emacs@gnu.org>
2013-05-24  8:38         ` Miguel Guedes
2013-05-24  6:40     ` Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.