From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.bugs Subject: bug#41810: [PATCH][ELPA] adaptive-wrap: Fontify wrap-prefix Date: Sun, 21 Jun 2020 19:32:17 +0100 Message-ID: <87zh8w6zim.fsf@tcd.ie> References: <87k10d7f2v.fsf@gmail.com> <87bllovfb5.fsf@gmail.com> <87y2or99zq.fsf@gmail.com> <87ftaosa9g.fsf_-_@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="71779"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 41810@debbugs.gnu.org, Stefan Monnier , Stephen Berman To: =?UTF-8?Q?K=C3=A9vin?= Le Gouguec Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jun 21 20:33:10 2020 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 1jn4mD-000IYv-TE for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 21 Jun 2020 20:33:10 +0200 Original-Received: from localhost ([::1]:55202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jn4mC-0006uW-A2 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 21 Jun 2020 14:33:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44714) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jn4m6-0006u7-Et for bug-gnu-emacs@gnu.org; Sun, 21 Jun 2020 14:33:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49353) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jn4m6-0000ix-64 for bug-gnu-emacs@gnu.org; Sun, 21 Jun 2020 14:33:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jn4m6-0003jp-3N for bug-gnu-emacs@gnu.org; Sun, 21 Jun 2020 14:33:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Basil L. Contovounesios" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 21 Jun 2020 18:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41810 X-GNU-PR-Package: emacs Original-Received: via spool by 41810-submit@debbugs.gnu.org id=B41810.159276434814320 (code B ref 41810); Sun, 21 Jun 2020 18:33:02 +0000 Original-Received: (at 41810) by debbugs.gnu.org; 21 Jun 2020 18:32:28 +0000 Original-Received: from localhost ([127.0.0.1]:60899 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jn4lY-0003iu-FU for submit@debbugs.gnu.org; Sun, 21 Jun 2020 14:32:28 -0400 Original-Received: from mail-wr1-f49.google.com ([209.85.221.49]:39305) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jn4lW-0003ig-1q for 41810@debbugs.gnu.org; Sun, 21 Jun 2020 14:32:27 -0400 Original-Received: by mail-wr1-f49.google.com with SMTP id q5so2085028wru.6 for <41810@debbugs.gnu.org>; Sun, 21 Jun 2020 11:32:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=99We3h9x0YYaszXkzuwLNlNy8B8VhmPjRrkqvSMNxOc=; b=lAgcGNbgWifIhhOSEf8OsqE8LLf0x2ddkdA+2WCG2OU5nvKRGwIqb6qwZPOhiRAYdm 7k7I7ufucJQg9LNKmxTeN1uqDKjmNwPrL69PwJLLWpHcuA6ohITxI1vc9+/d/LFxk78L YDMKXQj8TYO4MsAg0fZOOkhSC9vNu4YXlmQi5m2HJ3KnJ+epGX1MkNZgoiRzm46zd3jO T0zh9QSbu1o6buZCW1X7OEpSwbHso0Jnaeh1UWVSqUz5n7wfwALcNCAP5sM7pggHVumD d9qJ4p6G9qJgrGAz3tn57r9Ugk+gll0IclXnsuy1rCQuLjDESr9F8rSXlN5zRXbXisUh YwOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=99We3h9x0YYaszXkzuwLNlNy8B8VhmPjRrkqvSMNxOc=; b=SDdrYFVJ3k9ONZ61nhaeeLn0aHhFCcO2+LUnvRGXHZ8ozaJpPhdH2XvXVzuX3aLhrI B+qSqlzvWdtmgEj0qNygNFiywGGyN2MWLTb2xZyYK3oEdpvrq36uHoeJupvqd7EXTCWY xXRU4FmNcx+05jc/3AGt31ZFAn+OsJGl3V4wesf2p1hjFD/VFILKut8YNj+Nb32T2KOw XzDAd143Ot35dCLyDfGXgGBJrbmCCsUAR0C4fWGXH3/2i9Mw4Qem66I8eczgPqp1wdgZ KmZb0x5UHE+i334iUIs+p8g8e7IOza67Ahk0o6X0JBC3QelnDNJxz0hEsyZpgIRAUSzU iXrw== X-Gm-Message-State: AOAM531tolXpFHftK2raHPg/09lOJyp09fSTihakekzfmZihfsawv8wV nFUhHNDL9A5kXijFxCuHrwqfJw== X-Google-Smtp-Source: ABdhPJyGCEaNK+kOxTi34bKnN8UdPgd+teOYiFsU14mHA0HsDmTpk/7bRRiImzmODeAnEVLtBVxurg== X-Received: by 2002:a5d:6601:: with SMTP id n1mr14428320wru.23.1592764340156; Sun, 21 Jun 2020 11:32:20 -0700 (PDT) Original-Received: from localhost ([2a02:8084:20e2:c380:1f68:7ff5:120d:64e]) by smtp.gmail.com with ESMTPSA id i17sm7733332wrc.34.2020.06.21.11.32.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jun 2020 11:32:19 -0700 (PDT) In-Reply-To: <87ftaosa9g.fsf_-_@gmail.com> ("=?UTF-8?Q?K=C3=A9vin?= Le Gouguec"'s message of "Sun, 21 Jun 2020 17:34:35 +0200") 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:182255 Archived-At: K=C3=A9vin Le Gouguec writes: > OK, here is a patch that I think should be good to push, tested against > Emacs 28 and 26.3. Thanks, just some minor comments from me. > +(defun adaptive-wrap--prefix-face (fcp beg end) > + (or (get-text-property 0 'face fcp) > + ;; If the last character is a newline and has a face that > + ;; extends beyond EOL, assume that this face spans the whole > + ;; line and apply it to the prefix to preserve the "block" > + ;; visual effect. > + ;; NB: the face might not actually span the whole line: see for > + ;; example removed lines in diff-mode, where the first character > + ;; has the diff-indicator-removed face, while the rest of the > + ;; line has the diff-removed face. > + (when (=3D (char-before end) ?\n) > + (let ((eol-face (get-text-property (1- end) 'face))) Is it guaranteed that (< (point-min) end (1+ (point-max)))? Otherwise =3D and get-text-property will barf. > + (when (and eol-face (adaptive-wrap--face-extends eol-face)) > + eol-face))))) Nit: Can't the when+and be replaced with a single and? > +(defun adaptive-wrap--prefix (fcp) > + (let ((fcp-len (string-width fcp))) > + (cond > + ((=3D 0 adaptive-wrap-extra-indent) > + fcp) > + ((< 0 adaptive-wrap-extra-indent) > + (concat > + fcp > + (make-string adaptive-wrap-extra-indent > + (if (< 0 fcp-len) > + (string-to-char (substring fcp -1)) > + ?\ )))) Please change this to ?\s regardless of whether the second patch is installed. > + ((< 0 (+ adaptive-wrap-extra-indent fcp-len)) > + (substring fcp > + 0 > + (+ adaptive-wrap-extra-indent fcp-len))) > + (t > + "")))) > Open questions: > > - The (or =E2=80=A6 (when =E2=80=A6 (let =E2=80=A6 (when (and =E2=80=A6))= ))) chain looks clumsy but I > don't really know how to improve it off the top of my head. Maybe a > when-let or two would help? That'd mean requiring Emacs 25.1 though. Apart from the redundant when, I think it's fine. If you really want to shave off some forms you can write e.g. (defun adaptive-wrap--prefix-face (fcp beg end) (or (get-text-property 0 'face fcp) (let ((face (and (=3D (char-before end) ?\n) (get-text-property (1- end) 'face)))) (and face (adaptive-wrap--face-extends face) face)))) or (defun adaptive-wrap--prefix-face (fcp beg end) (cond ((get-text-property 0 'face fcp)) ((=3D (char-before end) ?\n) (let ((face ...)) (and face (adaptive-wrap--face-extends face) face))))) Thanks, --=20 Basil