aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2014-01-23 10:01:41 -0500
committerStefan Monnier2014-01-23 10:01:41 -0500
commitd4f0427be7fc035f0c3c0d63bb4707277fdc347e (patch)
tree7473fc439f64706ef30d6998ce8e0dddac151d3e
parent565935c89fb5332d8742b9d0f9f6431c359a2e15 (diff)
downloademacs-d4f0427be7fc035f0c3c0d63bb4707277fdc347e.tar.gz
emacs-d4f0427be7fc035f0c3c0d63bb4707277fdc347e.zip
* lisp/emacs-lisp/cl-macs.el: Improve type->predicate mapping.
(cl--macroexp-fboundp): New function. (cl--make-type-test): Use it. Fixes: debbugs:16520
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/emacs-lisp/cl-macs.el19
2 files changed, 23 insertions, 2 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 962fbcf89d9..738fe6d37be 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12014-01-23 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * emacs-lisp/cl-macs.el: Improve type->predicate mapping (bug#16520).
4 (cl--macroexp-fboundp): New function.
5 (cl--make-type-test): Use it.
6
12014-01-23 Glenn Morris <rgm@gnu.org> 72014-01-23 Glenn Morris <rgm@gnu.org>
2 8
3 * emacs-lisp/lisp-mode.el (eval-print-last-sexp, eval-last-sexp): 9 * emacs-lisp/lisp-mode.el (eval-print-last-sexp, eval-last-sexp):
diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el
index bfc4f69a56b..45448ecf5dc 100644
--- a/lisp/emacs-lisp/cl-macs.el
+++ b/lisp/emacs-lisp/cl-macs.el
@@ -2588,6 +2588,17 @@ The type name can then be used in `cl-typecase', `cl-check-type', etc."
2588 (put ',name 'cl-deftype-handler 2588 (put ',name 'cl-deftype-handler
2589 (cl-function (lambda (&cl-defs '('*) ,@arglist) ,@body))))) 2589 (cl-function (lambda (&cl-defs '('*) ,@arglist) ,@body)))))
2590 2590
2591(defvar byte-compile-function-environment)
2592(defvar byte-compile-macro-environment)
2593
2594(defun cl--macroexp-fboundp (sym)
2595 "Return non-nil if SYM will be bound when we run the code.
2596Of course, we really can't know that for sure, so it's just a heuristic."
2597 (or (fboundp sym)
2598 (and (cl--compiling-file)
2599 (or (cdr (assq sym byte-compile-function-environment))
2600 (cdr (assq sym byte-compile-macro-environment))))))
2601
2591(defun cl--make-type-test (val type) 2602(defun cl--make-type-test (val type)
2592 (if (symbolp type) 2603 (if (symbolp type)
2593 (cond ((get type 'cl-deftype-handler) 2604 (cond ((get type 'cl-deftype-handler)
@@ -2603,8 +2614,12 @@ The type name can then be used in `cl-typecase', `cl-check-type', etc."
2603 (t 2614 (t
2604 (let* ((name (symbol-name type)) 2615 (let* ((name (symbol-name type))
2605 (namep (intern (concat name "p")))) 2616 (namep (intern (concat name "p"))))
2606 (if (fboundp namep) (list namep val) 2617 (cond
2607 (list (intern (concat name "-p")) val))))) 2618 ((cl--macroexp-fboundp namep) (list namep val))
2619 ((cl--macroexp-fboundp
2620 (setq namep (intern (concat name "-p"))))
2621 (list namep val))
2622 (t (list type val))))))
2608 (cond ((get (car type) 'cl-deftype-handler) 2623 (cond ((get (car type) 'cl-deftype-handler)
2609 (cl--make-type-test val (apply (get (car type) 'cl-deftype-handler) 2624 (cl--make-type-test val (apply (get (car type) 'cl-deftype-handler)
2610 (cdr type)))) 2625 (cdr type))))