summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/cl-generic.el
diff options
context:
space:
mode:
authorMichael R. Mauger <michael@mauger.com>2017-08-06 20:58:08 -0400
committerMichael R. Mauger <michael@mauger.com>2017-08-06 20:58:08 -0400
commit6e2c0929bac8d3896d0472222cd3e6b77cb24c35 (patch)
tree62668da72d88140958ed22273a6ed6557bc61a4a /lisp/emacs-lisp/cl-generic.el
parentdf1a71272e5cdd10b511e2ffd702ca50ddd8a773 (diff)
parentc2f1830d69f5a5e20dac6fcbf3af4d51afba92bd (diff)
downloademacs-6e2c0929bac8d3896d0472222cd3e6b77cb24c35.tar.gz
emacs-6e2c0929bac8d3896d0472222cd3e6b77cb24c35.tar.bz2
emacs-6e2c0929bac8d3896d0472222cd3e6b77cb24c35.zip
Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs
Diffstat (limited to 'lisp/emacs-lisp/cl-generic.el')
-rw-r--r--lisp/emacs-lisp/cl-generic.el55
1 files changed, 37 insertions, 18 deletions
diff --git a/lisp/emacs-lisp/cl-generic.el b/lisp/emacs-lisp/cl-generic.el
index 6a4ee47ac24..1a3f8e1f4d5 100644
--- a/lisp/emacs-lisp/cl-generic.el
+++ b/lisp/emacs-lisp/cl-generic.el
@@ -166,6 +166,10 @@ SPECIALIZERS-FUNCTION takes as first argument a tag value TAG
(defmacro cl--generic (name)
`(get ,name 'cl--generic))
+(defun cl-generic-p (f)
+ "Return non-nil if F is a generic function."
+ (and (symbolp f) (cl--generic f)))
+
(defun cl-generic-ensure-function (name &optional noerror)
(let (generic
(origname name))
@@ -409,7 +413,7 @@ The set of acceptable TYPEs (also called \"specializers\") is defined
\(and can be extended) by the various methods of `cl-generic-generalizers'.
\(fn NAME [QUALIFIER] ARGS &rest [DOCSTRING] BODY)"
- (declare (doc-string 3) (indent 2)
+ (declare (doc-string 3) (indent defun)
(debug
(&define ; this means we are defining something
[&or name ("setf" name :name setf)]
@@ -500,25 +504,26 @@ The set of acceptable TYPEs (also called \"specializers\") is defined
(cons method mt)
;; Keep the ordering; important for methods with :extra qualifiers.
(mapcar (lambda (x) (if (eq x (car me)) method x)) mt)))
- (cl-pushnew `(cl-defmethod . ,(cl--generic-load-hist-format
- (cl--generic-name generic)
- qualifiers specializers))
- current-load-list :test #'equal)
- ;; FIXME: Try to avoid re-constructing a new function if the old one
- ;; is still valid (e.g. still empty method cache)?
- (let ((gfun (cl--generic-make-function generic))
- ;; Prevent `defalias' from recording this as the definition site of
- ;; the generic function.
- current-load-list)
- ;; For aliases, cl--generic-name gives us the actual name.
- (let ((purify-flag
- ;; BEWARE! Don't purify this function definition, since that leads
- ;; to memory corruption if the hash-tables it holds are modified
- ;; (the GC doesn't trace those pointers).
- nil))
+ (let ((sym (cl--generic-name generic))) ; Actual name (for aliases).
+ (unless (symbol-function sym)
+ (defalias sym 'dummy)) ;Record definition into load-history.
+ (cl-pushnew `(cl-defmethod . ,(cl--generic-load-hist-format
+ (cl--generic-name generic)
+ qualifiers specializers))
+ current-load-list :test #'equal)
+ ;; FIXME: Try to avoid re-constructing a new function if the old one
+ ;; is still valid (e.g. still empty method cache)?
+ (let ((gfun (cl--generic-make-function generic))
+ ;; Prevent `defalias' from recording this as the definition site of
+ ;; the generic function.
+ current-load-list
+ ;; BEWARE! Don't purify this function definition, since that leads
+ ;; to memory corruption if the hash-tables it holds are modified
+ ;; (the GC doesn't trace those pointers).
+ (purify-flag nil))
;; But do use `defalias', so that it interacts properly with nadvice,
;; e.g. for tracing/debug-on-entry.
- (defalias (cl--generic-name generic) gfun)))))
+ (defalias sym gfun)))))
(defmacro cl--generic-with-memoization (place &rest code)
(declare (indent 1) (debug t))
@@ -1022,6 +1027,20 @@ The value returned is a list of elements of the form
(push (cl--generic-method-info method) docs))))
docs))
+(defun cl--generic-method-files (method)
+ "Return a list of files where METHOD is defined by `cl-defmethod'.
+The list will have entries of the form (FILE . (METHOD ...))
+where (METHOD ...) contains the qualifiers and specializers of
+the method and is a suitable argument for
+`find-function-search-for-symbol'. Filenames are absolute."
+ (let (result)
+ (pcase-dolist (`(,file . ,defs) load-history)
+ (dolist (def defs)
+ (when (and (eq (car-safe def) 'cl-defmethod)
+ (eq (cadr def) method))
+ (push (cons file (cdr def)) result))))
+ result))
+
;;; Support for (head <val>) specializers.
;; For both the `eql' and the `head' specializers, the dispatch