From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Felix Dietrich Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] mailcap-add-mailcap-entry: Superfluous setcdr, readability, entry overriding Date: Thu, 10 Mar 2022 06:45:56 +0100 Message-ID: <87v8wmbbsb.fsf@sperrhaken.name> References: <87tuc9pvp0.fsf@sperrhaken.name> <87sfrr5ika.fsf@gnus.org> 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="30457"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Mar 10 07:22:15 2022 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 1nSCBi-0007jU-Vs for ged-emacs-devel@m.gmane-mx.org; Thu, 10 Mar 2022 07:22:15 +0100 Original-Received: from localhost ([::1]:34404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSCBh-00018I-JW for ged-emacs-devel@m.gmane-mx.org; Thu, 10 Mar 2022 01:22:13 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:60598) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSBcn-0008Rn-FB for emacs-devel@gnu.org; Thu, 10 Mar 2022 00:46:09 -0500 Original-Received: from mout.kundenserver.de ([212.227.126.130]:42281) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSBck-0003z7-JL for emacs-devel@gnu.org; Thu, 10 Mar 2022 00:46:09 -0500 Original-Received: from localhost ([89.12.188.198]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1N2V8Z-1o9L9w0j0x-013zg7 for ; Thu, 10 Mar 2022 06:46:03 +0100 In-Reply-To: <87sfrr5ika.fsf@gnus.org> (Lars Ingebrigtsen's message of "Wed, 09 Mar 2022 15:03:49 +0100") X-Provags-ID: V03:K1:0a+3E+81P9jIVJMKEHWwXBULRGzUfkJLrSwS1PdZmpQXg05J/AH U5XyJEZJwWwc6rTfIkvmtATh4ioEePAEbJwoQg0Ui9y2FkWI1RAhqvmNAt1DUKaJWJTsecQ 85IRgvNpEA9QOx0YZznNHR6umKKLcK5APzKtr+vVckrPRl84/S9SRR30dNINbLOG4UGpV3O 8LrkLoPZ9eo/rIjO0Yd8w== X-UI-Out-Filterresults: notjunk:1;V03:K0:u/H4+1nEn0M=:sZbrc3sVjbwalhb1TsLCZS NovglfMNAZHcw32+vPo0NIRKCZfKpMATFn3ThLREU6iRo/L5lNJCJkM2CGIbCyeTmVsrOh7eo 1lAVgo4Z+LLZyigCEBRt3gegBfL1HgyyeXZDfSwepgURACcG7r7i8l56wNrZbo68vYWcRKUUs S3mvyxEBn94OkkEvrPG9XFzmA3dClpIvN/RWOrRYVXLj9F0SG0wseHjyfsn5h5eR3vZLD1zzG v84U+5ZQO2bmebXUJhfUMlL/fbvNhlWr7RDgs22cWOeu5ldLj/fDQAYyS0mfxmednXd/BIBX2 GieM+4K5p/y1WXKOijg0ZIUYnIhWrxBfuMCBzW7+FHbAlQk9jvzTzhVIp4yJRo7jRrqplys8y SgSM6ltqUNYSnetSTUpXghN9IuN/VWEwKNrLxWdKNiXIY3oin7o/m3S7Pwp8XR69m7t3vGZ4U kAxQKwRkAiRLQqDy+elKZ1laLnWdo6j4C+Em4d0fIMBMcwblg6+ISKzxcO00ZHcFo2SHKisJA Ox0536cjyZYyRXzbdvvSdY2HbZAk1FXSADLwH5aBlVrwzKp0sx8mH7rNNqhnTD/hWwAmWamiZ Xf+Knw0MjsrHtvlqRo97LCVfcvQizmJojsvYBe7E2Ri0cVJff/ttutVhUjTwNHWMn9Y0QmZPb 890NnLiwB+8KBcuWquC2XmZoRGQQ3o79JG5hWc7AYczRsree9ZKsy/NjsCfYfcstBZQrH9ash NY1lBzhO4Md9BBeK Received-SPF: none client-ip=212.227.126.130; envelope-from=felix.dietrich@sperrhaken.name; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 10 Mar 2022 01:21:33 -0500 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" Xref: news.gmane.io gmane.emacs.devel:286984 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Lars Ingebrigtsen writes: > Felix Dietrich writes: > >> The first, relating to readability: I found it quit difficult to follow >> the flow of the function=CA=BCs code due to its nesting and idiosyncratic >> order of condition checking. I want to, therefore, propose a >> restructured version, which I believe to be functionally equivalent. > > Yes, the code is pretty confusing... so reading the patches, I'm not > quite sure whether the new one is equivalent or not. So I think we'd > want to have a number of tests in mailcap-tests.el to test that the > results really are equivalent before and after the change, too. I agree that adding some automated tests is a good idea, but, since I am not familiar with writing these in Emacs Lisp, I will first have to spent a bit of time with the ERT manual and the existing tests, before I cans start writing the tests. Meanwhile, to shorten the wait ;), here is a series of patches that go through the transformation steps of =E2=80=98mailcap-add-mailcap-entry=E2=80=99 and demonstrate that it is stil= l the same function (unless I misstepped). (I don=CA=BCt know if this will end up all that readable and useful; it seemed like a good idea when I started and might end up as time better spent learning ERT.) --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Merge-the-inner-let-with-the-outer.patch >From 938e2bb38ea43a2cb87c8442c7c3b78a2e587f78 Mon Sep 17 00:00:00 2001 From: Felix Dietrich Date: Thu, 10 Mar 2022 03:29:47 +0100 Subject: [PATCH 01/10] =?UTF-8?q?Merge=20the=20inner=20=E2=80=98let?= =?UTF-8?q?=E2=80=99=20with=20the=20outer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note that it does not matter should there be no old-major: (assoc minor nil) is valid and will simply yield nil. --- lisp/net/mailcap.el | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el index b65f7c25b8..633d43320e 100644 --- a/lisp/net/mailcap.el +++ b/lisp/net/mailcap.el @@ -719,26 +719,26 @@ to supply to the test." (defun mailcap-add-mailcap-entry (major minor info &optional storage) (let* ((storage (or storage 'mailcap--computed-mime-data)) - (old-major (assoc major (symbol-value storage)))) + (old-major (assoc major (symbol-value storage))) + (cur-minor (assoc minor old-major))) (if (null old-major) ; New major area (set storage (cons (cons major (list (cons minor info))) (symbol-value storage))) - (let ((cur-minor (assoc minor old-major))) - (cond - ((or (null cur-minor) ; New minor area, or - (assq 'test info)) ; Has a test, insert at beginning - (setcdr old-major - (cons (cons minor info) (cdr old-major)))) - ((and (not (assq 'test info)) ; No test info, replace completely - (not (assq 'test cur-minor)) - (equal (assq 'viewer info) ; Keep alternative viewer - (assq 'viewer cur-minor))) - (setcdr cur-minor info)) - (t - (setcdr old-major - (setcdr old-major - (cons (cons minor info) (cdr old-major)))))))))) + (cond + ((or (null cur-minor) ; New minor area, or + (assq 'test info)) ; Has a test, insert at beginning + (setcdr old-major + (cons (cons minor info) (cdr old-major)))) + ((and (not (assq 'test info)) ; No test info, replace completely + (not (assq 'test cur-minor)) + (equal (assq 'viewer info) ; Keep alternative viewer + (assq 'viewer cur-minor))) + (setcdr cur-minor info)) + (t + (setcdr old-major + (setcdr old-major + (cons (cons minor info) (cdr old-major))))))))) (defun mailcap-add (type viewer &optional test) "Add VIEWER as a handler for TYPE. -- 2.35.1 --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=0002-Move-the-if-form-into-the-cond.patch Content-Transfer-Encoding: quoted-printable >From f9a68bd1696d0cbf9bb07d9178045640cfa02dfc Mon Sep 17 00:00:00 2001 From: Felix Dietrich Date: Thu, 10 Mar 2022 03:30:59 +0100 Subject: [PATCH 02/10] =3D?UTF-8?q?Move=3D20the=3D20=3DE2=3D80=3D98if=3DE2= =3D80=3D99=3D20form?=3D =3D?UTF-8?q?=3D20into=3D20the=3D20=3DE2=3D80=3D98cond=3DE2=3D80=3D99?=3D MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit Its condition and then-form become the first alternative of the =E2=80=98cond=E2=80=99. The rest of the =E2=80=98cond=E2=80=99 remains, in= a way, the previous else-form of the =E2=80=98if=E2=80=99. --- lisp/net/mailcap.el | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el index 633d43320e..c30b9e096d 100644 --- a/lisp/net/mailcap.el +++ b/lisp/net/mailcap.el @@ -721,24 +721,24 @@ to supply to the test." (let* ((storage (or storage 'mailcap--computed-mime-data)) (old-major (assoc major (symbol-value storage))) (cur-minor (assoc minor old-major))) - (if (null old-major) ; New major area - (set storage - (cons (cons major (list (cons minor info))) - (symbol-value storage))) - (cond - ((or (null cur-minor) ; New minor area, or - (assq 'test info)) ; Has a test, insert at beginning - (setcdr old-major - (cons (cons minor info) (cdr old-major)))) - ((and (not (assq 'test info)) ; No test info, replace completely - (not (assq 'test cur-minor)) - (equal (assq 'viewer info) ; Keep alternative viewer - (assq 'viewer cur-minor))) - (setcdr cur-minor info)) - (t - (setcdr old-major - (setcdr old-major - (cons (cons minor info) (cdr old-major))))))))) + (cond + ((null old-major) ; New major area + (set storage + (cons (cons major (list (cons minor info))) + (symbol-value storage)))) + ((or (null cur-minor) ; New minor area, or + (assq 'test info)) ; Has a test, insert at beginning + (setcdr old-major + (cons (cons minor info) (cdr old-major)))) + ((and (not (assq 'test info)) ; No test info, replace completely + (not (assq 'test cur-minor)) + (equal (assq 'viewer info) ; Keep alternative viewer + (assq 'viewer cur-minor))) + (setcdr cur-minor info)) + (t + (setcdr old-major + (setcdr old-major + (cons (cons minor info) (cdr old-major)))))))) =20 (defun mailcap-add (type viewer &optional test) "Add VIEWER as a handler for TYPE. --=20 2.35.1 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0003-Remove-the-superfluous-setcdr-call.patch >From aa5f2640223db603ae158d2177d1bfc73aa0f2f9 Mon Sep 17 00:00:00 2001 From: Felix Dietrich Date: Thu, 10 Mar 2022 03:36:17 +0100 Subject: [PATCH 03/10] =?UTF-8?q?Remove=20the=20superfluous=20=E2=80=98set?= =?UTF-8?q?cdr=E2=80=99=20call?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note the duplication of code in the second and last cond alternatives: both setcdr calls are identical. --- lisp/net/mailcap.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el index c30b9e096d..bb34fb86c0 100644 --- a/lisp/net/mailcap.el +++ b/lisp/net/mailcap.el @@ -737,8 +737,7 @@ to supply to the test." (setcdr cur-minor info)) (t (setcdr old-major - (setcdr old-major - (cons (cons minor info) (cdr old-major)))))))) + (cons (cons minor info) (cdr old-major))))))) (defun mailcap-add (type viewer &optional test) "Add VIEWER as a handler for TYPE. -- 2.35.1 --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=0004-Add-the-negated-condition-of-the-second-to-the-third.patch Content-Transfer-Encoding: quoted-printable >From 4ddb4dbaced88a36ef2a0735c1b911cb60f4f597 Mon Sep 17 00:00:00 2001 From: Felix Dietrich Date: Thu, 10 Mar 2022 03:45:09 +0100 Subject: [PATCH 04/10] Add the negated condition of the second to the third alternative MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit The negation of the absence of a cur-minor entry (null cur-minor) is simply cur-minor. The negation of (assq =E2=80=99test info) is already there: (not (assq =E2=80=99test cur-minor)). Also: =C2=AC(a =E2=88=A8 b) =3D =C2=ACa =E2=88=A7 =C2=ACb --- lisp/net/mailcap.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el index bb34fb86c0..48701ddee8 100644 --- a/lisp/net/mailcap.el +++ b/lisp/net/mailcap.el @@ -730,7 +730,8 @@ to supply to the test." (assq 'test info)) ; Has a test, insert at beginning (setcdr old-major (cons (cons minor info) (cdr old-major)))) - ((and (not (assq 'test info)) ; No test info, replace completely + ((and cur-minor + (not (assq 'test info)) ; No test info, replace completely (not (assq 'test cur-minor)) (equal (assq 'viewer info) ; Keep alternative viewer (assq 'viewer cur-minor))) --=20 2.35.1 --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=0005-Remove-the-second-condition.patch Content-Transfer-Encoding: quoted-printable >From 2cfb0760c28e2afbb59ad01996b611d28cff47f9 Mon Sep 17 00:00:00 2001 From: Felix Dietrich Date: Thu, 10 Mar 2022 03:51:08 +0100 Subject: [PATCH 05/10] Remove the second condition MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit With the conjunction of the negation of the second alternative=CA=BCs condition with the third alternative=CA=BCs condition in the previous patch, the second alternative has become redundant, because the condition of the third alternative now ensure that it will not run in cases that were previously handled by the second alternative. Since the second alternative had the same body-form as the last, that is the default alternative, it can be correctly handled by the default alternative as well. --- lisp/net/mailcap.el | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el index 48701ddee8..165945040d 100644 --- a/lisp/net/mailcap.el +++ b/lisp/net/mailcap.el @@ -726,10 +726,6 @@ to supply to the test." (set storage (cons (cons major (list (cons minor info))) (symbol-value storage)))) - ((or (null cur-minor) ; New minor area, or - (assq 'test info)) ; Has a test, insert at beginning - (setcdr old-major - (cons (cons minor info) (cdr old-major)))) ((and cur-minor (not (assq 'test info)) ; No test info, replace completely (not (assq 'test cur-minor)) --=20 2.35.1 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0006-Remove-unnecessary-cons-move-list-one-element-to-the.patch >From eb3c3d46e06647976bfebe43dfb18f729cda0d26 Mon Sep 17 00:00:00 2001 From: Felix Dietrich Date: Thu, 10 Mar 2022 04:02:58 +0100 Subject: [PATCH 06/10] =?UTF-8?q?Remove=20unnecessary=20=E2=80=98cons?= =?UTF-8?q?=E2=80=99=20(move=20=E2=80=98list=E2=80=99=20one=20element=20to?= =?UTF-8?q?=20the=20left)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cons something (list something-else)) is the same as (list something something-else). --- lisp/net/mailcap.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el index 165945040d..2d93720a56 100644 --- a/lisp/net/mailcap.el +++ b/lisp/net/mailcap.el @@ -724,7 +724,7 @@ to supply to the test." (cond ((null old-major) ; New major area (set storage - (cons (cons major (list (cons minor info))) + (cons (list major (cons minor info)) (symbol-value storage)))) ((and cur-minor (not (assq 'test info)) ; No test info, replace completely -- 2.35.1 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0007-Add-extra-variables-to-make-things-clearer.patch >From befca96cd7ea332c9bec4136d23dfbc58d0ba805 Mon Sep 17 00:00:00 2001 From: Felix Dietrich Date: Thu, 10 Mar 2022 04:20:27 +0100 Subject: [PATCH 07/10] Add extra variables to make things clearer --- lisp/net/mailcap.el | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el index 2d93720a56..e7575e8097 100644 --- a/lisp/net/mailcap.el +++ b/lisp/net/mailcap.el @@ -720,12 +720,14 @@ to supply to the test." (defun mailcap-add-mailcap-entry (major minor info &optional storage) (let* ((storage (or storage 'mailcap--computed-mime-data)) (old-major (assoc major (symbol-value storage))) - (cur-minor (assoc minor old-major))) + (cur-minor (assoc minor old-major)) + (new-minor-entry (cons minor info)) + new-major) (cond ((null old-major) ; New major area + (setq new-major (list major new-minor-entry)) (set storage - (cons (list major (cons minor info)) - (symbol-value storage)))) + (cons new-major (symbol-value storage)))) ((and cur-minor (not (assq 'test info)) ; No test info, replace completely (not (assq 'test cur-minor)) @@ -734,7 +736,7 @@ to supply to the test." (setcdr cur-minor info)) (t (setcdr old-major - (cons (cons minor info) (cdr old-major))))))) + (cons new-minor-entry (cdr old-major))))))) (defun mailcap-add (type viewer &optional test) "Add VIEWER as a handler for TYPE. -- 2.35.1 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0008-Use-macros-with-Generalized-Variables.patch >From 293a324649e23a93cfaf6f277fd835340ebdefa9 Mon Sep 17 00:00:00 2001 From: Felix Dietrich Date: Thu, 10 Mar 2022 04:36:52 +0100 Subject: [PATCH 08/10] =?UTF-8?q?Use=20macros=20with=20=E2=80=9CGeneralize?= =?UTF-8?q?d=20Variables=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For the last one (push new-minor-entry (cdr old-major)) it helped me to remember that old-major has the form: ("major" ("minor" . info) ("minor" . info)) So, to push a new entry to the front of the list of minor entries, you push it after "major", that is at the cdr. --- lisp/net/mailcap.el | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el index e7575e8097..72d292c3e4 100644 --- a/lisp/net/mailcap.el +++ b/lisp/net/mailcap.el @@ -726,17 +726,15 @@ to supply to the test." (cond ((null old-major) ; New major area (setq new-major (list major new-minor-entry)) - (set storage - (cons new-major (symbol-value storage)))) + (push new-major (symbol-value storage))) ((and cur-minor (not (assq 'test info)) ; No test info, replace completely (not (assq 'test cur-minor)) (equal (assq 'viewer info) ; Keep alternative viewer (assq 'viewer cur-minor))) - (setcdr cur-minor info)) + (setf (cdr cur-minor) info)) (t - (setcdr old-major - (cons new-minor-entry (cdr old-major))))))) + (push new-minor-entry (cdr old-major)))))) (defun mailcap-add (type viewer &optional test) "Add VIEWER as a handler for TYPE. -- 2.35.1 --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0009-Clean-up-rename-variables-remove-comments.patch >From abc8b4410adf05d185c5f9293150d25980567181 Mon Sep 17 00:00:00 2001 From: Felix Dietrich Date: Thu, 10 Mar 2022 04:43:45 +0100 Subject: [PATCH 09/10] Clean-up, rename variables, remove comments --- lisp/net/mailcap.el | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el index 72d292c3e4..5d60e7ece4 100644 --- a/lisp/net/mailcap.el +++ b/lisp/net/mailcap.el @@ -719,22 +719,21 @@ to supply to the test." (defun mailcap-add-mailcap-entry (major minor info &optional storage) (let* ((storage (or storage 'mailcap--computed-mime-data)) - (old-major (assoc major (symbol-value storage))) - (cur-minor (assoc minor old-major)) - (new-minor-entry (cons minor info)) - new-major) + (major-entry (assoc major (symbol-value storage))) + (new-minor-entry (cons minor info)) + minor-entry) (cond - ((null old-major) ; New major area - (setq new-major (list major new-minor-entry)) - (push new-major (symbol-value storage))) - ((and cur-minor - (not (assq 'test info)) ; No test info, replace completely - (not (assq 'test cur-minor)) - (equal (assq 'viewer info) ; Keep alternative viewer - (assq 'viewer cur-minor))) - (setf (cdr cur-minor) info)) + ((null major-entry) + (setf major-entry (list major new-minor-entry)) + (push major-entry (symbol-value storage))) + ((and (setf minor-entry (assoc minor major-entry)) + (not (assq 'test info)) + (not (assq 'test minor-entry)) + (equal (assq 'viewer info) + (assq 'viewer minor-entry))) + (setf (cdr minor-entry) info)) (t - (push new-minor-entry (cdr old-major)))))) + (push new-minor-entry (cdr major-entry)))))) (defun mailcap-add (type viewer &optional test) "Add VIEWER as a handler for TYPE. -- 2.35.1 --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=0010-Add-docstring-and-comments-this-is-the-version-I-sen.patch Content-Transfer-Encoding: quoted-printable >From 2e2d02c5ff7bfe939a96a40fcf8fac7e6e255315 Mon Sep 17 00:00:00 2001 From: Felix Dietrich Date: Thu, 10 Mar 2022 04:44:30 +0100 Subject: [PATCH 10/10] Add docstring and comments (this is the version I se= nt) --- lisp/net/mailcap.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lisp/net/mailcap.el b/lisp/net/mailcap.el index 5d60e7ece4..efcf9d7134 100644 --- a/lisp/net/mailcap.el +++ b/lisp/net/mailcap.el @@ -718,12 +718,26 @@ to supply to the test." result)))) =20 (defun mailcap-add-mailcap-entry (major minor info &optional storage) + "Add handler INFO for mime type MAJOR/MINOR to STORAGE. + +MAJOR and MINOR should be strings. MINOR is treated as a regexp +in later lookups, and, therefore, you may need to escape it +appropriately. + +The format of INFO is described in =E2=80=98mailcap-mime-data=E2=80=99. + +STORAGE should be a symbol refering to a variable. The value of +this variable should have the same format as =E2=80=98mailcap-mime-data=E2= =80=99. +STORAGE defaults to =E2=80=98mailcap--computed-mime-data=E2=80=99. + +None of this is enforced." (let* ((storage (or storage 'mailcap--computed-mime-data)) (major-entry (assoc major (symbol-value storage))) (new-minor-entry (cons minor info)) minor-entry) (cond ((null major-entry) + ;; Add a new major entry containing the new minor entry. (setf major-entry (list major new-minor-entry)) (push major-entry (symbol-value storage))) ((and (setf minor-entry (assoc minor major-entry)) @@ -731,8 +745,15 @@ to supply to the test." (not (assq 'test minor-entry)) (equal (assq 'viewer info) (assq 'viewer minor-entry))) + ;; Replace a previous MINOR entry if it and the entry to be + ;; added both do *not* have a =E2=80=98test=E2=80=99 associated in t= heir info + ;; alist and both use the same =E2=80=98viewer=E2=80=99 command. Th= is ignores + ;; other fields in the previous entry=CA=BCs info alist: they will be + ;; lost when the info alist in the cdr of the previous entry is + ;; replaced with the new INFO alist. (setf (cdr minor-entry) info)) (t + ;; Add the new minor entry to the existing major entry. (push new-minor-entry (cdr major-entry)))))) =20 (defun mailcap-add (type viewer &optional test) --=20 2.35.1 --=-=-= Content-Type: text/plain -- Felix Dietrich --=-=-=--