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.bugs Subject: bug#52129: 29.0.50; Wish: Extend `:align-to center' to work on lines in buffer Date: Sat, 27 Nov 2021 11:15:16 +0200 Message-ID: <834k7y0xjv.fsf@gnu.org> References: <83o86616m2.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32584"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 52129@debbugs.gnu.org To: Arthur Miller Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 27 10:16:16 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1mqtoe-0008Jo-ED for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 27 Nov 2021 10:16:16 +0100 Original-Received: from localhost ([::1]:53856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mqtod-0003pk-1O for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 27 Nov 2021 04:16:15 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:38254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mqtoQ-0003hf-OS for bug-gnu-emacs@gnu.org; Sat, 27 Nov 2021 04:16:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49606) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mqtoQ-0006Sd-F6 for bug-gnu-emacs@gnu.org; Sat, 27 Nov 2021 04:16:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mqtoQ-0003Fo-9d for bug-gnu-emacs@gnu.org; Sat, 27 Nov 2021 04:16:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 27 Nov 2021 09:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 52129 X-GNU-PR-Package: emacs Original-Received: via spool by 52129-submit@debbugs.gnu.org id=B52129.163800452012457 (code B ref 52129); Sat, 27 Nov 2021 09:16:02 +0000 Original-Received: (at 52129) by debbugs.gnu.org; 27 Nov 2021 09:15:20 +0000 Original-Received: from localhost ([127.0.0.1]:32919 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mqtnj-0003El-Sk for submit@debbugs.gnu.org; Sat, 27 Nov 2021 04:15:20 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:37362) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mqtnh-0003EQ-1Z for 52129@debbugs.gnu.org; Sat, 27 Nov 2021 04:15:17 -0500 Original-Received: from [2001:470:142:3::e] (port=50430 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mqtnb-0006Ey-Nc; Sat, 27 Nov 2021 04:15:11 -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=WZK/pXZL4xO8GJuAMYK1LYXs6B5LxgBmqPlkqJoLVKE=; b=sKaWTnro2+Vo dFR8LVvJDcCO370el1dGH5t+TL7d+aGHD4z07CGtWH503QUVlvavWjhUzjzM/MIl0yFMglRrbDeJo SdfYB555S1LRz1OEbfE2h1kHrpMIMyBk/nnA0IxoKZ0DlP7U5Wf1KpSOAIPC6RKH180/JpMnmaNYq kGJw/LKVT8hHH3ma0/fCS6IlvWjgK+miE4mDJo8gKQS8IqxeXt8Ng5dku4g1q4xY+zJjpj6rEETro LvCC00JvddAEPmmpqPm8ex1SvosXUkO0VLs+5sRzq+fAYO5l3wledrZmUP6UcEYFcUR/UcHEbFces NYSi3XM3mmEkab8Q8lQmLA==; Original-Received: from [87.69.77.57] (port=2986 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 1mqtna-0004um-H6; Sat, 27 Nov 2021 04:15:11 -0500 In-Reply-To: (message from Arthur Miller on Sat, 27 Nov 2021 09:47:58 +0100) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:220897 Archived-At: > From: Arthur Miller > Cc: 52129@debbugs.gnu.org > Date: Sat, 27 Nov 2021 09:47:58 +0100 > > Eli Zaretskii writes: > > > I don't understand what exactly are you asking for. Is your problem > > that you have to prepend some character to the string and put the > > :align-to spec on that character? Because AFAIU that simple measure > > should achieve your goal. > > You mean something like this: > > #+begin_src emacs-lisp > (defun evc--time () > (propertize > (time-stamp-string " %H:%M") 'face evc--time-face 'display '(space :align-to center))) > > (defun evc--date () > (propertize > (concat > " " > (capitalize (time-stamp-string "%A")) ". " > (capitalize (time-stamp-string "%B %d"))) 'face evc--date-face 'display '(space :align-to center))) No, I mean to put this property: 'display '(space :align-to center) on a space character (or any other character, which will not be displayed) that is prepended to the time-stamp-string you want to display. > (let* ((tlen (* 0.5 (string-pixel-width time))) > (dlen (* 0.5 (string-pixel-width date))) > (spct (propertize " " 'display `(space :align-to (- center (,tlen))))) > (spcd (propertize " " 'display `(space :align-to (- center (,dlen)))))) > (insert spct time "\n" spcd date)) > > I hope above illustrates that it is not just to prepend a space, you have to > calculate how much it should extend to. So you want to center the string, not its first character? OK, but why is the above a problem? It's simple enough code, I think. > Also, even if it would be just to prepend a spacer character, the goal is still > to align text in center of a line, so why can't we just renderer to do it for > us, instead of having such procedural way of telling it what to do. Why can we > not just tell: > > (defun evc--time () > (propertize > (time-stamp-string " %H:%M") 'face evc--time-face 'display '(line :align-to center))) > > or something similar. Because the Emacs display code examines buffer text one character at a time, left to right, and produces the glyphs for display for each character before it goes to the next. You are asking the display engine to know the display width of your string before it performs the layout calculations for that string, and that cannot work. The display code cannot even assume that it will traverse all the characters of a line, it could be forced to stop before it reaches the end of the line, in which case it cannot know that width even post-factum. > Also what if the text is longer then visual line? Would it be possible for the > rendering engine to center part of the tring with 'aligne-to center' property, > and cull extensive part on sides that are outside. That is not acheavable with a spacer. You want the display engine to decide where to break such a long line? Or do you want to decide that up front and indicate that via the portion of the text on which you put this hypothetical property? IOW, what exactly is the meaning of "cull" here?