diff options
| author | Luc Teirlinck | 2005-01-30 00:32:39 +0000 |
|---|---|---|
| committer | Luc Teirlinck | 2005-01-30 00:32:39 +0000 |
| commit | 28cb725d59def882d9346d05ad8a93059ecbc44f (patch) | |
| tree | c68c5f3ec43f3dfc1c3ebc530eb5420ce624323d | |
| parent | 49b8b5dcb303bb12ab4f503c42ed1d7c1e6a2132 (diff) | |
| download | emacs-28cb725d59def882d9346d05ad8a93059ecbc44f.tar.gz emacs-28cb725d59def882d9346d05ad8a93059ecbc44f.zip | |
(undo-ask-before-discard): New var.
(undo-outer-limit-truncate): Implement it.
(undo-extra-outer-limit): Doc update.
| -rw-r--r-- | lisp/simple.el | 83 |
1 files changed, 63 insertions, 20 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index b195874e2f6..e6b445f9ec7 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -1525,33 +1525,76 @@ is not *inside* the region START...END." | |||
| 1525 | '(0 . 0))) | 1525 | '(0 . 0))) |
| 1526 | '(0 . 0))) | 1526 | '(0 . 0))) |
| 1527 | 1527 | ||
| 1528 | (defcustom undo-ask-before-discard t | ||
| 1529 | "If non-nil ask about discarding undo info for the current command. | ||
| 1530 | Normally, Emacs discards the undo info for the current command if | ||
| 1531 | it exceeds `undo-outer-limit'. But if you set this option | ||
| 1532 | non-nil, it asks in the echo area whether to discard the info. | ||
| 1533 | If you answer no, there a slight risk that Emacs might crash, so | ||
| 1534 | only do it if you really want to undo the command. | ||
| 1535 | |||
| 1536 | This option is mainly intended for debugging. You have to be | ||
| 1537 | careful if you use it for other purposes. Garbage collection is | ||
| 1538 | inhibited while the question is asked, meaning that Emacs might | ||
| 1539 | leak memory. So you should make sure that you do not wait | ||
| 1540 | excessively long before answering the question." | ||
| 1541 | :type 'boolean | ||
| 1542 | :group 'undo | ||
| 1543 | :version "21.4") | ||
| 1544 | |||
| 1528 | (defvar undo-extra-outer-limit nil | 1545 | (defvar undo-extra-outer-limit nil |
| 1529 | "If non-nil, an extra level of size that's ok in an undo item. | 1546 | "If non-nil, an extra level of size that's ok in an undo item. |
| 1530 | We don't ask the user about truncating the undo list until the | 1547 | We don't ask the user about truncating the undo list until the |
| 1531 | current item gets bigger than this amount.") | 1548 | current item gets bigger than this amount. |
| 1549 | |||
| 1550 | This variable only matters if `undo-ask-before-discard' is non-nil.") | ||
| 1532 | (make-variable-buffer-local 'undo-extra-outer-limit) | 1551 | (make-variable-buffer-local 'undo-extra-outer-limit) |
| 1533 | 1552 | ||
| 1534 | ;; When the first undo batch in an undo list is longer than undo-outer-limit, | 1553 | ;; When the first undo batch in an undo list is longer than |
| 1535 | ;; this function gets called to ask the user what to do. | 1554 | ;; undo-outer-limit, this function gets called to warn the user that |
| 1536 | ;; Garbage collection is inhibited around the call, | 1555 | ;; the undo info for the current command was discarded. Garbage |
| 1537 | ;; so it had better not do a lot of consing. | 1556 | ;; collection is inhibited around the call, so it had better not do a |
| 1557 | ;; lot of consing. | ||
| 1538 | (setq undo-outer-limit-function 'undo-outer-limit-truncate) | 1558 | (setq undo-outer-limit-function 'undo-outer-limit-truncate) |
| 1539 | (defun undo-outer-limit-truncate (size) | 1559 | (defun undo-outer-limit-truncate (size) |
| 1540 | (when (or (null undo-extra-outer-limit) | 1560 | (if undo-ask-before-discard |
| 1541 | (> size undo-extra-outer-limit)) | 1561 | (when (or (null undo-extra-outer-limit) |
| 1542 | ;; Don't ask the question again unless it gets even bigger. | 1562 | (> size undo-extra-outer-limit)) |
| 1543 | ;; This applies, in particular, if the user quits from the question. | 1563 | ;; Don't ask the question again unless it gets even bigger. |
| 1544 | ;; Such a quit quits out of GC, but something else will call GC | 1564 | ;; This applies, in particular, if the user quits from the question. |
| 1545 | ;; again momentarily. It will call this function again, | 1565 | ;; Such a quit quits out of GC, but something else will call GC |
| 1546 | ;; but we don't want to ask the question again. | 1566 | ;; again momentarily. It will call this function again, |
| 1547 | (setq undo-extra-outer-limit (+ size 50000)) | 1567 | ;; but we don't want to ask the question again. |
| 1548 | (if (let (use-dialog-box) | 1568 | (setq undo-extra-outer-limit (+ size 50000)) |
| 1549 | (yes-or-no-p (format "Buffer %s undo info is %d bytes long; discard it? " | 1569 | (if (let (use-dialog-box track-mouse executing-kbd-macro ) |
| 1550 | (buffer-name) size))) | 1570 | (yes-or-no-p (format "Buffer %s undo info is %d bytes long; discard it? " |
| 1551 | (progn (setq buffer-undo-list nil) | 1571 | (buffer-name) size))) |
| 1552 | (setq undo-extra-outer-limit nil) | 1572 | (progn (setq buffer-undo-list nil) |
| 1553 | t) | 1573 | (setq undo-extra-outer-limit nil) |
| 1554 | nil))) | 1574 | t) |
| 1575 | nil)) | ||
| 1576 | (display-warning '(undo discard-info) | ||
| 1577 | (concat | ||
| 1578 | (format "Buffer %s undo info was %d bytes long.\n" | ||
| 1579 | (buffer-name) size) | ||
| 1580 | "The undo info was discarded because it exceeded \ | ||
| 1581 | `undo-outer-limit'. | ||
| 1582 | |||
| 1583 | This is normal if you executed a command that made a huge change | ||
| 1584 | to the buffer. In that case, to prevent similar problems in the | ||
| 1585 | future, set `undo-outer-limit' to a value that is large enough to | ||
| 1586 | cover the maximum size of normal changes you expect a single | ||
| 1587 | command to make, but not so large that it might exceed the | ||
| 1588 | maximum memory allotted to Emacs. | ||
| 1589 | |||
| 1590 | If you did not execute any such command, the situation is | ||
| 1591 | probably due to a bug and you should report it. | ||
| 1592 | |||
| 1593 | You can disable the popping up of this buffer by adding the entry | ||
| 1594 | \(undo discard-info) to the user option `warning-suppress-types'.\n") | ||
| 1595 | :warning) | ||
| 1596 | (setq buffer-undo-list nil) | ||
| 1597 | t)) | ||
| 1555 | 1598 | ||
| 1556 | (defvar shell-command-history nil | 1599 | (defvar shell-command-history nil |
| 1557 | "History list for some commands that read shell commands.") | 1600 | "History list for some commands that read shell commands.") |