diff options
| author | Phillip Lord | 2015-11-12 22:01:22 +0000 |
|---|---|---|
| committer | Phillip Lord | 2015-11-12 22:01:22 +0000 |
| commit | 20aa42e8204f8f0139ba3880cb32ddf88acc9bf4 (patch) | |
| tree | f77644c920b0f6a5a2f5849a064c6828c17530b1 /lisp | |
| parent | d2f73db50bec29724cb1324910350ad24420b174 (diff) | |
| parent | 44dfa86b7d382b84564d68472da1448d08f48129 (diff) | |
| download | emacs-20aa42e8204f8f0139ba3880cb32ddf88acc9bf4.tar.gz emacs-20aa42e8204f8f0139ba3880cb32ddf88acc9bf4.zip | |
; Merge branch 'fix/no-undo-boundary-on-secondary-buffer-change'
Conflicts:
src/cmds.c
src/keyboard.c
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/simple.el | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index 1f2f4fe0444..2781ad02b97 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -2768,6 +2768,143 @@ with < or <= based on USE-<." | |||
| 2768 | '(0 . 0))) | 2768 | '(0 . 0))) |
| 2769 | '(0 . 0))) | 2769 | '(0 . 0))) |
| 2770 | 2770 | ||
| 2771 | ;;; Default undo-boundary addition | ||
| 2772 | ;; | ||
| 2773 | ;; This section adds a new undo-boundary at either after a command is | ||
| 2774 | ;; called or in some cases on a timer called after a change is made in | ||
| 2775 | ;; any buffer. | ||
| 2776 | (defvar-local undo-auto--last-boundary-cause nil | ||
| 2777 | "Describe the cause of the last undo-boundary. | ||
| 2778 | |||
| 2779 | If `explicit', the last boundary was caused by an explicit call to | ||
| 2780 | `undo-boundary', that is one not called by the code in this | ||
| 2781 | section. | ||
| 2782 | |||
| 2783 | If it is equal to `timer', then the last boundary was inserted | ||
| 2784 | by `undo-auto--boundary-timer'. | ||
| 2785 | |||
| 2786 | If it is equal to `command', then the last boundary was inserted | ||
| 2787 | automatically after a command, that is by the code defined in | ||
| 2788 | this section. | ||
| 2789 | |||
| 2790 | If it is equal to a list, then the last boundary was inserted by | ||
| 2791 | an amalgamating command. The car of the list is the number of | ||
| 2792 | times an amalgamating command has been called, and the cdr are the | ||
| 2793 | buffers that were changed during the last command.") | ||
| 2794 | |||
| 2795 | (defvar undo-auto--current-boundary-timer nil | ||
| 2796 | "Current timer which will run `undo-auto--boundary-timer' or nil. | ||
| 2797 | |||
| 2798 | If set to non-nil, this will effectively disable the timer.") | ||
| 2799 | |||
| 2800 | (defvar undo-auto--this-command-amalgamating nil | ||
| 2801 | "Non-nil if `this-command' should be amalgamated. | ||
| 2802 | This variable is set to nil by `undo-auto--boundaries' and is set | ||
| 2803 | by `undo-auto--amalgamate'." ) | ||
| 2804 | |||
| 2805 | (defun undo-auto--needs-boundary-p () | ||
| 2806 | "Return non-nil if `buffer-undo-list' needs a boundary at the start." | ||
| 2807 | (car-safe buffer-undo-list)) | ||
| 2808 | |||
| 2809 | (defun undo-auto--last-boundary-amalgamating-number () | ||
| 2810 | "Return the number of amalgamating last commands or nil. | ||
| 2811 | Amalgamating commands are, by default, either | ||
| 2812 | `self-insert-command' and `delete-char', but can be any command | ||
| 2813 | that calls `undo-auto--amalgamate'." | ||
| 2814 | (car-safe undo-auto--last-boundary-cause)) | ||
| 2815 | |||
| 2816 | (defun undo-auto--ensure-boundary (cause) | ||
| 2817 | "Add an `undo-boundary' to the current buffer if needed. | ||
| 2818 | REASON describes the reason that the boundary is being added; see | ||
| 2819 | `undo-auto--last-boundary' for more information." | ||
| 2820 | (when (and | ||
| 2821 | (undo-auto--needs-boundary-p)) | ||
| 2822 | (let ((last-amalgamating | ||
| 2823 | (undo-auto--last-boundary-amalgamating-number))) | ||
| 2824 | (undo-boundary) | ||
| 2825 | (setq undo-auto--last-boundary-cause | ||
| 2826 | (if (eq 'amalgamate cause) | ||
| 2827 | (cons | ||
| 2828 | (if last-amalgamating (1+ last-amalgamating) 0) | ||
| 2829 | undo-auto--undoably-changed-buffers) | ||
| 2830 | cause))))) | ||
| 2831 | |||
| 2832 | (defun undo-auto--boundaries (cause) | ||
| 2833 | "Check recently changed buffers and add a boundary if necessary. | ||
| 2834 | REASON describes the reason that the boundary is being added; see | ||
| 2835 | `undo-last-boundary' for more information." | ||
| 2836 | (dolist (b undo-auto--undoably-changed-buffers) | ||
| 2837 | (when (buffer-live-p b) | ||
| 2838 | (with-current-buffer b | ||
| 2839 | (undo-auto--ensure-boundary cause)))) | ||
| 2840 | (setq undo-auto--undoably-changed-buffers nil)) | ||
| 2841 | |||
| 2842 | (defun undo-auto--boundary-timer () | ||
| 2843 | "Timer which will run `undo--auto-boundary-timer'." | ||
| 2844 | (setq undo-auto--current-boundary-timer nil) | ||
| 2845 | (undo-auto--boundaries 'timer)) | ||
| 2846 | |||
| 2847 | (defun undo-auto--boundary-ensure-timer () | ||
| 2848 | "Ensure that the `undo-auto-boundary-timer' is set." | ||
| 2849 | (unless undo-auto--current-boundary-timer | ||
| 2850 | (setq undo-auto--current-boundary-timer | ||
| 2851 | (run-at-time 10 nil #'undo-auto--boundary-timer)))) | ||
| 2852 | |||
| 2853 | (defvar undo-auto--undoably-changed-buffers nil | ||
| 2854 | "List of buffers that have changed recently. | ||
| 2855 | |||
| 2856 | This list is maintained by `undo-auto--undoable-change' and | ||
| 2857 | `undo-auto--boundaries' and can be affected by changes to their | ||
| 2858 | default values. | ||
| 2859 | |||
| 2860 | See also `undo-auto--buffer-undoably-changed'.") | ||
| 2861 | |||
| 2862 | (defun undo-auto--add-boundary () | ||
| 2863 | "Add an `undo-boundary' in appropriate buffers." | ||
| 2864 | (undo-auto--boundaries | ||
| 2865 | (if undo-auto--this-command-amalgamating | ||
| 2866 | 'amalgamate | ||
| 2867 | 'command)) | ||
| 2868 | (setq undo-auto--this-command-amalgamating nil)) | ||
| 2869 | |||
| 2870 | (defun undo-auto--amalgamate () | ||
| 2871 | "Amalgamate undo if necessary. | ||
| 2872 | This function can be called after an amalgamating command. It | ||
| 2873 | removes the previous `undo-boundary' if a series of such calls | ||
| 2874 | have been made. By default `self-insert-command' and | ||
| 2875 | `delete-char' are the only amalgamating commands, although this | ||
| 2876 | function could be called by any command wishing to have this | ||
| 2877 | behaviour." | ||
| 2878 | (let ((last-amalgamating-count | ||
| 2879 | (undo-auto--last-boundary-amalgamating-number))) | ||
| 2880 | (setq undo-auto--this-command-amalgamating t) | ||
| 2881 | (when | ||
| 2882 | last-amalgamating-count | ||
| 2883 | (if | ||
| 2884 | (and | ||
| 2885 | (< last-amalgamating-count 20) | ||
| 2886 | (eq this-command last-command)) | ||
| 2887 | ;; Amalgamate all buffers that have changed. | ||
| 2888 | (dolist (b (cdr undo-auto--last-boundary-cause)) | ||
| 2889 | (when (buffer-live-p b) | ||
| 2890 | (with-current-buffer | ||
| 2891 | b | ||
| 2892 | (when | ||
| 2893 | ;; The head of `buffer-undo-list' is nil. | ||
| 2894 | ;; `car-safe' doesn't work because | ||
| 2895 | ;; `buffer-undo-list' need not be a list! | ||
| 2896 | (and (listp buffer-undo-list) | ||
| 2897 | (not (car buffer-undo-list))) | ||
| 2898 | (setq buffer-undo-list | ||
| 2899 | (cdr buffer-undo-list)))))) | ||
| 2900 | (setq undo-auto--last-boundary-cause 0))))) | ||
| 2901 | |||
| 2902 | (defun undo-auto--undoable-change () | ||
| 2903 | "Called after every undoable buffer change." | ||
| 2904 | (add-to-list 'undo-auto--undoably-changed-buffers (current-buffer)) | ||
| 2905 | (undo-auto--boundary-ensure-timer)) | ||
| 2906 | ;; End auto-boundary section | ||
| 2907 | |||
| 2771 | (defcustom undo-ask-before-discard nil | 2908 | (defcustom undo-ask-before-discard nil |
| 2772 | "If non-nil ask about discarding undo info for the current command. | 2909 | "If non-nil ask about discarding undo info for the current command. |
| 2773 | Normally, Emacs discards the undo info for the current command if | 2910 | Normally, Emacs discards the undo info for the current command if |