From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Unbalanced change hooks (part 2) [Documentation fix still remaining] Date: Wed, 10 Aug 2016 15:50:06 -0400 Message-ID: References: <83tweugeu9.fsf@gnu.org> <20160809163814.GD4893@acm.fritz.box> <83inv9hkjd.fsf@gnu.org> <83h9ashfgx.fsf@gnu.org> <831t1wharr.fsf@gnu.org> <20160810161821.GB3413@acm.fritz.box> <83wpjofttf.fsf@gnu.org> <20160810185735.GD3413@acm.fritz.box> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1470859552 19950 195.159.176.226 (10 Aug 2016 20:05:52 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 10 Aug 2016 20:05:52 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) Cc: Eli Zaretskii , emacs-devel@gnu.org To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Aug 10 22:05:48 2016 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 1bXZl4-0004za-Cn for ged-emacs-devel@m.gmane.org; Wed, 10 Aug 2016 22:05:46 +0200 Original-Received: from localhost ([::1]:43686 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXZl1-0007SR-BU for ged-emacs-devel@m.gmane.org; Wed, 10 Aug 2016 16:05:43 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53588) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXZkp-0007QH-Ec for emacs-devel@gnu.org; Wed, 10 Aug 2016 16:05:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bXZkn-0001hS-6A for emacs-devel@gnu.org; Wed, 10 Aug 2016 16:05:30 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:45259) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bXZki-0001g0-3y; Wed, 10 Aug 2016 16:05:24 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CYFACJI6tX/2aIs2tdHAEBgyeES4VQsF2BfYYXBAICgV07EgEBAQEBAQFdJ4RfAQEDAVYPFAULCw4mEhQYDSSIPAjBXAEBCAIlineEEIVuHQWTeIVEmFmFfJAsJQkmhBYghhmBRQEBAQ X-IPAS-Result: A0CYFACJI6tX/2aIs2tdHAEBgyeES4VQsF2BfYYXBAICgV07EgEBAQEBAQFdJ4RfAQEDAVYPFAULCw4mEhQYDSSIPAjBXAEBCAIlineEEIVuHQWTeIVEmFmFfJAsJQkmhBYghhmBRQEBAQ X-IronPort-AV: E=Sophos;i="5.28,500,1464667200"; d="scan'208";a="251012876" Original-Received: from 107-179-136-102.cpe.teksavvy.com (HELO pastel.home) ([107.179.136.102]) by smtp.teksavvy.com with ESMTP; 10 Aug 2016 16:05:20 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id 43F6564E1D; Wed, 10 Aug 2016 15:50:06 -0400 (EDT) In-Reply-To: <20160810185735.GD3413@acm.fritz.box> (Alan Mackenzie's message of "Wed, 10 Aug 2016 18:57:35 +0000") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.181 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:206554 Archived-At: > Do @emph{not} expect the before-change hooks and the after-change > hooks be called in balanced pairs around each buffer change. Also > don't expect the before-change hooks to be called for every chunk of > text Emacs is about to delete. These hooks are provided on the > assumption that Lisp programs will use either before- or the > after-change hooks, but not both, and the boundaries of the region > where the changes happen might include more than just the actual > changed text, or even lump together several changes done piecemeal. That looks OK, thank you. It does make it sound like sometimes b-c-f won't be called at all, whereas AFAIU it is *always* called before a change, tho maybe "too early" (i.e. announcing several changes at the same time), but I think it's good enough for now. > One can (indeed, often MUST) expect b-c-f and a-c-f to work in pairs, No. I know you *want* to expect it, but that assumption has not been true for many years and we don't want to impose it on ourselves. Furthermore there is no evidence that you "MUST". I gave various examples of ways you can live with only a-c-f. > Editing text involves deletions and insertions. It also involves replacements. > Deletions can be known only in before-change-functions, insertions > only in after-change-functions. Not at all. Deletions are definitely announced to a-c-f. > CC Mode absolutely requires to know both deletions and insertions for > its proper functioning. Nobody has yet demonstrated that it can work > properly knowing only insertions, despite Stefan loudly and repeatedly > proclaiming it can. All major modes using syntax-propertize demonstrate it. C++ has its share of syntactic quirks, but none that are fundamentally very different from what we find in other languages such as Perl. I also outlined in more detailed how to deal with a specific example you seemed to think required absolutely to know what was there before the deletion. > enabling state to be determined in a before-change function and used > in an after-change function. That's exactly what I want to strongly discourage. Based on my experience with CC-mode, I'd even say that it's just a bad design, even if the hooks were always called in pairs. I don't know nor care about how we ended up with such a design, and I understand that you might prefer to try and live with it than to go back and rethink it, but it's still a bad design (nor is it the only bad design we have in Emacs, of course). Stefan