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: :align-to space spec and line wrap Date: Tue, 25 Apr 2023 10:22:49 +0300 Message-ID: <83leigwhme.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37182"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Qiantan Hong Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Apr 25 09:22:56 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 1prD0q-0009T0-DL for ged-emacs-devel@m.gmane-mx.org; Tue, 25 Apr 2023 09:22:56 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prD0Q-0001GP-1k; Tue, 25 Apr 2023 03:22:30 -0400 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 1prD0O-0001Dj-9Z for emacs-devel@gnu.org; Tue, 25 Apr 2023 03:22:28 -0400 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 1prD0N-0002yQ-Fp; Tue, 25 Apr 2023 03:22:27 -0400 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=FQa5hpDIOAzNi17fUVSS9O16Z+SsZ+XZsnRpcokCy8E=; b=r5Hc0QjtJc8S 06PH41WyMm9kgGxEiwGlwiril2nABRB8TvjGiHQB3T8XIww0PIayplsxHisFzRoH0tJ2/kEIaA6r9 PvX7/WJHuNxS0xLrraNHveHc/36TfuykO02YExg2mmhSrh1W3UCqWAF9MYltz4uwz+Fu7mcqHCGKd ImUgbH9ocF4LmjRqGEjtY/CJSl9ppLj+4LilFfzydmqEJhRdth/EJj6yT5CeoUizg+h0JGRos9+uV v/V2lylpDw6i0ORX5idr5nc7V7kjgEcBedYfmm56z6YI5QTHCSRKMCQm0T3CTfp77Kqezg36/yBv+ vh8sXPIQoeny6MJ4N79m1w==; Original-Received: from [87.69.77.57] (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 1prD0K-0000ML-4W; Tue, 25 Apr 2023 03:22:26 -0400 In-Reply-To: (message from Qiantan Hong on Mon, 24 Apr 2023 19:23:48 +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:305639 Archived-At: > From: Qiantan Hong > Date: Mon, 24 Apr 2023 19:23:48 +0000 > > I use the :align-to space spec to right align texts, like this: > > (defun k-insert-fill-right (string) > ;; More correct than `k-fill-right' in some cases, respect current > ;; buffer settings (e.g. invisibility spec) > (let ((from (point))) > (insert " " string) > (save-restriction > (narrow-to-region (1+ from) (point)) > (let ((width (car (buffer-text-pixel-size)))) > (widen) > (put-text-property from (1+ from) > 'display > `(space :align-to (- right-fringe (,width)))))) > nil)) > > It works when there is no line wrap. However, when there is line wrap, > the space width shrink to zero rather than fill to (- right-fringe > (,width)) position on the new line. Seem that the width calculation > does not take line wrap into account. Is this intended? The :align-to display spec counts columns, and column number doesn't get reset to zero when the line is continued on the next screen line. The column numbers on the continuation lines keep counting from the last column displayed on the previous screen line. So you are in effect trying to align to a column whose number is smaller than the column where the text is displayed, and thus the space width indeed comes out as zero, because you are already past the target column. > Is the behavior that align to the right position on the new line > possible to implement? You need to dynamically calculate the value of the column for continuation lines.