From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kaushal Modi Subject: [RFC] Replace lambda functions added to org-mode-hook with named funcs Date: Thu, 4 Oct 2018 11:10:55 -0400 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45084) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g85Hs-0003pD-EK for emacs-orgmode@gnu.org; Thu, 04 Oct 2018 11:11:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g85Hr-0002Fs-AH for emacs-orgmode@gnu.org; Thu, 04 Oct 2018 11:11:36 -0400 Received: from mail-lj1-x229.google.com ([2a00:1450:4864:20::229]:46629) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g85Hq-0002DW-TQ for emacs-orgmode@gnu.org; Thu, 04 Oct 2018 11:11:35 -0400 Received: by mail-lj1-x229.google.com with SMTP id 203-v6so8681643ljj.13 for ; Thu, 04 Oct 2018 08:11:34 -0700 (PDT) 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-org list Hello, Yesterday, while helping someone out[0] with why their custom functions added to org-mode-hook didn't work, I asked them to reveal the value of org-mode-hook, and they presented this as the default value of org-mode-hook once Org was loaded: ===== '(org-mode-hook (quote (#[0 "\300\301\302\303\304$\207" [add-hook change-major-mode-hook org-show-block-all append local] 5] #[0 "\300\301\302\303\304$\207" [add-hook change-major-mode-hook org-babel-show-result-all append local] 5] org-babel-result-hide-spec org-babel-hide-all-hashes))) ===== Going down the rabbit hole, I discovered many places in Org source where lambdas were added to org-mode-hook. I propose to replace such lamba functions with named functions. Here's an example of diff on maint branch, after making one such change: ===== diff --git a/lisp/org.el b/lisp/org.el index 2cc9b6a1c..9f28502d4 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -7429,10 +7429,10 @@ a block. Return a non-nil value when toggling is successful." (when (eq (overlay-get ov 'invisible) 'org-hide-block) (delete-overlay ov)))))))) -;; 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) ;;; Org-goto ===== If there is no objection to this, I can fix this everywhere in maint, and then merge that into master. Comments? -- Kaushal Modi [0]: https://www.reddit.com/r/emacs/comments/9l1aji/org_mode_hooks_dont_work/e73awsc/