From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?K=C3=A9vin?= Le Gouguec Newsgroups: gmane.emacs.bugs Subject: bug#69555: 30.0.50; shr - Preserve indentation when shr-fill-text is nil Date: Mon, 04 Mar 2024 23:08:20 +0100 Message-ID: <87jzmhzm3v.fsf@gmail.com> References: <87o7btzmdo.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1878"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Rahguzar To: 69555@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Mar 04 23:11:00 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 1rhGWR-0000H5-Ui for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 04 Mar 2024 23:11:00 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhGW4-0006v6-5a; Mon, 04 Mar 2024 17:10:36 -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 1rhGW1-0006ue-GA for bug-gnu-emacs@gnu.org; Mon, 04 Mar 2024 17:10:33 -0500 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 1rhGW0-0001wj-QU for bug-gnu-emacs@gnu.org; Mon, 04 Mar 2024 17:10:32 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rhGWU-0006kL-Iw for bug-gnu-emacs@gnu.org; Mon, 04 Mar 2024 17:11:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?K=C3=A9vin?= Le Gouguec Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 04 Mar 2024 22:11:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69555 X-GNU-PR-Package: emacs Original-Received: via spool by 69555-submit@debbugs.gnu.org id=B69555.170959020425854 (code B ref 69555); Mon, 04 Mar 2024 22:11:02 +0000 Original-Received: (at 69555) by debbugs.gnu.org; 4 Mar 2024 22:10:04 +0000 Original-Received: from localhost ([127.0.0.1]:45136 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rhGVX-0006is-RD for submit@debbugs.gnu.org; Mon, 04 Mar 2024 17:10:04 -0500 Original-Received: from mail-wr1-f41.google.com ([209.85.221.41]:54766) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rhGVR-0006i1-Oy for 69555@debbugs.gnu.org; Mon, 04 Mar 2024 17:10:02 -0500 Original-Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-33e122c8598so2998137f8f.1 for <69555@debbugs.gnu.org>; Mon, 04 Mar 2024 14:09:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709590102; x=1710194902; darn=debbugs.gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=iACQJDTjcB8M4nYnaI1yjcwOi78QEV0x3HiP4/zWeDQ=; b=gJP4wnu08JBE7UWX4PN+9szMrxxa+z2dquF5LQpzKf7lvcWu5vv/D0nXlEgSq6fC56 GEzrRhU6gSNR3Y+XsL1JTNQznhceM8BQGql8zmkBZJI45bAXyH1iybW403akpFMg46bb yvDQd8HQ0LolZYlBHHsye/p4OXmeULrhbwF5oUCTPt2M5aJgTWzzYR8MhIinGgNN4uwC he7EYcMoYmWFMlqP6YKXqLRm3/94BtfFLIEQJwwou9chSWRbzjtKcowV8rpvkgvs3oM4 p9l91Tx5ifAqrXe+8JgEmI/hakS7Fp+iKIJ1uPLImzqFkyHAw6By0xgsYNNoUGH5vXfT HzRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709590102; x=1710194902; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=iACQJDTjcB8M4nYnaI1yjcwOi78QEV0x3HiP4/zWeDQ=; b=NuHUfBDL+7zPzKsy244iwuXSKf68GUoi2Voc2AepOBGGGJDNuG5QN+coEAonJuujjA rQWCnynsw9caSsLkZt1GomrkGze1F+HyQaN2ngWo1vbMHSbUrmAtrnoWA0DMw7TeWQTi 2n7lJyxz/OS4UQ0mLHxL8PWsR305ACBe1GFBkjEtkj7rZkqaeiaAYEYyv8q0Qv4cresE InBlVdzhMGi5kh2jrvgEnoGuyrZunYkEGpNz02Q6m+r4/kW27POsE+XR6VMVqUKY78JR aLh3AguwKfGpaeFAQkZnLQcZEX4Jtqf6TniUxjnI5ziqOqpYPeIx4F6oqGvWr+8g7/8O CVGQ== X-Gm-Message-State: AOJu0Yym80OlFqgPjIrTD2ev8Aix+x0f2vllmfcwbme8i5cliBXmWr6g QKZVj8KYaR2xDOmQzNFVyG13BFVuutvdb2IsFxxzNgPBhuodz7tV X-Google-Smtp-Source: AGHT+IHl5TZ8tkoY3MHdWVu2xzRCB5um4Zr9s5JbF8hHcH233Ax+lv+gRFGKRdDAWc85r5TvtZ2Qkg== X-Received: by 2002:a5d:51cd:0:b0:33e:3cf:e88 with SMTP id n13-20020a5d51cd000000b0033e03cf0e88mr8127310wrv.56.1709590101513; Mon, 04 Mar 2024 14:08:21 -0800 (PST) Original-Received: from amdahl30 ([2a01:e0a:253:fe0:2ef0:5dff:fed2:7b49]) by smtp.gmail.com with ESMTPSA id b7-20020a05600003c700b0033e44b23921sm1862752wrg.24.2024.03.04.14.08.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 14:08:20 -0800 (PST) In-Reply-To: <87o7btzmdo.fsf@gmail.com> ("=?UTF-8?Q?K=C3=A9vin?= Le Gouguec"'s message of "Mon, 04 Mar 2024 23:02:27 +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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:281024 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable K=C3=A9vin Le Gouguec writes: > Will post an updated patch once I have a > bug number to replace the "bug#TODO" placeholders. See attached. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=0001-Keep-indenting-text-when-shr-fill-text-is-nil-bug-69.patch Content-Transfer-Encoding: quoted-printable >From ea41aa4ef92357f00bc7814d7020a81104e4b95f Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?K=3DC3=3DA9vin=3D20Le=3D20Gouguec?=3D Date: Sun, 3 Mar 2024 17:20:56 +0100 Subject: [PATCH] Keep indenting text when 'shr-fill-text' is nil (bug#69555) MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit The 'shr-fill-=E2=80=A6' functions handle both hard-filling (adding newline= s to break long lines) and indentation. Setting 'shr-fill-text' to nil currently causes these functions to be short-circuited completely, so e.g. blockquotes are no longer indented, whereas the intent of this user option is only to prevent hard-filling to let visual-line-mode reflow text. * lisp/net/shr.el (shr-fill-lines): Document that the function handles more than just filling; move the 'shr-fill-text' check=E2=80=A6 (shr-fill-line): =E2=80=A6 here, after indentation has been taken care of. * test/lisp/net/shr-resources/blockquote.html: * test/lisp/net/shr-resources/blockquote.txt: New test resources. * test/lisp/net/shr-tests.el (shr-test--rendering-check): Rename from 'shr-test', to make the relationship with the 'rendering' testcase clearer; prefer 'file-name-concat' to 'format'; raise ERT failure if need be, calling (ert-fail =E2=80=A6) directly instead of (should (not (list =E2= =80=A6))). (shr-test--rendering-extra-configs): New variable to easily check that user customizations do not degrade rendering. (rendering): Consult that new variable; delegate failure-raising to reduce duplication. --- lisp/net/shr.el | 15 +++-- test/lisp/net/shr-resources/blockquote.html | 2 + test/lisp/net/shr-resources/blockquote.txt | 3 + test/lisp/net/shr-tests.el | 72 +++++++++++++++------ 4 files changed, 67 insertions(+), 25 deletions(-) create mode 100644 test/lisp/net/shr-resources/blockquote.html create mode 100644 test/lisp/net/shr-resources/blockquote.txt diff --git a/lisp/net/shr.el b/lisp/net/shr.el index e23fc6104d2..09df5f5a9bb 100644 --- a/lisp/net/shr.el +++ b/lisp/net/shr.el @@ -784,8 +784,9 @@ shr-insert (or shr-current-font 'shr-text))))))))) =20 (defun shr-fill-lines (start end) - (if (or (not shr-fill-text) (<=3D shr-internal-width 0)) - nil + "Indent and fill text from START to END. +When `shr-fill-text' is nil, only indent." + (unless (<=3D shr-internal-width 0) (save-restriction (narrow-to-region start end) (goto-char start) @@ -807,6 +808,8 @@ shr-vertical-motion (forward-char 1)))) =20 (defun shr-fill-line () + "Indent and fill the current line. +When `shr-fill-text' is nil, only indent." (let ((shr-indentation (or (get-text-property (point) 'shr-indentation) shr-indentation)) (continuation (get-text-property @@ -821,9 +824,11 @@ shr-fill-line `,(shr-face-background face)))) (setq start (point)) (setq shr-indentation (or continuation shr-indentation)) - ;; If we have an indentation that's wider than the width we're - ;; trying to fill to, then just give up and don't do any filling. - (when (< shr-indentation shr-internal-width) + ;; Fill the current line, unless `shr-fill-text' is unset, or we + ;; have an indentation that's wider than the width we're trying to + ;; fill to. + (when (and shr-fill-text + (< shr-indentation shr-internal-width)) (shr-vertical-motion shr-internal-width) (when (looking-at " $") (delete-region (point) (line-end-position))) diff --git a/test/lisp/net/shr-resources/blockquote.html b/test/lisp/net/sh= r-resources/blockquote.html new file mode 100644 index 00000000000..412caf8bae6 --- /dev/null +++ b/test/lisp/net/shr-resources/blockquote.html @@ -0,0 +1,2 @@ +
Citation.
+
Reply.
diff --git a/test/lisp/net/shr-resources/blockquote.txt b/test/lisp/net/shr= -resources/blockquote.txt new file mode 100644 index 00000000000..8ed610b8ea2 --- /dev/null +++ b/test/lisp/net/shr-resources/blockquote.txt @@ -0,0 +1,3 @@ + Citation. + +Reply. diff --git a/test/lisp/net/shr-tests.el b/test/lisp/net/shr-tests.el index 0c6e2c091bf..17138053450 100644 --- a/test/lisp/net/shr-tests.el +++ b/test/lisp/net/shr-tests.el @@ -29,30 +29,62 @@ =20 (declare-function libxml-parse-html-region "xml.c") =20 -(defun shr-test (name) - (with-temp-buffer - (insert-file-contents (format (concat (ert-resource-directory) "/%s.ht= ml") name)) - (let ((dom (libxml-parse-html-region (point-min) (point-max))) - (shr-width 80) - (shr-use-fonts nil)) - (erase-buffer) - (shr-insert-document dom) - (cons (buffer-substring-no-properties (point-min) (point-max)) - (with-temp-buffer - (insert-file-contents - (format (concat (ert-resource-directory) "/%s.txt") name)) - (while (re-search-forward "%\\([0-9A-F][0-9A-F]\\)" nil t) - (replace-match (string (string-to-number (match-string 1) = 16)) - t t)) - (buffer-string)))))) +(defun shr-test--rendering-check (name &optional context) + "Render NAME.html and compare it to NAME.txt. +Raise a test failure if the rendered buffer does not match NAME.txt. +Append CONTEXT to the failure data, if non-nil." + (let ((text-file (file-name-concat (ert-resource-directory) (concat name= ".txt"))) + (html-file (file-name-concat (ert-resource-directory) (concat name= ".html"))) + (description (if context (format "%s (%s)" name context) name))) + (with-temp-buffer + (insert-file-contents html-file) + (let ((dom (libxml-parse-html-region (point-min) (point-max))) + (shr-width 80) + (shr-use-fonts nil)) + (erase-buffer) + (shr-insert-document dom) + (let ((result (buffer-substring-no-properties (point-min) (point-m= ax))) + (expected + (with-temp-buffer + (insert-file-contents text-file) + (while (re-search-forward "%\\([0-9A-F][0-9A-F]\\)" nil t) + (replace-match (string (string-to-number (match-string = 1) 16)) + t t)) + (buffer-string)))) + (unless (equal result expected) + (ert-fail (list description result expected)))))))) + +(defconst shr-test--rendering-extra-configs + '(("blockquote" + ;; Make sure blockquotes remain indented even when filling is + ;; disabled (bug#69555). + . ((shr-fill-text . nil)))) + "Extra customizations which can impact rendering. +This is a list of (NAME . SETTINGS) pairs. NAME is the basename of a +set of txt/html files under shr-resources/, as passed to `shr-test'. +SETTINGS is a list of (OPTION . VALUE) pairs that are interesting to +validate for the NAME testcase. + +The `rendering' testcase will test NAME once without altering any +settings, then once more for each (OPTION . VALUE) pair.") =20 (ert-deftest rendering () (skip-unless (fboundp 'libxml-parse-html-region)) (dolist (file (directory-files (ert-resource-directory) nil "\\.html\\'"= )) - (let* ((name (replace-regexp-in-string "\\.html\\'" "" file)) - (result (shr-test name))) - (unless (equal (car result) (cdr result)) - (should (not (list name (car result) (cdr result)))))))) + (let* ((name (string-remove-suffix ".html" file)) + (extra-options (alist-get name shr-test--rendering-extra-configs + nil nil 'string=3D))) + ;; Test once with default settings. + (shr-test--rendering-check name) + ;; Test once more for every extra option for this specific NAME. + (pcase-dolist (`(,option-sym ,option-val) + extra-options) + (let ((option-old (symbol-value option-sym))) + (set option-sym option-val) + (unwind-protect + (shr-test--rendering-check + name (format "with %s %s" option-sym option-val)) + (set option-sym option-old))))))) =20 (ert-deftest use-cookies () (let ((shr-cookie-policy 'same-origin)) --=20 2.44.0 --=-=-=--