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#71605: 30.0.50; [PATCH] Support variable-width text in 'visual-wrap-prefix-mode' Date: Mon, 17 Jun 2024 14:37:43 +0300 Message-ID: <868qz3ssu0.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38331"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 71605@debbugs.gnu.org To: Jim Porter Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jun 17 13:38:28 2024 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 1sJAgs-0009gC-Mg for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 17 Jun 2024 13:38:27 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJAgT-0006Qx-Qw; Mon, 17 Jun 2024 07:38:01 -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 1sJAgS-0006QZ-Aq for bug-gnu-emacs@gnu.org; Mon, 17 Jun 2024 07:38:00 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sJAgS-0005OH-2o for bug-gnu-emacs@gnu.org; Mon, 17 Jun 2024 07:38:00 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sJAgT-0002CR-Oh for bug-gnu-emacs@gnu.org; Mon, 17 Jun 2024 07:38:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 17 Jun 2024 11:38:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71605 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 71605-submit@debbugs.gnu.org id=B71605.17186242788446 (code B ref 71605); Mon, 17 Jun 2024 11:38:01 +0000 Original-Received: (at 71605) by debbugs.gnu.org; 17 Jun 2024 11:37:58 +0000 Original-Received: from localhost ([127.0.0.1]:60392 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sJAgQ-0002C7-2X for submit@debbugs.gnu.org; Mon, 17 Jun 2024 07:37:58 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:46710) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sJAgM-0002Bq-UN for 71605@debbugs.gnu.org; Mon, 17 Jun 2024 07:37:56 -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 1sJAgF-0005BD-9f; Mon, 17 Jun 2024 07:37:47 -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=0jr1pMOUB6MVpeJFxK8OpKljSE6c2aOOy79CdTZkDDo=; b=DyGQbEhXMJxJ jOrOqxrQMVyhkrpsVMIPcFG9fWJzue/D09JiGSGUCJxrh6sSE0lniWWDeunBsGjcIePOKepSwZ4CM uVFgANLj5LJmacwsZd+q3BRPPHFn03fD1cXn4i3UZbS0gkY7N9cUV7s2PzHrtCMd5XHP7LK6EFW8J MvIl6V2JkrWmIpDM6O4cuINHU28yeuAKEs1QiNFvLtD+O8qG84DAD3+9tjPPBXejF8hw8+06NYKp0 VAmy8cJ0g1nNNDd7Cp4ATEPdvO42mnn/FUqeA81nUSboHiUqu+LjQVblZp9E26YPW5PpYm95iO6Po mxgrqk1OBnhRSfnbnYf09g==; In-Reply-To: (message from Jim Porter on Sun, 16 Jun 2024 19:56:44 -0700) 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:287382 Archived-At: > Date: Sun, 16 Jun 2024 19:56:44 -0700 > From: Jim Porter > > (Note: I plan to merge this only after we cut the Emacs 30 release > branch, since it seems a bit too substantial a change to sneak in right > near the end. However, I think the patch is mostly done aside from one > remaining issue, so any feedback is very welcome.) OK. > 'visual-wrap-prefix-mode' has one small issue: since the wrap prefix is > just a string, the wrapped text may not line up for variable-width > fonts. This is mainly in cases like so: > > * here is some text that > got visually wrapped > > If the "* " is variable-width, the second line will probably be indented > wrong by a few pixels. It also means the line after "*", the one that begins with "here is", will also move horizontally. Isn't that a misfeature? Perhaps this mode should align the text to some fixed pixel-coordinate, in which case changes in font should not matter? Or am I missing something? > The attached patch adds a display spec in this case so that the text > lines up perfectly. Can you explain the idea of the patch? I don't think I understand why you use '(space :width)' rather than '(space :align-to)'. > There's currently one problem though: I'm not sure > how to regenerate the wrap prefix automatically if the face changes. > It's not hard to handle for 'text-scale-adjust', but I don't know how to > handle 'global-text-scale-adjust' (or other things that could change the > face[1]). > > Does anyone have any ideas for this part? Perhaps we could provide a function "face-change (&optional frame)" which would access the frame's face_change flag and the global face_change flag. Then you could test those in a post-command-hook or somesuch. (However, using :align-to, if feasible, sounds like a better solution to me.) > -@defun string-pixel-width string > +@defun string-pixel-width string &optional buffer > This is a convenience function that uses @code{window-text-pixel-size} > -to compute the width of @var{string} (in pixels). > +to compute the width of @var{string} (in pixels). If @var{buffer} is > +non-@code{nil}, use the face remappings from that buffer when > +determining the width (@pxref{Face Remapping}). An alternative would be to provide a face to use. In any case, using BUFFER only for face-remapping-alist is only a small part of what a buffer can do to a string: there's the major mode with its fontifications and whatnot. > +(defun string-pixel-width (string &optional buffer) > + "Return the width of STRING in pixels. > +If BUFFER is non-nil, use the face remappings from that buffer when > +determining the width." > (declare (important-return-value t)) > (if (zerop (length string)) > 0 > @@ -348,6 +350,11 @@ string-pixel-width > ;; Disable line-prefix and wrap-prefix, for the same reason. > (setq line-prefix nil > wrap-prefix nil) > + (if buffer ^^^^^^^^^ This should test buffer-live-p, I think, not just buffer non-nil. > +(defun visual-wrap--adjust-display-width (fcp n) > + (when-let ((display (get-text-property 0 'display fcp)) > + ((eq (car-safe display) 'space)) Doesn't this only work with very simple 'display' specs? The 'space' part could be in some place deep in the spec, not just the second symbol. > (defun visual-wrap-fill-context-prefix (beg end) > "Compute visual wrap prefix from text between BEG and END. > -This is like `fill-context-prefix', but with prefix length adjusted > -by `visual-wrap-extra-indent'." > - (let* ((fcp > - ;; `fill-context-prefix' ignores prefixes that look like > - ;; paragraph starts, in order to avoid inadvertently > - ;; creating a new paragraph while filling, but here we're > - ;; only dealing with single-line "paragraphs" and we don't > - ;; actually modify the buffer, so this restriction doesn't > - ;; make much sense (and is positively harmful in > - ;; taskpaper-mode where paragraph-start matches everything). > - (or (let ((paragraph-start regexp-unmatchable)) > - (fill-context-prefix beg end)) > - ;; Note: fill-context-prefix may return nil; See: > - ;; http://article.gmane.org/gmane.emacs.devel/156285 > - "")) The comment above and the URL it included are deleted: is that because they are no longer relevant? If not, maybe move them with the code, so that the information is not lost.