aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2016-08-05 14:10:30 -0700
committerPaul Eggert2016-08-05 14:10:30 -0700
commit0274862f395807d05585eb6325c5285f1bf775d8 (patch)
treeda85c643cf8040db118538bf7705d2a461ec055a /src
parentf902a6b89e6970eabaaf3c2c1452bf2104e2004b (diff)
parentd08afa1d0339425f03a48e533166a7cadfa66139 (diff)
downloademacs-0274862f395807d05585eb6325c5285f1bf775d8.tar.gz
emacs-0274862f395807d05585eb6325c5285f1bf775d8.zip
Merge from origin/emacs-25
d08afa1 * etc/AUTHORS: Update the AUTHORS file 2668500 ;; * ChangeLog.2: ChangeLog update. 7acfaea ; ChangeLog fixes 97d28b4 * admin/authors.el (authors-valid-file-names): Addition. 9ab52f6 * admin/authors.el: Additions. 0e646c7 Warn about Cairo-related problems bc4c07f Don't let completion break `declare' handling 66f95e0 Adjust match data before calling after-change-funs 52cf0d5 Do not show string-rectangle preview if minibuffer is empty 6a3d031 * etc/PROBLEMS: Add entry about selection problems under Plas... # Conflicts: # ChangeLog.2 # src/lisp.h
Diffstat (limited to 'src')
-rw-r--r--src/cmds.c2
-rw-r--r--src/editfns.c6
-rw-r--r--src/insdel.c10
-rw-r--r--src/lisp.h4
-rw-r--r--src/search.c56
5 files changed, 47 insertions, 31 deletions
diff --git a/src/cmds.c b/src/cmds.c
index 1e44dddfbf6..4003d8bfa47 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -447,7 +447,7 @@ internal_self_insert (int c, EMACS_INT n)
447 string = concat2 (string, tem); 447 string = concat2 (string, tem);
448 } 448 }
449 449
450 replace_range (PT, PT + chars_to_delete, string, 1, 1, 1); 450 replace_range (PT, PT + chars_to_delete, string, 1, 1, 1, 0);
451 Fforward_char (make_number (n)); 451 Fforward_char (make_number (n));
452 } 452 }
453 else if (n > 1) 453 else if (n > 1)
diff --git a/src/editfns.c b/src/editfns.c
index 61b2a871b73..732306af868 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -3244,7 +3244,7 @@ Both characters must have the same length of multi-byte form. */)
3244 /* replace_range is less efficient, because it moves the gap, 3244 /* replace_range is less efficient, because it moves the gap,
3245 but it handles combining correctly. */ 3245 but it handles combining correctly. */
3246 replace_range (pos, pos + 1, string, 3246 replace_range (pos, pos + 1, string,
3247 0, 0, 1); 3247 0, 0, 1, 0);
3248 pos_byte_next = CHAR_TO_BYTE (pos); 3248 pos_byte_next = CHAR_TO_BYTE (pos);
3249 if (pos_byte_next > pos_byte) 3249 if (pos_byte_next > pos_byte)
3250 /* Before combining happened. We should not increment 3250 /* Before combining happened. We should not increment
@@ -3457,7 +3457,7 @@ It returns the number of characters changed. */)
3457 /* This is less efficient, because it moves the gap, 3457 /* This is less efficient, because it moves the gap,
3458 but it should handle multibyte characters correctly. */ 3458 but it should handle multibyte characters correctly. */
3459 string = make_multibyte_string ((char *) str, 1, str_len); 3459 string = make_multibyte_string ((char *) str, 1, str_len);
3460 replace_range (pos, pos + 1, string, 1, 0, 1); 3460 replace_range (pos, pos + 1, string, 1, 0, 1, 0);
3461 len = str_len; 3461 len = str_len;
3462 } 3462 }
3463 else 3463 else
@@ -3498,7 +3498,7 @@ It returns the number of characters changed. */)
3498 { 3498 {
3499 string = Fmake_string (make_number (1), val); 3499 string = Fmake_string (make_number (1), val);
3500 } 3500 }
3501 replace_range (pos, pos + len, string, 1, 0, 1); 3501 replace_range (pos, pos + len, string, 1, 0, 1, 0);
3502 pos_byte += SBYTES (string); 3502 pos_byte += SBYTES (string);
3503 pos += SCHARS (string); 3503 pos += SCHARS (string);
3504 cnt += SCHARS (string); 3504 cnt += SCHARS (string);
diff --git a/src/insdel.c b/src/insdel.c
index ec7bbb3e715..5d3884b4059 100644
--- a/src/insdel.c
+++ b/src/insdel.c
@@ -1340,7 +1340,9 @@ adjust_after_insert (ptrdiff_t from, ptrdiff_t from_byte,
1340/* Replace the text from character positions FROM to TO with NEW, 1340/* Replace the text from character positions FROM to TO with NEW,
1341 If PREPARE, call prepare_to_modify_buffer. 1341 If PREPARE, call prepare_to_modify_buffer.
1342 If INHERIT, the newly inserted text should inherit text properties 1342 If INHERIT, the newly inserted text should inherit text properties
1343 from the surrounding non-deleted text. */ 1343 from the surrounding non-deleted text.
1344 If ADJUST_MATCH_DATA, then adjust the match data before calling
1345 signal_after_change. */
1344 1346
1345/* Note that this does not yet handle markers quite right. 1347/* Note that this does not yet handle markers quite right.
1346 Also it needs to record a single undo-entry that does a replacement 1348 Also it needs to record a single undo-entry that does a replacement
@@ -1351,7 +1353,8 @@ adjust_after_insert (ptrdiff_t from, ptrdiff_t from_byte,
1351 1353
1352void 1354void
1353replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new, 1355replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new,
1354 bool prepare, bool inherit, bool markers) 1356 bool prepare, bool inherit, bool markers,
1357 bool adjust_match_data)
1355{ 1358{
1356 ptrdiff_t inschars = SCHARS (new); 1359 ptrdiff_t inschars = SCHARS (new);
1357 ptrdiff_t insbytes = SBYTES (new); 1360 ptrdiff_t insbytes = SBYTES (new);
@@ -1508,6 +1511,9 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new,
1508 MODIFF++; 1511 MODIFF++;
1509 CHARS_MODIFF = MODIFF; 1512 CHARS_MODIFF = MODIFF;
1510 1513
1514 if (adjust_match_data)
1515 update_search_regs (from, to, from + SCHARS (new));
1516
1511 signal_after_change (from, nchars_del, GPT - from); 1517 signal_after_change (from, nchars_del, GPT - from);
1512 update_compositions (from, GPT, CHECK_BORDER); 1518 update_compositions (from, GPT, CHECK_BORDER);
1513} 1519}
diff --git a/src/lisp.h b/src/lisp.h
index 089f3977cd2..8ac9cc1d2a9 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3530,7 +3530,7 @@ extern void adjust_markers_for_delete (ptrdiff_t, ptrdiff_t,
3530 ptrdiff_t, ptrdiff_t); 3530 ptrdiff_t, ptrdiff_t);
3531extern void adjust_markers_bytepos (ptrdiff_t, ptrdiff_t, 3531extern void adjust_markers_bytepos (ptrdiff_t, ptrdiff_t,
3532 ptrdiff_t, ptrdiff_t, int); 3532 ptrdiff_t, ptrdiff_t, int);
3533extern void replace_range (ptrdiff_t, ptrdiff_t, Lisp_Object, bool, bool, bool); 3533extern void replace_range (ptrdiff_t, ptrdiff_t, Lisp_Object, bool, bool, bool, bool);
3534extern void replace_range_2 (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t, 3534extern void replace_range_2 (ptrdiff_t, ptrdiff_t, ptrdiff_t, ptrdiff_t,
3535 const char *, ptrdiff_t, ptrdiff_t, bool); 3535 const char *, ptrdiff_t, ptrdiff_t, bool);
3536extern void syms_of_insdel (void); 3536extern void syms_of_insdel (void);
@@ -4019,6 +4019,8 @@ extern Lisp_Object make_temp_name (Lisp_Object, bool);
4019/* Defined in search.c. */ 4019/* Defined in search.c. */
4020extern void shrink_regexp_cache (void); 4020extern void shrink_regexp_cache (void);
4021extern void restore_search_regs (void); 4021extern void restore_search_regs (void);
4022extern void update_search_regs (ptrdiff_t oldstart,
4023 ptrdiff_t oldend, ptrdiff_t newend);
4022extern void record_unwind_save_match_data (void); 4024extern void record_unwind_save_match_data (void);
4023struct re_registers; 4025struct re_registers;
4024extern struct re_pattern_buffer *compile_pattern (Lisp_Object, 4026extern struct re_pattern_buffer *compile_pattern (Lisp_Object,
diff --git a/src/search.c b/src/search.c
index 3d4846644ee..5dc4d355304 100644
--- a/src/search.c
+++ b/src/search.c
@@ -2712,16 +2712,23 @@ since only regular expressions have distinguished subexpressions. */)
2712 2712
2713 /* The functions below modify the buffer, so they could trigger 2713 /* The functions below modify the buffer, so they could trigger
2714 various modification hooks (see signal_before_change and 2714 various modification hooks (see signal_before_change and
2715 signal_after_change), which might clobber the match data we need 2715 signal_after_change). If these hooks clobber the match data we
2716 to adjust after the replacement. If that happens, we error out. */ 2716 error out since otherwise this will result in confusing bugs. */
2717 ptrdiff_t sub_start = search_regs.start[sub]; 2717 ptrdiff_t sub_start = search_regs.start[sub];
2718 ptrdiff_t sub_end = search_regs.end[sub]; 2718 ptrdiff_t sub_end = search_regs.end[sub];
2719 unsigned num_regs = search_regs.num_regs; 2719 unsigned num_regs = search_regs.num_regs;
2720 newpoint = search_regs.start[sub] + SCHARS (newtext);
2720 2721
2721 /* Replace the old text with the new in the cleanest possible way. */ 2722 /* Replace the old text with the new in the cleanest possible way. */
2722 replace_range (search_regs.start[sub], search_regs.end[sub], 2723 replace_range (search_regs.start[sub], search_regs.end[sub],
2723 newtext, 1, 0, 1); 2724 newtext, 1, 0, 1, 1);
2724 newpoint = search_regs.start[sub] + SCHARS (newtext); 2725 /* Update saved data to match adjustment made by replace_range. */
2726 {
2727 ptrdiff_t change = newpoint - sub_end;
2728 if (sub_start >= sub_end)
2729 sub_start += change;
2730 sub_end += change;
2731 }
2725 2732
2726 if (case_action == all_caps) 2733 if (case_action == all_caps)
2727 Fupcase_region (make_number (search_regs.start[sub]), 2734 Fupcase_region (make_number (search_regs.start[sub]),
@@ -2736,26 +2743,6 @@ since only regular expressions have distinguished subexpressions. */)
2736 || search_regs.num_regs != num_regs) 2743 || search_regs.num_regs != num_regs)
2737 error ("Match data clobbered by buffer modification hooks"); 2744 error ("Match data clobbered by buffer modification hooks");
2738 2745
2739 /* Adjust search data for this change. */
2740 {
2741 ptrdiff_t oldend = search_regs.end[sub];
2742 ptrdiff_t oldstart = search_regs.start[sub];
2743 ptrdiff_t change = newpoint - search_regs.end[sub];
2744 ptrdiff_t i;
2745
2746 for (i = 0; i < search_regs.num_regs; i++)
2747 {
2748 if (search_regs.start[i] >= oldend)
2749 search_regs.start[i] += change;
2750 else if (search_regs.start[i] > oldstart)
2751 search_regs.start[i] = oldstart;
2752 if (search_regs.end[i] >= oldend)
2753 search_regs.end[i] += change;
2754 else if (search_regs.end[i] > oldstart)
2755 search_regs.end[i] = oldstart;
2756 }
2757 }
2758
2759 /* Put point back where it was in the text. */ 2746 /* Put point back where it was in the text. */
2760 if (opoint <= 0) 2747 if (opoint <= 0)
2761 TEMP_SET_PT (opoint + ZV); 2748 TEMP_SET_PT (opoint + ZV);
@@ -3096,6 +3083,27 @@ restore_search_regs (void)
3096 } 3083 }
3097} 3084}
3098 3085
3086/* Called from replace-match via replace_range. */
3087void
3088update_search_regs (ptrdiff_t oldstart, ptrdiff_t oldend, ptrdiff_t newend)
3089{
3090 /* Adjust search data for this change. */
3091 ptrdiff_t change = newend - oldend;
3092 ptrdiff_t i;
3093
3094 for (i = 0; i < search_regs.num_regs; i++)
3095 {
3096 if (search_regs.start[i] >= oldend)
3097 search_regs.start[i] += change;
3098 else if (search_regs.start[i] > oldstart)
3099 search_regs.start[i] = oldstart;
3100 if (search_regs.end[i] >= oldend)
3101 search_regs.end[i] += change;
3102 else if (search_regs.end[i] > oldstart)
3103 search_regs.end[i] = oldstart;
3104 }
3105}
3106
3099static void 3107static void
3100unwind_set_match_data (Lisp_Object list) 3108unwind_set_match_data (Lisp_Object list)
3101{ 3109{