From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.devel Subject: RE: Should mode commands be idempotent? Date: Wed, 20 Sep 2017 16:05:35 -0700 (PDT) Message-ID: <17c87841-5941-4310-9b31-34d69a3e8d64@default> References: <5358b04b-70cb-bbaf-1887-bd83613e9c2b@gmail.com> <00b0c4e4-a02f-8c9f-ef52-7ad5a65798d1@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1505948753 19816 195.159.176.226 (20 Sep 2017 23:05:53 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 20 Sep 2017 23:05:53 +0000 (UTC) To: Stefan Monnier , emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Sep 21 01:05:47 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1duo3t-0004li-Om for ged-emacs-devel@m.gmane.org; Thu, 21 Sep 2017 01:05:45 +0200 Original-Received: from localhost ([::1]:51035 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duo40-00029G-PR for ged-emacs-devel@m.gmane.org; Wed, 20 Sep 2017 19:05:52 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48928) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duo3u-00028w-7V for emacs-devel@gnu.org; Wed, 20 Sep 2017 19:05:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1duo3q-00083I-Tu for emacs-devel@gnu.org; Wed, 20 Sep 2017 19:05:46 -0400 Original-Received: from userp1040.oracle.com ([156.151.31.81]:45453) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1duo3q-000808-LF for emacs-devel@gnu.org; Wed, 20 Sep 2017 19:05:42 -0400 Original-Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v8KN5c50012212 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Sep 2017 23:05:39 GMT Original-Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v8KN5cjq029536 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Sep 2017 23:05:38 GMT Original-Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v8KN5a9E002075; Wed, 20 Sep 2017 23:05:38 GMT In-Reply-To: X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 12.0.6776.5000 (x86)] X-Source-IP: userv0021.oracle.com [156.151.31.71] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 156.151.31.81 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:218613 Archived-At: > > Also, is there a motivation for introducing this new requirement, seein= g > > as how we've never had such a restriction in the past? >=20 > In the case of minor modes, I think a good implementation of a minor > mode should be idempotent, because it can easily happen that a minor > mode is enabled twice via different hooks, e.g.: >=20 > (add-hook 'text-mode-hook #'visual-line-mode) > (add-hook 'xml-mode-hook #'visual-line-mode) >=20 > If you know that xml-mode runs text-mode-hook, you can drop the second > line, but it's good if the second line is just redundant rather > than harmful (after all, some people prefer xml-mode not to run > text-mode-hook). >=20 > For major modes, I don't know what is the intention exactly, because I'm > not sure exactly what kind of non-idempotence there is out there. > I think for major modes a more significant issue is to make sure that >=20 > (with-temp-buffer (insert text) (funcall mode)) >=20 > doesn't do anything undesirable (and currently, we're pretty far from > having such a guarantee, although we do have code like the above at > various places). Those are good points. What should not be taken for granted, I think, is that enabling twice can have only harmful effects if a mode is not idempotent. Not being idempotent only means that invoking it more than once does not have zero effect. It does not follow that it has harmful effects. That's my point, about not imposing a convention or a requirement without a good reason. Not that I have in mind some particular good use case for "beneficial" effects of multiple invocations. Just that more than one invocation does not necessarily imply harm instead of benefit.