emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[ELPA-diffs] [elpa] 01/01: * cl-lib.el: Resolve conflicts with old inter


From: Stefan Monnier
Subject: [ELPA-diffs] [elpa] 01/01: * cl-lib.el: Resolve conflicts with old internal definitions (bug#16353). (dolist fun): Don't skip definitions silently. (define-setf-expander): Remove, not in cl-lib. (cl-position, cl-delete-duplicates): Add advice to distinguish the use case. (cl-member): Override old definition.
Date: Sat, 25 Jan 2014 05:18:43 +0000

monnier pushed a commit to branch master
in repository elpa.

commit 324e000025e09600bb57e1b59e15461911443b5f
Author: Stefan Monnier <address@hidden>
Date:   Sat Jan 25 00:18:33 2014 -0500

    * cl-lib.el: Resolve conflicts with old internal definitions (bug#16353).
    (dolist fun): Don't skip definitions silently.
    (define-setf-expander): Remove, not in cl-lib.
    (cl-position, cl-delete-duplicates): Add advice to distinguish the use case.
    (cl-member): Override old definition.
---
 packages/cl-lib/cl-lib.el |   55 ++++++++++++++++++++++++++++++++++++++------
 1 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/packages/cl-lib/cl-lib.el b/packages/cl-lib/cl-lib.el
index 0720afe..1ea22e0 100644
--- a/packages/cl-lib/cl-lib.el
+++ b/packages/cl-lib/cl-lib.el
@@ -1,10 +1,10 @@
 ;;; cl-lib.el --- Properly prefixed CL functions and macros  -*- coding: utf-8 
-*-
 
-;; Copyright (C) 2012, 2013  Free Software Foundation, Inc.
+;; Copyright (C) 2012, 2013, 2014  Free Software Foundation, Inc.
 
 ;; Author: Stefan Monnier <address@hidden>
 ;; vcomment: Emacs-24.3's version is 1.0 so this has to stay below.
-;; Version: 0.3
+;; Version: 0.4
 
 ;; This program is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
@@ -93,6 +93,17 @@
   (let ((new (intern (format "cl-%s" var))))
     (unless (boundp new) (defvaralias new var))))
 
+;; The following cl-lib functions were already defined in the old cl.el,
+;; with a different meaning:
+;; - cl-position and cl-delete-duplicates
+;;   the two meanings are clearly different, but we can distinguish which was
+;;   meant by looking at the arguments.
+;; - cl-member
+;;   the old meaning hasn't been used for a long time and is a subset of the
+;;   new, so we can simply override it.
+;; - cl-adjoin
+;;   the old meaning is actually the same as the new except for optimizations.
+
 (dolist (fun '(
                (get* . cl-get)
                (random* . cl-random)
@@ -104,7 +115,7 @@
                (floor* . cl-floor)
                (rassoc* . cl-rassoc)
                (assoc* . cl-assoc)
-               (member* . cl-member)
+               ;; (member* . cl-member) ;Handle specially below.
                (delete* . cl-delete)
                (remove* . cl-remove)
                (defsubst* . cl-defsubst)
@@ -171,7 +182,7 @@
                count
                position-if-not
                position-if
-               position
+               ;; position ;Handle specially via defadvice below.
                find-if-not
                find-if
                find
@@ -181,7 +192,7 @@
                substitute-if-not
                substitute-if
                substitute
-               delete-duplicates
+               ;; delete-duplicates ;Handle specially via defadvice below.
                remove-duplicates
                delete-if-not
                delete-if
@@ -205,7 +216,6 @@
                shiftf
                remf
                psetf
-               (define-setf-method . define-setf-expander)
                declare
                the
                locally
@@ -237,7 +247,7 @@
                pairlis
                acons
                subst
-               adjoin
+               ;; adjoin ;It's already defined.
                copy-list
                ldiff
                list*
@@ -301,7 +311,36 @@
                ))
   (let ((new (if (consp fun) (prog1 (cdr fun) (setq fun (car fun)))
                (intern (format "cl-%s" fun)))))
-    (unless (fboundp new) (defalias new fun))))
+    (if (fboundp new)
+        (unless (or (eq (symbol-function new) fun)
+                    (eq new (and (symbolp fun) (fboundp fun)
+                                 (symbol-function fun))))
+          (message "%S already defined, not rebinding" new))
+      (defalias new fun))))
+
+(autoload 'cl-position "cl-seq")
+(defadvice cl-position (around cl-lib (cl-item cl-seq &rest cl-keys) activate)
+  (let ((argk (ad-get-args 2)))
+    (if (or (null argk) (keywordp (car argk)))
+        ;; This is a call to cl-lib's `cl-position'.
+        (setq ad-return-value
+              (apply #'position (ad-get-arg 0) (ad-get-arg 1) argk))
+      ;; Must be a call to cl's old `cl-position'.
+      ad-do-it)))
+
+(autoload 'cl-delete-duplicates "cl-seq")
+(defadvice cl-delete-duplicates (around cl-lib (cl-seq &rest cl-keys) activate)
+  (let ((argk (ad-get-args 1)))
+    (if (or (null argk) (keywordp (car argk)))
+        ;; This is a call to cl-lib's `cl-delete-duplicates'.
+        (setq ad-return-value
+              (apply #'delete-duplicates (ad-get-arg 0) argk))
+      ;; Must be a call to cl's old `cl-delete-duplicates'.
+      ad-do-it)))
+
+(when (or (not (fboundp 'cl-member))
+          (eq (symbol-function 'cl-member) #'memq))
+  (defalias 'cl-member #'member*))
 
 ;; `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



reply via email to

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