13

I'm trying to use use-package to set up my org-mode initialization. I have the following in my ~/.emacs file:

(use-package org-mode
  :mode "\\.org$"
  :ensure org
  :config
  (progn
    (setq org-log-done 'time)
    (setq org-confirm-babel-evaluate nil)
    (setq org-export-babel-evaluate nil)
    (setq org-html-validation-link nil)
    ;; ... more stuff
  )
)

None of that :config initialization stuff is getting run, though. Do I have the package names wrong or something? I get a bit confused on package names vs. ELPA names vs. invocation commands....

Ken Williams
  • 390
  • 2
  • 12
  • 1
    Take a look at `org.el` and you'll see toward the end: `(provide 'org)`. That symbol (`org`) is what you would use to load the package, as in: `(require 'org)`. That is ultimately what `use-package` is doing, just with some useful stuff around it. A given package can define lots of modes so the package and mode names are not always the same. This is really the same issue as the other question about `html-mode` being defined by the `sgml-mode` package. – glucas Oct 29 '15 at 13:24
  • The "other question" @glucas mentions: http://emacs.stackexchange.com/q/10396/8899 – Ken Williams Oct 29 '15 at 17:05

2 Answers2

25

The below would work. For the sake of clarity, I am using :ensure org-plus-contrib which deviates a bit from the example in your question.

(use-package org
  :mode (("\\.org$" . org-mode))
  :ensure org-plus-contrib
  :config
  (progn
    ;; config stuff
    ))

Here are some explanation notes for the above:

  • (use-package FEATURE-NAME
    • FEATURE-NAME is what goes in the (provide ..) line of a package. For org-mode, that line is (provide 'org).
  • :mode ((FILE-REGEXP . MAJOR-MODE))
    • FILE-REGEXP is the regular expression for which you want a particular major mode to be enabled. You had that correct: "\\.org$".
    • MAJOR-MODE is the name of the major mode that you want to enable (including the -mode part of the major mode name). In this case, the major mode name is org-mode.
    • The style :mode (FILE-REGEXP) that you used would only work if FEATURE-NAME and MAJOR-MODE are the exact same. Example: cperl-mode.
  • :ensure PACKAGE-NAME
    • PACKAGE-NAME is what I see listed in the package list (M-x package-list-packages). For clarity, in my solution above, we are installing the org-plus-contrib1 package. This is to demonstrate the feature name, major mode and the actual package name do not have to be the exact same. And also I prefer installing that instead of plain org-mode as you get all the contrib/ package goodies too! :)

1 You will need to add (add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t) to your emacs config in order to install org-plus-contrib. See the official org-mode installation page for more info.


Note

The best way to make the above use-package snippet to work is to save it to your emacs config first, then delete prior Package Manager installed versions of org, and then restart emacs.

Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179
  • Thanks - I'm still having trouble with one aspect, getting org's R support to work using `org-babel-do-load-languages` in this context, it gives the error `Error (use-package): org :config: Invalid function: org-babel-header-args-safe-fn`. Other languages (e.g. `sh` or `perl` or `emacs-lisp`) seem to work fine. – Ken Williams Oct 29 '15 at 15:50
  • That looks like an unrelated issue. Are you using that macro as intended? You can learn more about it by doing `C-h f org-babel-header-args-safe-fn`. Also you don't have that code snippet in your question. So it's difficult to guess what's going on. – Kaushal Modi Oct 29 '15 at 15:54
  • It seems to be this problem: https://www.mail-archive.com/emacs-orgmode@gnu.org/msg98818.html . Not sure how to resolve it yet. My full config is here: https://gist.github.com/kenahoo/8bca2ecc5cbe6e48a91c and commenting out the `(R . t)` line stops the error. So yeah, unrelated issue I think. Might need to open *another* question... – Ken Williams Oct 29 '15 at 16:03
  • Looks like my org-mode itself broke with the latest update. Fixed that by doing `emacs -Q` to start clean, carefully load my `'package` configuration, uninstalling `org` and `org-plus-contrib`, then re-installing them. The problem is explained here: http://emacs.stackexchange.com/a/13576/8899 – Ken Williams Oct 29 '15 at 17:38
  • Ah, sorry about that. Probably installing `org-plus-contrib` messed up your org installation and you ended up having a mix of versions. btw, you need to install just `org-plus-contrib`. You do not need to install the separate `org` package too. – Kaushal Modi Oct 29 '15 at 17:41
  • `org-plus-contrib` isn't maintained anymore. Now, there are two packages: `org` in GnuELPA and `org-contrib` in NonGnuELPA. See https://orgmode.org/elpa.html – jmg Aug 27 '23 at 10:50
4

With the caveat that I haven't used use-package before, I believe you want org rather than org-mode. I'm basing this on the fact that, on my Emacs, (package-installed-p 'org-mode) returns nil while (package-installed-p 'org) does not.

Aaron Harris
  • 2,664
  • 17
  • 22