emacs-devel
[Top][All Lists]
Advanced

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

Re: How to walk a Lisp_String?


From: Eli Zaretskii
Subject: Re: How to walk a Lisp_String?
Date: Fri, 02 Sep 2022 13:52:42 +0300

> From: Manuel Giraud <manuel@ledu-giraud.fr>
> Cc: emacs-devel@gnu.org
> Date: Fri, 02 Sep 2022 10:56:56 +0200
> 
> > Why would you need to create a unibyte string?  More importantly, why
> > would you trust make_string to make the decision that is right for
> > your purposes?
> 
> Because it was written by Emacs' hackers… more seriously, for the
> purpose of menu entries, I think that most strings will be unibyte ASCII
> strings.

ASCII strings can be unibyte or multibyte, Emacs does TRT with both.
So you don't need to worry about that.

> But I thought I needed a Lisp_String in order to use some
> other emacs interfaces.

Depends on the interface.

> > Before you could ask Emacs what is the face of a particular character
> > of a Lisp string, some code should place the face information on that
> > string.  In Lisp, you do that by calling 'propertize' or similar
> > APIs.  If you don't place the face information on a Lisp string, how
> > can you expect the string to have it?
> 
> This code :
> --8<---------------cut here---------------start------------->8---
> static int
> face_upto (Lisp_Object frame, struct Lisp_String *string, int start, int 
> *face_id)
> {
>   struct frame *f = XFRAME (frame);
>   struct face *face = FACE_FROM_ID (f, DEFAULT_FACE_ID);
>   int mychar = 128517;
> 
>   *face_id = FACE_FOR_CHAR (f, face, mychar, -1, Qnil);
>   face = FACE_FROM_ID_OR_NULL (f, *face_id);
>   if (face && face->font)
>     fprintf(stderr, ">>> %d %s\n", mychar,
>           SDATA (face->font->props[FONT_NAME_INDEX]));
> 
> 
>   mychar = 'c';
>   *face_id = FACE_FOR_CHAR (f, face, mychar, -1, Qnil);
>   face = FACE_FROM_ID_OR_NULL (f, *face_id);
>   if (face && face->font)
>     fprintf(stderr, ">>> %d %s\n", mychar,
>           SDATA (face->font->props[FONT_NAME_INDEX]));
> 
>   return 0;
> }
> --8<---------------cut here---------------end--------------->8---
> 
> called from xlwmenu.c/display_menu_item with the retrieved frame works
> for me and displays this:

You probably modified display_menu_item, because I see no Lisp_String
objects there no or Lisp_Object frame.  So I still don't understand
how you intend to put face information on your Lisp strings, nor even
how you produce those Lisp strings in a function that currently
manipulates only C data types, without any Emacs-specific Lisp data
types.

In any case, what you did above is show the font that Emacs will use
for a particular character on a particular frame.  It has nothing to
do with the string or its faces.  That should be obvious given the
fact that none of APIs you call accept the string as its argument.

> But I guess I should propertized those menu strings with the menu face
> and then use face_at_string_position.  That's right?

At least, yes.  And then I'd expect the currently active
(a.k.a. "selected") menu item to have a different face from the other
items, so that the active menu item stands out on display and provides
a visual feedback for the user moving the mouse to select menu items.



reply via email to

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