1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-28 00:01:33 -08:00

* editfns.c (Fdelete_and_extract_region): New function.

(syms_of_editfns): register it.
* insdel.c (del_range): update del_range_1 call.
(del_range_1, del_range_2): Add a ret_string argument to
request that the deleted text be returned.
(del_range_byte, del_range_both): Update del_range_2 call.
* lisp.h (del_range_1, del_range_2): change prototype
* casefiddle.c (casify_region): Update del_range_1 call.
* coding.c (code_convert_region): Update del_range_2 call.
* fileio.c (Finsert_file_contents): Update del_range_2 call.
This commit is contained in:
Stefan Monnier 1999-12-07 04:42:40 +00:00
parent 397e4fae84
commit 7dae4502b6
7 changed files with 55 additions and 19 deletions

View file

@ -1,3 +1,16 @@
1999-12-06 Stefan Monnier <monnier@cs.yale.edu>
* editfns.c (Fdelete_and_extract_region): New function.
(syms_of_editfns): register it.
* insdel.c (del_range): update del_range_1 call.
(del_range_1, del_range_2): Add a ret_string argument to
request that the deleted text be returned.
(del_range_byte, del_range_both): Update del_range_2 call.
* lisp.h (del_range_1, del_range_2): change prototype
* casefiddle.c (casify_region): Update del_range_1 call.
* coding.c (code_convert_region): Update del_range_2 call.
* fileio.c (Finsert_file_contents): Update del_range_2 call.
1999-12-06 Gerd Moellmann <gerd@gnu.org> 1999-12-06 Gerd Moellmann <gerd@gnu.org>
* xfaces.c (set_lface_from_font_name): Fix incomplete merge. * xfaces.c (set_lface_from_font_name): Fix incomplete merge.

View file

@ -265,7 +265,7 @@ casify_region (flag, b, e)
error ("Can't casify letters that change length"); error ("Can't casify letters that change length");
#if 0 /* This is approximately what we'd like to be able to do here */ #if 0 /* This is approximately what we'd like to be able to do here */
if (tolen < fromlen) if (tolen < fromlen)
del_range_1 (i + tolen, i + fromlen, 0); del_range_1 (i + tolen, i + fromlen, 0, 0);
else if (tolen > fromlen) else if (tolen > fromlen)
{ {
TEMP_SET_PT (i + fromlen); TEMP_SET_PT (i + fromlen);

View file

@ -4387,7 +4387,7 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace)
len = ZV - BEGV; len = ZV - BEGV;
new = Fcurrent_buffer (); new = Fcurrent_buffer ();
set_buffer_internal_1 (prev); set_buffer_internal_1 (prev);
del_range_2 (from, from_byte, to, to_byte); del_range_2 (from, from_byte, to, to_byte, 0);
TEMP_SET_PT_BOTH (from, from_byte); TEMP_SET_PT_BOTH (from, from_byte);
insert_from_buffer (XBUFFER (new), 1, len, 0); insert_from_buffer (XBUFFER (new), 1, len, 0);
Fkill_buffer (new); Fkill_buffer (new);

View file

@ -2509,6 +2509,16 @@ positions (integers or markers) specifying the stretch to be deleted.")
del_range (XINT (start), XINT (end)); del_range (XINT (start), XINT (end));
return Qnil; return Qnil;
} }
DEFUN ("delete-and-extract-region", Fdelete_and_extract_region,
Sdelete_and_extract_region, 2, 2, 0,
"Delete the text between START and END and return it.")
(start, end)
Lisp_Object start, end;
{
validate_region (&start, &end);
return del_range_1 (XINT (start), XINT (end), 1, 1);
}
DEFUN ("widen", Fwiden, Swiden, 0, 0, "", DEFUN ("widen", Fwiden, Swiden, 0, 0, "",
"Remove restrictions (narrowing) from current buffer.\n\ "Remove restrictions (narrowing) from current buffer.\n\
@ -3767,6 +3777,7 @@ functions if all the text being accessed has this property.");
defsubr (&Ssubst_char_in_region); defsubr (&Ssubst_char_in_region);
defsubr (&Stranslate_region); defsubr (&Stranslate_region);
defsubr (&Sdelete_region); defsubr (&Sdelete_region);
defsubr (&Sdelete_and_extract_region);
defsubr (&Swiden); defsubr (&Swiden);
defsubr (&Snarrow_to_region); defsubr (&Snarrow_to_region);
defsubr (&Ssave_restriction); defsubr (&Ssave_restriction);

View file

@ -3688,7 +3688,7 @@ actually used.")
emacs_close (fd); emacs_close (fd);
specpdl_ptr--; specpdl_ptr--;
/* Truncate the buffer to the size of the file. */ /* Truncate the buffer to the size of the file. */
del_range_1 (same_at_start, same_at_end, 0); del_range_1 (same_at_start, same_at_end, 0, 0);
goto handled; goto handled;
} }
immediate_quit = 1; immediate_quit = 1;

View file

@ -2053,16 +2053,19 @@ void
del_range (from, to) del_range (from, to)
register int from, to; register int from, to;
{ {
del_range_1 (from, to, 1); del_range_1 (from, to, 1, 0);
} }
/* Like del_range; PREPARE says whether to call prepare_to_modify_buffer. */ /* Like del_range; PREPARE says whether to call prepare_to_modify_buffer.
RET_STRING says to return the deleted text. */
void Lisp_Object
del_range_1 (from, to, prepare) del_range_1 (from, to, prepare, ret_string)
int from, to, prepare; int from, to, prepare, ret_string;
{ {
int from_byte, to_byte; int from_byte, to_byte;
Lisp_Object deletion;
struct gcpro gcpro1;
/* Make args be valid */ /* Make args be valid */
if (from < BEGV) if (from < BEGV)
@ -2071,7 +2074,7 @@ del_range_1 (from, to, prepare)
to = ZV; to = ZV;
if (to <= from) if (to <= from)
return; return Qnil;
if (prepare) if (prepare)
{ {
@ -2083,8 +2086,11 @@ del_range_1 (from, to, prepare)
from_byte = CHAR_TO_BYTE (from); from_byte = CHAR_TO_BYTE (from);
to_byte = CHAR_TO_BYTE (to); to_byte = CHAR_TO_BYTE (to);
del_range_2 (from, from_byte, to, to_byte); deletion = del_range_2 (from, from_byte, to, to_byte, ret_string);
GCPRO1(deletion);
signal_after_change (from, to - from, 0); signal_after_change (from, to - from, 0);
UNGCPRO;
return deletion;
} }
/* Like del_range_1 but args are byte positions, not char positions. */ /* Like del_range_1 but args are byte positions, not char positions. */
@ -2120,7 +2126,7 @@ del_range_byte (from_byte, to_byte, prepare)
to_byte = CHAR_TO_BYTE (to); to_byte = CHAR_TO_BYTE (to);
} }
del_range_2 (from, from_byte, to, to_byte); del_range_2 (from, from_byte, to, to_byte, 0);
signal_after_change (from, to - from, 0); signal_after_change (from, to - from, 0);
} }
@ -2158,17 +2164,18 @@ del_range_both (from, from_byte, to, to_byte, prepare)
to_byte = CHAR_TO_BYTE (to); to_byte = CHAR_TO_BYTE (to);
} }
del_range_2 (from, from_byte, to, to_byte); del_range_2 (from, from_byte, to, to_byte, 0);
signal_after_change (from, to - from, 0); signal_after_change (from, to - from, 0);
} }
/* Delete a range of text, specified both as character positions /* Delete a range of text, specified both as character positions
and byte positions. FROM and TO are character positions, and byte positions. FROM and TO are character positions,
while FROM_BYTE and TO_BYTE are byte positions. */ while FROM_BYTE and TO_BYTE are byte positions.
If RET_STRING is true, the deleted area is returned as a string. */
void Lisp_Object
del_range_2 (from, from_byte, to, to_byte) del_range_2 (from, from_byte, to, to_byte, ret_string)
int from, from_byte, to, to_byte; int from, from_byte, to, to_byte, ret_string;
{ {
register int nbytes_del, nchars_del; register int nbytes_del, nchars_del;
int combined_after_bytes; int combined_after_bytes;
@ -2199,12 +2206,15 @@ del_range_2 (from, from_byte, to, to_byte)
else else
from_byte_1 = from_byte; from_byte_1 = from_byte;
if (! EQ (current_buffer->undo_list, Qt)) if (ret_string || ! EQ (current_buffer->undo_list, Qt))
deletion deletion
= make_buffer_string_both (from - !!combined_after_bytes, = make_buffer_string_both (from - !!combined_after_bytes,
from_byte_1, from_byte_1,
to + combined_after_bytes, to + combined_after_bytes,
to_byte + combined_after_bytes, 1); to_byte + combined_after_bytes, 1);
else
deletion = Qnil;
if (combined_after_bytes) if (combined_after_bytes)
/* COMBINED_AFTER_BYTES nonzero means that the above code moved /* COMBINED_AFTER_BYTES nonzero means that the above code moved
the gap. We must move the gap again to a proper place. */ the gap. We must move the gap again to a proper place. */
@ -2286,6 +2296,8 @@ del_range_2 (from, from_byte, to, to_byte)
CHECK_MARKERS (); CHECK_MARKERS ();
evaporate_overlays (from); evaporate_overlays (from);
return deletion;
} }
/* Call this if you're about to change the region of BUFFER from /* Call this if you're about to change the region of BUFFER from

View file

@ -2010,10 +2010,10 @@ extern void insert_before_markers P_ ((unsigned char *, int));
extern void insert_before_markers_and_inherit P_ ((unsigned char *, int)); extern void insert_before_markers_and_inherit P_ ((unsigned char *, int));
extern void insert_from_string_before_markers P_ ((Lisp_Object, int, int, int, int, int)); extern void insert_from_string_before_markers P_ ((Lisp_Object, int, int, int, int, int));
extern void del_range P_ ((int, int)); extern void del_range P_ ((int, int));
extern void del_range_1 P_ ((int, int, int)); extern Lisp_Object del_range_1 P_ ((int, int, int, int));
extern void del_range_byte P_ ((int, int, int)); extern void del_range_byte P_ ((int, int, int));
extern void del_range_both P_ ((int, int, int, int, int)); extern void del_range_both P_ ((int, int, int, int, int));
extern void del_range_2 P_ ((int, int, int, int)); extern Lisp_Object del_range_2 P_ ((int, int, int, int, int));
extern void modify_region P_ ((struct buffer *, int, int)); extern void modify_region P_ ((struct buffer *, int, int));
extern void prepare_to_modify_buffer P_ ((int, int, int *)); extern void prepare_to_modify_buffer P_ ((int, int, int *));
extern void signal_before_change P_ ((int, int, int *)); extern void signal_before_change P_ ((int, int, int *));