aboutsummaryrefslogtreecommitdiffstats
path: root/src/editfns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/editfns.c')
-rw-r--r--src/editfns.c95
1 files changed, 27 insertions, 68 deletions
diff --git a/src/editfns.c b/src/editfns.c
index cbc1082b2cc..90520d0dced 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -948,10 +948,10 @@ DEFUN ("position-bytes", Fposition_bytes, Sposition_bytes, 1, 1, 0,
948If POSITION is out of range, the value is nil. */) 948If POSITION is out of range, the value is nil. */)
949 (Lisp_Object position) 949 (Lisp_Object position)
950{ 950{
951 CHECK_FIXNUM_COERCE_MARKER (position); 951 EMACS_INT pos = fix_position (position);
952 if (XFIXNUM (position) < BEG || XFIXNUM (position) > Z) 952 if (! (BEG <= pos && pos <= Z))
953 return Qnil; 953 return Qnil;
954 return make_fixnum (CHAR_TO_BYTE (XFIXNUM (position))); 954 return make_fixnum (CHAR_TO_BYTE (pos));
955} 955}
956 956
957DEFUN ("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,
@@ -1068,11 +1068,11 @@ If POS is out of range, the value is nil. */)
1068 } 1068 }
1069 else 1069 else
1070 { 1070 {
1071 CHECK_FIXNUM_COERCE_MARKER (pos); 1071 EMACS_INT p = fix_position (pos);
1072 if (XFIXNUM (pos) < BEGV || XFIXNUM (pos) >= ZV) 1072 if (! (BEGV <= p && p < ZV))
1073 return Qnil; 1073 return Qnil;
1074 1074
1075 pos_byte = CHAR_TO_BYTE (XFIXNUM (pos)); 1075 pos_byte = CHAR_TO_BYTE (p);
1076 } 1076 }
1077 1077
1078 return make_fixnum (FETCH_CHAR (pos_byte)); 1078 return make_fixnum (FETCH_CHAR (pos_byte));
@@ -1102,12 +1102,12 @@ If POS is out of range, the value is nil. */)
1102 } 1102 }
1103 else 1103 else
1104 { 1104 {
1105 CHECK_FIXNUM_COERCE_MARKER (pos); 1105 EMACS_INT p = fix_position (pos);
1106 1106
1107 if (XFIXNUM (pos) <= BEGV || XFIXNUM (pos) > ZV) 1107 if (! (BEGV < p && p <= ZV))
1108 return Qnil; 1108 return Qnil;
1109 1109
1110 pos_byte = CHAR_TO_BYTE (XFIXNUM (pos)); 1110 pos_byte = CHAR_TO_BYTE (p);
1111 } 1111 }
1112 1112
1113 if (!NILP (BVAR (current_buffer, enable_multibyte_characters))) 1113 if (!NILP (BVAR (current_buffer, enable_multibyte_characters)))
@@ -1726,21 +1726,8 @@ using `string-make-multibyte' or `string-make-unibyte', which see. */)
1726 if (!BUFFER_LIVE_P (bp)) 1726 if (!BUFFER_LIVE_P (bp))
1727 error ("Selecting deleted buffer"); 1727 error ("Selecting deleted buffer");
1728 1728
1729 if (NILP (start)) 1729 b = !NILP (start) ? fix_position (start) : BUF_BEGV (bp);
1730 b = BUF_BEGV (bp); 1730 e = !NILP (end) ? fix_position (end) : BUF_ZV (bp);
1731 else
1732 {
1733 CHECK_FIXNUM_COERCE_MARKER (start);
1734 b = XFIXNUM (start);
1735 }
1736 if (NILP (end))
1737 e = BUF_ZV (bp);
1738 else
1739 {
1740 CHECK_FIXNUM_COERCE_MARKER (end);
1741 e = XFIXNUM (end);
1742 }
1743
1744 if (b > e) 1731 if (b > e)
1745 temp = b, b = e, e = temp; 1732 temp = b, b = e, e = temp;
1746 1733
@@ -1794,21 +1781,8 @@ determines whether case is significant or ignored. */)
1794 error ("Selecting deleted buffer"); 1781 error ("Selecting deleted buffer");
1795 } 1782 }
1796 1783
1797 if (NILP (start1)) 1784 begp1 = !NILP (start1) ? fix_position (start1) : BUF_BEGV (bp1);
1798 begp1 = BUF_BEGV (bp1); 1785 endp1 = !NILP (end1) ? fix_position (end1) : BUF_ZV (bp1);
1799 else
1800 {
1801 CHECK_FIXNUM_COERCE_MARKER (start1);
1802 begp1 = XFIXNUM (start1);
1803 }
1804 if (NILP (end1))
1805 endp1 = BUF_ZV (bp1);
1806 else
1807 {
1808 CHECK_FIXNUM_COERCE_MARKER (end1);
1809 endp1 = XFIXNUM (end1);
1810 }
1811
1812 if (begp1 > endp1) 1786 if (begp1 > endp1)
1813 temp = begp1, begp1 = endp1, endp1 = temp; 1787 temp = begp1, begp1 = endp1, endp1 = temp;
1814 1788
@@ -1832,21 +1806,8 @@ determines whether case is significant or ignored. */)
1832 error ("Selecting deleted buffer"); 1806 error ("Selecting deleted buffer");
1833 } 1807 }
1834 1808
1835 if (NILP (start2)) 1809 begp2 = !NILP (start2) ? fix_position (start2) : BUF_BEGV (bp2);
1836 begp2 = BUF_BEGV (bp2); 1810 endp2 = !NILP (end2) ? fix_position (end2) : BUF_ZV (bp2);
1837 else
1838 {
1839 CHECK_FIXNUM_COERCE_MARKER (start2);
1840 begp2 = XFIXNUM (start2);
1841 }
1842 if (NILP (end2))
1843 endp2 = BUF_ZV (bp2);
1844 else
1845 {
1846 CHECK_FIXNUM_COERCE_MARKER (end2);
1847 endp2 = XFIXNUM (end2);
1848 }
1849
1850 if (begp2 > endp2) 1811 if (begp2 > endp2)
1851 temp = begp2, begp2 = endp2, endp2 = temp; 1812 temp = begp2, begp2 = endp2, endp2 = temp;
1852 1813
@@ -2700,29 +2661,27 @@ See also `save-restriction'.
2700When calling from Lisp, pass two arguments START and END: 2661When calling from Lisp, pass two arguments START and END:
2701positions (integers or markers) bounding the text that should 2662positions (integers or markers) bounding the text that should
2702remain visible. */) 2663remain visible. */)
2703 (register Lisp_Object start, Lisp_Object end) 2664 (Lisp_Object start, Lisp_Object end)
2704{ 2665{
2705 CHECK_FIXNUM_COERCE_MARKER (start); 2666 EMACS_INT s = fix_position (start), e = fix_position (end);
2706 CHECK_FIXNUM_COERCE_MARKER (end);
2707 2667
2708 if (XFIXNUM (start) > XFIXNUM (end)) 2668 if (e < s)
2709 { 2669 {
2710 Lisp_Object tem; 2670 EMACS_INT tem = s; s = e; e = tem;
2711 tem = start; start = end; end = tem;
2712 } 2671 }
2713 2672
2714 if (!(BEG <= XFIXNUM (start) && XFIXNUM (start) <= XFIXNUM (end) && XFIXNUM (end) <= Z)) 2673 if (!(BEG <= s && s <= e && e <= Z))
2715 args_out_of_range (start, end); 2674 args_out_of_range (start, end);
2716 2675
2717 if (BEGV != XFIXNAT (start) || ZV != XFIXNAT (end)) 2676 if (BEGV != s || ZV != e)
2718 current_buffer->clip_changed = 1; 2677 current_buffer->clip_changed = 1;
2719 2678
2720 SET_BUF_BEGV (current_buffer, XFIXNAT (start)); 2679 SET_BUF_BEGV (current_buffer, s);
2721 SET_BUF_ZV (current_buffer, XFIXNAT (end)); 2680 SET_BUF_ZV (current_buffer, e);
2722 if (PT < XFIXNAT (start)) 2681 if (PT < s)
2723 SET_PT (XFIXNAT (start)); 2682 SET_PT (s);
2724 if (PT > XFIXNAT (end)) 2683 if (e < PT)
2725 SET_PT (XFIXNAT (end)); 2684 SET_PT (e);
2726 /* Changing the buffer bounds invalidates any recorded current column. */ 2685 /* Changing the buffer bounds invalidates any recorded current column. */
2727 invalidate_current_column (); 2686 invalidate_current_column ();
2728 return Qnil; 2687 return Qnil;