From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Keith David Bershatsky Newsgroups: gmane.emacs.bugs Subject: bug#27214: truncate_undo_list in undo.c: exclusions, warnings, documentation. Date: Wed, 05 Jul 2017 07:17:08 -0700 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Trace: blaine.gmane.org 1499264299 8767 195.159.176.226 (5 Jul 2017 14:18:19 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 5 Jul 2017 14:18:19 +0000 (UTC) To: 27214@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jul 05 16:18:11 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1dSl86-0001n3-Ba for geb-bug-gnu-emacs@m.gmane.org; Wed, 05 Jul 2017 16:18:11 +0200 Original-Received: from localhost ([::1]:46463 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dSl8B-0001eW-Kt for geb-bug-gnu-emacs@m.gmane.org; Wed, 05 Jul 2017 10:18:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dSl83-0001cz-3R for bug-gnu-emacs@gnu.org; Wed, 05 Jul 2017 10:18:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dSl7y-0007BG-PA for bug-gnu-emacs@gnu.org; Wed, 05 Jul 2017 10:18:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:50851) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dSl7y-0007B3-Gy for bug-gnu-emacs@gnu.org; Wed, 05 Jul 2017 10:18:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dSl7y-0007um-4L for bug-gnu-emacs@gnu.org; Wed, 05 Jul 2017 10:18:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Keith David Bershatsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 05 Jul 2017 14:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 27214 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 27214-submit@debbugs.gnu.org id=B27214.149926423430372 (code B ref 27214); Wed, 05 Jul 2017 14:18:02 +0000 Original-Received: (at 27214) by debbugs.gnu.org; 5 Jul 2017 14:17:14 +0000 Original-Received: from localhost ([127.0.0.1]:53528 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSl7C-0007tn-5o for submit@debbugs.gnu.org; Wed, 05 Jul 2017 10:17:14 -0400 Original-Received: from gateway34.websitewelcome.com ([192.185.149.105]:29753) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSl7A-0007tf-77 for 27214@debbugs.gnu.org; Wed, 05 Jul 2017 10:17:12 -0400 Original-Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway34.websitewelcome.com (Postfix) with ESMTP id AB078635D8 for <27214@debbugs.gnu.org>; Wed, 5 Jul 2017 09:17:11 -0500 (CDT) Original-Received: from gator3053.hostgator.com ([50.87.144.69]) by cmsmtp with SMTP id Sl73dClS8ZqNPSl73dli20; Wed, 05 Jul 2017 09:17:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lawlist.com ; s=default; h=Content-Type:MIME-Version:Subject:To:From:Message-ID:Date: Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=CKtqCoJ0JURngjMlFtV2aOn2Eta7suw5gl4r8ioWiA4=; b=aKu5TeIPX0QOtOi5OyTMdZhIU+ nIdy8RyE5NrSfMj5mI6iU8ZY17CzmY/mGNx1duT2tTVsHA8fdWPysuXzBVqrCud2vMwAStFnoXTiA Z8sBubq0NJocFI+G/Ca7dxdJxAuwGOmpHELFx0yNXHqyNlInbmjnAxIEkkmKDuhovBjTTmuSbYcta nO1Oy/RT2UGo5RvoC5UpGEmukpjw8w25o6IrYSIVED9duMyS2hZEcEX7KZbc8KX54Nca4/NpaNqLz nNjT8/5tIOf8b/dHZeQmrr3tuE3jl7vpqtIHZQqEmFNWRjRtFWzzvzmUrF0R6dzRXCe2NJ6Mb17k5 gw2+XYHg==; Original-Received: from cpe-45-48-239-195.socal.res.rr.com ([45.48.239.195]:49496 helo=server.local) by gator3053.hostgator.com with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.87) (envelope-from ) id 1dSl77-00378G-DE for 27214@debbugs.gnu.org; Wed, 05 Jul 2017 09:17:09 -0500 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator3053.hostgator.com X-AntiAbuse: Original Domain - debbugs.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lawlist.com X-BWhitelist: no X-Source-IP: 45.48.239.195 X-Exim-ID: 1dSl77-00378G-DE X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: cpe-45-48-239-195.socal.res.rr.com (server.local) [45.48.239.195]:49496 X-Source-Auth: lawlist X-Email-Count: 1 X-Source-Cap: bGF3bGlzdDtsYXdsaXN0O2dhdG9yMzA1My5ob3N0Z2F0b3IuY29t 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: 208.118.235.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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:134206 Archived-At: Here is an example of how I am modifying `undo.c` for my own usage, which is specifically tailored to the undo-tree.el library and also the fork that I am working on: In the definition for `syms_of_undo`, add the following: DEFSYM (Qundo_tree_canary, "undo-tree-canary"); And, modify `truncate_undo_list` as follows -- the modified section is labeled with an "undo-tree" notation: void truncate_undo_list (struct buffer *b) { Lisp_Object list; Lisp_Object prev, next, last_boundary; EMACS_INT size_so_far = 0; /* Make sure that calling undo-outer-limit-function won't cause another GC. */ ptrdiff_t count = inhibit_garbage_collection (); /* Make the buffer current to get its local values of variables such as undo_limit. Also so that Vundo_outer_limit_function can tell which buffer to operate on. */ record_unwind_current_buffer (); set_buffer_internal (b); list = BVAR (b, undo_list); prev = Qnil; next = list; last_boundary = Qnil; /* If the first element is an undo boundary, skip past it. */ if (CONSP (next) && NILP (XCAR (next))) { /* Add in the space occupied by this element and its chain link. */ size_so_far += sizeof (struct Lisp_Cons); /* Advance to next element. */ prev = next; next = XCDR (next); } /* Always preserve at least the most recent undo record unless it is really horribly big. Skip, skip, skip the undo, skip, skip, skip the undo, Skip, skip, skip the undo, skip to the undo bound'ry. */ while (CONSP (next) && ! NILP (XCAR (next))) { Lisp_Object elt; elt = XCAR (next); /* Add in the space occupied by this element and its chain link. */ size_so_far += sizeof (struct Lisp_Cons); if (CONSP (elt)) { size_so_far += sizeof (struct Lisp_Cons); if (STRINGP (XCAR (elt))) size_so_far += (sizeof (struct Lisp_String) - 1 + SCHARS (XCAR (elt))); } /* Advance to next element. */ prev = next; next = XCDR (next); } /* If by the first boundary we have already passed undo_outer_limit, we're heading for memory full, so offer to clear out the list. */ if (INTEGERP (Vundo_outer_limit) && size_so_far > XINT (Vundo_outer_limit) && !NILP (Vundo_outer_limit_function)) { Lisp_Object tem; /* Normally the function this calls is undo-outer-limit-truncate. */ tem = call1 (Vundo_outer_limit_function, make_number (size_so_far)); if (! NILP (tem)) { /* The function is responsible for making any desired changes in buffer-undo-list. */ unbind_to (count, Qnil); return; } } if (CONSP (next)) last_boundary = prev; /* Keep additional undo data, if it fits in the limits. */ while (CONSP (next)) { Lisp_Object elt; elt = XCAR (next); /* When we get to a boundary, decide whether to truncate either before or after it. The lower threshold, undo_limit, tells us to truncate after it. If its size pushes past the higher threshold undo_strong_limit, we truncate before it. */ if (NILP (elt)) { if (size_so_far > undo_strong_limit) break; last_boundary = prev; if (size_so_far > undo_limit) break; } /* Add in the space occupied by this element and its chain link. */ size_so_far += sizeof (struct Lisp_Cons); if (CONSP (elt)) { size_so_far += sizeof (struct Lisp_Cons); if (STRINGP (XCAR (elt))) size_so_far += (sizeof (struct Lisp_String) - 1 + SCHARS (XCAR (elt))); } /* Advance to next element. */ prev = next; next = XCDR (next); } /* If we scanned the whole list, it is short enough; don't change it. */ if (NILP (next)) ; /* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; */ /* undo-tree */ /* Truncate at the boundary where we decided to truncate. */ else if (!NILP (last_boundary)) { if (Fmemq (Qundo_tree_canary, last_boundary)) { AUTO_STRING (my_string, "truncate_undo_list: %s"); CALLN (Fmessage, my_string, last_boundary); } else XSETCDR (last_boundary, Qnil); } /* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; */ /* There's nothing we decided to keep, so clear it out. */ else bset_undo_list (b, Qnil); unbind_to (count, Qnil); }