From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.devel Subject: Re: A programming puzzle with buffer-local hooks Date: Fri, 19 May 2017 08:30:33 +0200 Message-ID: <591E9109.9080101@gmx.at> References: <9bb8a8be-2cc6-f7cb-b164-13ffb77b8488@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1495175480 14927 195.159.176.226 (19 May 2017 06:31:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 19 May 2017 06:31:20 +0000 (UTC) To: =?UTF-8?B?Q2zDqW1lbnQgUGl0LUNsYXVkZWw=?= , Emacs developers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri May 19 08:31:15 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dBbRR-0003ge-BX for ged-emacs-devel@m.gmane.org; Fri, 19 May 2017 08:31:13 +0200 Original-Received: from localhost ([::1]:56791 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBbRV-0003mB-5c for ged-emacs-devel@m.gmane.org; Fri, 19 May 2017 02:31:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34058) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBbQy-0003lu-9d for emacs-devel@gnu.org; Fri, 19 May 2017 02:30:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBbQt-0000Xx-BS for emacs-devel@gnu.org; Fri, 19 May 2017 02:30:44 -0400 Original-Received: from mout.gmx.net ([212.227.17.21]:49428) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dBbQt-0000Xf-2G for emacs-devel@gnu.org; Fri, 19 May 2017 02:30:39 -0400 Original-Received: from [192.168.1.100] ([46.125.249.100]) by mail.gmx.com (mrgmx103 [212.227.17.168]) with ESMTPSA (Nemesis) id 0LtZfc-1eA4Nz0Ayq-010rRG; Fri, 19 May 2017 08:30:35 +0200 In-Reply-To: <9bb8a8be-2cc6-f7cb-b164-13ffb77b8488@gmail.com> X-Provags-ID: V03:K0:GlUPr8/g9GkoAAi633oUMYo0peDscfnOEJ8OhcGzDxJyCmDnm/a aVh8Kucdbdzvw36oAaj2O4i1q2ExKqdM09t/OJzHUynBk75/Sw7q2byuyZW9pg/CioBb9k0 FNgkiNBgEYln2QcjnqIZyhB9zfTKrsR95/KKE70REr0CHC7UZJ/mJYq4pMAMZBc9HYaNg2D 2w/O+3X9XiPCB4Fy1RtTg== X-UI-Out-Filterresults: notjunk:1;V01:K0:G+EYrn/mK6k=:o1cu/ix9IX83GF++VYY1Ql DsIkDvzEmi2Cn6oDyOwTQlWGYuP3c9xQHjhhrLtng56KVkYPn1v3mTS1sa8pA6rjeQuYQCtsU MiIY8ZXDyg2EXQVyIitGnUT5pM8WvLIQpa7Lj38QhQ9qvTSYay6pxUmI82Q6AUXWnIqOjRl/7 HJ4O6ssUmuYK63u9wNVs3m2cPicEcBtjyj1452DsTLKSd4vk3wVWIyDQKwjVsm08Ip5ENhOSD 07dIf8uK5hSbCwgJ73g/Uug6X1FoYox0OAPqPRdGpFrbwnTnFL7lL4EqCudBSDWP8ZDED5TqT Np69jJoCelLfilNm0Hyf384U1YLXb30EfanVfdRdUlQ5TZaUBkUJiRe5GjEvOP/TdykGaZpmp CF1ATUfURDBUeUMx4QH0QOt5vS6J/jqynctO7JSO0eL2tH1xjU/WWelssUj3JVEzVr2fw5N3Z aB3YUfUvDLXfyfmrT5SdxPO3t+YUsWJvsUkthVgg7fk40N/zCOLYYAhV8Cc7j2DXQtjGd37MQ w+wjrXVRZUJi9KU1ewCmnrxA5GvoitUcN3Nh3I7oaiOrkE8E4gByQrtCuETER6ixGZtkQjreE m6ZM6HxKo4DUORNSoWyS9f1hnuBH9ZVJFE99UIiZmgVped72jPBsRY0p3jzsQudTsddb3k/fb bxTWVkq7vKapIPXcmrZmNylfV8iBR23gAeEWmjAz4pTny0ptx++FG6DyXM76cSGpUhiPYsM9Q TVkq8OiVP10blABa+ICoZ6nIYwB4OH7aaC4AWObxzaueHu2h9M0Y6pxmbCBDIWyYoj6HQcf1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.21 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:214976 Archived-At: > I can think of two other tricks: reference counting (every time the > mode is disabled, check whether it's enabled anywhere else), and never= > removing the hook. I would use reference counting with an increment call when the mode is enabled in a buffer and a decrement call run by =E2=80=98kill-buffer-hook= =E2=80=99 and when the mode gets disabled in a buffer. Obviously, the function on =E2=80=98kill-buffer-hook=E2=80=99 should be removed together with the ot= her functions when that count drops to zero. martin