(require 'cl)
(defvar emacs-modules-buffer-name
"*Emacs-Modules*"
"Buffer name to use for displaying and selecting emacs modules
to install.")
(defcustom emacs-modules-elisp-home
(expand-file-name "~/.elisp/")
"Location to store fetched Elisp files."
:type 'file
:group 'EmacsModules)
(defvar emacs-modules-tmp-dir
(expand-file-name "~/tmp/emacs-modules")
"Temp directory to hold downloads.
\nIt is created and deleted before and after every fetch.")
(defmacro emacs-modules-install-file (file)
"Simple install macro to copy an Elisp FILE to
`emacs-modules-elisp-home'."
`(lambda ()
(shell-command (concat
"cp " (shell-quote-argument ,file)
" " (shell-quote-argument ,emacs-modules-elisp-home)))
(batch-byte-compile-file ,file)))
(defmacro emacs-modules-install-tarball-dir (file dir)
"Install macro to unpack FILE and copy the contents to
directory DIR in `emacs-modules-elisp-home'."
`(lambda ()
(shell-command (concat
"tar xvfz " (shell-quote-argument ,file)))
(shell-command (concat
"mkdir -p " (shell-quote-argument ,emacs-modules-elisp-home)
"/" (shell-quote-argument ,dir)))
(shell-command (concat
"cp -r " (shell-quote-argument ,file) "/*"
" " (shell-quote-argument ,emacs-modules-elisp-home)
"/" (shell-quote-argument ,dir) "/"))
(batch-byte-compile-file ,file)))
(defvar emacs-modules-database-install
`(("apel" "a portable emacs library"
"ftp://ftp.m17n.org/pub/mule/apel/apel-9.23.tar.gz"
"apel.tar.gz"
,(emacs-modules-install-tarball-dir "apel-*.tar.gz" "apel"))
("ascii" "ascii table"
"http://www.emacswiki.org/cgi-bin/emacs/download/ascii.el"
"ascii.el"
,(emacs-modules-install-file "ascii.el"))
)
"Database of information about to fetch modules, unpack, and
install them.
The format is a list of lists as follows:
((NAME DESC URL FILE CODE) ...)
NAME is the name of the module.
DESC is a longer description.
URL is the url to fetch.
FILE is the temp file to use when downloading.
CODE is a function to run that will unpack, install, and
compile the module.")
(defun emacs-modules-fetch-url-to-file (url file)
"Fetch URL to FILE."
(let (cmd)
(setq cmd (concat
"wget"
" \"-O\" \"" (shell-quote-argument file) "\""
" \"" (shell-quote-argument url) "\""))
(shell-command cmd)))
(defun emacs-modules-install (module)
"Install MODULE using information from
`emacs-modules-database-fetch'.
\nThe URL part of the module information is fetched, then the CODE
portion is executed to handle installing it."
(interactive)
(let* ((info (assoc module emacs-modules-database-install))
(name (first info))
(desc (second info))
(url (third info))
(file (fourth info))
(code (fifth info)))
(unless (file-exists-p emacs-modules-tmp-dir)
(make-directory emacs-modules-tmp-dir))
(emacs-modules-fetch-url-to-file url file)
(eval code)))
(provide 'emacs-modules)