Mercurial > emacs
diff src/editfns.c @ 648:70b112526394
*** empty log message ***
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Mon, 18 May 1992 08:14:41 +0000 |
parents | eca8812e61cd |
children | be66b03cbead |
line wrap: on
line diff
--- a/src/editfns.c Mon May 18 08:13:37 1992 +0000 +++ b/src/editfns.c Mon May 18 08:14:41 1992 +0000 @@ -680,7 +680,32 @@ } -/* Return a string with the contents of the current region */ +/* Making strings from buffer contents. */ + +/* Return a Lisp_String containing the text of the current buffer from + START to END. + + We don't want to use plain old make_string here, because it calls + make_uninit_string, which can cause the buffer arena to be + compacted. make_string has no way of knowing that the data has + been moved, and thus copies the wrong data into the string. This + doesn't effect most of the other users of make_string, so it should + be left as is. But we should use this function when conjuring + buffer substrings. */ +Lisp_Object +make_buffer_string (start, end) + int start, end; +{ + Lisp_Object result; + + if (start < GPT && GPT < end) + move_gap (start); + + result = make_uninit_string (end - start); + bcopy (&FETCH_CHAR (start), XSTRING (result)->data, end - start); + + return result; +} DEFUN ("buffer-substring", Fbuffer_substring, Sbuffer_substring, 2, 2, 0, "Return the contents of part of the current buffer as a string.\n\ @@ -690,33 +715,19 @@ Lisp_Object b, e; { register int beg, end; - Lisp_Object result; validate_region (&b, &e); beg = XINT (b); end = XINT (e); - if (beg < GPT && end > GPT) - move_gap (beg); - - /* Plain old make_string calls make_uninit_string, which can cause - the buffer arena to be compacted. make_string has no way of - knowing that the data has been moved, and thus copies the wrong - data into the string. This doesn't effect most of the other - users of make_string, so it should be left as is. */ - result = make_uninit_string (end - beg); - bcopy (&FETCH_CHAR (beg), XSTRING (result)->data, end - beg); - - return result; + return make_buffer_string (beg, end); } DEFUN ("buffer-string", Fbuffer_string, Sbuffer_string, 0, 0, 0, "Return the contents of the current buffer as a string.") () { - if (BEGV < GPT && ZV > GPT) - move_gap (BEGV); - return make_string (BEGV_ADDR, ZV - BEGV); + return make_buffer_string (BEGV, ZV); } DEFUN ("insert-buffer-substring", Finsert_buffer_substring, Sinsert_buffer_substring,