Mercurial > emacs
comparison 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 |
comparison
equal
deleted
inserted
replaced
647:529171c8b71c | 648:70b112526394 |
---|---|
678 insert (string, n); | 678 insert (string, n); |
679 return Qnil; | 679 return Qnil; |
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. */ | |
695 Lisp_Object | |
696 make_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 |
685 DEFUN ("buffer-substring", Fbuffer_substring, Sbuffer_substring, 2, 2, 0, | 710 DEFUN ("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\ |
687 The two arguments START and END are character positions;\n\ | 712 The two arguments START and END are character positions;\n\ |
688 they can be in either order.") | 713 they can be in either order.") |
689 (b, e) | 714 (b, e) |
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 |
713 DEFUN ("buffer-string", Fbuffer_string, Sbuffer_string, 0, 0, 0, | 726 DEFUN ("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 |
722 DEFUN ("insert-buffer-substring", Finsert_buffer_substring, Sinsert_buffer_substring, | 733 DEFUN ("insert-buffer-substring", Finsert_buffer_substring, Sinsert_buffer_substring, |
723 1, 3, 0, | 734 1, 3, 0, |
724 "Insert before point a substring of the contents buffer BUFFER.\n\ | 735 "Insert before point a substring of the contents buffer BUFFER.\n\ |