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) Date: Tue, 02 Aug 2016 10:46:05 -0400 Message-ID: References: <20160731121642.GB2205@acm.fritz.box> <83a8gxq288.fsf@gnu.org> <20160731172804.GD2205@acm.fritz.box> <834m75ptij.fsf@gnu.org> <20160731212635.GF2205@acm.fritz.box> <83shuoocwp.fsf@gnu.org> <20160801165323.GB15055@acm.fritz.box> <20160801171552.GC15055@acm.fritz.box> <838twgnuso.fsf@gnu.org> <20160801205223.GD15055@acm.fritz.box> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1470505090 30895 195.159.176.226 (6 Aug 2016 17:38:10 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 6 Aug 2016 17:38:10 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Aug 06 19:38:07 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 1bW5Xw-000761-O9 for ged-emacs-devel@m.gmane.org; Sat, 06 Aug 2016 19:38:04 +0200 Original-Received: from localhost ([::1]:50123 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bW5Xt-0007NL-Gz for ged-emacs-devel@m.gmane.org; Sat, 06 Aug 2016 13:38:01 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45244) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bW5Xh-0007GJ-RY for emacs-devel@gnu.org; Sat, 06 Aug 2016 13:37:53 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bW5Xf-00074p-P1 for emacs-devel@gnu.org; Sat, 06 Aug 2016 13:37:48 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:37556) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bW5Xf-00074l-IP for emacs-devel@gnu.org; Sat, 06 Aug 2016 13:37:47 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0AxFgA731xV/2/xd0tcgxCEAoVVwwsEPoECPBEBAQEBAQEBgQpBBYNdAQQBVigLCzQSFBgNAxuIPQjPT4s6hCCBAoQXAQSfF5IUghSBRSOBRwyCQSKBNIFEAQEB X-IPAS-Result: A0AxFgA731xV/2/xd0tcgxCEAoVVwwsEPoECPBEBAQEBAQEBgQpBBYNdAQQBVigLCzQSFBgNAxuIPQjPT4s6hCCBAoQXAQSfF5IUghSBRSOBRwyCQSKBNIFEAQEB X-IronPort-AV: E=Sophos;i="5.13,465,1427774400"; d="scan'208";a="250424386" Original-Received: from 75-119-241-111.dsl.teksavvy.com (HELO fmsmemgm.homelinux.net) ([75.119.241.111]) by ironport2-out.teksavvy.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 06 Aug 2016 13:37:48 -0400 Original-Received: by fmsmemgm.homelinux.net (Postfix, from userid 20848) id 60E89AE539; Sat, 6 Aug 2016 13:37:46 -0400 (EDT) Original-Lines: 22 Original-Received: from list by blaine with local (Exim 4.84_2) (envelope-from ) id 1bUav4-0000Aw-Oe for emacs-devel@gnu.org; Tue, 02 Aug 2016 16:43:46 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:wWfUWXzw9wfddVIttPPmsxtoIgk= 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:206455 Archived-At: > Slightly less gross, perhaps: > (i) Abandon the use of before-change-functions. > (ii) Enable undo in pre-command-hook, if necessary. > (iii) At each after-change-functions call: > a - Analyze buffer-undo-list down as far as (or pos (next-nil)), and > revert the insertion or deletion which as been made, taking > particular care over coalesced multiple insertions/deletions. > b - (setq pos (current-position-in-undo-list)) > c - Perform what used to be before-change actions. > d - restore the insertion/deletion. > e - Perform the normal after-change functions. > (iv) Disable undo in post-command-hook, if appropriate. Alan. I urge you to take a step back and think about how to solve your problem without looking at the details of each change. I am 100% sure, based on my experience with lots of major modes (including cc-mode), that the result will be more robust, simpler, and at least as efficient. Stefan