aboutsummaryrefslogtreecommitdiffstats
path: root/src/editfns.c
diff options
context:
space:
mode:
authorJim Blandy1992-05-18 08:14:41 +0000
committerJim Blandy1992-05-18 08:14:41 +0000
commitffd56f97cf56501f7a6981c184192e9043e4eafd (patch)
treed463f4585c85fa76b33d3663271bbb4126d7b116 /src/editfns.c
parent502ddf238f0ed280a301426804b2ed16ec1c49cc (diff)
downloademacs-ffd56f97cf56501f7a6981c184192e9043e4eafd.tar.gz
emacs-ffd56f97cf56501f7a6981c184192e9043e4eafd.zip
*** empty log message ***
Diffstat (limited to 'src/editfns.c')
-rw-r--r--src/editfns.c45
1 files changed, 28 insertions, 17 deletions
diff --git a/src/editfns.c b/src/editfns.c
index 0ef059aa055..6164ef32799 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -680,7 +680,32 @@ Both arguments are required.")
680} 680}
681 681
682 682
683/* Return a string with the contents of the current region */ 683/* Making strings from buffer contents. */
684
685/* Return a Lisp_String containing the text of the current buffer from
686 START to END.
687
688 We don't want to use plain old make_string here, because it calls
689 make_uninit_string, which can cause the buffer arena to be
690 compacted. make_string has no way of knowing that the data has
691 been moved, and thus copies the wrong data into the string. This
692 doesn't effect most of the other users of make_string, so it should
693 be left as is. But we should use this function when conjuring
694 buffer substrings. */
695Lisp_Object
696make_buffer_string (start, end)
697 int start, end;
698{
699 Lisp_Object result;
700
701 if (start < GPT && GPT < end)
702 move_gap (start);
703
704 result = make_uninit_string (end - start);
705 bcopy (&FETCH_CHAR (start), XSTRING (result)->data, end - start);
706
707 return result;
708}
684 709
685DEFUN ("buffer-substring", Fbuffer_substring, Sbuffer_substring, 2, 2, 0, 710DEFUN ("buffer-substring", Fbuffer_substring, Sbuffer_substring, 2, 2, 0,
686 "Return the contents of part of the current buffer as a string.\n\ 711 "Return the contents of part of the current buffer as a string.\n\
@@ -690,33 +715,19 @@ they can be in either order.")
690 Lisp_Object b, e; 715 Lisp_Object b, e;
691{ 716{
692 register int beg, end; 717 register int beg, end;
693 Lisp_Object result;
694 718
695 validate_region (&b, &e); 719 validate_region (&b, &e);
696 beg = XINT (b); 720 beg = XINT (b);
697 end = XINT (e); 721 end = XINT (e);
698 722
699 if (beg < GPT && end > GPT) 723 return make_buffer_string (beg, end);
700 move_gap (beg);
701
702 /* Plain old make_string calls make_uninit_string, which can cause
703 the buffer arena to be compacted. make_string has no way of
704 knowing that the data has been moved, and thus copies the wrong
705 data into the string. This doesn't effect most of the other
706 users of make_string, so it should be left as is. */
707 result = make_uninit_string (end - beg);
708 bcopy (&FETCH_CHAR (beg), XSTRING (result)->data, end - beg);
709
710 return result;
711} 724}
712 725
713DEFUN ("buffer-string", Fbuffer_string, Sbuffer_string, 0, 0, 0, 726DEFUN ("buffer-string", Fbuffer_string, Sbuffer_string, 0, 0, 0,
714 "Return the contents of the current buffer as a string.") 727 "Return the contents of the current buffer as a string.")
715 () 728 ()
716{ 729{
717 if (BEGV < GPT && ZV > GPT) 730 return make_buffer_string (BEGV, ZV);
718 move_gap (BEGV);
719 return make_string (BEGV_ADDR, ZV - BEGV);
720} 731}
721 732
722DEFUN ("insert-buffer-substring", Finsert_buffer_substring, Sinsert_buffer_substring, 733DEFUN ("insert-buffer-substring", Finsert_buffer_substring, Sinsert_buffer_substring,