[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] fix/no-undo-boundary-on-secondary-buffer-change 1176b57 2/
From: |
Phillip Lord |
Subject: |
[Emacs-diffs] fix/no-undo-boundary-on-secondary-buffer-change 1176b57 2/4: Cosmetic changes. |
Date: |
Wed, 21 Oct 2015 07:09:58 +0000 |
branch: fix/no-undo-boundary-on-secondary-buffer-change
commit 1176b5750709c3ca99f6d832b21354621bd16346
Author: Phillip Lord <address@hidden>
Commit: Phillip Lord <address@hidden>
Cosmetic changes.
---
lisp/simple.el | 89 +++++++++++++++++++++++--------------------------------
src/cmds.c | 41 ++-----------------------
src/keyboard.c | 11 +++----
src/undo.c | 17 ++--------
4 files changed, 50 insertions(+), 108 deletions(-)
diff --git a/lisp/simple.el b/lisp/simple.el
index e090f8f..13e02a1 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2758,21 +2758,6 @@ 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.
-(defmacro undo-auto-message (&rest args)
- `(let ((msg
- (format ,@args)))
- (with-current-buffer
- (get-buffer-create
- "*undo-auto-log*")
- (goto-char (point-max))
- (insert msg)
- (insert "\n"))))
-
-(with-current-buffer
- (get-buffer-create "*undo-auto-log*")
- (setq buffer-undo-list t))
-(undo-auto-message "initialized")
-
(defvar-local undo-last-boundary nil
"Describe the cause of the last undo-boundary.
@@ -2790,15 +2775,21 @@ this section.
If it is equal to a number, then the last boundary was inserted
by an amalgamating command.")
-(defvar undo--last-command-amalgamating 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--amalgamating-commands '(self-insert-command delete-char))
+(defvar undo--this-command-amalgamating nil
+ "Non-nil if `this-command' should be amalgamated.
+This variable is set to nil by the command loop and is set by
+`undo--auto-pre-amalgamating-command'." )
-(defun undo-needs-boundary-p ()
+(defun undo--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 ()
+(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
@@ -2806,15 +2797,15 @@ these commands have been run if non-nil."
(and (integerp undo-last-boundary)
undo-last-boundary))
-(defun undo-ensure-boundary (reason)
+(defun undo--ensure-boundary (reason)
"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-last-boundary' for more information."
(when (and
buffer-undo-list
- (undo-needs-boundary-p))
+ (undo--needs-boundary-p))
(let ((last-amalgamating
- (undo-last-boundary-amalgamating-p)))
+ (undo--last-boundary-amalgamating-p)))
(when (and last-amalgamating
(eq 'amalgamate reason))
(setq reason (1+ last-amalgamating)))
@@ -2826,55 +2817,53 @@ REASON describes the reason that the boundary is being
added; see
(undo-auto-message "last-boundary now %s" undo-last-boundary)
t))
-(defun undo-auto-boundary (reason)
- "Checks recently change buffers and adds a boundary if necessary.
-
-See also `undo-ensure-boundary'."
- (dolist (b undo-undoably-changed-buffers)
+(defun undo--auto-boundary (reason)
+ "Check recently change 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)
(when (buffer-live-p b)
(with-current-buffer b
- (undo-ensure-boundary reason))))
- (setq undo-undoably-changed-buffers nil))
+ (undo--ensure-boundary reason))))
+ (setq undo--undoably-changed-buffers nil))
-(defvar undo-auto-current-boundary-timer nil
- "Current timer which will run `undo-auto-boundary-timer' or nil.")
-
-(defun undo-auto-boundary-timer ()
- "Timer which will run `undo-auto-boundary-timer'."
+(defun undo--auto-boundary-timer ()
+ "Timer which will run `undo--auto-boundary-timer'."
;;(undo-auto-message "running timer")
(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))))
-(defvar undo-undoably-changed-buffers nil
+(defvar undo--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--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--buffer-undoably-changed'.")
-(defun undo-auto-post-command-hook ()
+(defun undo--auto-post-command ()
+ "Add an `undo-boundary' is appropriate buffers."
(unless (eq buffer-undo-list t)
- (undo-auto-boundary
+ (undo--auto-boundary
(if undo--last-command-amalgamating
'amalgamate
'command))))
-(defun undo-auto-pre-amalgamating-command ()
+(defun undo--auto-pre-amalgamating-command ()
"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."
(condition-case err
(let ((last-amalgamating-count
- (undo-last-boundary-amalgamating-p)))
+ (undo--last-boundary-amalgamating-p)))
(setq undo--last-command-amalgamating t)
(when
last-amalgamating-count
@@ -2886,19 +2875,15 @@ calls have been made."
(setq buffer-undo-list
(cdr buffer-undo-list)))
(progn (undo-auto-message "Reset sic to 0")
- (setq undo-last-boundary 0)))))
+ (setq undo--last-boundary 0)))))
(error
(undo-auto-message "pre-command-error %s"
(error-message-string err)))))
-(defun undo-undoable-change ()
+(defun undo--undoable-change ()
"Called after every undoable buffer change."
- ;;(undo-auto-message "undo-auto adding-to-list %s" (current-buffer))
- (add-to-list 'undo-undoably-changed-buffers (current-buffer))
- (undo-auto-boundary-ensure-timer))
-
-(add-hook 'post-command-hook
- #'undo-auto-post-command-hook)
+ (add-to-list 'undo--undoably-changed-buffers (current-buffer))
+ (undo--auto-boundary-ensure-timer))
;; End auto-boundary section
diff --git a/src/cmds.c b/src/cmds.c
index 6931546..49c6a55 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -220,37 +220,6 @@ to t. */)
return Qnil;
}
-static int nonundocount;
-
-/* static void */
-/* remove_excessive_undo_boundaries (void) */
-/* { */
-/* bool remove_boundary = true; */
-
-/* if (!EQ (Vthis_command, KVAR (current_kboard, Vlast_command))) */
-/* nonundocount = 0; */
-
-/* if (NILP (Vexecuting_kbd_macro)) */
-/* { */
-/* if (nonundocount <= 0 || nonundocount >= 20) */
-/* { */
-/* remove_boundary = false; */
-/* nonundocount = 0; */
-/* } */
-/* nonundocount++; */
-/* } */
-
-/* if (remove_boundary */
-/* && CONSP (BVAR (current_buffer, undo_list)) */
-/* && NILP (XCAR (BVAR (current_buffer, undo_list))) */
-/* /\* Only remove auto-added boundaries, not boundaries */
-/* added by explicit calls to undo-boundary. *\/ */
-/* && EQ (BVAR (current_buffer, undo_list), */
-/* last_auto_keyboard_undo_boundary)) */
-/* /\* Remove the undo_boundary that was just pushed. *\/ */
-/* bset_undo_list (current_buffer, XCDR (BVAR (current_buffer,
undo_list))); */
-/* } */
-
DEFUN ("delete-char", Fdelete_char, Sdelete_char, 1, 2, "p\nP",
doc: /* Delete the following N characters (previous if N is negative).
Optional second arg KILLFLAG non-nil means kill instead (save in kill ring).
@@ -266,7 +235,7 @@ because it respects values of `delete-active-region' and
`overwrite-mode'. */)
CHECK_NUMBER (n);
if (abs (XINT (n)) < 2)
- call0(Qundo_auto_pre_amalgamating_command);
+ call0(Qundo__auto_pre_amalgamating_command);
pos = PT + XINT (n);
if (NILP (killflag))
@@ -312,9 +281,7 @@ At the end, it runs `post-self-insert-hook'. */)
error ("Negative repetition argument %"pI"d", XFASTINT (n));
if (XFASTINT (n) < 2)
- call0(Qundo_auto_pre_amalgamating_command);
-
- //remove_excessive_undo_boundaries ();
+ call0 (Qundo__auto_pre_amalgamating_command);
/* Barf if the key that invoked this was not a character. */
if (!CHARACTERP (last_command_event))
@@ -529,8 +496,8 @@ internal_self_insert (int c, EMACS_INT n)
void
syms_of_cmds (void)
{
- DEFSYM (Qundo_auto_pre_amalgamating_command,
- "undo-auto-pre-amalgamating-command" );
+ DEFSYM (Qundo__auto_pre_amalgamating_command,
+ "undo--auto-pre-amalgamating-command" );
DEFSYM (Qkill_forward_chars, "kill-forward-chars");
diff --git a/src/keyboard.c b/src/keyboard.c
index 852ceed..9117f25 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -1502,12 +1502,8 @@ command_loop_1 (void)
}
#endif
- Fset (Qundo__last_command_amalgamating, Qnil);
+ Fset (Qundo__this_command_amalgamating, Qnil);
- /* if (NILP (KVAR (current_kboard, Vprefix_arg))) /\* FIXME: Why?
--Stef *\/ */
- /* { */
- /* Fundo_auto_boundary(); */
- /* } */
call1 (Qcommand_execute, Vthis_command);
#ifdef HAVE_WINDOW_SYSTEM
@@ -1524,6 +1520,8 @@ command_loop_1 (void)
safe_run_hooks (Qpost_command_hook);
+ call0 (Qundo__auto_post_command);
+
/* If displaying a message, resize the echo area window to fit
that message's size exactly. */
if (!NILP (echo_area_buffer[0]))
@@ -11090,7 +11088,8 @@ syms_of_keyboard (void)
DEFSYM (Qpre_command_hook, "pre-command-hook");
DEFSYM (Qpost_command_hook, "post-command-hook");
- DEFSYM (Qundo__last_command_amalgamating, "undo--last-command-amalgamating");
+ DEFSYM (Qundo__this_command_amalgamating, "undo--this-command-amalgamating");
+ DEFSYM (Qundo__auto_post_command, "undo--auto-post-command");
DEFSYM (Qdeferred_action_function, "deferred-action-function");
DEFSYM (Qdelayed_warnings_hook, "delayed-warnings-hook");
diff --git a/src/undo.c b/src/undo.c
index 57ee037..d178757 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -74,8 +74,7 @@ record_point (ptrdiff_t pt)
if (at_boundary
&& current_buffer == last_boundary_buffer
&& last_boundary_position != pt)
-
- bset_undo_list (current_buffer,
+ bset_undo_list (current_buffer,
Fcons (make_number (last_boundary_position),
BVAR (current_buffer, undo_list)));
}
@@ -308,7 +307,7 @@ Returns nil if `buffer-undo-list' is t; that is there is no
undo list.
Otherwise, returns the size of `buffer-undo-list' in bytes.*/)
(Lisp_Object n)
{
- // We do not have an undo_list anyway.
+ /* We do not have an undo_list anyway.*/
if (EQ (BVAR (current_buffer, undo_list), Qt))
return Qnil;
@@ -331,7 +330,7 @@ Otherwise, returns the size of `buffer-undo-list' in
bytes.*/)
size_so_far += sizeof (struct Lisp_Cons);
if (CONSP (elt))
{
- // We have a boundary, so check we do not have too many.
+ /* We have a boundary, so check we do not have too many.*/
if (NILP (elt))
{
boundary_so_far = boundary_so_far + 1;
@@ -344,7 +343,7 @@ Otherwise, returns the size of `buffer-undo-list' in
bytes.*/)
+ SCHARS (XCAR (elt)));
}
- // and advance
+ /* and advance */
prev = next;
next = XCDR (next);
}
@@ -558,12 +557,4 @@ so it must make sure not to do a lot of consing. */);
DEFVAR_BOOL ("undo-inhibit-record-point", undo_inhibit_record_point,
doc: /* Non-nil means do not record `point' in
`buffer-undo-list'. */);
undo_inhibit_record_point = false;
-
- DEFVAR_LISP ("undo-first-undoable-change-hook",
- Vundo_first_undoable_change_hook,
- doc: /* Normal hook run when a buffer has its first recent
undo-able change.
-
-This hook will be run with `current-buffer' as the buffer that has
-changed. Recent means since the last boundary. */);
- Vundo_first_undoable_change_hook = Qnil;
}