Subject: Emacslisp packaging
To: None <tech-pkg@netbsd.org>
From: Masao Uebayashi <uebayasi@soum.co.jp>
List: tech-pkg
Date: 05/09/2002 15:24:02
----Next_Part(Thu_May__9_15:24:02_2002_343)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hello,

With the attached simple Emacslisp script, pkgsrc.el, users can use
installed Emacslisp packages very easily, without reading the manuals
for the apropriate configurations and copy&paste it into
${HOME}/.emacs.

Each pkgsrc'ized Emacslisp package installs a Emacslisp fragment
needed to be written in .emacs to use it. What users need to do is
`load' the fragment. `pkgsrc-require' enables users to load the
configuration fragments very easily.

For example, now my ${HOME}/.emacs contains the following lines

  (require 'pkgsrc)
  (pkgsrc-require 'lookup)

By the first line, pkgsrc.el located somewhere in the `load-path' is
loaded. By the second line, `pkgsrc-require' defined in pkgsrc.el
tries to load a config fragment for `lookup'. So lookup package has to
install a fragment, lookup.el, which looks like

  (pkgsrc-add-load-path "/usr/pkg/share/emacs/21.2/site-lisp/lookup")
  (autoload 'lookup "lookup" nil t)
  (autoload 'lookup-region "lookup" nil t)
  (autoload 'lookup-pattern "lookup" nil t)
  (pkgsrc-provide 'lookup)

(`pkgsrc-add-load-path' and `pkgsrc-provide' are to avoid `load-path'
 duplication and multiple inclusion of the fragment.)

This fragment `lookup.el' must NOT be located in `load-path', because
there should be another `lookup.el' which the original
installs. Currently, fragments are installed under "pkgsrc/"
directory, where is not in load-path. (The `lookup.el' fragment is
loaded as "pkgsrc/lookup" in pkgsrc.el.)

In such cases that an Emacslisp package foo depends another one bar,
the fragment `bar.el' should be pkgsrc-require'ed in the `foo.el'
fragment so that users who want to use Foo only need to add

  (pkgsrc-require 'foo)

in her/his ${HOME}/.emacs.

How do you think/feel about this? I'd like to see your comments...

Thanks,
Masao

----Next_Part(Thu_May__9_15:24:02_2002_343)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="pkgsrc.el"

;;; pkgsrc.el
;;; $Id$

(defvar pkgsrc-features '())

(defun pkgsrc-featurep (feature)
  ""
  (if (memq feature pkgsrc-features)
      t
    nil))

(defun pkgsrc-require (feature)
  ""
  (let ((the-file (concat "pkgsrc/" (symbol-name feature))))
    (if (not (pkgsrc-featurep feature))
	(load the-file))))

(defun pkgsrc-provide (feature)
  ""
  (setq pkgsrc-features (cons feature pkgsrc-features)))

(defun pkgsrc-add-to-load-path (path)
  ""
  (add-to-list load-path path))

(provide 'pkgsrc)

----Next_Part(Thu_May__9_15:24:02_2002_343)----