emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master feb654b460: Add new package.el commands for recompilation


From: Lars Ingebrigtsen
Subject: master feb654b460: Add new package.el commands for recompilation
Date: Thu, 16 Jun 2022 07:49:17 -0400 (EDT)

branch: master
commit feb654b4605cd84d1913d33a7d4c687bd4e71be7
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add new package.el commands for recompilation
    
    * 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     | 10 ++++++++++
 etc/NEWS                   |  5 +++++
 lisp/emacs-lisp/package.el | 28 ++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+)

diff --git a/doc/emacs/package.texi b/doc/emacs/package.texi
index eb4f5b0eda..2eb12e096a 100644
--- a/doc/emacs/package.texi
+++ b/doc/emacs/package.texi
@@ -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
diff --git a/etc/NEWS b/etc/NEWS
index 43b88e6cd4..e19b2f5eba 100644
--- 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
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 9aaeb052d0..ef46bd3a27 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]