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#16377: Undo Tree regression: (error "Unrecognized entry in undo list undo-tree-canary") Date: Wed, 05 Jul 2017 17:33:57 -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 1499301319 15306 195.159.176.226 (6 Jul 2017 00:35:19 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 6 Jul 2017 00:35:19 +0000 (UTC) To: 16377@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jul 06 02:35:13 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 1dSul9-0003Np-1H for geb-bug-gnu-emacs@m.gmane.org; Thu, 06 Jul 2017 02:35:07 +0200 Original-Received: from localhost ([::1]:48688 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dSulE-0007oA-8p for geb-bug-gnu-emacs@m.gmane.org; Wed, 05 Jul 2017 20:35:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34333) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dSul7-0007mp-Sp for bug-gnu-emacs@gnu.org; Wed, 05 Jul 2017 20:35:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dSul4-0005cV-MS for bug-gnu-emacs@gnu.org; Wed, 05 Jul 2017 20:35:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51236) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dSul4-0005cO-Dm for bug-gnu-emacs@gnu.org; Wed, 05 Jul 2017 20:35:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dSul3-0002Ae-QM for bug-gnu-emacs@gnu.org; Wed, 05 Jul 2017 20:35:01 -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: Thu, 06 Jul 2017 00:35:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16377 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 16377-submit@debbugs.gnu.org id=B16377.14993012648281 (code B ref 16377); Thu, 06 Jul 2017 00:35:01 +0000 Original-Received: (at 16377) by debbugs.gnu.org; 6 Jul 2017 00:34:24 +0000 Original-Received: from localhost ([127.0.0.1]:53912 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSukS-00029V-1R for submit@debbugs.gnu.org; Wed, 05 Jul 2017 20:34:24 -0400 Original-Received: from gateway24.websitewelcome.com ([192.185.51.139]:35180) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSukQ-00029L-0j for 16377@debbugs.gnu.org; Wed, 05 Jul 2017 20:34:22 -0400 Original-Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 3AC0129DFA9 for <16377@debbugs.gnu.org>; Wed, 5 Jul 2017 19:33:59 -0500 (CDT) Original-Received: from gator3053.hostgator.com ([50.87.144.69]) by cmsmtp with SMTP id SujhdR9AuUy7vSujhdUVPk; Wed, 05 Jul 2017 19:33:37 -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=9pvhzsKC0ES+mNW+DOdwwC/TYF281E4JGMX5NQz8Xwg=; b=ivEybSJ7JlBddTP0A1ANNQ6kl2 JQPVzMZStcYaRm8D5SSJgDi5I3h1dmuDxpyTvNouO842EWnFGcrt8RDybhviWfdo9McfzdIgP8Qsc vqxN+6PU8EQy2BotpjVq7yDAtnqD1np+pZClCPn7YpwO0CAPN8FZ56CEVHnW/UIaXyKR5GG9JyxBQ JVYDINgnzj9Xl34K5elSbDD5MvkTPHtvY6YHd5/o3dMeMU9AXG8edIRrOVZl7GB+Be2aNEz/YLAkJ eP3asb1C+9LUIN/7lpFziNf35iC5+VCXjW5mxO1zsc6NOWaGA8CBSvjfhjmnBTBdvmXD8QbYyDJ5F I9DlVteA==; Original-Received: from cpe-45-48-239-195.socal.res.rr.com ([45.48.239.195]:56396 helo=server.local) by gator3053.hostgator.com with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.87) (envelope-from ) id 1dSuk2-004G3N-ET for 16377@debbugs.gnu.org; Wed, 05 Jul 2017 19:33:58 -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: 1dSuk2-004G3N-ET 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]:56396 X-Source-Auth: lawlist X-Email-Count: 6 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:134233 Archived-At: I have been working on a fork of undo-tree.el, and am interested in resolving this particular bug. I saw a recent post on reddit/emacs asking for help on this issue, and thought I would take this opportunity to chime-in. I am presently using the following modified version of primitive-undo in my forked version for 2 reasons. First, is to just throw a message instead of an error if bug 16377 shows its head. Second, I like to have the window-point update in the target window while I am doing a change in the undo-tree visualization buffer. I have no idea whether bypassing the error about 16377 is a bad thing, so I thought I'd share my function and let the experts decide how best to handle the bug. I also wanted to remind the powers that be that this bug still affects people in today's day and age. Another user on reddit added a comment stating he/she also had the same problem. I have seen this bug as well when playing with undo/redo in region. Thanks. (defun undo-tree--primitive-undo (n list) "Undo N records from the front of the list LIST. Return what remains of the list." (let ((arg n) ;; In a writable buffer, enable undoing read-only text that is ;; so because of text properties. (inhibit-read-only t) ;; Don't let `intangible' properties interfere with undo. (inhibit-point-motion-hooks t) ;; We use oldlist only to check for EQ. ++kfs (oldlist buffer-undo-list) (did-apply nil) (next nil) (window-of-current-buffer (get-buffer-window (current-buffer))) (selected-window (selected-window))) (while (> arg 0) (while (setq next (pop list)) ;Exit inner loop at undo boundary. ;; Handle an integer by setting point to that value. (pcase next ((pred integerp) (goto-char next) (unless (eq window-of-current-buffer selected-window) (set-window-point window-of-current-buffer next))) ;; Element (t . TIME) records previous modtime. ;; Preserve any flag of NONEXISTENT_MODTIME_NSECS or ;; UNKNOWN_MODTIME_NSECS. (`(t . ,time) ;; If this records an obsolete save ;; (not matching the actual disk file) ;; then don't mark unmodified. (when (or (equal time (visited-file-modtime)) (and (consp time) (equal (list (car time) (cdr time)) (visited-file-modtime)))) (when (fboundp 'unlock-buffer) (unlock-buffer)) (set-buffer-modified-p nil))) ;; Element (nil PROP VAL BEG . END) is property change. (`(nil . ,(or `(,prop ,val ,beg . ,end) pcase--dontcare)) (when (or (> (point-min) beg) (< (point-max) end)) (let ((debug-on-quit nil) (msg (concat "undo-tree--primative-undo (1 of 4):" " " "Changes to be undone are outside visible portion of buffer."))) (signal 'quit `(,msg)))) (put-text-property beg end prop val)) ;; Element (BEG . END) means range was inserted. (`(,(and beg (pred integerp)) . ,(and end (pred integerp))) ;; (and `(,beg . ,end) `(,(pred integerp) . ,(pred integerp))) ;; Ideally: `(,(pred integerp beg) . ,(pred integerp end)) (when (or (> (point-min) beg) (< (point-max) end)) (let ((debug-on-quit nil) (msg (concat "undo-tree--primative-undo (2 of 4):" " " "Changes to be undone are outside visible portion of buffer."))) (signal 'quit `(,msg)))) ;; Set point first thing, so that undoing this undo ;; does not send point back to where it is now. (goto-char beg) (delete-region beg end) (unless (eq window-of-current-buffer selected-window) (set-window-point window-of-current-buffer beg))) ;; Element (apply FUN . ARGS) means call FUN to undo. (`(apply . ,fun-args) (let ((currbuff (current-buffer))) (if (integerp (car fun-args)) ;; Long format: (apply DELTA START END FUN . ARGS). (pcase-let* ((`(,delta ,start ,end ,fun . ,args) fun-args) (start-mark (copy-marker start nil)) (end-mark (copy-marker end t))) (when (or (> (point-min) start) (< (point-max) end)) (let ((debug-on-quit nil) (msg (concat "undo-tree--primative-undo (3 of 4):" " " "Changes to be undone are outside visible portion of buffer."))) (signal 'quit `(,msg)))) (apply fun args) ;; Use `save-current-buffer'? ;; Check that the function did what the entry ;; said it would do. (unless (and (= start start-mark) (= (+ delta end) end-mark)) (error "Changes to be undone by function different than announced")) (set-marker start-mark nil) (set-marker end-mark nil)) (apply fun-args)) (unless (eq currbuff (current-buffer)) (error "Undo function switched buffer")) (setq did-apply t))) ;; Element (STRING . POS) means STRING was deleted. (`(,(and string (pred stringp)) . ,(and pos (pred integerp))) (when (let ((apos (abs pos))) (or (< apos (point-min)) (> apos (point-max)))) (let ((debug-on-quit nil) (msg (concat "undo-tree--primative-undo (4 of 4):" " " "Changes to be undone are outside visible portion of buffer."))) (signal 'quit `(,msg)))) (let (valid-marker-adjustments) ;; Check that marker adjustments which were recorded ;; with the (STRING . POS) record are still valid, ie ;; the markers haven't moved. We check their validity ;; before reinserting the string so as we don't need to ;; mind marker insertion-type. (while (and (markerp (car-safe (car list))) (integerp (cdr-safe (car list)))) (let* ((marker-adj (pop list)) (m (car marker-adj))) (and (eq (marker-buffer m) (current-buffer)) (= pos m) (push marker-adj valid-marker-adjustments)))) ;; Insert string and adjust point (if (< pos 0) (progn (goto-char (- pos)) (insert string)) (goto-char pos) (insert string) (goto-char pos)) (unless (eq window-of-current-buffer selected-window) (set-window-point window-of-current-buffer pos)) ;; Adjust the valid marker adjustments (dolist (adj valid-marker-adjustments) (set-marker (car adj) (- (car adj) (cdr adj)))))) ;; (MARKER . OFFSET) means a marker MARKER was adjusted by OFFSET. (`(,(and marker (pred markerp)) . ,(and offset (pred integerp))) (let ((msg (concat "undo-tree--primitive-undo: " (format "Encountered %S entry in undo list with no matching (TEXT . POS) entry" next)))) (message msg)) ;; Even though these elements are not expected in the undo ;; list, adjust them to be conservative for the 24.4 ;; release. (Bug#16818) (when (marker-buffer marker) (set-marker marker (- marker offset) (marker-buffer marker)))) (_ (if (eq next 'undo-tree-canary) (message "undo-tree--primitive-undo: catch-all found `%s'." next) (error "Unrecognized entry in undo list %S" next))))) (setq arg (1- arg))) ;; Make sure an apply entry produces at least one undo entry, ;; so the test in `undo' for continuing an undo series ;; will work right. (if (and did-apply (eq oldlist buffer-undo-list)) (setq buffer-undo-list (cons (list 'apply 'cdr nil) buffer-undo-list)))) list)