From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?Q?Cl=c3=a9ment_Pit-Claudel?= Newsgroups: gmane.emacs.devel Subject: Re: Should mode commands be idempotent? Date: Sat, 23 Sep 2017 10:16:35 +0200 Message-ID: <81dcceb4-f939-1d63-0c31-0926a5dad823@gmail.com> 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: 7bit X-Trace: blaine.gmane.org 1506159945 22393 195.159.176.226 (23 Sep 2017 09:45:45 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 23 Sep 2017 09:45:45 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Sep 23 11:45:41 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 1dvh0D-0005KL-8g for ged-emacs-devel@m.gmane.org; Sat, 23 Sep 2017 11:45:37 +0200 Original-Received: from localhost ([::1]:34246 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvh0H-0000Fy-IS for ged-emacs-devel@m.gmane.org; Sat, 23 Sep 2017 05:45:41 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41986) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dvgyv-0007p3-Ex for emacs-devel@gnu.org; Sat, 23 Sep 2017 05:44:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dvgyu-0004EC-Am for emacs-devel@gnu.org; Sat, 23 Sep 2017 05:44:17 -0400 Original-Received: from mail-wr0-x234.google.com ([2a00:1450:400c:c0c::234]:56210) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dvgyu-0004Dp-3x for emacs-devel@gnu.org; Sat, 23 Sep 2017 05:44:16 -0400 Original-Received: by mail-wr0-x234.google.com with SMTP id l39so2340503wrl.12 for ; Sat, 23 Sep 2017 02:44:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=O6UrivHD6YD8FbZVGuNGSoBFstDx/tFQ64ilXQkeuh0=; b=EQqjXFUCtfU0nL1Xjyr1HRjfAQy/Gax1WYErPrE/Gsn6AZzBdTPIvtqoyEMUcYIWfx 5pJS8nfcS8dogbUzsiqBbUx1M7cz0kdmYo2T++fjSm3qFiRzwwHJc3/kI+tfw+06/26s f/DLRsCBv3DOlsG6LKAhLHWVhHRNu61+wTq2QzM0/yVBlT1Gmyz3Qk6tJTUxR3lZdHle 2U5iKato7CdnbWjhg48WlCkFESw6EUVlo4IC1MNeNuiNK/TxXNaAavNV0HWH0MX/9oZa RIzT4CfA84s9qi4YaAv7BFn4zXHrblagLsZFI35dUj6rOl+8G0jjt0YE9uZQI3Yk+6ih zMjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=O6UrivHD6YD8FbZVGuNGSoBFstDx/tFQ64ilXQkeuh0=; b=EtFg6DRLrLYU2a7wU7v2MgvWFBytTW7cbKgZKFGTYhNiU+BJSGnTA3i9h+CuaixFYm BNX1X9tbIM+o/CJrodZAZMZcTbDy8imlQq3nHDK7f6xUpXitN5sEeSU47LO31fRRCj2k otKuZI7IirEuKqqa0y7yZCHGa5sye4/BdMyvuqNI8Fi50Xqxo5shbw/Jdqazi/XMpwAI vWscNzkatiUTyp2kThiNG1izcRaOsWqsU62iB7Qb45F7M+ZdPLuXjZ41B2A41qC95Un+ NKPPNYSPvuGeYOSIe1OKesmJG9Up1EZCLmfNKFBsk8wqhvf3uomwfRtNMbsm+xe3UNMa 6JQQ== X-Gm-Message-State: AHPjjUj/sycQdxPtCt35OQSo44j9SGRdCJ73Qo+NB1zw5DIqvb4deO3B CPUmM193GVxzCFI20irEroql68z5Vbw= X-Google-Smtp-Source: AOwi7QA012+lOp+lC1uDA9PIGGszvYaXnDXRj7gDryLLJwFgZwSID5DiJD2eyOHOjXD6LELprYe+lw== X-Received: by 10.223.176.84 with SMTP id g20mr1328831wra.117.1506159854760; Sat, 23 Sep 2017 02:44:14 -0700 (PDT) Original-Received: from [192.168.43.95] ([37.169.175.60]) by smtp.gmail.com with ESMTPSA id m38sm1507020wrm.95.2017.09.23.02.44.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 23 Sep 2017 02:44:14 -0700 (PDT) In-Reply-To: Content-Language: en-GB X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::234 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:218721 Archived-At: On 2017-09-21 00:25, Stefan Monnier wrote: >>> It shouldn't be needed: the idempotence should emerge naturally from the >>> way the code is written, rather than being the result of special tests >>> to detect that particular situation. >> I'm not too sure: take the example of visual-line-mode: how do you make that >> idempotent without explicitly checking whether the mode has already >> been activated? > > In this case I'd typically do something like the patch below Thanks. AFAICT visual-line--saved-state acts mostly as a proxy for checking whether the mode was enabled, but I also see that it's not quite the same as not running the mode function if it's already enabled. Interestingly, what makes visual-line-mode not idempotent in the first place is that it goes to great lengths to save user settings and restore them. Had it not done this (that is, had it just killed the local variable bindings when disabled), it would have been idempotent but more annoying to use. It isn't even obvious that the current behavior (even with your patch) is what we want, anyway: what if I have another mode foo-mode that touches the same variables as visual-line-mode? Then I can run (visual-line-mode), (foo-mode), (visual-line-mode -1), and then which state should I be in? There's a more general problem here, and it's not an easy one :/