Commit 7fded690 authored by Jim Blandy's avatar Jim Blandy
Browse files

* fileio.c (Finsert_file_contents): Two new args, BEG and END.

parent 44257b1a
......@@ -2339,15 +2339,18 @@ otherwise, if FILE2 does not exist, the answer is t.")
DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents,
1, 2, 0,
1, 4, 0,
"Insert contents of file FILENAME after point.\n\
Returns list of absolute pathname and length of data inserted.\n\
Returns list of absolute file name and length of data inserted.\n\
If second argument VISIT is non-nil, the buffer's visited filename\n\
and last save file modtime are set, and it is marked unmodified.\n\
If visiting and the file does not exist, visiting is completed\n\
before the error is signaled.")
(filename, visit)
Lisp_Object filename, visit;
before the error is signaled.\n\n\
The optional third and fourth arguments BEG and END\n\
specify what portion of the file to insert.\n\
If VISIT is non-nil, BEG and END must be nil.")
(filename, visit, beg, end)
Lisp_Object filename, visit, beg, end;
struct stat st;
register int fd;
......@@ -2356,6 +2359,7 @@ before the error is signaled.")
int count = specpdl_ptr - specpdl;
struct gcpro gcpro1;
Lisp_Object handler, val;
int total;
val = Qnil;
......@@ -2371,7 +2375,7 @@ before the error is signaled.")
handler = Ffind_file_name_handler (filename);
if (!NILP (handler))
val = call3 (handler, Qinsert_file_contents, filename, visit);
val = call5 (handler, Qinsert_file_contents, filename, visit, beg, end);
st.st_mtime = 0;
goto handled;
......@@ -2410,12 +2414,32 @@ before the error is signaled.")
if (st.st_size < 0)
error ("File size is negative");
if (!NILP (beg) || !NILP (end))
if (!NILP (visit))
error ("Attempt to visit less than an entire file");
if (!NILP (beg))
CHECK_NUMBER (beg, 0);
XFASTINT (beg) = 0;
if (!NILP (end))
CHECK_NUMBER (end, 0);
XSETINT (end, st.st_size);
if (XINT (end) != st.st_size)
error ("maximum buffer size exceeded");
total = XINT (end) - XINT (beg);
register Lisp_Object temp;
/* Make sure point-max won't overflow after this insertion. */
XSET (temp, Lisp_Int, st.st_size + Z);
if (st.st_size + Z != XINT (temp))
XSET (temp, Lisp_Int, total);
if (total != XINT (temp))
error ("maximum buffer size exceeded");
......@@ -2423,12 +2447,18 @@ before the error is signaled.")
prepare_to_modify_buffer (point, point);
move_gap (point);
if (GAP_SIZE < st.st_size)
make_gap (st.st_size - GAP_SIZE);
if (GAP_SIZE < total)
make_gap (total - GAP_SIZE);
if (XINT (beg) != 0)
if (lseek (fd, XINT (beg), 0) < 0)
report_file_error ("Setting file position", Fcons (filename, Qnil));
while (1)
int try = min (st.st_size - inserted, 64 << 10);
int try = min (total - inserted, 64 << 10);
int this;
/* Allow quitting out of the actual I/O. */
......@@ -2503,7 +2533,7 @@ before the error is signaled.")
Fcons (make_number (inserted),
DEFUN ("write-region", Fwrite_region, Swrite_region, 3, 5,
"r\nFWrite region to file: ",
"Write current region into specified file.\n\
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment