-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathee-ell.el
executable file
·220 lines (182 loc) · 7 KB
/
ee-ell.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
;;; ee-ell.el --- browse the categorized Emacs Lisp List
;; Copyright (C) 2002, 2003, 2004, 2010 Juri Linkov <[email protected]>
;; Author: Juri Linkov <[email protected]>
;; Keywords: ee
;; This file is [not yet] part of GNU Emacs.
;; This package is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This package is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this package; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; See the file README and documentation for more information.
;;; Code:
(require 'ee)
;;; Constants
(defconst ee-ell-mode-name "ee-ell")
;;; Customizable Variables
(defgroup ee-ell nil
"Browse the categorized Emacs Lisp List."
:prefix "ee-ell-"
:group 'ee)
(defcustom ee-ell-url "http://www.damtp.cam.ac.uk/user/sje30/emacs/ell"
;; "http://anc.ed.ac.uk/~stephen/emacs/ell" - Moved Permanently
"URL of the Emacs Lisp List."
:type 'string
:group 'ee-ell)
(defcustom ee-ell-install-dir "~/.emacs.d/ell/"
"Path to install downloaded Emacs packages."
:type 'string
:group 'ee-ell)
;;; Global Variables
(defvar ee-ell-mark-install 'i
"Symbol used to mark records for installing.")
(defvar ee-ell-mark-uninstall 'u
"Symbol used to mark records for uninstalling.")
;;; Data Description and Default Data
(defvar ee-ell-data
'[(meta
(format-version . "0.0.1")
(database-version . "0.0.1")
(data-version . "0.0.1")
(data-file . "ell.ee")
(view-data-file . "view/ell.ee")
(collector . ee-ell-data-collect)
(fields name desc date site auth note ())
(key-fields name)
(mark-field mark))])
;;; Data Extraction
(defun ee-ell-data-collect (data)
(let* ((field-names (ee-data-field-names data))
(new-data
(ee-data-convert-lists-to-vectors
(with-temp-buffer
(let (name desc date site auth note res)
(message "Retrieving ell...")
(url-insert-file-contents ee-ell-url)
(message "Retrieving ell...done")
(goto-char (point-min))
(while (not (looking-at "^Authors:\\|### Local Variables"))
(cond
((looking-at "^;;; +\\([^ ]+\\) +--- +\\(.*\\)")
(setq name (match-string 1)
desc (match-string 2)))
((looking-at "^D: \\(.*\\)")
(setq date (match-string 1)))
((looking-at "^S: \\(.*\\)")
(setq site (cons (match-string 1) site)))
((looking-at "^A: \\(.*\\)")
(setq auth (match-string 1)))
((looking-at "^N: \\(.*\\)")
(setq note (match-string 1)))
((looking-at "^$")
(if name
(setq res
(cons
(mapcar
(lambda (field-name)
(cond
((eq field-name 'name) name)
((eq field-name 'desc) desc)
((eq field-name 'date) date)
((eq field-name 'site) (reverse site))
((eq field-name 'auth) auth)
((eq field-name 'note) note)))
field-names)
res)))
(setq name nil desc nil date nil
site nil auth nil note nil)))
(forward-line 1))
(nreverse res))))))
(aset new-data 0 (aref data 0))
new-data))
;;; Actions
(defun ee-ell-select (&optional arg)
(interactive)
(message "%s" (ee-view-record-get)))
(defun ee-ell-mark-install (&optional arg)
"Mark package on this line to be installed by \\<ee-mode-map>\\[ee-view-records-execute] command.
Prefix arg is how many records to install.
Negative arg means install backwards."
(interactive "p")
(ee-view-mark-lines ee-data-mark-field-name ee-ell-mark-install arg))
(defun ee-ell-mark-uninstall (&optional arg)
"Mark package on this line to be uninstalled by \\<ee-mode-map>\\[ee-view-records-execute] command.
Prefix arg is how many records to uninstall.
Negative arg means uninstall backwards."
(interactive "p")
(ee-view-mark-lines ee-data-mark-field-name ee-ell-mark-uninstall arg))
(defun ee-ell-execute (r marks)
(mapc (lambda (mark)
(cond
((eq mark ee-ell-mark-install)
(ee-ell-install r))
((eq mark ee-ell-mark-uninstall)
(ee-ell-uninstall r))))
marks))
(defun ee-ell-install (r)
(interactive)
(let* ((url (car (ee-field 'site r)))
(local-file (concat ee-ell-install-dir (file-name-nondirectory url))))
(when (string-match "\\.el" url)
(with-temp-buffer
(let* ((host (and (string-match "^http://\\([^/]+\\)" url)
(match-string-no-properties 1 url)))
(path (and (string-match "^http://[^/]+/\\(.*\\)" url)
(match-string-no-properties 1 url)))
(http (open-network-stream
"package-http-process" (current-buffer) host 80)))
(message "%s" (list host path))
(process-send-string
http (concat "GET /" path " HTTP/1.0\r\n\r\n"))
(message "Retrieving package...")
(while (eq (process-status http) 'open)
(sleep-for 1))
(message "Retrieving package...done")
(write-region (point-min) (point-max) local-file)))
(find-file local-file)
(load (concat ee-ell-install-dir local-file)))))
(defun ee-ell-uninstall (r)
(interactive)
;; TODO
)
;;; Key Bindings
(defvar ee-ell-keymap nil
"Local keymap for ee-ell mode.")
(defun ee-ell-keymap-make-default ()
"Defines default key bindings for `ee-ell-keymap'.
It inherits key bindings from `ee-mode-map'."
(or ee-mode-map
(ee-mode-map-make-default))
(let ((map (copy-keymap ee-mode-map)))
(define-key map "\C-o" 'ee-ell-select)
(define-key map "i" 'ee-ell-mark-install)
(define-key map "u" 'ee-ell-mark-uninstall)
(setq ee-ell-keymap map)))
(or ee-ell-keymap
(ee-ell-keymap-make-default))
;;; Top-Level Functions
;;;###autoload
(defun ee-ell (&optional arg)
"Browse the categorized Emacs Lisp List."
(interactive "P")
(ee-view-buffer-create
(format "*%s*" ee-ell-mode-name)
ee-ell-mode-name
ee-ell-keymap
ee-ell-data
nil
nil
nil
"ell.ee"
t ;; auto-save
))
(provide 'ee-ell)
;;; ee-ell.el ends here