diff options
Diffstat (limited to 'src/insdel.c')
-rw-r--r-- | src/insdel.c | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/src/insdel.c b/src/insdel.c index 773b2c85eb8..3809f8bc060 100644 --- a/src/insdel.c +++ b/src/insdel.c @@ -803,7 +803,7 @@ count_combining_before (const unsigned char *string, ptrdiff_t length, while (!CHAR_HEAD_P (*p) && p < string + length) p++; - return (combining_bytes < p - string ? combining_bytes : p - string); + return min (combining_bytes, p - string); } /* See if the bytes after POS/POS_BYTE combine with bytes @@ -865,7 +865,7 @@ count_combining_after (const unsigned char *string, bufp++, pos_byte++; while (!CHAR_HEAD_P (*bufp)) bufp++, pos_byte++; - return (bytes <= pos_byte - opos_byte ? bytes : pos_byte - opos_byte); + return min (bytes, pos_byte - opos_byte); } #endif @@ -1568,9 +1568,8 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new, /* Relocate point as if it were a marker. */ if (from < PT) - adjust_point ((from + inschars - (PT < to ? PT : to)), - (from_byte + outgoing_insbytes - - (PT_BYTE < to_byte ? PT_BYTE : to_byte))); + adjust_point ((from + inschars - min (PT, to)), + (from_byte + outgoing_insbytes - min (PT_BYTE, to_byte))); check_markers (); @@ -1715,6 +1714,44 @@ del_range (ptrdiff_t from, ptrdiff_t to) del_range_1 (from, to, 1, 0); } +struct safe_del_range_context +{ + /* From and to positions. */ + ptrdiff_t from, to; +}; + +static Lisp_Object +safe_del_range_1 (void *ptr) +{ + struct safe_del_range_context *context; + + context = ptr; + del_range (context->from, context->to); + return Qnil; +} + +static Lisp_Object +safe_del_range_2 (enum nonlocal_exit type, Lisp_Object value) +{ + return Qt; +} + +/* Like del_range; however, catch all non-local exits. Value is 0 if + the buffer contents were really deleted. Otherwise, it is 1. */ + +int +safe_del_range (ptrdiff_t from, ptrdiff_t to) +{ + struct safe_del_range_context context; + + context.from = from; + context.to = to; + + return !NILP (internal_catch_all (safe_del_range_1, + &context, + safe_del_range_2)); +} + /* Like del_range; PREPARE says whether to call prepare_to_modify_buffer. RET_STRING says to return the deleted text. */ @@ -1881,8 +1918,8 @@ del_range_2 (ptrdiff_t from, ptrdiff_t from_byte, /* Relocate point as if it were a marker. */ if (from < PT) - adjust_point (from - (PT < to ? PT : to), - from_byte - (PT_BYTE < to_byte ? PT_BYTE : to_byte)); + adjust_point (from - min (PT, to), + from_byte - min (PT_BYTE, to_byte)); offset_intervals (current_buffer, from, - nchars_del); |