From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: akater Newsgroups: gmane.emacs.bugs Subject: bug#50834: Feature request: cl-remove-method (prototyped) and buttons for it Date: Mon, 27 Sep 2021 14:44:13 +0000 Message-ID: <87wnn2nkn6.fsf@gmail.com> References: <8735pqq0yb.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1157"; mail-complaints-to="usenet@ciao.gmane.io" To: 50834@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Sep 27 16:56:14 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mUs3B-000Ad6-Nj for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 27 Sep 2021 16:56:13 +0200 Original-Received: from localhost ([::1]:35946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mUs39-0000sO-J9 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 27 Sep 2021 10:56:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50844) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mUs30-0000oa-My for bug-gnu-emacs@gnu.org; Mon, 27 Sep 2021 10:56:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:59050) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mUs30-0007Nt-8y for bug-gnu-emacs@gnu.org; Mon, 27 Sep 2021 10:56:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mUs30-0000Ct-5r for bug-gnu-emacs@gnu.org; Mon, 27 Sep 2021 10:56:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: akater Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 27 Sep 2021 14:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50834 X-GNU-PR-Package: emacs Original-Received: via spool by 50834-submit@debbugs.gnu.org id=B50834.1632754552775 (code B ref 50834); Mon, 27 Sep 2021 14:56:02 +0000 Original-Received: (at 50834) by debbugs.gnu.org; 27 Sep 2021 14:55:52 +0000 Original-Received: from localhost ([127.0.0.1]:42363 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mUs2p-0000CP-TV for submit@debbugs.gnu.org; Mon, 27 Sep 2021 10:55:52 -0400 Original-Received: from mail-pl1-f175.google.com ([209.85.214.175]:47078) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mUs2o-0000CA-KM for 50834@debbugs.gnu.org; Mon, 27 Sep 2021 10:55:51 -0400 Original-Received: by mail-pl1-f175.google.com with SMTP id w11so11925748plz.13 for <50834@debbugs.gnu.org>; Mon, 27 Sep 2021 07:55:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:in-reply-to:references:date:message-id:mime-version; bh=d27cYCU2aykiAgNPQbC8nLDDjYLLH9OMNE+N0F5LQ3w=; b=a8XDzWK5fq7djnJmN26uIprf1Ov1wC+S6MrjhU/RbCLY5HoiotIoYVDkarNiPqtlK6 wgzcZULmESZp2vGJ68MYpeSk1+8as5pLd6/9UMiA9RGiATBLOblalWqF93BN8UiMIZD+ 1kzz0hp5tGRkS/8VrmwSia/lps0gsDWxAdg+Ahieb0WPkoFLRq66ZT6rUO5tS5OOajKi ekdX3S7YoWMoC2r0YuKlDvzrqUU0dkkOc8AHt3/+KFpG0bL7L/MSuYBFWWAmITexN9Y+ cTXFaPV7xw3uoMDf2I96sGQb886Dw0octk7TTKt/1sWatsy7993r5YDVMBEcb+Fstmad Samg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:in-reply-to:references:date :message-id:mime-version; bh=d27cYCU2aykiAgNPQbC8nLDDjYLLH9OMNE+N0F5LQ3w=; b=u1TZ7/pylavXKAyr9SXmvzFfJkwm0KfXFeZPyRApwHfAUdA1nTBuW2T+HBkRrDe83n hnFmNqJCIJmCudGEUcb1nkoKZrhSjP80+SuDNV6yKR6z3vZHrjR59xXS/I3P2k7PZCCd AM+lVBQ2G3auaytKKSIjgEy/tSr28AESG3XP4uZWUxuRHn3o1/RTR7kuCWbWKhUwDJ0K H8V3bvvwfJMBxTVMF1C0C66C7O9APZDKy60+tWcqMeJWA4VUzYLYVZFVUuzKnbgLBRab sYQGXt2lgbRnpgrYFw66PRN0aQakOfdCnBYYDeuTc34HyEqJVYViqS89OMjp3jtWLMtt LW2w== X-Gm-Message-State: AOAM531wZ10HmNiqg1mKROXTmXsQzxs1lAccUVQWfxBWV/taxS4MmESb G9fpKzIJ7aNmftqE6bxkVMpzWJM5MCClxky1 X-Google-Smtp-Source: ABdhPJyyzGLJNdYS5YrXb0D6G8GwMFSwaqCfRX9JxXpmP/5opxFuGqnqp6Ttdq4j2e1bL5/2rzStIA== X-Received: by 2002:a17:902:b410:b0:13a:3f4a:db58 with SMTP id x16-20020a170902b41000b0013a3f4adb58mr265597plr.12.1632754544737; Mon, 27 Sep 2021 07:55:44 -0700 (PDT) Original-Received: from localhost ([23.129.64.130]) by smtp.googlemail.com with ESMTPSA id e24sm17218714pfn.8.2021.09.27.07.55.43 for <50834@debbugs.gnu.org> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 07:55:44 -0700 (PDT) In-Reply-To: <8735pqq0yb.fsf@gmail.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:215674 Archived-At: --=-=-= Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" --==-=-= Content-Type: text/plain Various fixes to the prototype patch: - require subr-x - more specific default signature - more extensive documentation --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJLBAEBCgA1FiEEgu5SJRdnQOF34djNsr6xYbHsf0QFAmFR2L0XHG51Y2xlYXJz cGFjZUBnbWFpbC5jb20ACgkQsr6xYbHsf0TcXhAAorEQxZdKc/aY/6EZz5dm1gR9 t07Pn/hsVLZL1ahBmPRph0SoMk8OdmhsuhPXxyh4oxiK3Cobuu7EZFbh/OxeIS3u x/6BY5o+uU9OUbrOM+ObdPP7j0vD2pPSVse6yC78Ag6RPLLlS4aASulTJ+uAaaPA uDCtCdh5KigKXJKc8xz9HwiZ0/8m+EKW0xuxk1EQAJysLn7+zy+OK9Q1PeeiiqMv UcAnhZyGlFb98H/NizWSj00qvqVcECwK89+m7Y1KacRMwHHxtPZOQOOHhOckbh66 9yjsVFaOQ/VudqgAE0+2uKRaIVKy2ue6yRwG3S2vXCnxf5Etz9KyrZ44q9p9dzwm vhu5DtGIo8w1gCioqJNruULm/WSzd7l6qeYwcdS1MNEZyoqCaIkjnXZlXNHWV+Jl Y83YIxuGW1esovmzFfBskHznedHq1HrYViRzGJD0oisDro5BDG/EgFN9W/CR97ZR ToKrPw5t4wt1OlUTnwKTYsK0NAciM08k7NKl3IB3bpOlCpQc5YvkMjtyo5r/9pyZ BP9dh+fKLHiyMXdJ4hEIrs9raXMhf7ATu/AiFJbQDvAqSD+6kYdoY2xmGmitdpjp FoZsIlcUP8b3aEkJ7IrPf0pUcl7HLRZApBDUrn9xFw15lSZOiCfwEkFfuyFp7tox 12v2wwTaRN5PWZJJGME= =pore -----END PGP SIGNATURE----- --==-=-=-- --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-cl-remove-method.patch Content-Description: Add cl-remove-method >From decd4e0ed24553981f9b87f59308a10ccdd1c5b6 Mon Sep 17 00:00:00 2001 From: akater Date: Sun, 26 Sep 2021 21:33:46 +0000 Subject: [PATCH] Add cl-remove-method --- lisp/emacs-lisp/cl-generic.el | 56 ++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/lisp/emacs-lisp/cl-generic.el b/lisp/emacs-lisp/cl-generic.el index 1640975b84..c1ef3af3c7 100644 --- a/lisp/emacs-lisp/cl-generic.el +++ b/lisp/emacs-lisp/cl-generic.el @@ -98,8 +98,9 @@ ;; usually be simplified, or even completely skipped. (eval-when-compile (require 'cl-lib)) -(eval-when-compile (require 'cl-macs)) ;For cl--find-class. +(eval-when-compile (require 'cl-macs)) ;For cl--find-class, cl-loop (eval-when-compile (require 'pcase)) +(eval-when-compile (require 'subr-x)) ;if-let (cl-defstruct (cl--generic-generalizer (:constructor nil) @@ -1255,6 +1256,59 @@ defun cl--generic-struct-specializers (tag &rest _) (cl--generic-prefill-dispatchers 0 integer) (cl--generic-prefill-dispatchers 0 cl--generic-generalizer integer) +(cl-defgeneric cl-remove-method (generic-function method) + "Remove METHOD from GENERIC-FUNCTION by modifying the +GENERIC-FUNCTION (if necessary). + +`cl-remove-method' does not signal an error if METHOD is not one +of the methods on the GENERIC-FUNCTION.") + +(cl-defmethod cl-remove-method ((generic-function cl--generic) + (method cl--generic-method)) + "An equivalent of Common Lisp's default method for remove-method. + +Compatibility note: +The Common Lisp HyperSpec page on remove-method says +in Arguments and Values: + > method---a method +and Exceptional Situations: none. +So then, according to +1.4.4.3 The ``Arguments and Values'' Section of a Dictionary Entry +http://www.lispworks.com/reference/HyperSpec/Body/01_ddc.htm + +the consequences are undefined if the second value is not a method. + +In cl-generic, `cl-remove-method' is not applicable to +non-methods by default." + ;; Credit for compatibility note goes to + ;; beach from #commonlisp at libera.chat + (setf (cl--generic-method-table generic-function) + ;; delq could cause bugs, let's see if it does + (delq method (cl--generic-method-table generic-function))) + + (cl-loop for k being hash-key in cl--generic-combined-method-memoization + when (and (eq generic-function (car k)) + (memq method (cdr k))) + do (remhash k cl--generic-combined-method-memoization)) + + ;; It might make sense to move this + (defalias (cl--generic-name generic-function) + (cl--generic-make-function generic-function)) + ;; to an :after method + ;; but it's not even clear to me whether + ;; having such :after method would be compatible with Common Lisp standard. + generic-function) + +(cl-defmethod cl-remove-method ((generic-function symbol) + (method cl--generic-method)) + "For Common Lisp compatibility in Elisp. + +Namely, (cl-remove-method #'f ..) should work correctly but #'f +returns symbol in Elisp, hence this method." + (if-let ((gf (cl--generic generic-function))) + (cl-remove-method gf method) + (error "No generic function named %s" generic-function))) + ;;; Dispatch on major mode. ;; Two parts: -- 2.32.0 --=-=-=--