aboutsummaryrefslogtreecommitdiffstats
path: root/src/editfns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/editfns.c')
-rw-r--r--src/editfns.c121
1 files changed, 44 insertions, 77 deletions
diff --git a/src/editfns.c b/src/editfns.c
index eb15566fb48..90520d0dced 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -725,18 +725,23 @@ boundaries, bind `inhibit-field-text-motion' to t.
725This function does not move point. */) 725This function does not move point. */)
726 (Lisp_Object n) 726 (Lisp_Object n)
727{ 727{
728 ptrdiff_t charpos, bytepos; 728 ptrdiff_t charpos, bytepos, count;
729 729
730 if (NILP (n)) 730 if (NILP (n))
731 XSETFASTINT (n, 1); 731 count = 0;
732 else if (FIXNUMP (n))
733 count = clip_to_bounds (-BUF_BYTES_MAX, XFIXNUM (n) - 1, BUF_BYTES_MAX);
732 else 734 else
733 CHECK_FIXNUM (n); 735 {
736 CHECK_INTEGER (n);
737 count = NILP (Fnatnump (n)) ? -BUF_BYTES_MAX : BUF_BYTES_MAX;
738 }
734 739
735 scan_newline_from_point (XFIXNUM (n) - 1, &charpos, &bytepos); 740 scan_newline_from_point (count, &charpos, &bytepos);
736 741
737 /* Return END constrained to the current input field. */ 742 /* Return END constrained to the current input field. */
738 return Fconstrain_to_field (make_fixnum (charpos), make_fixnum (PT), 743 return Fconstrain_to_field (make_fixnum (charpos), make_fixnum (PT),
739 XFIXNUM (n) != 1 ? Qt : Qnil, 744 count != 0 ? Qt : Qnil,
740 Qt, Qnil); 745 Qt, Qnil);
741} 746}
742 747
@@ -763,11 +768,14 @@ This function does not move point. */)
763 ptrdiff_t orig = PT; 768 ptrdiff_t orig = PT;
764 769
765 if (NILP (n)) 770 if (NILP (n))
766 XSETFASTINT (n, 1); 771 clipped_n = 1;
772 else if (FIXNUMP (n))
773 clipped_n = clip_to_bounds (-BUF_BYTES_MAX, XFIXNUM (n), BUF_BYTES_MAX);
767 else 774 else
768 CHECK_FIXNUM (n); 775 {
769 776 CHECK_INTEGER (n);
770 clipped_n = clip_to_bounds (PTRDIFF_MIN + 1, XFIXNUM (n), PTRDIFF_MAX); 777 clipped_n = NILP (Fnatnump (n)) ? -BUF_BYTES_MAX : BUF_BYTES_MAX;
778 }
771 end_pos = find_before_next_newline (orig, 0, clipped_n - (clipped_n <= 0), 779 end_pos = find_before_next_newline (orig, 0, clipped_n - (clipped_n <= 0),
772 NULL); 780 NULL);
773 781
@@ -940,10 +948,10 @@ DEFUN ("position-bytes", Fposition_bytes, Sposition_bytes, 1, 1, 0,
940If POSITION is out of range, the value is nil. */) 948If POSITION is out of range, the value is nil. */)
941 (Lisp_Object position) 949 (Lisp_Object position)
942{ 950{
943 CHECK_FIXNUM_COERCE_MARKER (position); 951 EMACS_INT pos = fix_position (position);
944 if (XFIXNUM (position) < BEG || XFIXNUM (position) > Z) 952 if (! (BEG <= pos && pos <= Z))
945 return Qnil; 953 return Qnil;
946 return make_fixnum (CHAR_TO_BYTE (XFIXNUM (position))); 954 return make_fixnum (CHAR_TO_BYTE (pos));
947} 955}
948 956
949DEFUN ("byte-to-position", Fbyte_to_position, Sbyte_to_position, 1, 1, 0, 957DEFUN ("byte-to-position", Fbyte_to_position, Sbyte_to_position, 1, 1, 0,
@@ -1060,11 +1068,11 @@ If POS is out of range, the value is nil. */)
1060 } 1068 }
1061 else 1069 else
1062 { 1070 {
1063 CHECK_FIXNUM_COERCE_MARKER (pos); 1071 EMACS_INT p = fix_position (pos);
1064 if (XFIXNUM (pos) < BEGV || XFIXNUM (pos) >= ZV) 1072 if (! (BEGV <= p && p < ZV))
1065 return Qnil; 1073 return Qnil;
1066 1074
1067 pos_byte = CHAR_TO_BYTE (XFIXNUM (pos)); 1075 pos_byte = CHAR_TO_BYTE (p);
1068 } 1076 }
1069 1077
1070 return make_fixnum (FETCH_CHAR (pos_byte)); 1078 return make_fixnum (FETCH_CHAR (pos_byte));
@@ -1094,12 +1102,12 @@ If POS is out of range, the value is nil. */)
1094 } 1102 }
1095 else 1103 else
1096 { 1104 {
1097 CHECK_FIXNUM_COERCE_MARKER (pos); 1105 EMACS_INT p = fix_position (pos);
1098 1106
1099 if (XFIXNUM (pos) <= BEGV || XFIXNUM (pos) > ZV) 1107 if (! (BEGV < p && p <= ZV))
1100 return Qnil; 1108 return Qnil;
1101 1109
1102 pos_byte = CHAR_TO_BYTE (XFIXNUM (pos)); 1110 pos_byte = CHAR_TO_BYTE (p);
1103 } 1111 }
1104 1112
1105 if (!NILP (BVAR (current_buffer, enable_multibyte_characters))) 1113 if (!NILP (BVAR (current_buffer, enable_multibyte_characters)))
@@ -1718,21 +1726,8 @@ using `string-make-multibyte' or `string-make-unibyte', which see. */)
1718 if (!BUFFER_LIVE_P (bp)) 1726 if (!BUFFER_LIVE_P (bp))
1719 error ("Selecting deleted buffer"); 1727 error ("Selecting deleted buffer");
1720 1728
1721 if (NILP (start)) 1729 b = !NILP (start) ? fix_position (start) : BUF_BEGV (bp);
1722 b = BUF_BEGV (bp); 1730 e = !NILP (end) ? fix_position (end) : BUF_ZV (bp);
1723 else
1724 {
1725 CHECK_FIXNUM_COERCE_MARKER (start);
1726 b = XFIXNUM (start);
1727 }
1728 if (NILP (end))
1729 e = BUF_ZV (bp);
1730 else
1731 {
1732 CHECK_FIXNUM_COERCE_MARKER (end);
1733 e = XFIXNUM (end);
1734 }
1735
1736 if (b > e) 1731 if (b > e)
1737 temp = b, b = e, e = temp; 1732 temp = b, b = e, e = temp;
1738 1733
@@ -1786,21 +1781,8 @@ determines whether case is significant or ignored. */)
1786 error ("Selecting deleted buffer"); 1781 error ("Selecting deleted buffer");
1787 } 1782 }
1788 1783
1789 if (NILP (start1)) 1784 begp1 = !NILP (start1) ? fix_position (start1) : BUF_BEGV (bp1);
1790 begp1 = BUF_BEGV (bp1); 1785 endp1 = !NILP (end1) ? fix_position (end1) : BUF_ZV (bp1);
1791 else
1792 {
1793 CHECK_FIXNUM_COERCE_MARKER (start1);
1794 begp1 = XFIXNUM (start1);
1795 }
1796 if (NILP (end1))
1797 endp1 = BUF_ZV (bp1);
1798 else
1799 {
1800 CHECK_FIXNUM_COERCE_MARKER (end1);
1801 endp1 = XFIXNUM (end1);
1802 }
1803
1804 if (begp1 > endp1) 1786 if (begp1 > endp1)
1805 temp = begp1, begp1 = endp1, endp1 = temp; 1787 temp = begp1, begp1 = endp1, endp1 = temp;
1806 1788
@@ -1824,21 +1806,8 @@ determines whether case is significant or ignored. */)
1824 error ("Selecting deleted buffer"); 1806 error ("Selecting deleted buffer");
1825 } 1807 }
1826 1808
1827 if (NILP (start2)) 1809 begp2 = !NILP (start2) ? fix_position (start2) : BUF_BEGV (bp2);
1828 begp2 = BUF_BEGV (bp2); 1810 endp2 = !NILP (end2) ? fix_position (end2) : BUF_ZV (bp2);
1829 else
1830 {
1831 CHECK_FIXNUM_COERCE_MARKER (start2);
1832 begp2 = XFIXNUM (start2);
1833 }
1834 if (NILP (end2))
1835 endp2 = BUF_ZV (bp2);
1836 else
1837 {
1838 CHECK_FIXNUM_COERCE_MARKER (end2);
1839 endp2 = XFIXNUM (end2);
1840 }
1841
1842 if (begp2 > endp2) 1811 if (begp2 > endp2)
1843 temp = begp2, begp2 = endp2, endp2 = temp; 1812 temp = begp2, begp2 = endp2, endp2 = temp;
1844 1813
@@ -2692,29 +2661,27 @@ See also `save-restriction'.
2692When calling from Lisp, pass two arguments START and END: 2661When calling from Lisp, pass two arguments START and END:
2693positions (integers or markers) bounding the text that should 2662positions (integers or markers) bounding the text that should
2694remain visible. */) 2663remain visible. */)
2695 (register Lisp_Object start, Lisp_Object end) 2664 (Lisp_Object start, Lisp_Object end)
2696{ 2665{
2697 CHECK_FIXNUM_COERCE_MARKER (start); 2666 EMACS_INT s = fix_position (start), e = fix_position (end);
2698 CHECK_FIXNUM_COERCE_MARKER (end);
2699 2667
2700 if (XFIXNUM (start) > XFIXNUM (end)) 2668 if (e < s)
2701 { 2669 {
2702 Lisp_Object tem; 2670 EMACS_INT tem = s; s = e; e = tem;
2703 tem = start; start = end; end = tem;
2704 } 2671 }
2705 2672
2706 if (!(BEG <= XFIXNUM (start) && XFIXNUM (start) <= XFIXNUM (end) && XFIXNUM (end) <= Z)) 2673 if (!(BEG <= s && s <= e && e <= Z))
2707 args_out_of_range (start, end); 2674 args_out_of_range (start, end);
2708 2675
2709 if (BEGV != XFIXNAT (start) || ZV != XFIXNAT (end)) 2676 if (BEGV != s || ZV != e)
2710 current_buffer->clip_changed = 1; 2677 current_buffer->clip_changed = 1;
2711 2678
2712 SET_BUF_BEGV (current_buffer, XFIXNAT (start)); 2679 SET_BUF_BEGV (current_buffer, s);
2713 SET_BUF_ZV (current_buffer, XFIXNAT (end)); 2680 SET_BUF_ZV (current_buffer, e);
2714 if (PT < XFIXNAT (start)) 2681 if (PT < s)
2715 SET_PT (XFIXNAT (start)); 2682 SET_PT (s);
2716 if (PT > XFIXNAT (end)) 2683 if (e < PT)
2717 SET_PT (XFIXNAT (end)); 2684 SET_PT (e);
2718 /* Changing the buffer bounds invalidates any recorded current column. */ 2685 /* Changing the buffer bounds invalidates any recorded current column. */
2719 invalidate_current_column (); 2686 invalidate_current_column ();
2720 return Qnil; 2687 return Qnil;