From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Manuel Giraud Newsgroups: gmane.emacs.devel Subject: Re: How to walk a Lisp_String? Date: Fri, 02 Sep 2022 10:56:56 +0200 Message-ID: <87bkry6tnr.fsf@elite.giraud> References: <87a67jw1kw.fsf@elite.giraud> <83o7vzqey8.fsf@gnu.org> <83mtbjqemd.fsf@gnu.org> <87ler2963r.fsf@elite.giraud> <838rn2qnsf.fsf@gnu.org> <87wnam6y70.fsf@elite.giraud> <831qsuqllo.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31235"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (berkeley-unix) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Sep 02 11:08:45 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oU2fM-0007vg-Ap for ged-emacs-devel@m.gmane-mx.org; Fri, 02 Sep 2022 11:08:44 +0200 Original-Received: from localhost ([::1]:37256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU2fK-0001i5-N8 for ged-emacs-devel@m.gmane-mx.org; Fri, 02 Sep 2022 05:08:42 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50952) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU2UH-00049p-SO for emacs-devel@gnu.org; Fri, 02 Sep 2022 04:57:24 -0400 Original-Received: from ledu-giraud.fr ([51.159.28.247]:8887) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU2U2-00077W-SD; Fri, 02 Sep 2022 04:57:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=S21ukDTfUY8rKf6V TDJvlOdEzALCOv9uvMugIneRnvc=; h=date:references:in-reply-to:subject: cc:to:from; d=ledu-giraud.fr; b=ovfAGPwLvjd6qt7OloSc7+akLMEXTG6h0uYaDI lOwJuYQG5UyfZ3hUA5nfbsokaOEJGMYVd5D5hIYcd8lrjbyexfwnQ/fGBv/9DMKSTcE+Br N5sB4y+pEJezSYRixVjfb0nTek2NAH43tDHdd7FrRWsp/APs20TH8dr+LlX54Cz97sAYe3 gMokZufVW3wX52hGaBR71vIXzcTaz4AmiwsB0X+cNA60G3Bn81RvZfIFb/jandGm/pERnv z6bCcEvGwn5M/cIIej8ekKIdMwuQPp467Z9njER4UNeXq+FmaPoU3/WuOdZRNzrobbTyfy uu9MPxDwvjWls8Vo3l9cnZvg== Original-Received: from elite.giraud ( [10.1.1.1]) by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id da34c2b4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 2 Sep 2022 10:56:58 +0200 (CEST) In-Reply-To: <831qsuqllo.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 02 Sep 2022 10:30:43 +0300") Received-SPF: pass client-ip=51.159.28.247; envelope-from=manuel@ledu-giraud.fr; helo=ledu-giraud.fr X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:294523 Archived-At: Eli Zaretskii writes: [...] >> > make_multibyte_string is better, I think. >>=20 >> 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=E2=80=A6 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? >>=20 >> 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 *f= ace_id) { struct frame *f =3D XFRAME (frame); struct face *face =3D FACE_FROM_ID (f, DEFAULT_FACE_ID); int mychar =3D 128517; *face_id =3D FACE_FOR_CHAR (f, face, mychar, -1, Qnil); face =3D 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 =3D 'c'; *face_id =3D FACE_FOR_CHAR (f, face, mychar, -1, Qnil); face =3D 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-iso1= 0646-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? --=20 Manuel Giraud