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: Manuel Giraud
Subject: Re: How to walk a Lisp_String?
Date: Fri, 02 Sep 2022 10:56:56 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (berkeley-unix)

Eli Zaretskii <eliz@gnu.org> writes:

[...]

>> > make_multibyte_string is better, I think.
>> 
>> make_string seems to be a higher level interface: it calls
>> make_unibyte_string or make_multibyte_string whether the string is uni-
>> or multi-byte.
>
> 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.  But I thought I needed a Lisp_String in order to use some
other emacs interfaces.

>> > And I don't think I understand how you get the Lisp string to have the
>> > face information.  The original C char* string cannot have that
>> > information as part of the string's data, so where will the face data
>> > for the Lisp string come from?
>> 
>> I don't understand your question.  I thought it was the job of
>> FACE_FOR_CHAR: you give it a char and a frame and it returns the face
>> for this char in this frame.  What am I missing?
>
> 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:
--8<---------------cut here---------------start------------->8---
>>> 128517 -GOOG-Noto Color 
>>> Emoji-regular-normal-normal-*-13-*-*-*-m-0-iso10646-1
>>> 99 -UW  -Ttyp0-regular-normal-normal-*-13-*-*-*-m-*-iso10646-1
--8<---------------cut here---------------end--------------->8---

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



reply via email to

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