From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [Emacs-diffs] fix/no-undo-boundary-on-secondary-buffer-change 0f3c1db: Changed semantics of first-undoable-change-hook. Date: Tue, 29 Sep 2015 01:35:59 -0400 Message-ID: References: <20150928134935.25048.30653@vcs.savannah.gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1443521351 9644 80.91.229.3 (29 Sep 2015 10:09:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 29 Sep 2015 10:09:11 +0000 (UTC) Cc: Phillip Lord To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Sep 29 12:09:03 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZgrqJ-0006B9-93 for ged-emacs-devel@m.gmane.org; Tue, 29 Sep 2015 12:09:03 +0200 Original-Received: from localhost ([::1]:49338 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZgrqI-0004vH-KS for ged-emacs-devel@m.gmane.org; Tue, 29 Sep 2015 06:09:02 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41693) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zgna8-0007LN-6F for emacs-devel@gnu.org; Tue, 29 Sep 2015 01:36:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zgna4-0005PY-UR for emacs-devel@gnu.org; Tue, 29 Sep 2015 01:36:04 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:30233) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zgna4-0005Od-QW for emacs-devel@gnu.org; Tue, 29 Sep 2015 01:36:00 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CsCwA731xV/wihxEVcgxCEAsEMCYdLBAICgTw5FAEBAQEBAQGBCkEFg10BAQRWIxALNAcLFBgNiGPPIwEBAQcCAR+LOoUFBxaEFwWbZIMzE4NYjimCFIFFI4I7gVkigngBAQE X-IPAS-Result: A0CsCwA731xV/wihxEVcgxCEAsEMCYdLBAICgTw5FAEBAQEBAQGBCkEFg10BAQRWIxALNAcLFBgNiGPPIwEBAQcCAR+LOoUFBxaEFwWbZIMzE4NYjimCFIFFI4I7gVkigngBAQE X-IronPort-AV: E=Sophos;i="5.13,465,1427774400"; d="scan'208";a="166223930" Original-Received: from 69-196-161-8.dsl.teksavvy.com (HELO ceviche.home) ([69.196.161.8]) by ironport2-out.teksavvy.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 29 Sep 2015 01:35:59 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id 28A9766110; Tue, 29 Sep 2015 01:35:59 -0400 (EDT) In-Reply-To: (Phillip Lord's message of "Mon, 28 Sep 2015 13:49:36 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) 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.14 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-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:190475 Archived-At: > +(defun undo-needs-boundary-p () > + "Returns t if `buffer-undo-list' needs a boundary at the start." ^^^ non-nil > + ;; buffer-undo-list can be t > + (listp buffer-undo-list) > + ;; first element of buffer-undo-list is nil Please capitalize and punctuate your comments. > +run_first_undo_hook() Please always add spaces before the open parens. > + list = BVAR(current_buffer, undo_list); Here as well (and ,many other places). > + if (CONSP (list) && NILP (XCAR (list))) > + { > + safe_run_hooks(Qundo_first_undoable_change_hook); > + } I think this fails to run the hook when list is nil. Also, I don't think we need the `safe' version of run-hooks here because we shouldn't be in a special context like redisplay where signals would have nasty consequences. > + > DEFUN ("undo-boundary", Fundo_boundary, Sundo_boundary, 0, 0, 0, Try to avoid adding spurious empty lines. It looks pretty good. Remaining problems I noticed: - run_first_undo_hook is defined to take no argument, yet it's always called with `current_buffer' as argument. - in src/keyboard.c we push undo-boundaries after every command. This is now made redundant by your code, so you might like to remove it. - when trying to remove that code, you'll notice that Fself_insert_command (and Fdelete_char, IIRC) depends on that code to know whether the last boundary can be removed (so as to implement the "bundling"). - It looks like run_first_undo_hook is often called in an "unclean" state where the C code has set current_buffer rather than calling set_buffer_internal. This is an optimization that only works when we know exactly the code that might possibly be run before current_buffer is set back to its previous value, but it can't be used when running arbitrary Elisp code. So we should call run_first_undo_hook *before* setting current_buffer, and run_first_undo_hook should set_buffer_internal when needed. Stefan