el-get-emacswiki.el 4.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
;;; el-get --- Manage the external elisp bits and pieces you depend upon
;;
;; Copyright (C) 2010-2011 Dimitri Fontaine
;;
;; Author: Dimitri Fontaine <dim@tapoueh.org>
;; URL: http://www.emacswiki.org/emacs/el-get
;; GIT: https://github.com/dimitri/el-get
;; Licence: WTFPL, grab your copy here: http://sam.zoy.org/wtfpl/
;;
;; This file is NOT part of GNU Emacs.
;;
;; Install
;;     Please see the README.asciidoc file from the same distribution

(require 'el-get-http)

(defcustom el-get-emacswiki-base-url
18
  "http://www.emacswiki.org/emacs/download/"
19 20 21 22
  "The base URL where to fetch :emacswiki packages"
  :group 'el-get
  :type 'string)

23 24 25 26 27 28
(defcustom el-get-emacswiki-elisp-file-list-url
  "http://www.emacswiki.org/cgi-bin/wiki?action=elisp"
  "The emacswiki URL where to fetch a list of elisp files with descriptions.

We get back list of filename space first line, and in general
that matches the following pattern:
29

30
filename.el ;;; filename.el --- description"
31 32 33 34 35
  :group 'el-get
  :type 'string)

(defun el-get-emacswiki-install (package url post-install-fun)
  "Download a single-file PACKAGE over HTTP from emacswiki."
36
  (let ((url (or url (format "%s%s.el" el-get-emacswiki-base-url package))))
37 38
    (el-get-http-install package url post-install-fun)))

39 40 41
(el-get-register-derived-method :emacswiki :http
  :install #'el-get-emacswiki-install
  :update #'el-get-emacswiki-install)
42 43 44 45

;;;
;;; Functions to maintain a local recipe list from EmacsWiki
;;;
46
(defun el-get-emacswiki-retrieve-package-list ()
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
  "return a list of (URL PACKAGE DESCRIPTION) from emacswiki"
  (loop for line in
	(split-string
	 (with-current-buffer
	     (url-retrieve-synchronously el-get-emacswiki-elisp-file-list-url)
	   ;; prune HTTP headers
	   (goto-char (point-min))
	   (re-search-forward "^$" nil 'move)
	   (forward-char)
	   (delete-region (point-min) (point))
	   (buffer-string))
	 "\n")
	for filename = (substring line 0 (string-match " " line))
	for description = (if (string-match "--?-? " line)
			      (substring line (match-end 0)) "")
	for url = (format "%s%s" el-get-emacswiki-base-url filename)
	collect (list url filename description)))
64 65 66 67 68 69

(defun el-get-emacswiki-build-local-recipes (&optional target-dir)
  "retrieve the index of elisp pages at emacswiki and turn them
into a local recipe file set"
  (let ((target-dir (or target-dir
			(car command-line-args-left)
70 71
			el-get-recipe-path-emacswiki))
	(coding-system-for-write 'utf-8))
72 73
    (unless (file-directory-p target-dir) (make-directory target-dir))
    (loop
74
     for (url package description) in (el-get-emacswiki-retrieve-package-list)
75 76 77 78
     for recipe = (replace-regexp-in-string "el$" "rcp" package)
     for rfile  = (expand-file-name recipe target-dir)
     unless (file-exists-p rfile)
     do (with-temp-file (expand-file-name rfile target-dir)
79 80 81 82 83 84 85
	  (message "%s: %s" package description)
	  (insert
	   (format
	    "(:name %s\n:type emacswiki\n:description \"%s\"\n:website \"%s\")"
	    (file-name-sans-extension package) description url))
	  ;; (encode-coding-region (point-min) (point-max) 'utf-8)
	  (indent-region (point-min) (point-max))))))
86

87
;;;###autoload
88 89 90 91 92 93 94 95 96 97 98 99
(defun el-get-emacswiki-refresh (&optional target-dir)
  "run Emacs -Q in an asynchronous subprocess to get the package
list from emacswiki and build a local recipe directory out of
that"
  (interactive
   (list (let ((dummy (unless (file-directory-p el-get-recipe-path-emacswiki)
			(make-directory el-get-recipe-path-emacswiki))))
	   (read-directory-name "emacswiki recipes go to: "
				el-get-recipe-path-emacswiki))))
  (let* ((name "*el-get-emacswiki*")
	 (dummy (when (get-buffer name) (kill-buffer name)))
	 (args
100 101 102 103 104 105 106
	  (format
	   "-Q -batch -L %s -L %s -l %s -f el-get-emacswiki-build-local-recipes %s"
	   (el-get-package-directory 'el-get)
	   (expand-file-name "methods" (el-get-package-directory 'el-get))
	   (file-name-sans-extension
	    (symbol-file 'el-get-emacswiki-build-local-recipes 'defun))
	   target-dir))
107 108 109 110 111 112 113 114 115 116 117
	 (process
	  (apply 'start-process name name el-get-emacs (split-string args))))
    (message "%s %s" el-get-emacs args)
    (set-process-sentinel
     process
     '(lambda (proc event)
	(when (eq (process-status proc) 'exit)
	  (el-get-notify "el-get: EmacsWiki"
			 "EmacsWiki local recipe list refreshed"))))))

(provide 'el-get-emacswiki)