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: [PATCH] User-defined fringe tooltips (a request for review) Date: Thu, 21 Dec 2023 19:37:07 +0200 Message-ID: <83plyzfoe4.fsf@gnu.org> References: <83sf3xgimq.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11439"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Vladimir Kazanov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Dec 21 18:38:06 2023 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 1rGMzm-0002mG-CP for ged-emacs-devel@m.gmane-mx.org; Thu, 21 Dec 2023 18:38:06 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGMz5-00076I-RH; Thu, 21 Dec 2023 12:37:23 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rGMz3-000765-EC for emacs-devel@gnu.org; Thu, 21 Dec 2023 12:37:21 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rGMz3-0002LT-1C; Thu, 21 Dec 2023 12:37:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=S7abpEBz1U2vMTUYUexU4zf8kCaC2UtdO/clEl3dz4A=; b=Xp3q8DPAfWP0 27kcoR66o9hIgMcWGeZnjkVsQzNtEqUU5VeMPjDCgwi5+DCDlqc/T09/CtIIVxbXzMdGmDRNYFiHr 24WtXtUivoWx9UycBVUeD4rWA13jzW5/7upnc2QFruvaqd3cuhohJlf8hHoGgbOzeKfQkRJ8mocxQ 1BvuD7HhXvzQmPDW6FbMTrSy+YzyxTn7HfKnATlgFt5SCOWc5vGm26lqi3LJW8+7Me1tV/UiqMAZL 3iah3JCxNrCRxLLq4ppa8LpWcyUD/I3cdc0ZH+03ICiT0COE1ftRZWjkfMAcZGLDYa0WbptNQsP8w 98GO0iHOHJnGiviffLPnHA==; In-Reply-To: (message from Vladimir Kazanov on Thu, 21 Dec 2023 16:51:15 +0000) 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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:314045 Archived-At: > From: Vladimir Kazanov > Date: Thu, 21 Dec 2023 16:51:15 +0000 > Cc: emacs-devel@gnu.org > > > The code in note_mouse_highlight examines > > the buffer text and overlays for text properties whose meaning is to > > display a help-echo string, so why cannot you do the same to look for > > a 'display' property of this specific structure, and extract the > > help-echo directly from there at mouse-highlight time instead of at > > glyph-generation time? > > Yes, having Lispy stuff in the glyph_row struct doesn't make sense, > and this is why I was in doubt. > > Anyway, a new patch is attached with the approach you suggested (the > way I understood it). I use "struct it" to iterate over the line for > which the fringe indicator is defined, in note_mouse_highlight. The > iterator then pulls out the display spec and saves the last left/right > fringe captions it walked over. > > Does that feel right? No, there's no need to use the iterator. Just look at the positions recorded in the glyphs of the relevant glyph_row, and then look up text properties at those positions using Fget_char_property etc., like we already do to look for the 'help-echo' property in the same function. Here's a typical fragment: Lisp_Object obj = glyph->object; ptrdiff_t charpos = glyph->charpos; /* Try text properties. */ if (STRINGP (obj) && charpos >= 0 && charpos < SCHARS (obj)) { help = Fget_text_property (make_fixnum (charpos), Qhelp_echo, obj); Since the 'display' property that shows a fringe bitmap can be on any character of a screen line, you will need to loop over all the glyphs of the glyph_row where the mouse pointer is, testing the 'display' property as above. Something like this: for (glyph = row->glyphs[TEXT_AREA]; glyph < row->glyphs[TEXT_AREA] + row->used[TEXT_AREA]; glyph++) where 'row' is row = MATRIX_ROW (w->current_matrix, vpos); and 'vpos' is returned by this call which we already have in note_mouse_highlight: /* Find the glyph under X/Y. */ glyph = x_y_to_hpos_vpos (w, x, y, &hpos, &vpos, &dx, &dy, &area); If Fget_text_property returns non-nil for the 'display' property, you will then need to look at the value and see whether it specifies a help-echo for the fringe; if it does, extract the string and assign it to 'help_echo_string'. Then you won't need to use 'struct it', and won't need any new caption members in 'struct it'. Thanks.