From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: =?UTF-8?Q?=C5=A0t=C4=9Bp=C3=A1n_?= =?UTF-8?Q?N=C4=9Bmec?= Newsgroups: gmane.emacs.bugs Subject: bug#5293: 23.1; unload-feature on buffer-local hooks Date: Mon, 06 Apr 2020 21:17:34 +0200 Message-ID: <87v9mcjuep.fsf@gmail.com> References: <87hbr4p67t.fsf@blah.blah> <871uxsl778.fsf@blah.blah> <87aabnnxna.fsf@blah.blah> <87zhbojzmv.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="14392"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Notmuch/0.29.3 (https://notmuchmail.org) Emacs/28.0.50 (x86_64-pc-linux-gnu) Cc: Juanma Barranquero , Kevin Ryde , 5293@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Apr 06 21:19:13 2020 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 1jLXH7-0003eg-FM for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 06 Apr 2020 21:19:13 +0200 Original-Received: from localhost ([::1]:37396 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLXH6-0007Kp-GX for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 06 Apr 2020 15:19:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53121) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLXFz-0006UL-CT for bug-gnu-emacs@gnu.org; Mon, 06 Apr 2020 15:18:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jLXFy-0003SY-6s for bug-gnu-emacs@gnu.org; Mon, 06 Apr 2020 15:18:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37706) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jLXFy-0003SQ-1u for bug-gnu-emacs@gnu.org; Mon, 06 Apr 2020 15:18:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jLXFx-000882-UD for bug-gnu-emacs@gnu.org; Mon, 06 Apr 2020 15:18:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?=C5=A0t=C4=9Bp=C3=A1n_?= =?UTF-8?Q?N=C4=9Bmec?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 06 Apr 2020 19:18:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 5293 X-GNU-PR-Package: emacs Original-Received: via spool by 5293-submit@debbugs.gnu.org id=B5293.158620063631124 (code B ref 5293); Mon, 06 Apr 2020 19:18:01 +0000 Original-Received: (at 5293) by debbugs.gnu.org; 6 Apr 2020 19:17:16 +0000 Original-Received: from localhost ([127.0.0.1]:49252 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jLXFE-00085v-Fw for submit@debbugs.gnu.org; Mon, 06 Apr 2020 15:17:16 -0400 Original-Received: from mail-wr1-f53.google.com ([209.85.221.53]:37716) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jLXFC-00085V-AM for 5293@debbugs.gnu.org; Mon, 06 Apr 2020 15:17:14 -0400 Original-Received: by mail-wr1-f53.google.com with SMTP id w10so872365wrm.4 for <5293@debbugs.gnu.org>; Mon, 06 Apr 2020 12:17:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version; bh=BGAXL9JJB7eIFqLl47bpfwPNcHadc1L3IKYl8qwxI9M=; b=FNvCiRclSo7y2ZSIW35VS3XJsvi0x4+bsOyLmKno/7/2kqixGnfQC9GEl3T4xulVe9 7eyLn2lJSQ9jceRGo68PcaWX/4SwQ+Fkj+jZr5atcTpKalY3i6WomqKIpHFziIdj6eYZ 436tvv4uhnLCxFvHEZWulcb8ie+eQSMvZglERMBIU2M5hLYmMHzdjkQ9KQV78rxYYSJ8 1skvk1C1TzyfEiJLw42JR80Equ5hfpDhCHLpKBZrleuJacafMz4pzvYLQ6PffNQWX+9a k7LusFQWukNt5yNXtVnuYX8NHtdzKfDpdD1VGI6FSX3vhnPzCl+sbIjmHmArMBHNlJ5o b26Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references :user-agent:date:message-id:mime-version; bh=BGAXL9JJB7eIFqLl47bpfwPNcHadc1L3IKYl8qwxI9M=; b=Q549HfYIjB8QQWFsNv8vX98aCUlwKEEHADbdzihhljylzpF2OCnj5VypT/vtaAt/2h c6LxGGWsDJRfskqejoFIpMFc4tbRAFHL11/f42m0NxqPRoypMNZIGcEEaXe9jStlaTZO E+1d5Z18IwLmo2M/4NIrxsvjxeJgr3oqZBe3/YnaebcUlolpe2cVe2K/cww8hK0B96IE MiI//E/Cx92DOA0PvCbMJqA/dF70i39USgE31J0p9B24Wpdr4rcm8PvjMX2YMkEoe+0A VgGoyhILUiAvJPUQ3fA0ljhF4EKx04gkvqxfPl1JYruM+Oms3o9OGYBDp6qcqcGw7HNr 1HhQ== X-Gm-Message-State: AGi0PuaI7DRhXVa8z4eRrLxDNwnBzc6YcoMEJit+xIpOEx6NBryBzM/5 IUKgtqZHHyp3sIk4Ih5F2TI= X-Google-Smtp-Source: APiQypIgCe8sKBx8rhTNpVkdBTsLDca+n+uaymJVb2UbMFg4bMcMHp+n8FZLqG2C2uhz7m7S0t3ZDg== X-Received: by 2002:adf:f1ce:: with SMTP id z14mr807096wro.68.1586200628427; Mon, 06 Apr 2020 12:17:08 -0700 (PDT) Original-Received: from localhost ([185.112.167.47]) by smtp.gmail.com with ESMTPSA id u22sm591639wmu.43.2020.04.06.12.17.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Apr 2020 12:17:07 -0700 (PDT) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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:178102 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Mon, 06 Apr 2020 14:06:02 -0400 Stefan Monnier wrote: >> @@ -299,7 +299,11 @@ unload-feature >> ;; Known abnormal hooks etc. >> (memq x unload-feature-special-hooks))) >> (dolist (func removables) >> - (remove-hook x func))))) >> + (remove-hook x func) >> + (save-current-buffer >> + (dolist (buffer (buffer-list)) >> + (set-buffer buffer) >> + (remove-hook x func t))))))) >> ;; Remove any feature-symbols from auto-mode-alist as well. >> (dolist (func removables) >> (setq auto-mode-alist > > Maybe instead of `(dolist (buffer (buffer-list))` within that big > `mapatoms` within `(dolist (func removables)` (which is O(B*F*V) where > B is the number of buffers, F is the number of functions and V is the > number of hook vars), we should instead do it as: > > (dolist (buffer (buffer-list)) > (dolist (varvar (buffer-local-variables buffer)) ^^^^^^^^^^^^^^^^^^^^^^ Ha! Didn't know/think about that one, and indeed it makes a world of difference. Thanks! So I guess my defeatism will not prevail after all. Updated [2/3] attached. --=20 =C5=A0t=C4=9Bp=C3=A1n --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-unload-feature-Handle-local-hooks.patch >From fd9b67b10fcc9596fc1eeae50bb351ef235eea68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20N=C4=9Bmec?= Date: Mon, 6 Apr 2020 13:30:11 +0200 Subject: [PATCH 2/3 v2] unload-feature: Handle local hooks Buffer-local hooks were introduced in 1994-09-30T20:47:13+00:00!rms@gnu.org 0e4d378b32 (add-hook): Initialize default value and local value. but `unload-feature' has not been updated to handle them. * lisp/loadhist.el (unload-feature): Handle local hooks. --- etc/NEWS | 3 +++ lisp/loadhist.el | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index 765a923bf7..fa90edc4d1 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -297,6 +297,9 @@ optional argument specifying whether to follow symbolic links. ** 'parse-time-string' can now parse ISO 8601 format strings, such as "2020-01-15T16:12:21-08:00". +--- +** 'unload-feature' now also tries to undo additions to buffer-local hooks. + * Changes in Emacs 28.1 on Non-Free Operating Systems diff --git a/lisp/loadhist.el b/lisp/loadhist.el index 60da00cceb..81576679c3 100644 --- a/lisp/loadhist.el +++ b/lisp/loadhist.el @@ -300,6 +300,15 @@ unload-feature (memq x unload-feature-special-hooks))) (dolist (func removables) (remove-hook x func))))) + (save-current-buffer + (dolist (buffer (buffer-list)) + (pcase-dolist (`(,sym . ,val) (buffer-local-variables buffer)) + (when (or (and (consp val) + (string-match "-hooks?\\'" (symbol-name sym))) + (memq sym unload-feature-special-hooks)) + (set-buffer buffer) + (dolist (func removables) + (remove-hook sym func t)))))) ;; Remove any feature-symbols from auto-mode-alist as well. (dolist (func removables) (setq auto-mode-alist -- 2.26.0 --=-=-=--