From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: How to walk a Lisp_String? Date: Fri, 02 Sep 2022 13:52:42 +0300 Message-ID: <83tu5qoxol.fsf@gnu.org> 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> <87bkry6tnr.fsf@elite.giraud> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34862"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Manuel Giraud Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Sep 02 12:54:35 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 1oU4Jn-0008tA-57 for ged-emacs-devel@m.gmane-mx.org; Fri, 02 Sep 2022 12:54:35 +0200 Original-Received: from localhost ([::1]:60718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU4Jl-0002z7-Q8 for ged-emacs-devel@m.gmane-mx.org; Fri, 02 Sep 2022 06:54:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53162) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU4HX-0000y7-1T for emacs-devel@gnu.org; Fri, 02 Sep 2022 06:52:15 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:47168) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU4HW-0007bf-6T; Fri, 02 Sep 2022 06:52:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=MaAFTqJx5fx4XMK3pktPfZsTTRtXGnXDgJ9PiwbSiOI=; b=i6s/Qi6c2Jciiq+ElA2u DULeF3QNgf5ZuRb7nKk0bTVXak9R7kpGcqjRmPF3CCnxqz+eAMDAjC8daCTir6SXhELvTm34iXh9L qzPArrKr9AZ5y8TdYRlw0KUbyMzqDpnFoUikpc3ZZs7IywwiK6khfKeml+uTlU2SOfxFHmGS4ROGC iAAqfF3EgT9P+cggCG8Cd9mcdwJ8YVKbZChbpbY3QcJ8VHrbgR76UM5TghifnwDMUjpFnwagB2x5a RVH6vuD4zbyiHY5XtAR2TACpMhzi1lfbjbxesYhhOfyVDkGaqjgBHqdwsnwKnUcQyy3+4fw5v4A4V APOkRX+4gBcC5Q==; Original-Received: from [87.69.77.57] (port=2342 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU4HV-0008Mu-Fq; Fri, 02 Sep 2022 06:52:13 -0400 In-Reply-To: <87bkry6tnr.fsf@elite.giraud> (message from Manuel Giraud on Fri, 02 Sep 2022 10:56:56 +0200) 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:294529 Archived-At: > From: Manuel Giraud > 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.