4

I would like to make a few changes to a package installed via package-install. What's the canonical way to do so?

I understand that it would probably involve:

  1. Uninstalling the package via list-packages. (Is this necessary?)
  2. Place the package files manually somewhere under ~/.emacs.d (e.g. by cloning the Git repository)
  3. Tell Emacs to load the package from the new location. (How?)
1
  • Whenever I find the need to modify a package, I can usually achieve it with advice. Is that a possibility for you?
    – PythonNut
    Mar 25, 2016 at 18:03

3 Answers 3

3

Uninstalling the package via list-packages. (Is this necessary?)

Not at all. Just make sure that the git clone is ahead of ELPA on load-path.

Place the package files manually somewhere under ~/.emacs.d (e.g. by cloning the Git repository) Tell Emacs to load the package from the new location. (How?)

I have a dedicated git/ directory in my site-lisp. And just clone there. This code will put all packages in git/ ahead of ELPA on the load-path:

(package-initialize)
(let ((emacs-git (expand-file-name "git/" emacs-d)))
  (mapc (lambda (x)
          (add-to-list 'load-path (expand-file-name x emacs-git)))
        (delete ".." (directory-files emacs-git))))
2
  • A lot of time has passed so this may only be a little incompatibility, but: what is the variable emacs-d? I can't find it on my system Sep 2, 2022 at 17:28
  • 1
    It's a custom variable I defined that points to a directory where the "git" folder is. You can adapt something similar to your config.
    – abo-abo
    Sep 2, 2022 at 19:26
4

If you wish to use the package manager for this (which is entirely reasonable -- it will take care of byte-compilation, ensure all the autoloads are processed, etc), then:

  • Copy the package (somewhere that isn't in your Emacs load-path) and make whatever changes you wish to make.

  • If it is a simple package built from a single .el file (ignoring *.elc, *-pkg.el, and *-autoloads.el files):

    • Update the version string in the .el file.

    • Invoke package-install-file on the modified .el file.

  • If it is a complex package built from multiple files:

    • Update the version string in the *-pkg.el file

    • If you're running Emacs 25+, invoke package-install-file on the directory.

    • If you're running Emacs 24, create a tar file of the directory (include the directory itself; not just its contents), and invoke package-install-file on the tar file.

You should be able to safely delete the unnecessary files from your modified source for the package (e.g. *.elc, *-autoloads.el, and for the simple package case, *-pkg.el).

See C-hig (elisp) Packaging for more information.

3
  • I've accepted abo-abo's answer as it seems to allow contributing changes upstream the easiest, but this answer is interesting too. I would like to ask, though - is running package-install-file necessary every time I want an edit to take effect? And, will the package manager clobber my installed package when the upstream package is updated? Mar 26, 2016 at 5:06
  • Emacs does not automatically install newer releases of any package -- it's not going to clobber a package unless you ask it to. You would need to run package-install-file every time, unless you took to editing and re-compiling the installed versions under ~/.emacs.d/elpa directly (but I don't think that's what you were wanting to do).
    – phils
    Mar 26, 2016 at 5:57
  • Note that if a package is derived from a git repository, it's fairly likely that you can check that out and use it as your target for package-install-file.
    – phils
    Mar 26, 2016 at 5:59
1

Or install use-package, and explicitly supply the load path this way:

(use-package example
  :load-path "/directory/of/your/package")

Your Answer

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

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