From mboxrd@z Thu Jan 1 00:00:00 1970 From: Phil Sainty Subject: Re: [RFC] Replace lambda functions added to org-mode-hook with named funcs Date: Tue, 01 Oct 2019 18:00:18 +1300 Message-ID: <8946ae80757155f64bd5dcaddf547732@webmail.orcon.net.nz> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:37211) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iFAGx-0006GW-7a for emacs-orgmode@gnu.org; Tue, 01 Oct 2019 01:00:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iFAGv-00076Z-FT for emacs-orgmode@gnu.org; Tue, 01 Oct 2019 01:00:26 -0400 Received: from smtp-3.orcon.net.nz ([60.234.4.44]:49171) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iFAGv-00070u-5B for emacs-orgmode@gnu.org; Tue, 01 Oct 2019 01:00:25 -0400 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Cc: Nicolas Goaziou , Kaushal Modi On Fri, Oct 5, 2018, 6:42 AM Nicolas Goaziou wrote: > Kaushal Modi writes: > > I propose to replace such lamba functions with named functions. > > Here's an example of diff on maint branch, after making one such change: > > > > -;; Remove overlays when changing major mode > > -(add-hook 'org-mode-hook > > - (lambda () (add-hook 'change-major-mode-hook > > - 'org-show-block-all 'append 'local))) > > +(defun org--unfold-all-blocks-on-major-mode-change () > > + "Remove overlays when changing major mode." > > + (add-hook 'change-major-mode-hook #'org-show-block-all 'append 'local)) > > +(add-hook 'org-mode-hook #'org--unfold-all-blocks-on-major-mode-change) > > If that's a function added to `org-mode-hook', it is not useful to > add "on major mode change". Certainly it's useful. Or at least in general it's a common *pattern* for a major mode to add a function to `change-major-mode-hook' so that if the user changes from that major mode to some other major mode, the function will be called and can put the buffer into a sensible state before the replacement mode function is called. The only curious thing about it to me is that this code is being run via `org-mode-hook' rather than in the `org-mode' body; but maybe there's some reason for that. Regarding the general issue: Grep shows me all of the following instances in the master branch (commit d215c3a8c0b4c027), where a lambda is added to a hook variable (a few of them in the form of commented suggestions to the user). It's never a good idea; all of these should be changed to use named functions, IMO. -Phil -*- grep -*- ./ob-core.el:1429:(add-hook 'org-mode-hook ./ob-haskell.el:66: (add-hook 'inferior-haskell-hook ./ol-w3m.el:171:(add-hook ./ol-w3m.el:176:(add-hook ./org-agenda.el:2246: (add-hook 'filter-buffer-substring-functions ./org-agenda.el:2935: (add-hook ./org-attach.el:697:;; (add-hook ./org-compat.el:813: (add-hook 'imenu-after-jump-hook ./org-compat.el:817: (add-hook 'org-mode-hook ./org-compat.el:880: (add-hook 'speedbar-visiting-tag-hook ./org-crypt.el:144: (add-hook 'auto-save-hook ./org-crypt.el:267: (add-hook ./org-ctags.el:196:(add-hook 'org-mode-hook ./org-ctags.el:59:;; (add-hook 'org-mode-hook ./org-indent.el:188: (add-hook 'filter-buffer-substring-functions ./org-mouse.el:1085:(add-hook 'org-agenda-mode-hook ./org-mouse.el:856:(add-hook 'org-mode-hook ./org-src.el:745: (add-hook \\='org-src-mode-hook ./org.el:15697: (add-hook 'after-save-hook ./org.el:18978:(add-hook 'occur-mode-find-occurrence-hook ./org.el:21221:(add-hook 'org-mode-hook ;remove overlays when changing major mode ./org.el:2916: (add-hook \\='org-capture-mode-hook