From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: Redundant (harmful) duplication of run-hooks in define-globalized-minor-mode [patch-2] Date: Fri, 1 Feb 2013 19:53:52 +0000 Message-ID: <20130201195352.GB23075@acm.acm> References: <20130114163003.GC3274@acm.acm> <20130115140855.GA3430@acm.acm> <20130117175159.GA3114@acm.acm> <20130131110404.GA3459@acm.acm> <20130201154453.GA23075@acm.acm> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1359749128 19188 80.91.229.3 (1 Feb 2013 20:05:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 1 Feb 2013 20:05:28 +0000 (UTC) Cc: =?iso-8859-1?Q?Jo=E3o_T=E1vora?= , Chong Yidong , Leo Liu , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Feb 01 21:05:46 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1U1Mrq-0000X5-2H for ged-emacs-devel@m.gmane.org; Fri, 01 Feb 2013 21:05:46 +0100 Original-Received: from localhost ([::1]:53253 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1MrX-0004li-Qc for ged-emacs-devel@m.gmane.org; Fri, 01 Feb 2013 15:05:27 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:60288) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1MqR-0003XU-9d for emacs-devel@gnu.org; Fri, 01 Feb 2013 15:05:25 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U1Mmp-0005hP-CH for emacs-devel@gnu.org; Fri, 01 Feb 2013 15:04:19 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:31243 helo=mail.muc.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1Mmp-0005fj-20 for emacs-devel@gnu.org; Fri, 01 Feb 2013 15:00:35 -0500 Original-Received: (qmail 39545 invoked by uid 3782); 1 Feb 2013 20:00:32 -0000 Original-Received: from acm.muc.de (pD955693B.dip.t-dialin.net [217.85.105.59]) by colin.muc.de (tmda-ofmipd) with ESMTP; Fri, 01 Feb 2013 21:00:30 +0100 Original-Received: (qmail 5968 invoked by uid 1000); 1 Feb 2013 19:53:52 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 8.x X-Received-From: 193.149.48.1 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:156770 Archived-At: Hi, Stefan. On Fri, Feb 01, 2013 at 11:28:00AM -0500, Stefan Monnier wrote: > > I'm not so sure about this. These complicated structures of macros and > > hooks and generated functions are making my head hurt. ;-( Are you > > sure there are no ways of invoking this which won't bypass > > kill-all-local-variables? (That's a real question, not a rhetorical > > one.) > Any major mode will have to call kill-all-local-variables, so it's > pretty sure. OK, I see it now. I've removed that function, replacing it with a comment about kill-all-local-variables attending to disable-MODE. I've also tidied up the new bit of doc-string I added, Is it OK to commit this change to emacs-24 now, and close bug#11152? Here's the patch: === modified file 'lisp/emacs-lisp/easy-mmode.el' *** lisp/emacs-lisp/easy-mmode.el 2013-01-01 09:11:05 +0000 --- lisp/emacs-lisp/easy-mmode.el 2013-02-01 19:13:42 +0000 *************** *** 340,348 **** enabled, then disabling and reenabling MODE should make MODE work correctly with the current major mode. This is important to prevent problems with derived modes, that is, major modes that ! call another major mode in their body." (declare (doc-string 2)) (let* ((global-mode-name (symbol-name global-mode)) (pretty-name (easy-mmode-pretty-mode-name mode)) (pretty-global-name (easy-mmode-pretty-mode-name global-mode)) (group nil) --- 340,353 ---- enabled, then disabling and reenabling MODE should make MODE work correctly with the current major mode. This is important to prevent problems with derived modes, that is, major modes that ! call another major mode in their body. ! ! When a major mode is initialized, MODE is actually turned on just ! after running the major mode's hook. However, MODE is not turned ! on if the hook has expllicitly disabled it." (declare (doc-string 2)) (let* ((global-mode-name (symbol-name global-mode)) + (mode-name (symbol-name mode)) (pretty-name (easy-mmode-pretty-mode-name mode)) (pretty-global-name (easy-mmode-pretty-mode-name global-mode)) (group nil) *************** *** 353,358 **** --- 358,367 ---- (MODE-check-buffers (intern (concat global-mode-name "-check-buffers"))) (MODE-cmhh (intern (concat global-mode-name "-cmhh"))) + (MODE-disable-in-buffer + (intern (concat global-mode-name "-disable-in-buffer"))) + (minor-MODE-hook (intern (concat mode-name "-hook"))) + (disable-MODE (intern (concat "disable-" mode-name))) (MODE-major-mode (intern (concat (symbol-name mode) "-major-mode"))) keyw) *************** *** 396,403 **** (progn (add-hook 'after-change-major-mode-hook ',MODE-enable-in-buffers) - (add-hook 'change-major-mode-after-body-hook - ',MODE-enable-in-buffers) (add-hook 'find-file-hook ',MODE-check-buffers) (add-hook 'change-major-mode-hook ',MODE-cmhh)) (remove-hook 'after-change-major-mode-hook ',MODE-enable-in-buffers) --- 405,410 ---- *************** *** 415,420 **** --- 422,431 ---- ;; up-to-here. :autoload-end + ;; A function which checks whether MODE has been disabled in the major + ;; mode hook which has just been run. + (add-hook ',minor-MODE-hook ',MODE-disable-in-buffer) + ;; List of buffers left to process. (defvar ,MODE-buffers nil) *************** *** 423,436 **** (dolist (buf ,MODE-buffers) (when (buffer-live-p buf) (with-current-buffer buf ! (unless (eq ,MODE-major-mode major-mode) ! (if ,mode ! (progn ! (,mode -1) ! (,turn-on) ! (setq ,MODE-major-mode major-mode)) ! (,turn-on) ! (setq ,MODE-major-mode major-mode))))))) (put ',MODE-enable-in-buffers 'definition-name ',global-mode) (defun ,MODE-check-buffers () --- 434,448 ---- (dolist (buf ,MODE-buffers) (when (buffer-live-p buf) (with-current-buffer buf ! (if ,disable-MODE ! (if ,mode (,mode -1)) ! (unless (eq ,MODE-major-mode major-mode) ! (if ,mode ! (progn ! (,mode -1) ! (,turn-on)) ! (,turn-on)))) ! (setq ,MODE-major-mode major-mode))))) (put ',MODE-enable-in-buffers 'definition-name ',global-mode) (defun ,MODE-check-buffers () *************** *** 443,449 **** (defun ,MODE-cmhh () (add-to-list ',MODE-buffers (current-buffer)) (add-hook 'post-command-hook ',MODE-check-buffers)) ! (put ',MODE-cmhh 'definition-name ',global-mode)))) ;;; ;;; easy-mmode-defmap --- 455,468 ---- (defun ,MODE-cmhh () (add-to-list ',MODE-buffers (current-buffer)) (add-hook 'post-command-hook ',MODE-check-buffers)) ! (put ',MODE-cmhh 'definition-name ',global-mode) ! ;; disable-MODE is set in MODE-disable-in-buffer and cleared by ! ;; kill-all-local-variables. ! (defvar-local ,disable-MODE nil) ! (defun ,MODE-disable-in-buffer () ! (unless ,mode ! (setq ,disable-MODE t))) ! (put ',MODE-disable-in-buffer 'definition-name ',global-mode)))) ;;; ;;; easy-mmode-defmap > Stefan -- Alan Mackenzie (Nuremberg, Germany).