I'm currently running this version of Emacs:
GNU Emacs 26.1 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.7) of 2019-04-11, modified by Debian
I'm attempting to use use-package to configure the latest version of org-mode, and not the one that comes with Emacs. My initial attempt at configuration used :hook
directive (commented out in the elisp code below) does not work, as the resulting value of org-mode-hook
does not have my-org-mode-hook
at all (the actual value is shown later on):
;; Define org and melpa as package sources, and install `use-package' if it's
;; not already there. Origination:
;; https://www.reddit.com/r/emacs/comments/5sx7j0/how_do_i_get_usepackage_to_ignore_the_bundled/
;; Here, I *DO* actually desire automatic updating of the latest packages in this
;; case (specifically org-mode which receives frequent updates.
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
;; Ensure that "org" and "melpa" are found first in this order (higher numbers are higher priority):
(when (>= emacs-major-version 25) (setq package-archive-priorities '(("org" . 3)
("melpa" . 2)
("gnu" . 1))))
;; This is the key!! --> " The symbol ‘all’ says to load the latest installed
;; versions of all packages not specified by other elements." and for org-mode,
;; this means always get that latest version.
(setq package-load-list '(all))
(package-initialize)
;; Not sure why we need this:
(setq package-enable-at-startup nil)
;; Install use-package:
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(eval-when-compile
(require 'use-package))
;; Load org mode early to ensure that the orgmode ELPA version gets picked up, not the
;; shipped version.
;;
;; Reference https://github.com/jwiegley/use-package#package-installation
;;
(require 'use-package-ensure)
(setq use-package-always-ensure t)
;;
;; Now the configuration for org-mode:
;;
(use-package org
;; Install both org and "contrib"-uted org-related packages:
:ensure org-plus-contrib
:pin org
;;
;; This seems to be correct way to add my hook function to org-mode-hook, but
;; it does not show up in the value of org-mode-hook, so I commented it out in
;; favor of the forced use of add-hook inside :config, later:
;;
;; :hook #'my-org-mode-hook
;;
:config
;;
;; This seems to be the only way to get my hook function to be added, as the
;; :hook directive is ignored or obliterated by something else:
;;
(add-hook 'org-mode-hook 'my-org-mode-hook))
When try to use :hook
that is commented out above (and of course also commenting out the call to add-hook
), I get this for the final value after opening up a .org
file:
org-mode-hook is a variable defined in ‘org.el’.
Its value is shown below.
This variable may be risky if used as a file-local variable.
Documentation:
Mode hook for Org mode, run after the mode was turned on.
You can customize this variable.
Value:
(#f(compiled-function
()
#<bytecode 0x1684c2d>)
#f(compiled-function
()
#<bytecode 0x1ab413d>)
org-babel-result-hide-spec org-babel-hide-all-hashes #f(compiled-function
()
#<bytecode 0x1ae75e1>)
org-eldoc-load)
Original value was nil
As seen above, the my-org-mode-hook
function is not in the value. My understanding is that use-package
should add it there (per use-package Hooks section) but does not, and I have to force it with the explicit call to add-hook
.
What am I doing wrong here?