all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Manuel Giraud <manuel@ledu-giraud.fr>
Cc: emacs-devel@gnu.org
Subject: Re: How to walk a Lisp_String?
Date: Fri, 02 Sep 2022 13:52:42 +0300	[thread overview]
Message-ID: <83tu5qoxol.fsf@gnu.org> (raw)
In-Reply-To: <87bkry6tnr.fsf@elite.giraud> (message from Manuel Giraud on Fri,  02 Sep 2022 10:56:56 +0200)

> 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	other threads:[~2022-09-02 10:52 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-01 15:34 How to walk a Lisp_String? Manuel Giraud
2022-09-01 15:42 ` Stefan Monnier
2022-09-01 15:42 ` Eli Zaretskii
2022-09-01 15:49   ` Eli Zaretskii
2022-09-01 20:45     ` Manuel Giraud
2022-09-02  1:08       ` Po Lu
2022-09-02  6:32         ` Eli Zaretskii
2022-09-02  8:27           ` Po Lu
2022-09-02 10:36             ` Eli Zaretskii
2022-09-02 11:03               ` Po Lu
2022-09-02 11:15                 ` Eli Zaretskii
2022-09-02 12:48                   ` Po Lu
2022-09-02 13:17                     ` Eli Zaretskii
2022-09-02  6:51         ` Manuel Giraud
2022-09-02  7:20           ` Eli Zaretskii
2022-09-02  8:31           ` Po Lu
2022-09-02  6:43       ` Eli Zaretskii
2022-09-02  7:18         ` Manuel Giraud
2022-09-02  7:30           ` Eli Zaretskii
2022-09-02  8:56             ` Manuel Giraud
2022-09-02 10:52               ` Eli Zaretskii [this message]
2022-09-02 11:40                 ` Manuel Giraud
2022-09-02 12:51                   ` Po Lu
2022-09-02 15:07                     ` Manuel Giraud
2022-09-03  0:58                       ` Po Lu
2022-09-03  5:46                         ` Tomas Hlavaty
2022-09-03  6:19                           ` Po Lu
2022-09-03  8:05                             ` Tomas Hlavaty
2022-09-02 13:08                   ` Eli Zaretskii
2022-09-02 14:58                     ` Manuel Giraud
2022-09-02 15:33                       ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83tu5qoxol.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=manuel@ledu-giraud.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.