From a4aa32bdfff7aaf54efbacbb04b7f2b52fef92a7 Mon Sep 17 00:00:00 2001 From: Gregory Heytings Date: Thu, 9 Feb 2023 01:09:10 +0000 Subject: Fix 'save-restriction' for narrowing locks * src/editfns.c (narrowing_locks_save): (narrowing_locks_restore): Make them non-static. * src/lisp.h: Make them externally visible. * src/bytecode.c (exec_byte_code): Save and restore narrowing locks. * lisp/emacs-lisp/bytecomp.el (byte-compile-save-restriction): Increment unbinding count. * src/comp.c (helper_save_restriction): Save and restore narrowing locks. --- lisp/emacs-lisp/bytecomp.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 5df1205869c..c6cda6b588a 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -4900,7 +4900,7 @@ binding slots have been popped." (defun byte-compile-save-restriction (form) (byte-compile-out 'byte-save-restriction 0) (byte-compile-body-do-effect (cdr form)) - (byte-compile-out 'byte-unbind 1)) + (byte-compile-out 'byte-unbind 2)) (defun byte-compile-save-current-buffer (form) (byte-compile-out 'byte-save-current-buffer 0) -- cgit v1.2.3 From 6a32ba8b69c9d7a9c356611bb8033a0a83b4e8b8 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Tue, 14 Feb 2023 19:48:01 +0100 Subject: ; Fix the installation of dependencies for VC packages * lisp/emacs-lisp/package-vc.el (package-vc-install-dependencies): Work with package-desc objects instead of (PACKAGE-NAME VERSION) pairs. --- lisp/emacs-lisp/package-vc.el | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/package-vc.el b/lisp/emacs-lisp/package-vc.el index bf49f274bfd..4a987052949 100644 --- a/lisp/emacs-lisp/package-vc.el +++ b/lisp/emacs-lisp/package-vc.el @@ -435,24 +435,29 @@ version of that package." (push pkg missing)))))) (version-order (a b) "Predicate to sort packages in order." - (version-list-< (cadr b) (cadr a))) + (version-list-< + (package-desc-version b) + (package-desc-version a))) (duplicate-p (a b) "Are A and B the same package?" - (eq (car a) (car b))) + (equal a (car b))) (depends-on-p (target package) "Does PACKAGE depend on TARGET?" (or (eq target package) (let* ((pac package-archive-contents) (desc (cadr (assoc package pac)))) - (seq-some - (apply-partially #'depends-on-p target) - (package-desc-reqs desc))))) + (and desc (seq-some + (apply-partially #'depends-on-p target) + (package-desc-reqs desc)))))) (dependent-order (a b) - (or (not (depends-on-p (car b) (car a))) - (depends-on-p (car a) (car b))))) + (let ((desc-a (package-desc-name a)) + (desc-b (package-desc-name b))) + (or (not desc-a) (not desc-b) + (not (depends-on-p desc-b desc-a)) + (depends-on-p desc-a desc-b))))) (mapc #'search requirements) (cl-callf sort to-install #'version-order) - (cl-callf seq-uniq to-install #'duplicate-p) + (cl-callf seq-uniq to-install) (cl-callf sort to-install #'dependent-order)) (mapc #'package-install-from-archive to-install) missing)) -- cgit v1.2.3 From a3751b5d0c1a6aa4edaa16504012fb4a0e6302f9 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Tue, 14 Feb 2023 19:49:51 +0100 Subject: ; Raise an error if a VC package checkout is empty * lisp/emacs-lisp/package-vc.el (package-vc--unpack): Check if PKG-DIR is empty before proceeding with the installation. --- lisp/emacs-lisp/package-vc.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/package-vc.el b/lisp/emacs-lisp/package-vc.el index 4a987052949..bad59aa6c0f 100644 --- a/lisp/emacs-lisp/package-vc.el +++ b/lisp/emacs-lisp/package-vc.el @@ -611,7 +611,7 @@ checkout. This overrides the `:branch' attribute in PKG-SPEC." (pcase-let* (((map :lisp-dir) pkg-spec) (name (package-desc-name pkg-desc)) (dirname (package-desc-full-name pkg-desc)) - (pkg-dir (expand-file-name dirname package-user-dir))) + (pkg-dir (file-name-as-directory (expand-file-name dirname package-user-dir)))) (when (string-empty-p name) (user-error "Empty package name")) (setf (package-desc-dir pkg-desc) pkg-dir) @@ -620,6 +620,9 @@ checkout. This overrides the `:branch' attribute in PKG-SPEC." (package--delete-directory pkg-dir) (error "There already exists a checkout for %s" name))) (package-vc--clone pkg-desc pkg-spec pkg-dir rev) + (when (directory-empty-p pkg-dir) + (delete-directory pkg-dir) + (error "Empty checkout for %s" name)) ;; When nothing is specified about a `lisp-dir', then should ;; heuristically check if there is a sub-directory with lisp -- cgit v1.2.3 From 5206a551c166fc1908edff4fdf1695f7cef3600a Mon Sep 17 00:00:00 2001 From: Gregory Heytings Date: Tue, 14 Feb 2023 20:22:50 +0000 Subject: Improve backward compatibility of save-restriction * src/editfns.c (save_restriction_save_1): Renamed from 'save_restrictions_save'. Make it static. (save_restriction_restore_1): Renamed from 'save_restriction_restore'. Make it static. (save_restriction_restore): New function, combining 'save_restriction_save_1' and 'narrowing_locks_save'. (save_restriction_save): New function, combining 'save_restriction_restore_1' and 'narrowing_locks_restore'. (Fsave_restriction): Restore the previous code. (narrowing_locks_save, narrowing_locks_restore): Make them static. * src/lisp.h: Remove two functions that are not externally visible anymore. * src/comp.c (helper_save_restriction): Restore the previous code. * src/bytecode.c (exec_byte_code): Restore the previous code. * lisp/emacs-lisp/bytecomp.el (byte-compile-save-restriction): Decrement unbinding count. --- lisp/emacs-lisp/bytecomp.el | 2 +- src/bytecode.c | 2 -- src/comp.c | 2 -- src/editfns.c | 28 +++++++++++++++++++++------- src/lisp.h | 2 -- 5 files changed, 22 insertions(+), 14 deletions(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index c6cda6b588a..5df1205869c 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -4900,7 +4900,7 @@ binding slots have been popped." (defun byte-compile-save-restriction (form) (byte-compile-out 'byte-save-restriction 0) (byte-compile-body-do-effect (cdr form)) - (byte-compile-out 'byte-unbind 2)) + (byte-compile-out 'byte-unbind 1)) (defun byte-compile-save-current-buffer (form) (byte-compile-out 'byte-save-current-buffer 0) diff --git a/src/bytecode.c b/src/bytecode.c index 8e214560f30..124348e5b35 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -942,8 +942,6 @@ exec_byte_code (Lisp_Object fun, ptrdiff_t args_template, CASE (Bsave_restriction): record_unwind_protect (save_restriction_restore, save_restriction_save ()); - record_unwind_protect (narrowing_locks_restore, - narrowing_locks_save ()); NEXT; CASE (Bcatch): /* Obsolete since 25. */ diff --git a/src/comp.c b/src/comp.c index 0e2dfd3913b..10cf7962ba1 100644 --- a/src/comp.c +++ b/src/comp.c @@ -5063,8 +5063,6 @@ helper_save_restriction (void) { record_unwind_protect (save_restriction_restore, save_restriction_save ()); - record_unwind_protect (narrowing_locks_restore, - narrowing_locks_save ()); } static bool diff --git a/src/editfns.c b/src/editfns.c index ce133785e0b..f83c5c7259b 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -2794,7 +2794,7 @@ reset_outermost_narrowings (void) /* Helper functions to save and restore the narrowing locks of the current buffer in Fsave_restriction. */ -Lisp_Object +static Lisp_Object narrowing_locks_save (void) { Lisp_Object buf = Fcurrent_buffer (); @@ -2804,7 +2804,7 @@ narrowing_locks_save (void) return Fcons (buf, Fcopy_sequence (locks)); } -void +static void narrowing_locks_restore (Lisp_Object buf_and_saved_locks) { Lisp_Object buf = XCAR (buf_and_saved_locks); @@ -2975,8 +2975,8 @@ This is an internal function used by `without-restriction'. */) return Qnil; } -Lisp_Object -save_restriction_save (void) +static Lisp_Object +save_restriction_save_1 (void) { if (BEGV == BEG && ZV == Z) /* The common case that the buffer isn't narrowed. @@ -2999,8 +2999,8 @@ save_restriction_save (void) } } -void -save_restriction_restore (Lisp_Object data) +static void +save_restriction_restore_1 (Lisp_Object data) { struct buffer *cur = NULL; struct buffer *buf = (CONSP (data) @@ -3068,6 +3068,21 @@ save_restriction_restore (Lisp_Object data) set_buffer_internal (cur); } +Lisp_Object +save_restriction_save (void) +{ + Lisp_Object restr = save_restriction_save_1 (); + Lisp_Object locks = narrowing_locks_save (); + return Fcons (restr, locks); +} + +void +save_restriction_restore (Lisp_Object data) +{ + narrowing_locks_restore (XCDR (data)); + save_restriction_restore_1 (XCAR (data)); +} + DEFUN ("save-restriction", Fsave_restriction, Ssave_restriction, 0, UNEVALLED, 0, doc: /* Execute BODY, saving and restoring current buffer's restrictions. The buffer's restrictions make parts of the beginning and end invisible. @@ -3092,7 +3107,6 @@ usage: (save-restriction &rest BODY) */) specpdl_ref count = SPECPDL_INDEX (); record_unwind_protect (save_restriction_restore, save_restriction_save ()); - record_unwind_protect (narrowing_locks_restore, narrowing_locks_save ()); val = Fprogn (body); return unbind_to (count, val); } diff --git a/src/lisp.h b/src/lisp.h index 93197d38176..1276285e2f2 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4684,8 +4684,6 @@ extern void save_excursion_save (union specbinding *); extern void save_excursion_restore (Lisp_Object, Lisp_Object); extern Lisp_Object save_restriction_save (void); extern void save_restriction_restore (Lisp_Object); -extern Lisp_Object narrowing_locks_save (void); -extern void narrowing_locks_restore (Lisp_Object); extern Lisp_Object make_buffer_string (ptrdiff_t, ptrdiff_t, bool); extern Lisp_Object make_buffer_string_both (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, bool); -- cgit v1.2.3 From 1c9d81a2b4272200082fc185880856866c0588e1 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Thu, 16 Feb 2023 11:11:23 +0100 Subject: Attempt to recognise if a VC package has no Elisp files * lisp/emacs-lisp/package-vc.el (package-vc-non-code-file-names): Add new variable used to avoid false-positives. (package-vc--unpack): Recursively search for .el files excluding the ones listed in 'package-vc-non-code-file-names', offering to abort the installation if none are found. --- lisp/emacs-lisp/package-vc.el | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/package-vc.el b/lisp/emacs-lisp/package-vc.el index bad59aa6c0f..05df89d264e 100644 --- a/lisp/emacs-lisp/package-vc.el +++ b/lisp/emacs-lisp/package-vc.el @@ -602,6 +602,13 @@ attribute in PKG-SPEC." (vc-retrieve-tag dir release-rev) (message "No release revision was found, continuing..."))))) +(defvar package-vc-non-code-file-names + '(".dir-locals.el" ".dir-locals-2.el") + "List of file names that do not contain Emacs Lisp code. +This list is used by `package-vc--unpack' to better check if the +user is fetching code from a repository that does not contain any +Emacs Lisp files.") + (defun package-vc--unpack (pkg-desc pkg-spec &optional rev) "Install the package described by PKG-DESC. PKG-SPEC is a package specification, a property list describing @@ -623,6 +630,14 @@ checkout. This overrides the `:branch' attribute in PKG-SPEC." (when (directory-empty-p pkg-dir) (delete-directory pkg-dir) (error "Empty checkout for %s" name)) + (unless (seq-remove + (lambda (file) + (member (file-name-nondirectory file) package-vc-non-code-file-names)) + (directory-files-recursively pkg-dir "\\.el\\'" nil)) + (when (yes-or-no-p (format "No Emacs Lisp files found when fetching \"%s\", \ +abort installation?" name)) + (delete-directory pkg-dir t) + (user-error "Installation aborted"))) ;; When nothing is specified about a `lisp-dir', then should ;; heuristically check if there is a sub-directory with lisp -- cgit v1.2.3 From 40f4bc4e0aa1d215136259f6ea497147e4311aed Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Thu, 16 Feb 2023 11:38:51 +0100 Subject: ; Avoid installing VC package dependencies multiple times * lisp/emacs-lisp/package-vc.el (package-vc-install-dependencies): Check if two package names are eq, instead checking the structural equality of package-desc objects. --- lisp/emacs-lisp/package-vc.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/package-vc.el b/lisp/emacs-lisp/package-vc.el index 05df89d264e..b753adcb8a0 100644 --- a/lisp/emacs-lisp/package-vc.el +++ b/lisp/emacs-lisp/package-vc.el @@ -440,7 +440,7 @@ version of that package." (package-desc-version a))) (duplicate-p (a b) "Are A and B the same package?" - (equal a (car b))) + (eq (package-desc-name a) (package-desc-name b))) (depends-on-p (target package) "Does PACKAGE depend on TARGET?" (or (eq target package) @@ -457,7 +457,7 @@ version of that package." (depends-on-p desc-a desc-b))))) (mapc #'search requirements) (cl-callf sort to-install #'version-order) - (cl-callf seq-uniq to-install) + (cl-callf seq-uniq to-install #'duplicate-p) (cl-callf sort to-install #'dependent-order)) (mapc #'package-install-from-archive to-install) missing)) -- cgit v1.2.3