[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] fix/no-undo-boundary-on-secondary-buffer-change 44242de 2/
From: |
Phillip Lord |
Subject: |
[Emacs-diffs] fix/no-undo-boundary-on-secondary-buffer-change 44242de 2/2: Rests of Stefan's changes. |
Date: |
Tue, 10 Nov 2015 20:47:12 +0000 |
branch: fix/no-undo-boundary-on-secondary-buffer-change
commit 44242de8c0ed8e62650ed97b7d1bd94f1e68221f
Author: Phillip Lord <address@hidden>
Commit: Phillip Lord <address@hidden>
Rests of Stefan's changes.
---
lisp/simple.el | 131 +++++++++++++++++++++++++++----------------------------
src/cmds.c | 7 ++-
src/undo.c | 8 ++--
3 files changed, 72 insertions(+), 74 deletions(-)
diff --git a/lisp/simple.el b/lisp/simple.el
index 306bc67..821144c 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2759,17 +2759,17 @@ with < or <= based on USE-<."
;; This section adds a new undo-boundary at either after a command is
;; called or in some cases on a timer called after a change is made in
;; any buffer.
-(defvar-local undo-last-boundary nil
+(defvar-local undo-auto--last-boundary-cause nil
"Describe the cause of the last undo-boundary.
-If 'explicit, the last boundary was caused by an explicit call to
+If `explicit', the last boundary was caused by an explicit call to
`undo-boundary', that is one not called by the code in this
section.
-If it is equal to 'timer, then the last boundary was inserted
-by `undo-auto-boundary-timer'.
+If it is equal to `timer', then the last boundary was inserted
+by `undo-auto--boundary-timer'.
-If it is equal to 'command, then the last boundary was inserted
+If it is equal to `command', then the last boundary was inserted
automatically after a command, that is by the code defined in
this section.
@@ -2778,103 +2778,100 @@ an amalgamating command. The car of the list is the
number of
times a amalgamating command has been called, and the cdr are the
buffers that were changed during the last command.")
-(defvar undo-auto-current-boundary-timer nil
- "Current timer which will run `undo-auto-boundary-timer' or nil.
+(defvar undo-auto--current-boundary-timer nil
+ "Current timer which will run `undo-auto--boundary-timer' or nil.
If set to non-nil, this will effectively disable the timer.")
-(defvar undo--this-command-amalgamating nil
+(defvar undo-auto--this-command-amalgamating nil
"Non-nil if `this-command' should be amalgamated.
-This variable is set to nil by `undo--auto-boundary' and is set
+This variable is set to nil by `undo-auto--boundary' and is set
by `undo-auto--amalgamate'." )
-(defun undo--needs-boundary-p ()
+(defun undo-auto--needs-boundary-p ()
"Return non-nil if `buffer-undo-list' needs a boundary at the start."
(car-safe buffer-undo-list))
-(defun undo--last-boundary-amalgamating-p ()
- "Return non-nil if the last boundary was from an amalgamating command.
-Amalgamating commands are either `self-insert-command' and
-`delete-char'. The return value is actual number of times one of
-these commands have been run if non-nil."
- (car-safe undo-last-boundary))
+(defun undo-auto--last-boundary-amalgamating-number ()
+ "Return the number of amalgamating last commands or nil.
+Amalgamating commands are, by default, either
+`self-insert-command' and `delete-char', but can be any command
+that calls `undo-auto--amalgamate'."
+ (car-safe undo-auto--last-boundary-cause))
-(defun undo--ensure-boundary (reason)
+(defun undo-auto--ensure-boundary (cause)
"Add an `undo-boundary' to the current buffer if needed.
REASON describes the reason that the boundary is being added; see
-`undo-last-boundary' for more information."
+`undo-auto--last-boundary' for more information."
(when (and
- buffer-undo-list
- (undo--needs-boundary-p))
+ (undo-auto--needs-boundary-p))
(let ((last-amalgamating
- (undo--last-boundary-amalgamating-p)))
- (when (and last-amalgamating
- (eq 'amalgamate reason))
- (setq reason
- (cons (1+ last-amalgamating)
- undo--undoably-changed-buffers)))
+ (undo-auto--last-boundary-amalgamating-number)))
(undo-boundary)
- (setq undo-last-boundary
- (if (eq 'amalgamate reason)
- (cons 0 undo--undoably-changed-buffers)
- reason)))
- t))
-
-(defun undo--auto-boundary (reason)
- "Check recently change buffers and add a boundary if necessary.
+ (setq undo-auto--last-boundary-cause
+ (if (eq 'amalgamate cause)
+ (cons
+ (if last-amalgamating (1+ last-amalgamating) 0)
+ undo-auto--undoably-changed-buffers)
+ cause)))))
+
+(defun undo-auto--boundary (cause)
+ "Check recently changed buffers and add a boundary if necessary.
REASON describes the reason that the boundary is being added; see
`undo-last-boundary' for more information."
- (dolist (b undo--undoably-changed-buffers)
+ (dolist (b undo-auto--undoably-changed-buffers)
(when (buffer-live-p b)
(with-current-buffer b
- (undo--ensure-boundary reason))))
- (setq undo--undoably-changed-buffers nil))
+ (undo-auto--ensure-boundary cause))))
+ (setq undo-auto--undoably-changed-buffers nil))
-(defun undo--auto-boundary-timer ()
+(defun undo-auto--boundary-timer ()
"Timer which will run `undo--auto-boundary-timer'."
- (undo--auto-boundary 'timer)
- (setq undo-auto-current-boundary-timer nil))
+ (undo-auto--boundary 'timer)
+ (setq undo-auto--current-boundary-timer nil))
-(defun undo--auto-boundary-ensure-timer ()
+(defun undo-auto--boundary-ensure-timer ()
"Ensure that the `undo-auto-boundary-timer' is set."
- (unless undo-auto-current-boundary-timer
- (setq undo-auto-current-boundary-timer
- (run-at-time 10 nil 'undo--auto-boundary-timer))))
+ (unless undo-auto--current-boundary-timer
+ (setq undo-auto--current-boundary-timer
+ (run-at-time 10 nil #'undo-auto--boundary-timer))))
-(defvar undo--undoably-changed-buffers nil
+(defvar undo-auto--undoably-changed-buffers nil
"List of buffers that have changed recently.
-This list is maintained by `undo--undoable-change' and
-`undo--auto-boundary' and can be affected by changes to their
+This list is maintained by `undo-auto--undoable-change' and
+`undo-auto--boundary' and can be affected by changes to their
default values.
-See also `undo--buffer-undoably-changed'.")
+See also `undo-auto--buffer-undoably-changed'.")
-(defun undo--auto-add-boundary ()
- "Add an `undo-boundary' is appropriate buffers."
- (unless (eq buffer-undo-list t)
- (undo--auto-boundary
- (if undo--this-command-amalgamating
- 'amalgamate
- 'command)))
- (setq undo--this-command-amalgamating nil))
+(defun undo-auto--add-boundary ()
+ "Add an `undo-boundary' in appropriate buffers."
+ (undo-auto--boundary
+ (if undo-auto--this-command-amalgamating
+ 'amalgamate
+ 'command))
+ (setq undo-auto--this-command-amalgamating nil))
(defun undo-auto--amalgamate ()
"Amalgamate undo if necessary.
-This function is called before `self-insert-command', and removes
-the previous `undo-boundary' if a series of `self-insert-command'
-calls have been made."
+This function can be called after an amalgamating command. It
+removes the previous `undo-boundary' if a series of such calls
+have been made. By default `self-insert-command' and
+`delete-char' are the only amalgamating commands, although this
+function could be called by any command wishing to have this
+behaviour."
(let ((last-amalgamating-count
- (undo--last-boundary-amalgamating-p)))
- (setq undo--this-command-amalgamating t)
+ (undo-auto--last-boundary-amalgamating-number)))
+ (setq undo-auto--this-command-amalgamating t)
(when
last-amalgamating-count
(if
(and
(< last-amalgamating-count 20)
(eq this-command last-command))
- ;; amalgamate all buffers that have changed
- (dolist (b (cdr undo-last-boundary))
+ ;; Amalgamate all buffers that have changed.
+ (dolist (b (cdr undo-auto--last-boundary-cause))
(when (buffer-live-p b)
(with-current-buffer
b
@@ -2886,12 +2883,12 @@ calls have been made."
(not (car buffer-undo-list)))
(setq buffer-undo-list
(cdr buffer-undo-list))))))
- (setq undo-last-boundary 0)))))
+ (setq undo-auto--last-boundary-cause 0)))))
-(defun undo--undoable-change ()
+(defun undo-auto--undoable-change ()
"Called after every undoable buffer change."
- (add-to-list 'undo--undoably-changed-buffers (current-buffer))
- (undo--auto-boundary-ensure-timer))
+ (add-to-list 'undo-auto--undoably-changed-buffers (current-buffer))
+ (undo-auto--boundary-ensure-timer))
;; End auto-boundary section
(defcustom undo-ask-before-discard nil
diff --git a/src/cmds.c b/src/cmds.c
index 39de5fc..2a4d0a1 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -291,7 +291,7 @@ At the end, it runs `post-self-insert-hook'. */)
XINT (last_command_event));
int val = internal_self_insert (character, XFASTINT (n));
if (val==2)
- Fset (Qundo__this_command_amalgamating, Qnil);
+ Fset (Qundo_auto__this_command_amalgamating, Qnil);
frame_make_pointer_invisible (SELECTED_FRAME ());
}
@@ -496,8 +496,9 @@ internal_self_insert (int c, EMACS_INT n)
void
syms_of_cmds (void)
{
- DEFSYM (Qundo_auto__amalgamate,
- "undo-auto--amalgamate" );
+ DEFSYM (Qundo_auto__amalgamate, "undo-auto--amalgamate");
+ DEFSYM (Qundo_auto__this_command_amalgamating,
+ "undo-auto--this-command-amalgamating");
DEFSYM (Qkill_forward_chars, "kill-forward-chars");
diff --git a/src/undo.c b/src/undo.c
index 4958aa5..293e181 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -40,7 +40,7 @@ static Lisp_Object pending_boundary;
void
run_undoable_change ()
{
- call0 (Qundo__undoable_change);
+ call0 (Qundo_auto__undoable_change);
}
/* Record point as it was at beginning of this command (if necessary)
@@ -293,7 +293,7 @@ but another undo command will undo to the previous
boundary. */)
last_boundary_position = PT;
last_boundary_buffer = current_buffer;
- Fset (Qundo_last_boundary, Qexplicit);
+ Fset (Qundo_auto__last_boundary, Qexplicit);
return Qnil;
}
@@ -436,8 +436,8 @@ void
syms_of_undo (void)
{
DEFSYM (Qinhibit_read_only, "inhibit-read-only");
- DEFSYM (Qundo__undoable_change, "undo--undoable-change");
- DEFSYM (Qundo_last_boundary, "undo-last-boundary");
+ DEFSYM (Qundo_auto__undoable_change, "undo-auto--undoable-change");
+ DEFSYM (Qundo_auto__last_boundary, "undo-auto--last-boundary");
DEFSYM (Qexplicit, "explicit");
/* Marker for function call undo list elements. */