aboutsummaryrefslogtreecommitdiffstats
path: root/src/undo.c
diff options
context:
space:
mode:
authorK. Handa2016-01-03 17:53:43 +0900
committerK. Handa2016-01-03 17:53:43 +0900
commitfb6d826c69939c2d016c1b824d4e9bcb53d9e643 (patch)
treeb9ce862d6cbe25e740203421984df21e4cbadbf4 /src/undo.c
parent536f48e9a2251b9e654ea974bd90ff2f40218753 (diff)
parent91917dd58ec5278e555b9c693a830749083e8f89 (diff)
downloademacs-fb6d826c69939c2d016c1b824d4e9bcb53d9e643.tar.gz
emacs-fb6d826c69939c2d016c1b824d4e9bcb53d9e643.zip
Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs
Diffstat (limited to 'src/undo.c')
-rw-r--r--src/undo.c69
1 files changed, 27 insertions, 42 deletions
diff --git a/src/undo.c b/src/undo.c
index 214beaeb9ea..1cc6de48393 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -22,10 +22,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 22
23#include "lisp.h" 23#include "lisp.h"
24#include "buffer.h" 24#include "buffer.h"
25 25#include "keyboard.h"
26/* Position of point last time we inserted a boundary. */
27static struct buffer *last_boundary_buffer;
28static ptrdiff_t last_boundary_position;
29 26
30/* The first time a command records something for undo. 27/* The first time a command records something for undo.
31 it also allocates the undo-boundary object 28 it also allocates the undo-boundary object
@@ -34,45 +31,42 @@ static ptrdiff_t last_boundary_position;
34 an undo-boundary. */ 31 an undo-boundary. */
35static Lisp_Object pending_boundary; 32static Lisp_Object pending_boundary;
36 33
34/* Record point as it was at beginning of this command (if necessary)
35 and prepare the undo info for recording a change.
36 Prepare the undo info for recording a change. */
37static void 37static void
38run_undoable_change (void) 38prepare_record (void)
39{ 39{
40 call0 (Qundo_auto__undoable_change); 40 /* Allocate a cons cell to be the undo boundary after this command. */
41 if (NILP (pending_boundary))
42 pending_boundary = Fcons (Qnil, Qnil);
43
44 if (MODIFF <= SAVE_MODIFF)
45 record_first_change ();
41} 46}
42 47
43/* Record point as it was at beginning of this command (if necessary) 48/* Record point as it was at beginning of this command.
44 and prepare the undo info for recording a change.
45 PT is the position of point that will naturally occur as a result of the 49 PT is the position of point that will naturally occur as a result of the
46 undo record that will be added just after this command terminates. */ 50 undo record that will be added just after this command terminates. */
47
48static void 51static void
49record_point (ptrdiff_t pt) 52record_point (ptrdiff_t pt)
50{ 53{
51 bool at_boundary;
52
53 /* Don't record position of pt when undo_inhibit_record_point holds. */ 54 /* Don't record position of pt when undo_inhibit_record_point holds. */
54 if (undo_inhibit_record_point) 55 if (undo_inhibit_record_point)
55 return; 56 return;
56 57
57 /* Allocate a cons cell to be the undo boundary after this command. */ 58 bool at_boundary;
58 if (NILP (pending_boundary))
59 pending_boundary = Fcons (Qnil, Qnil);
60
61 run_undoable_change ();
62 59
63 at_boundary = ! CONSP (BVAR (current_buffer, undo_list)) 60 at_boundary = ! CONSP (BVAR (current_buffer, undo_list))
64 || NILP (XCAR (BVAR (current_buffer, undo_list))); 61 || NILP (XCAR (BVAR (current_buffer, undo_list)));
65 62
66 if (MODIFF <= SAVE_MODIFF) 63 prepare_record ();
67 record_first_change ();
68 64
69 /* If we are just after an undo boundary, and 65 /* If we are just after an undo boundary, and
70 point wasn't at start of deleted range, record where it was. */ 66 point wasn't at start of deleted range, record where it was. */
71 if (at_boundary 67 if (at_boundary)
72 && current_buffer == last_boundary_buffer
73 && last_boundary_position != pt)
74 bset_undo_list (current_buffer, 68 bset_undo_list (current_buffer,
75 Fcons (make_number (last_boundary_position), 69 Fcons (make_number (pt),
76 BVAR (current_buffer, undo_list))); 70 BVAR (current_buffer, undo_list)));
77} 71}
78 72
@@ -89,7 +83,7 @@ record_insert (ptrdiff_t beg, ptrdiff_t length)
89 if (EQ (BVAR (current_buffer, undo_list), Qt)) 83 if (EQ (BVAR (current_buffer, undo_list), Qt))
90 return; 84 return;
91 85
92 record_point (beg); 86 prepare_record ();
93 87
94 /* If this is following another insertion and consecutive with it 88 /* If this is following another insertion and consecutive with it
95 in the buffer, combine the two. */ 89 in the buffer, combine the two. */
@@ -130,8 +124,6 @@ record_marker_adjustments (ptrdiff_t from, ptrdiff_t to)
130 if (NILP (pending_boundary)) 124 if (NILP (pending_boundary))
131 pending_boundary = Fcons (Qnil, Qnil); 125 pending_boundary = Fcons (Qnil, Qnil);
132 126
133 run_undoable_change ();
134
135 for (m = BUF_MARKERS (current_buffer); m; m = m->next) 127 for (m = BUF_MARKERS (current_buffer); m; m = m->next)
136 { 128 {
137 charpos = m->charpos; 129 charpos = m->charpos;
@@ -163,7 +155,6 @@ record_marker_adjustments (ptrdiff_t from, ptrdiff_t to)
163/* Record that a deletion is about to take place, of the characters in 155/* Record that a deletion is about to take place, of the characters in
164 STRING, at location BEG. Optionally record adjustments for markers 156 STRING, at location BEG. Optionally record adjustments for markers
165 in the region STRING occupies in the current buffer. */ 157 in the region STRING occupies in the current buffer. */
166
167void 158void
168record_delete (ptrdiff_t beg, Lisp_Object string, bool record_markers) 159record_delete (ptrdiff_t beg, Lisp_Object string, bool record_markers)
169{ 160{
@@ -172,15 +163,19 @@ record_delete (ptrdiff_t beg, Lisp_Object string, bool record_markers)
172 if (EQ (BVAR (current_buffer, undo_list), Qt)) 163 if (EQ (BVAR (current_buffer, undo_list), Qt))
173 return; 164 return;
174 165
166 if (point_before_last_command_or_undo != beg
167 && buffer_before_last_command_or_undo == current_buffer)
168 record_point (point_before_last_command_or_undo);
169
175 if (PT == beg + SCHARS (string)) 170 if (PT == beg + SCHARS (string))
176 { 171 {
177 XSETINT (sbeg, -beg); 172 XSETINT (sbeg, -beg);
178 record_point (PT); 173 prepare_record ();
179 } 174 }
180 else 175 else
181 { 176 {
182 XSETFASTINT (sbeg, beg); 177 XSETFASTINT (sbeg, beg);
183 record_point (beg); 178 prepare_record ();
184 } 179 }
185 180
186 /* primitive-undo assumes marker adjustments are recorded 181 /* primitive-undo assumes marker adjustments are recorded
@@ -234,7 +229,7 @@ record_property_change (ptrdiff_t beg, ptrdiff_t length,
234 Lisp_Object buffer) 229 Lisp_Object buffer)
235{ 230{
236 Lisp_Object lbeg, lend, entry; 231 Lisp_Object lbeg, lend, entry;
237 struct buffer *obuf = current_buffer, *buf = XBUFFER (buffer); 232 struct buffer *buf = XBUFFER (buffer);
238 233
239 if (EQ (BVAR (buf, undo_list), Qt)) 234 if (EQ (BVAR (buf, undo_list), Qt))
240 return; 235 return;
@@ -243,11 +238,6 @@ record_property_change (ptrdiff_t beg, ptrdiff_t length,
243 if (NILP (pending_boundary)) 238 if (NILP (pending_boundary))
244 pending_boundary = Fcons (Qnil, Qnil); 239 pending_boundary = Fcons (Qnil, Qnil);
245 240
246 /* Switch temporarily to the buffer that was changed. */
247 set_buffer_internal (buf);
248
249 run_undoable_change ();
250
251 if (MODIFF <= SAVE_MODIFF) 241 if (MODIFF <= SAVE_MODIFF)
252 record_first_change (); 242 record_first_change ();
253 243
@@ -256,9 +246,6 @@ record_property_change (ptrdiff_t beg, ptrdiff_t length,
256 entry = Fcons (Qnil, Fcons (prop, Fcons (value, Fcons (lbeg, lend)))); 246 entry = Fcons (Qnil, Fcons (prop, Fcons (value, Fcons (lbeg, lend))));
257 bset_undo_list (current_buffer, 247 bset_undo_list (current_buffer,
258 Fcons (entry, BVAR (current_buffer, undo_list))); 248 Fcons (entry, BVAR (current_buffer, undo_list)));
259
260 /* Reset the buffer */
261 set_buffer_internal (obuf);
262} 249}
263 250
264DEFUN ("undo-boundary", Fundo_boundary, Sundo_boundary, 0, 0, 0, 251DEFUN ("undo-boundary", Fundo_boundary, Sundo_boundary, 0, 0, 0,
@@ -286,10 +273,11 @@ but another undo command will undo to the previous boundary. */)
286 bset_undo_list (current_buffer, 273 bset_undo_list (current_buffer,
287 Fcons (Qnil, BVAR (current_buffer, undo_list))); 274 Fcons (Qnil, BVAR (current_buffer, undo_list)));
288 } 275 }
289 last_boundary_position = PT;
290 last_boundary_buffer = current_buffer;
291 276
292 Fset (Qundo_auto__last_boundary_cause, Qexplicit); 277 Fset (Qundo_auto__last_boundary_cause, Qexplicit);
278 point_before_last_command_or_undo = PT;
279 buffer_before_last_command_or_undo = current_buffer;
280
293 return Qnil; 281 return Qnil;
294} 282}
295 283
@@ -432,7 +420,6 @@ void
432syms_of_undo (void) 420syms_of_undo (void)
433{ 421{
434 DEFSYM (Qinhibit_read_only, "inhibit-read-only"); 422 DEFSYM (Qinhibit_read_only, "inhibit-read-only");
435 DEFSYM (Qundo_auto__undoable_change, "undo-auto--undoable-change");
436 DEFSYM (Qundo_auto__last_boundary_cause, "undo-auto--last-boundary-cause"); 423 DEFSYM (Qundo_auto__last_boundary_cause, "undo-auto--last-boundary-cause");
437 DEFSYM (Qexplicit, "explicit"); 424 DEFSYM (Qexplicit, "explicit");
438 425
@@ -442,8 +429,6 @@ syms_of_undo (void)
442 pending_boundary = Qnil; 429 pending_boundary = Qnil;
443 staticpro (&pending_boundary); 430 staticpro (&pending_boundary);
444 431
445 last_boundary_buffer = NULL;
446
447 defsubr (&Sundo_boundary); 432 defsubr (&Sundo_boundary);
448 433
449 DEFVAR_INT ("undo-limit", undo_limit, 434 DEFVAR_INT ("undo-limit", undo_limit,