aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2016-08-02 13:01:26 -0400
committerStefan Monnier2016-08-02 13:01:26 -0400
commitd0838f201a87982ebee5d85b0a369e03f2598ab5 (patch)
tree38f78ec98485cd480ebb674578e66d3087f05a75
parent54a3c0c98f844ef6b21b011884132d5fe5ae5e1f (diff)
downloademacs-d0838f201a87982ebee5d85b0a369e03f2598ab5.tar.gz
emacs-d0838f201a87982ebee5d85b0a369e03f2598ab5.zip
* cl-generic.el: Fix problems introduced by new load-history format
* lisp/emacs-lisp/cl-generic.el (cl--generic-load-hist-format): New function. (cl-generic-define-method, cl--generic-describe): Use it. (cl--generic-search-method): Adjust for new format. * lisp/progmodes/elisp-mode.el (elisp--xref-find-definitions): * test/lisp/progmodes/elisp-mode-tests.el: Use cl--generic-load-hist-format rather than hard-coding cl-generic's internal format.
-rw-r--r--lisp/emacs-lisp/cl-generic.el26
-rw-r--r--lisp/progmodes/elisp-mode.el5
-rw-r--r--test/lisp/progmodes/elisp-mode-tests.el47
3 files changed, 59 insertions, 19 deletions
diff --git a/lisp/emacs-lisp/cl-generic.el b/lisp/emacs-lisp/cl-generic.el
index b7c8395f715..d5612f4eb13 100644
--- a/lisp/emacs-lisp/cl-generic.el
+++ b/lisp/emacs-lisp/cl-generic.el
@@ -446,6 +446,12 @@ The set of acceptable TYPEs (also called \"specializers\") is defined
446 (setq methods (cdr methods))) 446 (setq methods (cdr methods)))
447 methods) 447 methods)
448 448
449(defun cl--generic-load-hist-format (name qualifiers specializers)
450 ;; FIXME: This function is used in elisp-mode.el and
451 ;; elisp-mode-tests.el, but I still decided to use an internal name
452 ;; because these uses should be removed or moved into cl-generic.el.
453 `(,name ,qualifiers . ,specializers))
454
449;;;###autoload 455;;;###autoload
450(defun cl-generic-define-method (name qualifiers args uses-cnm function) 456(defun cl-generic-define-method (name qualifiers args uses-cnm function)
451 (pcase-let* 457 (pcase-let*
@@ -486,8 +492,9 @@ The set of acceptable TYPEs (also called \"specializers\") is defined
486 (cons method mt) 492 (cons method mt)
487 ;; Keep the ordering; important for methods with :extra qualifiers. 493 ;; Keep the ordering; important for methods with :extra qualifiers.
488 (mapcar (lambda (x) (if (eq x (car me)) method x)) mt))) 494 (mapcar (lambda (x) (if (eq x (car me)) method x)) mt)))
489 (cl-pushnew `(cl-defmethod . (,(cl--generic-name generic) 495 (cl-pushnew `(cl-defmethod . ,(cl--generic-load-hist-format
490 ,qualifiers . ,specializers)) 496 (cl--generic-name generic)
497 qualifiers specializers))
491 current-load-list :test #'equal) 498 current-load-list :test #'equal)
492 ;; FIXME: Try to avoid re-constructing a new function if the old one 499 ;; FIXME: Try to avoid re-constructing a new function if the old one
493 ;; is still valid (e.g. still empty method cache)? 500 ;; is still valid (e.g. still empty method cache)?
@@ -864,18 +871,22 @@ Can only be used from within the lexical body of a primary or around method."
864 871
865(defun cl--generic-search-method (met-name) 872(defun cl--generic-search-method (met-name)
866 "For `find-function-regexp-alist'. Searches for a cl-defmethod. 873 "For `find-function-regexp-alist'. Searches for a cl-defmethod.
867MET-NAME is a cons (SYMBOL . SPECIALIZERS)." 874MET-NAME is as returned by `cl--generic-load-hist-format'."
868 (let ((base-re (concat "(\\(?:cl-\\)?defmethod[ \t]+" 875 (let ((base-re (concat "(\\(?:cl-\\)?defmethod[ \t]+"
869 (regexp-quote (format "%s" (car met-name))) 876 (regexp-quote (format "%s" (car met-name)))
870 "\\_>"))) 877 "\\_>")))
871 (or 878 (or
872 (re-search-forward 879 (re-search-forward
873 (concat base-re "[^&\"\n]*" 880 (concat base-re "[^&\"\n]*"
881 (mapconcat (lambda (qualifier)
882 (regexp-quote (format "%S" qualifier)))
883 (cadr met-name)
884 "[ \t\n]*")
874 (mapconcat (lambda (specializer) 885 (mapconcat (lambda (specializer)
875 (regexp-quote 886 (regexp-quote
876 (format "%S" (if (consp specializer) 887 (format "%S" (if (consp specializer)
877 (nth 1 specializer) specializer)))) 888 (nth 1 specializer) specializer))))
878 (remq t (cdr met-name)) 889 (remq t (cddr met-name))
879 "[ \t\n]*)[^&\"\n]*")) 890 "[ \t\n]*)[^&\"\n]*"))
880 nil t) 891 nil t)
881 (re-search-forward base-re nil t)))) 892 (re-search-forward base-re nil t))))
@@ -932,9 +943,10 @@ MET-NAME is a cons (SYMBOL . SPECIALIZERS)."
932 (let* ((info (cl--generic-method-info method))) 943 (let* ((info (cl--generic-method-info method)))
933 ;; FIXME: Add hyperlinks for the types as well. 944 ;; FIXME: Add hyperlinks for the types as well.
934 (insert (format "%s%S" (nth 0 info) (nth 1 info))) 945 (insert (format "%s%S" (nth 0 info) (nth 1 info)))
935 (let* ((met-name `(,function 946 (let* ((met-name (cl--generic-load-hist-format
936 ,(cl--generic-method-qualifiers method) 947 function
937 . ,(cl--generic-method-specializers method))) 948 (cl--generic-method-qualifiers method)
949 (cl--generic-method-specializers method)))
938 (file (find-lisp-object-file-name met-name 'cl-defmethod))) 950 (file (find-lisp-object-file-name met-name 'cl-defmethod)))
939 (when file 951 (when file
940 (insert (substitute-command-keys " in `")) 952 (insert (substitute-command-keys " in `"))
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index f3607911aa1..2fbd60db0dd 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -712,7 +712,10 @@ non-nil result supercedes the xrefs produced by
712 (let* ((info (cl--generic-method-info method));; qual-string combined-args doconly 712 (let* ((info (cl--generic-method-info method));; qual-string combined-args doconly
713 (specializers (cl--generic-method-specializers method)) 713 (specializers (cl--generic-method-specializers method))
714 (non-default nil) 714 (non-default nil)
715 (met-name (cons symbol specializers)) 715 (met-name (cl--generic-load-hist-format
716 symbol
717 (cl--generic-method-qualifiers method)
718 specializers))
716 (file (find-lisp-object-file-name met-name 'cl-defmethod))) 719 (file (find-lisp-object-file-name met-name 'cl-defmethod)))
717 (dolist (item specializers) 720 (dolist (item specializers)
718 ;; default method has all 't' in specializers 721 ;; default method has all 't' in specializers
diff --git a/test/lisp/progmodes/elisp-mode-tests.el b/test/lisp/progmodes/elisp-mode-tests.el
index a7562a00c88..12e61cf8d18 100644
--- a/test/lisp/progmodes/elisp-mode-tests.el
+++ b/test/lisp/progmodes/elisp-mode-tests.el
@@ -347,7 +347,9 @@ to (xref-elisp-test-descr-to-target xref)."
347 (expand-file-name "elisp-mode-tests.el" emacs-test-dir))) 347 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
348 (xref-make "(cl-defmethod xref-elisp-generic-no-default ((this xref-elisp-root-type) arg2))" 348 (xref-make "(cl-defmethod xref-elisp-generic-no-default ((this xref-elisp-root-type) arg2))"
349 (xref-make-elisp-location 349 (xref-make-elisp-location
350 '(xref-elisp-generic-no-default xref-elisp-root-type t) 'cl-defmethod 350 (cl--generic-load-hist-format
351 'xref-elisp-generic-no-default nil '(xref-elisp-root-type t))
352 'cl-defmethod
351 (expand-file-name "elisp-mode-tests.el" emacs-test-dir))) 353 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
352 )) 354 ))
353 355
@@ -360,7 +362,10 @@ to (xref-elisp-test-descr-to-target xref)."
360 (expand-file-name "elisp-mode-tests.el" emacs-test-dir))) 362 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
361 (xref-make "(cl-defmethod xref-elisp-generic-co-located-default ((this xref-elisp-root-type) arg2))" 363 (xref-make "(cl-defmethod xref-elisp-generic-co-located-default ((this xref-elisp-root-type) arg2))"
362 (xref-make-elisp-location 364 (xref-make-elisp-location
363 '(xref-elisp-generic-co-located-default xref-elisp-root-type t) 'cl-defmethod 365 (cl--generic-load-hist-format
366 'xref-elisp-generic-co-located-default nil
367 '(xref-elisp-root-type t))
368 'cl-defmethod
364 (expand-file-name "elisp-mode-tests.el" emacs-test-dir))) 369 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
365 )) 370 ))
366 371
@@ -373,11 +378,16 @@ to (xref-elisp-test-descr-to-target xref)."
373 (expand-file-name "elisp-mode-tests.el" emacs-test-dir))) 378 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
374 (xref-make "(cl-defmethod xref-elisp-generic-separate-default (arg1 arg2))" 379 (xref-make "(cl-defmethod xref-elisp-generic-separate-default (arg1 arg2))"
375 (xref-make-elisp-location 380 (xref-make-elisp-location
376 '(xref-elisp-generic-separate-default t t) 'cl-defmethod 381 (cl--generic-load-hist-format
382 'xref-elisp-generic-separate-default nil '(t t))
383 'cl-defmethod
377 (expand-file-name "elisp-mode-tests.el" emacs-test-dir))) 384 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
378 (xref-make "(cl-defmethod xref-elisp-generic-separate-default ((this xref-elisp-root-type) arg2))" 385 (xref-make "(cl-defmethod xref-elisp-generic-separate-default ((this xref-elisp-root-type) arg2))"
379 (xref-make-elisp-location 386 (xref-make-elisp-location
380 '(xref-elisp-generic-separate-default xref-elisp-root-type t) 'cl-defmethod 387 (cl--generic-load-hist-format
388 'xref-elisp-generic-separate-default nil
389 '(xref-elisp-root-type t))
390 'cl-defmethod
381 (expand-file-name "elisp-mode-tests.el" emacs-test-dir))) 391 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
382 )) 392 ))
383 393
@@ -386,11 +396,16 @@ to (xref-elisp-test-descr-to-target xref)."
386 (list 396 (list
387 (xref-make "(cl-defmethod xref-elisp-generic-implicit-generic (arg1 arg2))" 397 (xref-make "(cl-defmethod xref-elisp-generic-implicit-generic (arg1 arg2))"
388 (xref-make-elisp-location 398 (xref-make-elisp-location
389 '(xref-elisp-generic-implicit-generic t t) 'cl-defmethod 399 (cl--generic-load-hist-format
400 'xref-elisp-generic-implicit-generic nil '(t t))
401 'cl-defmethod
390 (expand-file-name "elisp-mode-tests.el" emacs-test-dir))) 402 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
391 (xref-make "(cl-defmethod xref-elisp-generic-implicit-generic ((this xref-elisp-root-type) arg2))" 403 (xref-make "(cl-defmethod xref-elisp-generic-implicit-generic ((this xref-elisp-root-type) arg2))"
392 (xref-make-elisp-location 404 (xref-make-elisp-location
393 '(xref-elisp-generic-implicit-generic xref-elisp-root-type t) 'cl-defmethod 405 (cl--generic-load-hist-format
406 'xref-elisp-generic-implicit-generic nil
407 '(xref-elisp-root-type t))
408 'cl-defmethod
394 (expand-file-name "elisp-mode-tests.el" emacs-test-dir))) 409 (expand-file-name "elisp-mode-tests.el" emacs-test-dir)))
395 )) 410 ))
396 411
@@ -409,23 +424,33 @@ to (xref-elisp-test-descr-to-target xref)."
409 (expand-file-name "../../../lisp/progmodes/xref.el" emacs-test-dir))) 424 (expand-file-name "../../../lisp/progmodes/xref.el" emacs-test-dir)))
410 (xref-make "(cl-defmethod xref-location-marker ((l xref-elisp-location)))" 425 (xref-make "(cl-defmethod xref-location-marker ((l xref-elisp-location)))"
411 (xref-make-elisp-location 426 (xref-make-elisp-location
412 '(xref-location-marker xref-elisp-location) 'cl-defmethod 427 (cl--generic-load-hist-format
428 'xref-location-marker nil '(xref-elisp-location))
429 'cl-defmethod
413 (expand-file-name "../../../lisp/progmodes/elisp-mode.el" emacs-test-dir))) 430 (expand-file-name "../../../lisp/progmodes/elisp-mode.el" emacs-test-dir)))
414 (xref-make "(cl-defmethod xref-location-marker ((l xref-file-location)))" 431 (xref-make "(cl-defmethod xref-location-marker ((l xref-file-location)))"
415 (xref-make-elisp-location 432 (xref-make-elisp-location
416 '(xref-location-marker xref-file-location) 'cl-defmethod 433 (cl--generic-load-hist-format
434 'xref-location-marker nil '(xref-file-location))
435 'cl-defmethod
417 (expand-file-name "../../../lisp/progmodes/xref.el" emacs-test-dir))) 436 (expand-file-name "../../../lisp/progmodes/xref.el" emacs-test-dir)))
418 (xref-make "(cl-defmethod xref-location-marker ((l xref-buffer-location)))" 437 (xref-make "(cl-defmethod xref-location-marker ((l xref-buffer-location)))"
419 (xref-make-elisp-location 438 (xref-make-elisp-location
420 '(xref-location-marker xref-buffer-location) 'cl-defmethod 439 (cl--generic-load-hist-format
440 'xref-location-marker nil '(xref-buffer-location))
441 'cl-defmethod
421 (expand-file-name "../../../lisp/progmodes/xref.el" emacs-test-dir))) 442 (expand-file-name "../../../lisp/progmodes/xref.el" emacs-test-dir)))
422 (xref-make "(cl-defmethod xref-location-marker ((l xref-bogus-location)))" 443 (xref-make "(cl-defmethod xref-location-marker ((l xref-bogus-location)))"
423 (xref-make-elisp-location 444 (xref-make-elisp-location
424 '(xref-location-marker xref-bogus-location) 'cl-defmethod 445 (cl--generic-load-hist-format
446 'xref-location-marker nil '(xref-bogus-location))
447 'cl-defmethod
425 (expand-file-name "../../../lisp/progmodes/xref.el" emacs-test-dir))) 448 (expand-file-name "../../../lisp/progmodes/xref.el" emacs-test-dir)))
426 (xref-make "(cl-defmethod xref-location-marker ((l xref-etags-location)))" 449 (xref-make "(cl-defmethod xref-location-marker ((l xref-etags-location)))"
427 (xref-make-elisp-location 450 (xref-make-elisp-location
428 '(xref-location-marker xref-etags-location) 'cl-defmethod 451 (cl--generic-load-hist-format
452 'xref-location-marker nil '(xref-etags-location))
453 'cl-defmethod
429 (expand-file-name "../../../lisp/progmodes/etags.el" emacs-test-dir))) 454 (expand-file-name "../../../lisp/progmodes/etags.el" emacs-test-dir)))
430 )) 455 ))
431 456