Is there an automated way to discover “well-known” packages related to a given file type, e.g. scala-mode2 for Scala files, rust-mode for Rust files, etc., and install them automatically when opening a file of that type for the first time?

If several packages apply, the user could be prompted with a list of choices that she can then choose from if she so desires.

1 Answer 1


Emacs Prelude does this. The relevant macro:

(defmacro prelude-auto-install (extension package mode)
  "When file with EXTENSION is opened triggers auto-install of PACKAGE.
PACKAGE is installed only if not already present.  The file is opened in MODE."
  `(add-to-list 'auto-mode-alist
                `(,extension . (lambda ()
                                 (unless (package-installed-p ',package)
                                   (package-install ',package))
  • It hardcodes the list of packages associated with file types AFAICT; is that the only way? Commented Oct 13, 2014 at 19:24
  • 1
    The other way I could think of would be to do a catch-all in auto-mode-alist (like "\..*\'") and bind it to some function that does what you want. But I'm not really sure how useful that would be unless it actually knows which is the relevant mode for the relevant file type (in which case you're back to hard-coding).
    – shosti
    Commented Oct 13, 2014 at 19:29
  • 1
    You arespecifying the packages that you want to be installed to open the file using the function/mode you want. That necessarily means "hard-coding", no? You could easily change the code to allow for a list of packages to be installed together, or a list of packages that Emacs should try to install, in order, until one of them succeeds so that its function/mode can be used. Beyond that, what kind of "soft-coding" are you imagining? Do you want Emacs to guess what package and function you want used? If so, guess based on what? + see @shosti's comment about runtime pkg/mode determination.
    – Drew
    Commented Oct 13, 2014 at 20:41
  • 1
    In that case, please send your enhancement request to Emacs Dev: M-x report-emacs-bug.
    – Drew
    Commented Oct 13, 2014 at 21:13
  • 1
    @SébastienLeCallonnec Also you should be aware that the Emacs core devs have a strict policy against any reference to non-GNU packages (i.e. everything in MELPA and Marmalade), so even if it got into core Emacs it would most likely be limited to GNU ELPA packages.
    – shosti
    Commented Oct 13, 2014 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.