Skip to content

Commit

Permalink
Squash merge branch reload from DarwinAwardWinner, per dimitri#434.
Browse files Browse the repository at this point in the history
That cleans up the code and allow not to depend on the :reload property, and
cater with some edge cases like features currently loaded but no longer
present in the updated package.

Conflicts:
	el-get.el
  • Loading branch information
dimitri committed Oct 11, 2011
1 parent 76e8f0a commit 3c85a01
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 35 deletions.
41 changes: 23 additions & 18 deletions el-get-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,29 @@ directory or a symlink in el-get-dir."
(or (file-directory-p pdir)
(file-symlink-p pdir))))

(defun el-get-reload-alist (package &rest prefixes)
"Returns an alist of (feature . filename) for el-get packages
which uses given prefixes. For example, el-get features all begin
with 'el-get and gnus features are more spread, thus you would do
el-get-reload-alist 'gnus 'mail- 'mm- 'mess 'mml 'nn 'pgg 'sasl 'sieve 'spam
That's not the whole story for gnus but hopefully gives an idea
on how to call that function."
(loop with pdir = (el-get-package-directory package)
for (f . l) in load-history
for lib = (cdr (assoc 'provide l))
when (loop for p in (or prefixes package)
when (and (string-match (format "^%s" pdir) f)
(string-match (format "^%s" (symbol-name p))
(symbol-name lib)))
return t)
collect (cons lib f)))

;;
;; el-get-reload API functions
;;
(defun el-get-package-files (package)
"Return a list of files loaded from PACKAGE's directory."
(loop with pdir = (file-truename (el-get-package-directory package))
with regexp = (format "^%s" (regexp-quote (file-name-as-directory (expand-file-name pdir))))
for (f . nil) in load-history
when (and (stringp f) (string-match-p regexp (file-truename f)))
collect (if (string-match-p "\\.elc?$" f)
(file-name-sans-extension f)
f)))

(defun el-get-package-features (package)
"Return a list of features provided by files in PACKAGE."
(loop with pdir = (file-truename (el-get-package-directory package))
with regexp = (format "^%s" (regexp-quote (file-name-as-directory (expand-file-name pdir))))
for (f . l) in load-history
when (and (stringp f) (string-match-p regexp (file-truename f)))
nconc (loop for i in l
when (and (consp i) (eq (car i) 'provide))
collect (cdr i))))


;;
Expand Down
8 changes: 0 additions & 8 deletions el-get-custom.el
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,6 @@ definition provided by `el-get' recipes locally.
List of files to load, or a single file to load after having
installed the source but before `require'ing its features.
:reload
List of the features prefixes that the package requires, that
defaults to the package symbol itself (e.g. for the package
el-get, the :reload property defaults to 'el-get). This will
be used by both M-x el-get-reload and M-x el-get-update in
order to reload your package's files.
:features
List of features el-get will `require' for you.
Expand Down
42 changes: 41 additions & 1 deletion el-get.el
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
;; - deprecate package.el from the old days, only include the Emacs24 one
;; - implement :builtin property (useful for dealing with package.el)
;; - fix recipes :build commands, must be either lists of strings or expr
;; - add support for el-get-reload and do that at update time
;;
;; 3.1 - 2011-09-15 - Get a fix
;;
Expand Down Expand Up @@ -515,6 +516,45 @@ PACKAGE may be either a string or the corresponding symbol."
(funcall install package url 'el-get-post-install)
(message "el-get install %s" package))))

(defun el-get-reload (package)
"Reload PACKAGE."
(interactive
(list (el-get-read-package-with-status "Update" "installed")))
(el-get-verbose-message "el-get-reload: %s" package)
(let* ((all-features features)
(package-features (el-get-package-features package))
(package-files (el-get-package-files package))
(other-features
(remove-if (lambda (x) (memq x package-features)) all-features)))
(unwind-protect
(progn
;; We cannot let-bind `features' here, becauses the changes
;; made by `el-get-init' must persist.
(setq features other-features)
;; Reload all loaded files in package dir if they still
;; exist.
(loop for file in package-files
do (load file 'noerror))
;; Redo package initialization
(el-get-init package)
;; Reload all features provided by the package. This ensures
;; that autoloaded packages (which normally don't load
;; anything until one of their entry points is called) are
;; forced to reload immediately if they were already loaded.
(loop for f in package-features
do (require f nil 'noerror)))
;; We have to add all the removed features back in no matter
;; what, or else we would be lying about what has been loaded.
;; This covers the corner case where an updated package no
;; longer provides a certain feature. Technically that feature
;; is still provided, so not adding it back would be wrong.
(let ((missing-features
(remove-if (lambda (x) (memq x features)) package-features)))
(when missing-features
(warn "Adding %S back onto features, because the reloaded package did not provide them."
missing-features)
(setq features (append missing-features features)))))))


(defun el-get-post-update (package)
"Post update PACKAGE. This will get run by a sentinel."
Expand All @@ -526,7 +566,7 @@ PACKAGE may be either a string or the corresponding symbol."
;; fix trailing failed installs
(when (string= (el-get-read-package-status package) "required")
(el-get-save-package-status package "installed"))
(el-get-reload package)
(el-get-reload package)
(run-hook-with-args 'el-get-post-update-hooks package)))))

(defun el-get-update (package)
Expand Down
8 changes: 0 additions & 8 deletions recipes/nognus.rcp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,4 @@
:info "texi"
:load-path ("lisp")
:autoloads nil
:reload (gnus assistant binhex canlock color compface deuglify dgnus
dig dns ecomplete flow-fill format-spec gmm-
gravatar gssapi hashcash hex-util hmac- html2text
ietf-drums imap legacy-gnus lpath md4 netrc ntlm
parse-time password-cache plstore pop3 proto-stream qp
registry rfc rtree score-mode sha1 shr smiley smime
mail- mm- mess mml nn pgg sasl sieve spam starttls
time-date tls utf7 uudecode yenc)
:features gnus-load)

0 comments on commit 3c85a01

Please sign in to comment.