[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] fix/no-undo-boundary-on-secondary-buffer-change f59d1be: M
From: |
Phillip Lord |
Subject: |
[Emacs-diffs] fix/no-undo-boundary-on-secondary-buffer-change f59d1be: Move undo amalgamation to lisp. |
Date: |
Mon, 05 Oct 2015 13:41:19 +0000 |
branch: fix/no-undo-boundary-on-secondary-buffer-change
commit f59d1beb36c2aceb59a902cbc8ca97c598a8388a
Author: Phillip Lord <address@hidden>
Commit: Phillip Lord <address@hidden>
Move undo amalgamation to lisp.
---
lisp/simple.el | 85 ++++++++++++++++++++++++++++++++-----------------------
src/cmds.c | 65 ++++++++++++++++++++++--------------------
src/keyboard.c | 15 ++-------
src/lisp.h | 1 -
src/undo.c | 18 ++++-------
5 files changed, 94 insertions(+), 90 deletions(-)
diff --git a/lisp/simple.el b/lisp/simple.el
index 7aa3598..16cba7e 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2767,45 +2767,32 @@ with < or <= based on USE-<."
;; this case, the `undo-outer-limit' machinary will operate; this is
;; considered to be exceptional the user is warned.
(defmacro undo-auto-message (&rest args)
- `(with-current-buffer
- (get-buffer-create
- "*undo-auto-log*")
- (goto-char (point-max))
- (insert (format ,@args))
- (insert "\n")))
+ `(let ((msg
+ (format ,@args)))
+ (with-current-buffer
+ (get-buffer-create
+ "*undo-auto-log*")
+ (goto-char (point-max))
+ (insert msg)
+ (insert "\n")
+ (when (get-buffer-window)
+ (recenter))
+ )))
(undo-auto-message "initialized")
(with-current-buffer "*undo-auto-log*"
(setq buffer-undo-list t))
(defun undo-needs-boundary-p ()
- "Returns t if `buffer-undo-list' needs a boundary at the start."
+ "Returns non-nil if `buffer-undo-list' needs a boundary at the start."
(and
- ;; buffer-undo-list can be t
+ ;; `buffer-undo-list' can be t.
(listp buffer-undo-list)
- ;; first element of buffer-undo-list is nil
- (not (car buffer-undo-list))))
+ ;; The first element of buffer-undo-list is not nil.
+ (car buffer-undo-list)))
(defun undo-ensure-boundary ()
- "Add an `undo-boundary' if `buffer-undo-list' is long.
-
-Return t if an undo boundary has been added.
-
-Normally, Emacs will only garbage collect data from
-`buffer-undo-list' when this list is longer than `undo-limit'. It
-then collects data from after the first `undo-boundary' after
-`undo-limit'. If there are no boundaries in the list,
-`buffer-undo-list' will grow until it reaches
-`undo-outer-limit' (by default a much larger value than
-`undo-limit'), when it will discard the data anyway. In this
-case, however, it is treated as an exceptional case, and the a
-warning is signalled.
-
-This function add an `undo-boundary' to `buffer-undo-list' if
-there is no other `undo-boundary', and `buffer-undo-list' is
-longer than `undo-limit'. It provides a useful default mechanism
-for adding an `undo-boundary' which retains data where possible,
-without signalling warnings to the user."
+ ""
(when (and
buffer-undo-list
(undo-needs-boundary-p))
@@ -2820,7 +2807,6 @@ See also `undo-ensure-boundary'."
(lambda (b)
(when (buffer-live-p b)
(with-current-buffer b
- (undo-auto-message "undo-auto-boundary checking %s" b)
(when (undo-ensure-boundary)
(undo-auto-message "undo-auto-boundary boundary added %s" b)))))
undo-undoably-changed-buffers)
@@ -2831,14 +2817,12 @@ See also `undo-ensure-boundary'."
(defun undo-auto-boundary-timer ()
"Timer which will run `undo-auto-boundary-timer'."
- (undo-auto-message "running on timer")
(undo-auto-boundary)
(setq undo-auto-current-boundary-timer nil))
(defun undo-auto-boundary-ensure-timer ()
"Ensure that the `undo-auto-boundary-timer is set."
(unless undo-auto-current-boundary-timer
- (undo-auto-message "Starting timer")
(setq undo-auto-current-boundary-timer
(run-at-time 10 nil 'undo-auto-boundary-timer))))
@@ -2854,15 +2838,44 @@ See also `undo-buffer-undoably-changed'.")
(defun undo-auto-boundary-first-undoable-change-hook ()
"Default value of `undo-boundary-first-undoable-change-hook'."
- (undo-auto-message "undo-auto adding-to-list %s" (current-buffer))
+ ;;(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 'undo-first-undoable-change-hook
- #'undo-auto-boundary-first-undoable-change-hook)
+(defun undo-auto-post-command-hook ()
+ (unless (eq buffer-undo-list t)
+ (undo-auto-boundary)))
+
+(defun undo-auto-pre-command-hook()
+ (when (and (eq last-command 'self-insert-command)
+ (eq this-command 'self-insert-command))
+ ;; As last-command was s-i-c, there should be "insert" cons just
+ ;; before this. We need to check that there have not been too many
insertions
+ (let ((last-before-nil
+ (cadr buffer-undo-list)))
+ (when
+ (> 20
+ (- (cdr last-before-nil)
+ (car last-before-nil)))
+ (undo-auto-message "Removing last undo")
+ (setq buffer-undo-list
+ (cdr buffer-undo-list))))))
+
+(defun undo-auto-boundary-change (_ _ _)
+ ;;(undo-auto-message "undo-auto adding-to-list %s" (current-buffer))
+ (unless (eq buffer-undo-list t)
+ (add-to-list 'undo-undoably-changed-buffers
+ (current-buffer))
+ (undo-auto-boundary-ensure-timer)))
+
+(add-hook 'after-change-functions
+ #'undo-auto-boundary-change)
(add-hook 'post-command-hook
- #'undo-auto-boundary)
+ #'undo-auto-post-command-hook)
+
+(add-hook 'pre-command-hook
+ #'undo-auto-pre-command-hook)
(defcustom undo-ask-before-discard nil
"If non-nil ask about discarding undo info for the current command.
diff --git a/src/cmds.c b/src/cmds.c
index a975a8e..8e30417 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -222,33 +222,34 @@ to t. */)
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_undo_boundary))
- /* Remove the undo_boundary that was just pushed. */
- bset_undo_list (current_buffer, XCDR (BVAR (current_buffer, undo_list)));
-}
+/* 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).
@@ -264,8 +265,9 @@ because it respects values of `delete-active-region' and
`overwrite-mode'. */)
CHECK_NUMBER (n);
- if (abs (XINT (n)) < 2)
- remove_excessive_undo_boundaries ();
+ // PWL
+ //if (abs (XINT (n)) < 2)
+ // remove_excessive_undo_boundaries ();
pos = PT + XINT (n);
if (NILP (killflag))
@@ -310,8 +312,9 @@ At the end, it runs `post-self-insert-hook'. */)
if (XFASTINT (n) < 0)
error ("Negative repetition argument %"pI"d", XFASTINT (n));
- if (XFASTINT (n) < 2)
- remove_excessive_undo_boundaries ();
+ // PWL remove for now
+ //if (XFASTINT (n) < 2)
+ //remove_excessive_undo_boundaries ();
/* Barf if the key that invoked this was not a character. */
if (!CHARACTERP (last_command_event))
diff --git a/src/keyboard.c b/src/keyboard.c
index 5f86675..29307cb 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -1278,9 +1278,6 @@ static int read_key_sequence (Lisp_Object *, int,
Lisp_Object,
bool, bool, bool, bool);
static void adjust_point_for_property (ptrdiff_t, bool);
-/* The last boundary auto-added to buffer-undo-list. */
-Lisp_Object last_undo_boundary;
-
/* FIXME: This is wrong rather than test window-system, we should call
a new set-selection, which will then dispatch to x-set-selection, or
tty-set-selection, or w32-set-selection, ... */
@@ -1505,14 +1502,10 @@ command_loop_1 (void)
}
#endif
- if (NILP (KVAR (current_kboard, Vprefix_arg))) /* FIXME: Why?
--Stef */
- {
- Lisp_Object undo = BVAR (current_buffer, undo_list);
- Fundo_boundary ();
- last_undo_boundary
- = (EQ (undo, BVAR (current_buffer, undo_list))
- ? Qnil : BVAR (current_buffer, undo_list));
- }
+ /* if (NILP (KVAR (current_kboard, Vprefix_arg))) /\* FIXME: Why?
--Stef *\/ */
+ /* { */
+ /* Fundo_auto_boundary(); */
+ /* } */
call1 (Qcommand_execute, Vthis_command);
#ifdef HAVE_WINDOW_SYSTEM
diff --git a/src/lisp.h b/src/lisp.h
index 02109d7..aaf52bd 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4174,7 +4174,6 @@ extern void syms_of_casetab (void);
extern Lisp_Object echo_message_buffer;
extern struct kboard *echo_kboard;
extern void cancel_echoing (void);
-extern Lisp_Object last_undo_boundary;
extern bool input_pending;
#ifdef HAVE_STACK_OVERFLOW_HANDLING
extern sigjmp_buf return_to_command_loop;
diff --git a/src/undo.c b/src/undo.c
index a5776be..509b972 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -37,25 +37,22 @@ static ptrdiff_t last_boundary_position;
an undo-boundary. */
static Lisp_Object pending_boundary;
-
/*
Run the first-undo-hook if needed
*/
void
-run_first_undo_hook()
+run_first_undo_hook ()
{
Lisp_Object list;
- list = BVAR(current_buffer, undo_list);
+ list = BVAR (current_buffer, undo_list);
- if (CONSP (list) && NILP (XCAR (list)))
+ if (NILP (list) || CONSP (list) && NILP (XCAR (list)))
{
- safe_run_hooks(Qundo_first_undoable_change_hook);
+ safe_run_hooks (Qundo_first_undoable_change_hook);
}
}
-
-
/* Record point as it was at beginning of this command (if necessary)
and prepare the undo info for recording a change.
PT is the position of point that will naturally occur as a result of the
@@ -74,7 +71,7 @@ record_point (ptrdiff_t pt)
if (NILP (pending_boundary))
pending_boundary = Fcons (Qnil, Qnil);
- run_first_undo_hook(current_buffer);
+ run_first_undo_hook ();
at_boundary = ! CONSP (BVAR (current_buffer, undo_list))
|| NILP (XCAR (BVAR (current_buffer, undo_list)));
@@ -147,7 +144,7 @@ record_marker_adjustments (ptrdiff_t from, ptrdiff_t to)
pending_boundary = Fcons (Qnil, Qnil);
- run_first_undo_hook(current_buffer);
+ run_first_undo_hook ();
for (m = BUF_MARKERS (current_buffer); m; m = m->next)
{
@@ -264,7 +261,7 @@ record_property_change (ptrdiff_t beg, ptrdiff_t length,
/* Switch temporarily to the buffer that was changed. */
current_buffer = buf;
- run_first_undo_hook(buf);
+ run_first_undo_hook ();
if (MODIFF <= SAVE_MODIFF)
record_first_change ();
@@ -278,7 +275,6 @@ record_property_change (ptrdiff_t beg, ptrdiff_t length,
current_buffer = obuf;
}
-
DEFUN ("undo-boundary", Fundo_boundary, Sundo_boundary, 0, 0, 0,
doc: /* Mark a boundary between units of undo.
An undo command will stop at this point,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] fix/no-undo-boundary-on-secondary-buffer-change f59d1be: Move undo amalgamation to lisp.,
Phillip Lord <=