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: [Emacs-diffs] scratch/so-long 7273fb2: Add so-long library Date: Sat, 12 Jan 2019 10:11:05 -0500 Message-ID: References: <20190107065207.21793.53271@vcs0.savannah.gnu.org> <20190107065208.BA36C21736@vcs0.savannah.gnu.org> <16bb3884-c2de-b178-afe8-0b13a8b116a8@orcon.net.nz> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1547306381 25802 195.159.176.226 (12 Jan 2019 15:19:41 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 12 Jan 2019 15:19:41 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Phil Sainty Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jan 12 16:19:36 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1giL4S-0006c9-MK for ged-emacs-devel@m.gmane.org; Sat, 12 Jan 2019 16:19:36 +0100 Original-Received: from localhost ([127.0.0.1]:60200 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1giL6Z-0000OW-Gq for ged-emacs-devel@m.gmane.org; Sat, 12 Jan 2019 10:21:47 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:57640) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1giL6L-0008MP-IF for emacs-devel@gnu.org; Sat, 12 Jan 2019 10:21:34 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1giKwG-0007r2-44 for emacs-devel@gnu.org; Sat, 12 Jan 2019 10:11:09 -0500 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:55900) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1giKwF-0007qo-VJ for emacs-devel@gnu.org; Sat, 12 Jan 2019 10:11:08 -0500 Original-Received: from pastel.home (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id x0CFB5NX027338; Sat, 12 Jan 2019 10:11:05 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id 405EE68437; Sat, 12 Jan 2019 10:11:05 -0500 (EST) In-Reply-To: <16bb3884-c2de-b178-afe8-0b13a8b116a8@orcon.net.nz> (Phil Sainty's message of "Sat, 12 Jan 2019 15:20:32 +1300") X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 2 Rules triggered EDT_SA_DN_PASS=0, RV6459=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6459> : inlines <6992> : streams <1809875> : uri <2778814> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 132.204.246.20 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:232322 Archived-At: > If I define a global mode, then there's another variable which is > ostensibly tracking the 'enabled' state of the functionality, which > seemed ugly. I don't see why. If you don't want to get rid of the so-long-enabled variable, then just make it a defvaralias and you're done. > that I could de-sync the mode and that variable (I forget how, but > possibly by calling `so-long-disable' which I need to keep for > backwards-compatibility), Redefine so-long-enable as an obsolete function that just calls (so-long-auto-mode 1). Side note: I mistakenly thought so-long was pretty much a brand new package. How far back does it go? > and then it just struck me that I was making more work and a bit of > a headache for myself in an effort to allow people to add > '(global-so-long-mode)' in their init files instead of > '(so-long-enable)' and I immediately lost all interest in spending > more time on achieving that. The issue is consistency (a minor mode is a standard interface and UI to enable&disable&test a feature) and ease of use (a global minor mode can be enabled via Customize). > `so-long-enable' is autoloaded, so I could drop the test for > (require 'so-long nil :noerror) in the Commentary. That's a hold- > over from the earlier releases, and it seemed harmless to keep, Users will copy it and wonder why Emacs has to be so complicated, and it will then fail the day the file is renamed. > but I'm happy to remove it, as it's not needed for either 27 or ELPA. That would be good. >> On the design side, I think you should merge `so-long` and >> `so-long-mode` into a single function and make that function >> a (buffer-local) minor-mode (i.e. not have any major mode, just use >> fundamental-mode instead). Making it a minor mode rather than >> a major-mode will also make it easier to remember the previous >> major-mode without any need for a change-major-mode-hook hack. > > These changes are too significant, so I don't wish to do any of that. I think they're just some minor shuffling of code. > There's backwards-compatibility with the earlier releases to consider > (so-long-mode has always been a major mode); Then use another name for the minor mode and make so-long-mode be the combination of fundamental-mode + so-long-minor-mode. > and I also see a benefit to retaining a major mode option (I have > a use-case for using it as a file-local 'mode' on one project, and > I've had cause to suggest the same thing to other users). Minor modes can also be used on the "mode:" thingy, tho I don't think that should make a big difference. > I did consider turning `so-long' into a > `so-long-minor-mode' at one point, but I think it either seemed like > a fairly needless change, or possibly the idea of implementing a > feature which was designed to mess with minor mode states *as* a minor > mode seemed wrong to me. 'M-x so-long' is also shorter :) The point of a minor mode is to provide a standard UI to enable *and* disable something. >> Rather than defadvice, please use advice-add. > I know defadvice and I don't know advice-add, so perhaps someone else > can write those changes. E.g. (defadvice hack-local-variables (after so-long--file-local-mode disable) "..." ;; The first arg to `hack-local-variables' is HANDLE-MODE since Emacs 26.1, ;; and MODE-ONLY in earlier versions. In either case we are interested in ;; whether it has the value `t'. (and (eq (ad-get-arg 0) t) ad-return-value ; A file-local mode was set. (so-long-handle-file-local-mode ad-return-value))) can be turned into (advice-add 'hack-local-variables :around #'so-long--hlv) (defun so-long--hlv (orig-fun &optional handle-mode &rest args) ;; The first arg to `hack-local-variables' is HANDLE-MODE since Emacs 26.1, ;; and MODE-ONLY in earlier versions. In either case we are interested in ;; whether it has the value `t'. (let ((retval (apply orig-fun handle-mode args))) (and (eq handle-mode t) retval ; A file-local mode was set. (so-long-handle-file-local-mode retval)))) BTW, while reading that code, I couldn't quite understand what this advice is about. I think a comment describing a use-case would be valuable. > Such changes will need to work in Emacs 25 at least, and ideally back > to 24.3 advice-add was added to Emacs-24.4 and it is available in GNU ELPA for earlier Emacsen, so it's OK. Stefan