Re: [PATCH v2] emacs: Pass a copy to notmuch-saved-search-sort-function
authorJani Nikula <jani@nikula.org>
Tue, 6 Mar 2012 08:20:23 +0000 (10:20 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:45:15 +0000 (09:45 -0800)
f6/75c27fe07c425f7897b0343265f9204dea09a4 [new file with mode: 0644]

diff --git a/f6/75c27fe07c425f7897b0343265f9204dea09a4 b/f6/75c27fe07c425f7897b0343265f9204dea09a4
new file mode 100644 (file)
index 0000000..97e79d3
--- /dev/null
@@ -0,0 +1,318 @@
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 874BA431FAF\r
+       for <notmuch@notmuchmail.org>; Tue,  6 Mar 2012 00:20:29 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.699\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5\r
+       tests=[HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 2w-l4cFUj+9W for <notmuch@notmuchmail.org>;\r
+       Tue,  6 Mar 2012 00:20:25 -0800 (PST)\r
+Received: from mail-pz0-f45.google.com (mail-pz0-f45.google.com\r
+       [209.85.210.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 79689431FAE\r
+       for <notmuch@notmuchmail.org>; Tue,  6 Mar 2012 00:20:25 -0800 (PST)\r
+Received: by dadp14 with SMTP id p14so4753431dad.18\r
+       for <notmuch@notmuchmail.org>; Tue, 06 Mar 2012 00:20:23 -0800 (PST)\r
+Received-SPF: pass (google.com: domain of jani@nikula.org designates\r
+       10.68.239.195 as permitted sender) client-ip=10.68.239.195; \r
+Authentication-Results: mr.google.com;\r
+       spf=pass (google.com: domain of jani@nikula.org\r
+       designates 10.68.239.195 as permitted sender)\r
+       smtp.mail=jani@nikula.org\r
+Received: from mr.google.com ([10.68.239.195])\r
+       by 10.68.239.195 with SMTP id vu3mr29119326pbc.49.1331022023585\r
+       (num_hops = 1); Tue, 06 Mar 2012 00:20:23 -0800 (PST)\r
+MIME-Version: 1.0\r
+Received: by 10.68.239.195 with SMTP id vu3mr25105581pbc.49.1331022023409;\r
+       Tue, 06 Mar 2012 00:20:23 -0800 (PST)\r
+Received: by 10.68.12.103 with HTTP; Tue, 6 Mar 2012 00:20:23 -0800 (PST)\r
+Received: by 10.68.12.103 with HTTP; Tue, 6 Mar 2012 00:20:23 -0800 (PST)\r
+In-Reply-To: <87zkbukb59.fsf@gmail.com>\r
+References: <1330613059-5130-1-git-send-email-daniel@schoepe.org>\r
+       <1330613059-5130-2-git-send-email-daniel@schoepe.org>\r
+       <CAB+hUn-iQbXq_UDcj97h2Duq=gJdxpiJjOn6YzmVcZw+GEgK0A@mail.gmail.com>\r
+       <87zkbukb59.fsf@gmail.com>\r
+Date: Tue, 6 Mar 2012 10:20:23 +0200\r
+Message-ID:\r
+ <CAB+hUn-jcxyS8wR7UfC1skRsUtF+r04hCc-oVrBwUsvZefNPzw@mail.gmail.com>\r
+Subject: Re: [PATCH v2] emacs: Pass a copy to\r
+       notmuch-saved-search-sort-function\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
+Content-Type: multipart/alternative; boundary=047d7b33d5cce4bfa104ba8eb662\r
+X-Gm-Message-State:\r
+ ALoCoQkkZWmRJUzPGJ8IzVvJjStyYZMwy7rS9BfK1ngtNpK3IOwCF2KBhsmx6irk5rzMTkA9fbvg\r
+Cc: notmuch@notmuchmail.org\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 06 Mar 2012 08:20:29 -0000\r
+\r
+--047d7b33d5cce4bfa104ba8eb662\r
+Content-Type: text/plain; charset=UTF-8\r
+\r
+On Mar 5, 2012 11:11 PM, "Dmitry Kurochkin" <dmitry.kurochkin@gmail.com>\r
+wrote:\r
+>\r
+> On Mon, 5 Mar 2012 22:55:54 +0200, Jani Nikula <jani@nikula.org> wrote:\r
+> > On Mar 5, 2012 5:43 PM, "Dmitry Kurochkin" <dmitry.kurochkin@gmail.com>\r
+> > wrote:\r
+> > >\r
+> > > On Mon, 05 Mar 2012 12:17:43 +0100, Daniel Schoepe <daniel@schoepe.org\r
+>\r
+> > wrote:\r
+> > > > On Mon, 05 Mar 2012 06:21:52 +0400, Dmitry Kurochkin <\r
+> > dmitry.kurochkin@gmail.com> wrote:\r
+> > > > > On Thu,  1 Mar 2012 21:24:38 +0100, Daniel Schoepe <\r
+daniel@schoepe.org>\r
+> > wrote:\r
+> > > > > > notmuch-saved-search-sort-function might destructively modify\r
+its\r
+> > > > > > input (`sort' does that, for instance), so it should not be\r
+given\r
+> > > > > > notmuch-saved-searches directly.\r
+> > > > > > ---\r
+> > > > >\r
+> > > > > -1\r
+> > > > >\r
+> > > > > I think we should require `notmuch-saved-search-sort-function'\r
+not to\r
+> > > > > have side effects.  Current documentation should be more clear\r
+about\r
+> > > > > this.  We need to fix `notmuch-sort-saved-searches' to copy the\r
+list\r
+> > > > > before calling `sort'.  But we should not do it in\r
+> > > > > `notmuch-hello-insert-saved-searches' for any sorting function\r
+(which\r
+> > > > > may not need this copying).\r
+> > > >\r
+> > > > My reasoning was that since sort is such a common function, many\r
+users\r
+> > > > will probably use sort for their own sorting functions, not\r
+realizing\r
+> > > > that it has side effects. This will lead to confusing behavior\r
+that's\r
+> > > > not so easy to track down.\r
+> > > >\r
+> > > > Copying the list of saved searches when running notmuch-hello does\r
+not\r
+> > > > seem be relevant to performance to me, since it's a) not called that\r
+> > > > often and b) the list of saved searches will rarely exceed 30\r
+elements.\r
+> > > >\r
+> > > > Hence, this way we can avoid some headaches for users who define\r
+their\r
+> > > > own sorting functions at a negligible (performance) cost.\r
+Incidentally,\r
+> > > > this is also how notmuch-hello did it before the user-defined\r
+sections\r
+> > > > patches.\r
+> > > >\r
+> > >\r
+> > > I do not buy the argument that we should help users who implement\r
+their\r
+> > > own sorting functions but do not read documentation for functions they\r
+> > > use.  Apparently, those who implemented the `sort' function had\r
+similar\r
+> > > ideas.  And I do not think it is our job to add workarounds for it.\r
+> > >\r
+> > > An alternative (and IMO better) solution would be to allow\r
+customization\r
+> > > of compare function used for sorting instead of the sorting function\r
+> > > itself.\r
+> >\r
+> > Providing the customization of the sort function is more powerful than\r
+the\r
+> > compare function. In the case of saved searches I can imagine people\r
+might\r
+> > want to partially use the original order while sort the rest (e.g.\r
+> > important ones first in predefined order, others sorted).\r
+>\r
+> Valid point.\r
+>\r
+> > In fact this also\r
+> > allows dropping out some elements. And renaming. And changing the\r
+queries...\r
+> >\r
+> > (I had something like that in mind originally but then settled with just\r
+> > capitalizing the important ones to show them first.)\r
+> >\r
+>\r
+> All of these are invalid usages of `notmuch-saved-search-sort-function'.\r
+> The function is meant for sorting only (hence the name).  So the code\r
+> might assume that the function does only sorting.\r
+>\r
+> I do not understand why we need such functionality (renaming,\r
+> capitalizing, etc.).  You can just rename the query itself if you want\r
+> to.  Should be easier IMO.\r
+\r
+Just for the record, I have a few important searches capitalized in the\r
+saved searches and just use the regular sort. Capitalized entries sort\r
+before the lowercase ones.\r
+\r
+> But if we need such functionality, we should\r
+> not misuse sorting function for it.  We can add `notmuch-saved-searches'\r
+> function which would return saved searches list (sorted, renamed and\r
+> mangled in any other way).  By default it would return\r
+> `notmuch-saved-searches' variable as is.\r
+\r
+Agreed.\r
+\r
+As to the problem at hand, we should just fix the sort function not to\r
+modify its input. I wouldn't hold my breath waiting for someone to provide\r
+patches for the rest...\r
+\r
+BR,\r
+Jani.\r
+\r
+--047d7b33d5cce4bfa104ba8eb662\r
+Content-Type: text/html; charset=UTF-8\r
+Content-Transfer-Encoding: quoted-printable\r
+\r
+<p><br>\r
+On Mar 5, 2012 11:11 PM, &quot;Dmitry Kurochkin&quot; &lt;<a href=3D"mailto=\r
+:dmitry.kurochkin@gmail.com">dmitry.kurochkin@gmail.com</a>&gt; wrote:<br>\r
+&gt;<br>\r
+&gt; On Mon, 5 Mar 2012 22:55:54 +0200, Jani Nikula &lt;<a href=3D"mailto:j=\r
+ani@nikula.org">jani@nikula.org</a>&gt; wrote:<br>\r
+&gt; &gt; On Mar 5, 2012 5:43 PM, &quot;Dmitry Kurochkin&quot; &lt;<a href=\r
+=3D"mailto:dmitry.kurochkin@gmail.com">dmitry.kurochkin@gmail.com</a>&gt;<b=\r
+r>\r
+&gt; &gt; wrote:<br>\r
+&gt; &gt; &gt;<br>\r
+&gt; &gt; &gt; On Mon, 05 Mar 2012 12:17:43 +0100, Daniel Schoepe &lt;<a hr=\r
+ef=3D"mailto:daniel@schoepe.org">daniel@schoepe.org</a>&gt;<br>\r
+&gt; &gt; wrote:<br>\r
+&gt; &gt; &gt; &gt; On Mon, 05 Mar 2012 06:21:52 +0400, Dmitry Kurochkin &l=\r
+t;<br>\r
+&gt; &gt; <a href=3D"mailto:dmitry.kurochkin@gmail.com">dmitry.kurochkin@gm=\r
+ail.com</a>&gt; wrote:<br>\r
+&gt; &gt; &gt; &gt; &gt; On Thu, =C2=A01 Mar 2012 21:24:38 +0100, Daniel Sc=\r
+hoepe &lt;<a href=3D"mailto:daniel@schoepe.org">daniel@schoepe.org</a>&gt;<=\r
+br>\r
+&gt; &gt; wrote:<br>\r
+&gt; &gt; &gt; &gt; &gt; &gt; notmuch-saved-search-sort-function might dest=\r
+ructively modify its<br>\r
+&gt; &gt; &gt; &gt; &gt; &gt; input (`sort&#39; does that, for instance), s=\r
+o it should not be given<br>\r
+&gt; &gt; &gt; &gt; &gt; &gt; notmuch-saved-searches directly.<br>\r
+&gt; &gt; &gt; &gt; &gt; &gt; ---<br>\r
+&gt; &gt; &gt; &gt; &gt;<br>\r
+&gt; &gt; &gt; &gt; &gt; -1<br>\r
+&gt; &gt; &gt; &gt; &gt;<br>\r
+&gt; &gt; &gt; &gt; &gt; I think we should require `notmuch-saved-search-so=\r
+rt-function&#39; not to<br>\r
+&gt; &gt; &gt; &gt; &gt; have side effects. =C2=A0Current documentation sho=\r
+uld be more clear about<br>\r
+&gt; &gt; &gt; &gt; &gt; this. =C2=A0We need to fix `notmuch-sort-saved-sea=\r
+rches&#39; to copy the list<br>\r
+&gt; &gt; &gt; &gt; &gt; before calling `sort&#39;. =C2=A0But we should not=\r
+ do it in<br>\r
+&gt; &gt; &gt; &gt; &gt; `notmuch-hello-insert-saved-searches&#39; for any =\r
+sorting function (which<br>\r
+&gt; &gt; &gt; &gt; &gt; may not need this copying).<br>\r
+&gt; &gt; &gt; &gt;<br>\r
+&gt; &gt; &gt; &gt; My reasoning was that since sort is such a common funct=\r
+ion, many users<br>\r
+&gt; &gt; &gt; &gt; will probably use sort for their own sorting functions,=\r
+ not realizing<br>\r
+&gt; &gt; &gt; &gt; that it has side effects. This will lead to confusing b=\r
+ehavior that&#39;s<br>\r
+&gt; &gt; &gt; &gt; not so easy to track down.<br>\r
+&gt; &gt; &gt; &gt;<br>\r
+&gt; &gt; &gt; &gt; Copying the list of saved searches when running notmuch=\r
+-hello does not<br>\r
+&gt; &gt; &gt; &gt; seem be relevant to performance to me, since it&#39;s a=\r
+) not called that<br>\r
+&gt; &gt; &gt; &gt; often and b) the list of saved searches will rarely exc=\r
+eed 30 elements.<br>\r
+&gt; &gt; &gt; &gt;<br>\r
+&gt; &gt; &gt; &gt; Hence, this way we can avoid some headaches for users w=\r
+ho define their<br>\r
+&gt; &gt; &gt; &gt; own sorting functions at a negligible (performance) cos=\r
+t. Incidentally,<br>\r
+&gt; &gt; &gt; &gt; this is also how notmuch-hello did it before the user-d=\r
+efined sections<br>\r
+&gt; &gt; &gt; &gt; patches.<br>\r
+&gt; &gt; &gt; &gt;<br>\r
+&gt; &gt; &gt;<br>\r
+&gt; &gt; &gt; I do not buy the argument that we should help users who impl=\r
+ement their<br>\r
+&gt; &gt; &gt; own sorting functions but do not read documentation for func=\r
+tions they<br>\r
+&gt; &gt; &gt; use. =C2=A0Apparently, those who implemented the `sort&#39; =\r
+function had similar<br>\r
+&gt; &gt; &gt; ideas. =C2=A0And I do not think it is our job to add workaro=\r
+unds for it.<br>\r
+&gt; &gt; &gt;<br>\r
+&gt; &gt; &gt; An alternative (and IMO better) solution would be to allow c=\r
+ustomization<br>\r
+&gt; &gt; &gt; of compare function used for sorting instead of the sorting =\r
+function<br>\r
+&gt; &gt; &gt; itself.<br>\r
+&gt; &gt;<br>\r
+&gt; &gt; Providing the customization of the sort function is more powerful=\r
+ than the<br>\r
+&gt; &gt; compare function. In the case of saved searches I can imagine peo=\r
+ple might<br>\r
+&gt; &gt; want to partially use the original order while sort the rest (e.g=\r
+.<br>\r
+&gt; &gt; important ones first in predefined order, others sorted).<br>\r
+&gt;<br>\r
+&gt; Valid point.<br>\r
+&gt;<br>\r
+&gt; &gt; In fact this also<br>\r
+&gt; &gt; allows dropping out some elements. And renaming. And changing the=\r
+ queries...<br>\r
+&gt; &gt;<br>\r
+&gt; &gt; (I had something like that in mind originally but then settled wi=\r
+th just<br>\r
+&gt; &gt; capitalizing the important ones to show them first.)<br>\r
+&gt; &gt;<br>\r
+&gt;<br>\r
+&gt; All of these are invalid usages of `notmuch-saved-search-sort-function=\r
+&#39;.<br>\r
+&gt; The function is meant for sorting only (hence the name). =C2=A0So the =\r
+code<br>\r
+&gt; might assume that the function does only sorting.<br>\r
+&gt;<br>\r
+&gt; I do not understand why we need such functionality (renaming,<br>\r
+&gt; capitalizing, etc.). =C2=A0You can just rename the query itself if you=\r
+ want<br>\r
+&gt; to. =C2=A0Should be easier IMO. =C2=A0</p>\r
+<p>Just for the record, I have a few important searches capitalized in the =\r
+saved searches and just use the regular sort. Capitalized entries sort befo=\r
+re the lowercase ones.</p>\r
+<p>&gt; But if we need such functionality, we should<br>\r
+&gt; not misuse sorting function for it. =C2=A0We can add `notmuch-saved-se=\r
+arches&#39;<br>\r
+&gt; function which would return saved searches list (sorted, renamed and<b=\r
+r>\r
+&gt; mangled in any other way). =C2=A0By default it would return<br>\r
+&gt; `notmuch-saved-searches&#39; variable as is.</p>\r
+<p>Agreed.</p>\r
+<p>As to the problem at hand, we should just fix the sort function not to m=\r
+odify its input. I wouldn&#39;t hold my breath waiting for someone to provi=\r
+de patches for the rest...</p>\r
+<p>BR,<br>\r
+Jani.<br>\r
+</p>\r
+\r
+--047d7b33d5cce4bfa104ba8eb662--\r