From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Should mode commands be idempotent? Date: Wed, 20 Sep 2017 18:30:47 -0400 Message-ID: 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 X-Trace: blaine.gmane.org 1505946725 7757 195.159.176.226 (20 Sep 2017 22:32:05 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 20 Sep 2017 22:32:05 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Sep 21 00:32:02 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 1dunXF-0001dZ-09 for ged-emacs-devel@m.gmane.org; Thu, 21 Sep 2017 00:32:01 +0200 Original-Received: from localhost ([::1]:50950 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dunXM-0003Es-AB for ged-emacs-devel@m.gmane.org; Wed, 20 Sep 2017 18:32:08 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33211) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dunWH-0003Dx-OG for emacs-devel@gnu.org; Wed, 20 Sep 2017 18:31:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dunWG-00010g-VM for emacs-devel@gnu.org; Wed, 20 Sep 2017 18:31:01 -0400 Original-Received: from [195.159.176.226] (port=52180 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dunWG-0000we-OW for emacs-devel@gnu.org; Wed, 20 Sep 2017 18:31:00 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1dunW5-0006Jp-1G for emacs-devel@gnu.org; Thu, 21 Sep 2017 00:30:49 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 27 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:9Apvdp4XVbUkyBGb1YYAPCqcESA= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 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:218611 Archived-At: > Also, is there a motivation for introducing this new requirement, seeing as > how we've never had such a restriction in the past? 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.: (add-hook 'text-mode-hook #'visual-line-mode) (add-hook 'xml-mode-hook #'visual-line-mode) 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). 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 (with-temp-buffer (insert text) (funcall mode)) 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). Stefan