]> git.eshelyaron.com Git - emacs.git/commitdiff
Add new package.el commands for recompilation
authorLars Ingebrigtsen <larsi@gnus.org>
Thu, 16 Jun 2022 11:49:02 +0000 (13:49 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Thu, 16 Jun 2022 11:49:11 +0000 (13:49 +0200)
* doc/emacs/package.texi (Package Installation): Document them.

* lisp/emacs-lisp/package.el (package-recompile):
(package-recompile-all): New commands (bug#27253).

doc/emacs/package.texi
etc/NEWS
lisp/emacs-lisp/package.el

index eb4f5b0edab401d292c75dd571a55eff0d77cf0c..2eb12e096a90d57217d5c9191fd3612027c45a5b 100644 (file)
@@ -483,6 +483,16 @@ The default value is just @code{'(all)}.
 installed will be ignored.  The @samp{muse} package will be listed in
 the package menu with the @samp{held} status.
 
+@findex package-recompile
+@findex package-recompile-all
+  Emacs byte code is quite stable, but it's possible for byte code to
+become outdated, or for the compiled files to rely on macros that have
+changed in new versions of Emacs.  You can use the @kbd{M-x
+package-recompile} command to recompile a particular package, or
+@kbd{M-x package-recompile-all} to rebuild all the packages.  (The
+latter command might take quite a while to run if you have many
+installed packages.)
+
 @node Package Files
 @section Package Files and Directory Layout
 @cindex package directory
index 43b88e6cd4e2f8fa2954b164b589db1938a77a6a..e19b2f5ebafa4523c6631c1fe8d854511c5b529d 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -982,6 +982,11 @@ list-packages'.
 *** New command 'package-update-all'.
 This command allows updating all packages without any queries.
 
++++
+*** New commands 'package-recompile' and 'package-recompile-all'.
+These commands can be useful if the .elc files are out of date
+(invalid byte code and macros).
+
 +++
 *** New DWIM action on 'x' in "*Packages*" buffer.
 If no packages are marked, 'x' will install the package under point if
index 9aaeb052d0dec97a33393fa9757a4995982a7b6c..ef46bd3a278aee3677c938716bc12db01662b25a 100644 (file)
@@ -2422,6 +2422,34 @@ object."
    'force 'nosave)
   (package-install pkg 'dont-select))
 
+;;;###autoload
+(defun package-recompile (pkg)
+  "Byte-compile package PKG again.
+PKG should be either a symbol, the package name, or a `package-desc'
+object."
+  (interactive (list (intern (completing-read
+                              "Recompile package: "
+                              (mapcar #'symbol-name
+                                      (mapcar #'car package-alist))))))
+  (let ((pkg-desc (if (package-desc-p pkg)
+                      pkg
+                    (cadr (assq pkg package-alist)))))
+    ;; Delete the old .elc files to ensure that we don't inadvertently
+    ;; load them (in case they contain byte code/macros that are now
+    ;; invalid).
+    (dolist (elc (directory-files (package-desc-dir pkg-desc) t "\\.elc\\'"))
+      (delete-file elc))
+    (package--compile pkg-desc)))
+
+;;;###autoload
+(defun package-recompile-all ()
+  "Byte-compile all installed packages.
+This is meant to be used only in the case the byte-compiled files
+are invalid due to changed byte-code, macros or the like."
+  (interactive)
+  (pcase-dolist (`(_ ,pkg-desc) package-alist)
+    (package-recompile pkg-desc)))
+
 ;;;###autoload
 (defun package-autoremove ()
   "Remove packages that are no longer needed.