diff options
| author | Stefan Monnier | 1999-12-07 04:42:40 +0000 |
|---|---|---|
| committer | Stefan Monnier | 1999-12-07 04:42:40 +0000 |
| commit | 7dae4502b6f69a9f0961f8abbb83b254e24dcc8d (patch) | |
| tree | 79d017d734bc11e4f7f2e5af3cb758ce42b45ee7 /src | |
| parent | 397e4fae84e4f568b7280fbc5c39cd04f1f67653 (diff) | |
| download | emacs-7dae4502b6f69a9f0961f8abbb83b254e24dcc8d.tar.gz emacs-7dae4502b6f69a9f0961f8abbb83b254e24dcc8d.zip | |
* 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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 13 | ||||
| -rw-r--r-- | src/casefiddle.c | 2 | ||||
| -rw-r--r-- | src/coding.c | 2 | ||||
| -rw-r--r-- | src/editfns.c | 11 | ||||
| -rw-r--r-- | src/fileio.c | 2 | ||||
| -rw-r--r-- | src/insdel.c | 40 | ||||
| -rw-r--r-- | src/lisp.h | 4 |
7 files changed, 55 insertions, 19 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 091604204d8..c000e0f58bd 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,16 @@ | |||
| 1 | 1999-12-06 Stefan Monnier <monnier@cs.yale.edu> | ||
| 2 | |||
| 3 | * editfns.c (Fdelete_and_extract_region): New function. | ||
| 4 | (syms_of_editfns): register it. | ||
| 5 | * insdel.c (del_range): update del_range_1 call. | ||
| 6 | (del_range_1, del_range_2): Add a ret_string argument to | ||
| 7 | request that the deleted text be returned. | ||
| 8 | (del_range_byte, del_range_both): Update del_range_2 call. | ||
| 9 | * lisp.h (del_range_1, del_range_2): change prototype | ||
| 10 | * casefiddle.c (casify_region): Update del_range_1 call. | ||
| 11 | * coding.c (code_convert_region): Update del_range_2 call. | ||
| 12 | * fileio.c (Finsert_file_contents): Update del_range_2 call. | ||
| 13 | |||
| 1 | 1999-12-06 Gerd Moellmann <gerd@gnu.org> | 14 | 1999-12-06 Gerd Moellmann <gerd@gnu.org> |
| 2 | 15 | ||
| 3 | * xfaces.c (set_lface_from_font_name): Fix incomplete merge. | 16 | * xfaces.c (set_lface_from_font_name): Fix incomplete merge. |
diff --git a/src/casefiddle.c b/src/casefiddle.c index 24f63637bf1..113885fad69 100644 --- a/src/casefiddle.c +++ b/src/casefiddle.c | |||
| @@ -265,7 +265,7 @@ casify_region (flag, b, e) | |||
| 265 | error ("Can't casify letters that change length"); | 265 | error ("Can't casify letters that change length"); |
| 266 | #if 0 /* This is approximately what we'd like to be able to do here */ | 266 | #if 0 /* This is approximately what we'd like to be able to do here */ |
| 267 | if (tolen < fromlen) | 267 | if (tolen < fromlen) |
| 268 | del_range_1 (i + tolen, i + fromlen, 0); | 268 | del_range_1 (i + tolen, i + fromlen, 0, 0); |
| 269 | else if (tolen > fromlen) | 269 | else if (tolen > fromlen) |
| 270 | { | 270 | { |
| 271 | TEMP_SET_PT (i + fromlen); | 271 | TEMP_SET_PT (i + fromlen); |
diff --git a/src/coding.c b/src/coding.c index 8d840fc85fd..05fe37fcabf 100644 --- a/src/coding.c +++ b/src/coding.c | |||
| @@ -4387,7 +4387,7 @@ code_convert_region (from, from_byte, to, to_byte, coding, encodep, replace) | |||
| 4387 | len = ZV - BEGV; | 4387 | len = ZV - BEGV; |
| 4388 | new = Fcurrent_buffer (); | 4388 | new = Fcurrent_buffer (); |
| 4389 | set_buffer_internal_1 (prev); | 4389 | set_buffer_internal_1 (prev); |
| 4390 | del_range_2 (from, from_byte, to, to_byte); | 4390 | del_range_2 (from, from_byte, to, to_byte, 0); |
| 4391 | TEMP_SET_PT_BOTH (from, from_byte); | 4391 | TEMP_SET_PT_BOTH (from, from_byte); |
| 4392 | insert_from_buffer (XBUFFER (new), 1, len, 0); | 4392 | insert_from_buffer (XBUFFER (new), 1, len, 0); |
| 4393 | Fkill_buffer (new); | 4393 | Fkill_buffer (new); |
diff --git a/src/editfns.c b/src/editfns.c index a54fb1363d3..ab73b51a160 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -2509,6 +2509,16 @@ positions (integers or markers) specifying the stretch to be deleted.") | |||
| 2509 | del_range (XINT (start), XINT (end)); | 2509 | del_range (XINT (start), XINT (end)); |
| 2510 | return Qnil; | 2510 | return Qnil; |
| 2511 | } | 2511 | } |
| 2512 | |||
| 2513 | DEFUN ("delete-and-extract-region", Fdelete_and_extract_region, | ||
| 2514 | Sdelete_and_extract_region, 2, 2, 0, | ||
| 2515 | "Delete the text between START and END and return it.") | ||
| 2516 | (start, end) | ||
| 2517 | Lisp_Object start, end; | ||
| 2518 | { | ||
| 2519 | validate_region (&start, &end); | ||
| 2520 | return del_range_1 (XINT (start), XINT (end), 1, 1); | ||
| 2521 | } | ||
| 2512 | 2522 | ||
| 2513 | DEFUN ("widen", Fwiden, Swiden, 0, 0, "", | 2523 | DEFUN ("widen", Fwiden, Swiden, 0, 0, "", |
| 2514 | "Remove restrictions (narrowing) from current buffer.\n\ | 2524 | "Remove restrictions (narrowing) from current buffer.\n\ |
| @@ -3767,6 +3777,7 @@ functions if all the text being accessed has this property."); | |||
| 3767 | defsubr (&Ssubst_char_in_region); | 3777 | defsubr (&Ssubst_char_in_region); |
| 3768 | defsubr (&Stranslate_region); | 3778 | defsubr (&Stranslate_region); |
| 3769 | defsubr (&Sdelete_region); | 3779 | defsubr (&Sdelete_region); |
| 3780 | defsubr (&Sdelete_and_extract_region); | ||
| 3770 | defsubr (&Swiden); | 3781 | defsubr (&Swiden); |
| 3771 | defsubr (&Snarrow_to_region); | 3782 | defsubr (&Snarrow_to_region); |
| 3772 | defsubr (&Ssave_restriction); | 3783 | defsubr (&Ssave_restriction); |
diff --git a/src/fileio.c b/src/fileio.c index b6c1e4d5510..9a346ac9436 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -3688,7 +3688,7 @@ actually used.") | |||
| 3688 | emacs_close (fd); | 3688 | emacs_close (fd); |
| 3689 | specpdl_ptr--; | 3689 | specpdl_ptr--; |
| 3690 | /* Truncate the buffer to the size of the file. */ | 3690 | /* Truncate the buffer to the size of the file. */ |
| 3691 | del_range_1 (same_at_start, same_at_end, 0); | 3691 | del_range_1 (same_at_start, same_at_end, 0, 0); |
| 3692 | goto handled; | 3692 | goto handled; |
| 3693 | } | 3693 | } |
| 3694 | immediate_quit = 1; | 3694 | immediate_quit = 1; |
diff --git a/src/insdel.c b/src/insdel.c index a3db343219f..60a9284ce45 100644 --- a/src/insdel.c +++ b/src/insdel.c | |||
| @@ -2053,16 +2053,19 @@ void | |||
| 2053 | del_range (from, to) | 2053 | del_range (from, to) |
| 2054 | register int from, to; | 2054 | register int from, to; |
| 2055 | { | 2055 | { |
| 2056 | del_range_1 (from, to, 1); | 2056 | del_range_1 (from, to, 1, 0); |
| 2057 | } | 2057 | } |
| 2058 | 2058 | ||
| 2059 | /* Like del_range; PREPARE says whether to call prepare_to_modify_buffer. */ | 2059 | /* Like del_range; PREPARE says whether to call prepare_to_modify_buffer. |
| 2060 | RET_STRING says to return the deleted text. */ | ||
| 2060 | 2061 | ||
| 2061 | void | 2062 | Lisp_Object |
| 2062 | del_range_1 (from, to, prepare) | 2063 | del_range_1 (from, to, prepare, ret_string) |
| 2063 | int from, to, prepare; | 2064 | int from, to, prepare, ret_string; |
| 2064 | { | 2065 | { |
| 2065 | int from_byte, to_byte; | 2066 | int from_byte, to_byte; |
| 2067 | Lisp_Object deletion; | ||
| 2068 | struct gcpro gcpro1; | ||
| 2066 | 2069 | ||
| 2067 | /* Make args be valid */ | 2070 | /* Make args be valid */ |
| 2068 | if (from < BEGV) | 2071 | if (from < BEGV) |
| @@ -2071,7 +2074,7 @@ del_range_1 (from, to, prepare) | |||
| 2071 | to = ZV; | 2074 | to = ZV; |
| 2072 | 2075 | ||
| 2073 | if (to <= from) | 2076 | if (to <= from) |
| 2074 | return; | 2077 | return Qnil; |
| 2075 | 2078 | ||
| 2076 | if (prepare) | 2079 | if (prepare) |
| 2077 | { | 2080 | { |
| @@ -2083,8 +2086,11 @@ del_range_1 (from, to, prepare) | |||
| 2083 | from_byte = CHAR_TO_BYTE (from); | 2086 | from_byte = CHAR_TO_BYTE (from); |
| 2084 | to_byte = CHAR_TO_BYTE (to); | 2087 | to_byte = CHAR_TO_BYTE (to); |
| 2085 | 2088 | ||
| 2086 | del_range_2 (from, from_byte, to, to_byte); | 2089 | deletion = del_range_2 (from, from_byte, to, to_byte, ret_string); |
| 2090 | GCPRO1(deletion); | ||
| 2087 | signal_after_change (from, to - from, 0); | 2091 | signal_after_change (from, to - from, 0); |
| 2092 | UNGCPRO; | ||
| 2093 | return deletion; | ||
| 2088 | } | 2094 | } |
| 2089 | 2095 | ||
| 2090 | /* Like del_range_1 but args are byte positions, not char positions. */ | 2096 | /* Like del_range_1 but args are byte positions, not char positions. */ |
| @@ -2120,7 +2126,7 @@ del_range_byte (from_byte, to_byte, prepare) | |||
| 2120 | to_byte = CHAR_TO_BYTE (to); | 2126 | to_byte = CHAR_TO_BYTE (to); |
| 2121 | } | 2127 | } |
| 2122 | 2128 | ||
| 2123 | del_range_2 (from, from_byte, to, to_byte); | 2129 | del_range_2 (from, from_byte, to, to_byte, 0); |
| 2124 | signal_after_change (from, to - from, 0); | 2130 | signal_after_change (from, to - from, 0); |
| 2125 | } | 2131 | } |
| 2126 | 2132 | ||
| @@ -2158,17 +2164,18 @@ del_range_both (from, from_byte, to, to_byte, prepare) | |||
| 2158 | to_byte = CHAR_TO_BYTE (to); | 2164 | to_byte = CHAR_TO_BYTE (to); |
| 2159 | } | 2165 | } |
| 2160 | 2166 | ||
| 2161 | del_range_2 (from, from_byte, to, to_byte); | 2167 | del_range_2 (from, from_byte, to, to_byte, 0); |
| 2162 | signal_after_change (from, to - from, 0); | 2168 | signal_after_change (from, to - from, 0); |
| 2163 | } | 2169 | } |
| 2164 | 2170 | ||
| 2165 | /* Delete a range of text, specified both as character positions | 2171 | /* Delete a range of text, specified both as character positions |
| 2166 | and byte positions. FROM and TO are character positions, | 2172 | and byte positions. FROM and TO are character positions, |
| 2167 | while FROM_BYTE and TO_BYTE are byte positions. */ | 2173 | while FROM_BYTE and TO_BYTE are byte positions. |
| 2174 | If RET_STRING is true, the deleted area is returned as a string. */ | ||
| 2168 | 2175 | ||
| 2169 | void | 2176 | Lisp_Object |
| 2170 | del_range_2 (from, from_byte, to, to_byte) | 2177 | del_range_2 (from, from_byte, to, to_byte, ret_string) |
| 2171 | int from, from_byte, to, to_byte; | 2178 | int from, from_byte, to, to_byte, ret_string; |
| 2172 | { | 2179 | { |
| 2173 | register int nbytes_del, nchars_del; | 2180 | register int nbytes_del, nchars_del; |
| 2174 | int combined_after_bytes; | 2181 | int combined_after_bytes; |
| @@ -2199,12 +2206,15 @@ del_range_2 (from, from_byte, to, to_byte) | |||
| 2199 | else | 2206 | else |
| 2200 | from_byte_1 = from_byte; | 2207 | from_byte_1 = from_byte; |
| 2201 | 2208 | ||
| 2202 | if (! EQ (current_buffer->undo_list, Qt)) | 2209 | if (ret_string || ! EQ (current_buffer->undo_list, Qt)) |
| 2203 | deletion | 2210 | deletion |
| 2204 | = make_buffer_string_both (from - !!combined_after_bytes, | 2211 | = make_buffer_string_both (from - !!combined_after_bytes, |
| 2205 | from_byte_1, | 2212 | from_byte_1, |
| 2206 | to + combined_after_bytes, | 2213 | to + combined_after_bytes, |
| 2207 | to_byte + combined_after_bytes, 1); | 2214 | to_byte + combined_after_bytes, 1); |
| 2215 | else | ||
| 2216 | deletion = Qnil; | ||
| 2217 | |||
| 2208 | if (combined_after_bytes) | 2218 | if (combined_after_bytes) |
| 2209 | /* COMBINED_AFTER_BYTES nonzero means that the above code moved | 2219 | /* COMBINED_AFTER_BYTES nonzero means that the above code moved |
| 2210 | the gap. We must move the gap again to a proper place. */ | 2220 | 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) | |||
| 2286 | CHECK_MARKERS (); | 2296 | CHECK_MARKERS (); |
| 2287 | 2297 | ||
| 2288 | evaporate_overlays (from); | 2298 | evaporate_overlays (from); |
| 2299 | |||
| 2300 | return deletion; | ||
| 2289 | } | 2301 | } |
| 2290 | 2302 | ||
| 2291 | /* Call this if you're about to change the region of BUFFER from | 2303 | /* Call this if you're about to change the region of BUFFER from |
diff --git a/src/lisp.h b/src/lisp.h index 6a3c7e5ebb0..31c8c364aa9 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -2010,10 +2010,10 @@ extern void insert_before_markers P_ ((unsigned char *, int)); | |||
| 2010 | extern void insert_before_markers_and_inherit P_ ((unsigned char *, int)); | 2010 | extern void insert_before_markers_and_inherit P_ ((unsigned char *, int)); |
| 2011 | extern void insert_from_string_before_markers P_ ((Lisp_Object, int, int, int, int, int)); | 2011 | extern void insert_from_string_before_markers P_ ((Lisp_Object, int, int, int, int, int)); |
| 2012 | extern void del_range P_ ((int, int)); | 2012 | extern void del_range P_ ((int, int)); |
| 2013 | extern void del_range_1 P_ ((int, int, int)); | 2013 | extern Lisp_Object del_range_1 P_ ((int, int, int, int)); |
| 2014 | extern void del_range_byte P_ ((int, int, int)); | 2014 | extern void del_range_byte P_ ((int, int, int)); |
| 2015 | extern void del_range_both P_ ((int, int, int, int, int)); | 2015 | extern void del_range_both P_ ((int, int, int, int, int)); |
| 2016 | extern void del_range_2 P_ ((int, int, int, int)); | 2016 | extern Lisp_Object del_range_2 P_ ((int, int, int, int, int)); |
| 2017 | extern void modify_region P_ ((struct buffer *, int, int)); | 2017 | extern void modify_region P_ ((struct buffer *, int, int)); |
| 2018 | extern void prepare_to_modify_buffer P_ ((int, int, int *)); | 2018 | extern void prepare_to_modify_buffer P_ ((int, int, int *)); |
| 2019 | extern void signal_before_change P_ ((int, int, int *)); | 2019 | extern void signal_before_change P_ ((int, int, int *)); |