5

While there are many docs on how to write packages, mirror your own package git repo's ... etc. This seems quite a heavy solution.

What would be a good approach to having some local packages which can each be their own repository, without having to mirror MELPA for eg.

EDIT: I'm not so fussed exactly how this is setup, if it uses the package manager or not. However the items that are extracted into their own functionality should be packages - so if others find it useful, they can use it as a package too (otherwise this is no different from including files).


In VIM (VimPlug for eg) I can simply point to a git repo. I'm not necessarily looking for an exact equivalent to VimPlug in Emacs, just something better then including everything in my init.el ... or mirroring an entire package repo - would be handy.

  • Do you want packages installable with the package manage (package.el)? Or is this only about re-organizing your init file (then potentially sharing your files/code)? Or perhaps were you installing other people's packages by including them into your init file (that would be bad) and want to change this (which would be good)? I'm still not quite sure after reading your question multiple times... – YoungFrog Jul 27 '17 at 18:29
  • @YoungFrog - edited answer in response to your question. – ideasman42 Jul 27 '17 at 20:24
3

You can maintain your own package archive locally. It's not much more than a directory containing your packages. You just need to make sure you have an entry for it in your package-archives variable.

The easiest way is to use a library called package-x which will help you maintain such a local archive. The preliminary steps are :

  • Load the library: (require 'package-x)
  • Configure where your package archive will reside: (setq package-archive-upload-base "~/mypackagearchive/")
  • Add that directory to package-archives: (push (cons "myownarchive" package-archive-upload-base) package-archives)

Then you can use M-x package-upload-file to upload your file as a package to your archive, and M-x package-install to install it (you may need to refresh the package list in between).

You can read more maintaining a package archive (including how to handle multifiles packages) :

2

Yet another alternative would be to use quelpa, which allows you to use local folders or git repos as sources for package installation. It also has integration with use-package via quelpa-use-package.

Quelpa itself has a rather odd recommended install method:

(if (require 'quelpa nil t)
    (quelpa-self-upgrade)
  (with-temp-buffer
    (url-insert-file-contents "https://raw.github.com/quelpa/quelpa/master/bootstrap.el")
    (eval-buffer))) 

Install and configure quelpa-use-package by more conventional means:

(use-package quelpa-use-package
  :ensure t
  :init (setq quelpa-update-melpa-p nil))

And here is an example of how to use them to load a single-file package from the local disk:

;; Quelpa uses MELPA's recipe format (see
;; https://github.com/melpa/melpa), but with the addition of
;; additional fetchers, for example "file" for single-file packages
;; from local .el files
(use-package spanish-simple-prefix
  :quelpa ((spanish-simple-prefix
        :fetcher file
        :path "~/.emacs.d/lisp/spanish-simple-prefix.el")
       :update t)
  :config (setq default-input-method "spanish-simple-prefix"))

Note that the package file (which can be found here) needs to have header comments that conform to the conventional format for Emacs libraries, see manual. One easy way to do that is to use make-header from header2.el.

After making edits to any of your quelpa-loaded packages, do M-x quelpa-upgrade to byte-compile and reload the new versions.

  • 1
    I re-read your answer and wish there was a snippet illustrating it. Do you have such an example? Would be great. – YoungFrog Aug 20 '17 at 13:16
  • @YoungFrog: You have spurred me to test this out properly! It turned out to work really well, see latest edit – deprecated Sep 3 '17 at 7:04
1

A lightweight alternative to making a full-blown "package" that is amenable to the Emacs package-handling system (package.el) and is loadable into one of the existing package repositories is to simply put your code in a Lisp library, aka a Lisp file.

You can upload a Lisp library to Emacs Wiki, in the Elisp Area. You can also post snippets of Lisp (or other) code on any Emacs-Wiki page. Anyone can edit pages on Emacs Wiki.

Using the package system is handy for users, especially for large, complex packages that involve multiple Lisp files. But it is also simple for anyone to load a given Lisp file (aka library), whether or not it is a "package":

Just:

  1. Put the file in a directory that is in your load-path (a user option).
  2. Use load-library to load it. Or if the file contains a provide sexp then you can use require to load it.

See the Elisp manual:

  • If you don't want to change the load-path, you can also use load-file – YoungFrog Jul 27 '17 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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