[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/cl-lib cad1a4c 03/10: * cl-lib.el: Try and patch things
From: |
Stefan Monnier |
Subject: |
[elpa] externals/cl-lib cad1a4c 03/10: * cl-lib.el: Try and patch things up in case we're hiding the real cl-lib. |
Date: |
Tue, 1 Dec 2020 15:28:43 -0500 (EST) |
branch: externals/cl-lib
commit cad1a4ca02e6eb7cde3937feff5bdeb1c4ce09bd
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
* cl-lib.el: Try and patch things up in case we're hiding the real cl-lib.
---
cl-lib.el | 42 +++++++++++++++++++++++++++++++++++-------
1 file changed, 35 insertions(+), 7 deletions(-)
diff --git a/cl-lib.el b/cl-lib.el
index 015226a..e4719fc 100644
--- a/cl-lib.el
+++ b/cl-lib.el
@@ -28,13 +28,39 @@
;; Make sure this is installed *late* in your `load-path`, i.e. after Emacs's
;; built-in .../lisp/emacs-lisp directory, so that if/when you upgrade to
;; Emacs-24.3, the built-in version of the file will take precedence, otherwise
-;; you'll quickly get recursive-load errors.
+;; you could get into trouble (although we try to hack our way around the
+;; problem in case it happens).
;; This code is largely copied from Emacs-24.3's cl.el, with the alias bindings
;; simply reversed.
;;; Code:
+(when (functionp 'macroexp--compiler-macro)
+ ;; `macroexp--compiler-macro' was introduced as part of the big CL
+ ;; reorganization which moved/reimplemented some of CL into core (mostly the
+ ;; setf and compiler-macro support), so its presence indicates we're running
+ ;; in an Emacs that comes with the new cl-lib.el, where this file should
+ ;; never be loaded!
+ (message "Real cl-lib shadowed by compatibility cl-lib? (%s)" load-file-name)
+ (when load-file-name
+ ;; (message "Let's try to patch things up")
+ (let ((loaddir (file-name-directory load-file-name))
+ load-path-dir)
+ ;; Find the problematic directory from load-path.
+ (dolist (dir load-path)
+ (if (equal loaddir (expand-file-name (file-name-as-directory dir)))
+ (setq load-path-dir dir)))
+ (when load-path-dir
+ ;; (message "Let's move the offending dir to the end")
+ (setq load-path (append (remove load-path-dir load-path)
+ (list load-path-dir)))
+ ;; Here we could manually load cl-lib and then return immediately.
+ ;; But Emacs currently doesn't provide any way for a file to "return
+ ;; immediately", so instead we make sure the rest of the file does not
+ ;; throw away any pre-existing definition.
+ ))))
+
(require 'cl)
;; Some of Emacs-24.3's cl.el definition are not just aliases, because either
@@ -64,7 +90,8 @@
most-positive-float
;; custom-print-functions
))
- (defvaralias (intern (format "cl-%s" var)) var))
+ (let ((new (intern (format "cl-%s" var))))
+ (unless (boundp new) (defvaralias new var))))
(dolist (fun '(
(get* . cl-get)
@@ -274,16 +301,17 @@
))
(let ((new (if (consp fun) (prog1 (cdr fun) (setq fun (car fun)))
(intern (format "cl-%s" fun)))))
- (defalias new fun)))
+ (unless (fboundp new) (defalias new fun))))
;; `cl-labels' is not 100% compatible with `labels' when using dynamic scoping
;; (mostly because it does not turn lambdas that refer to those functions into
;; closures). OTOH it is compatible when using lexical scoping.
-(defmacro cl-labels (&rest args)
- (if (and (boundp 'lexical-binding) lexical-binding)
- `(labels ,@args)
- (error "`cl-labels' with dynamic scoping is not implemented")))
+(unless (fboundp 'cl-labels)
+ (defmacro cl-labels (&rest args)
+ (if (and (boundp 'lexical-binding) lexical-binding)
+ `(labels ,@args)
+ (error "`cl-labels' with dynamic scoping is not implemented"))))
(provide 'cl-lib)
;;; cl-lib.el ends here
- [elpa] branch externals/cl-lib created (now 2cd9e37), Stefan Monnier, 2020/12/01
- [elpa] externals/cl-lib 455a801 01/10: * packages/cl-lib: New package., Stefan Monnier, 2020/12/01
- [elpa] externals/cl-lib 6f4af5f 02/10: Add cl-letf and cl-labels., Stefan Monnier, 2020/12/01
- [elpa] externals/cl-lib cad1a4c 03/10: * cl-lib.el: Try and patch things up in case we're hiding the real cl-lib.,
Stefan Monnier <=
- [elpa] externals/cl-lib cf5c963 05/10: * cl-lib.el: Resolve conflicts with old internal definitions (bug#16353)., Stefan Monnier, 2020/12/01
- [elpa] externals/cl-lib 2cd9e37 10/10: * .gitignore: New file, Stefan Monnier, 2020/12/01
- [elpa] externals/cl-lib 9062b27 08/10: * cl-lib/cl-lib.el: Don't use `emacs` package for Emacs<24, Stefan Monnier, 2020/12/01
- [elpa] externals/cl-lib fb8701d 04/10: * cl-lib.el (cl-labels): Demote error to message and improve it., Stefan Monnier, 2020/12/01
- [elpa] externals/cl-lib fbed770 06/10: Fixes: debbugs:16671, Stefan Monnier, 2020/12/01
- [elpa] externals/cl-lib 67a7371 07/10: * cl-lib/cl-lib.el: Make it work for Emacs-21. Bump version to 0.6, Stefan Monnier, 2020/12/01
- [elpa] externals/cl-lib 59e400f 09/10: * cl-lib.el: Clarify that it's a forward compatibility version, Stefan Monnier, 2020/12/01