CHECK_TYPE (OVERLAYP (x), Qoverlayp, x);
}
+/* Convert the position POS to an EMACS_INT that fits in a fixnum.
+ Yield POS's value if POS is already a fixnum, POS's marker position
+ if POS is a marker, and MOST_NEGATIVE_FIXNUM or
+ MOST_POSITIVE_FIXNUM if POS is a negative or positive bignum.
+ Signal an error if POS is not of the proper form. */
+
+EMACS_INT
+fix_position (Lisp_Object pos)
+{
+ if (FIXNUMP (pos))
+ return XFIXNUM (pos);
+ if (MARKERP (pos))
+ return marker_position (pos);
+ CHECK_TYPE (BIGNUMP (pos), Qinteger_or_marker_p, pos);
+ return !NILP (Fnatnump (pos)) ? MOST_POSITIVE_FIXNUM : MOST_NEGATIVE_FIXNUM;
+}
+
/* These setters are used only in this file, so they can be private.
The public setters are inline functions defined in buffer.h. */
static void
}
void
-validate_region (register Lisp_Object *b, register Lisp_Object *e)
+validate_region (Lisp_Object *b, Lisp_Object *e)
{
- CHECK_FIXNUM_COERCE_MARKER (*b);
- CHECK_FIXNUM_COERCE_MARKER (*e);
+ EMACS_INT beg = fix_position (*b), end = fix_position (*e);
- if (XFIXNUM (*b) > XFIXNUM (*e))
+ if (end < beg)
{
- Lisp_Object tem;
- tem = *b; *b = *e; *e = tem;
+ EMACS_INT tem = beg; beg = end; end = tem;
}
- if (! (BEGV <= XFIXNUM (*b) && XFIXNUM (*e) <= ZV))
+ if (! (BEGV <= beg && end <= ZV))
args_out_of_range_3 (Fcurrent_buffer (), *b, *e);
+
+ *b = make_fixnum (beg);
+ *e = make_fixnum (end);
}
\f
/* Advance BYTE_POS up to a character boundary
extern Lisp_Object interval_insert_in_front_hooks;
\f
+extern EMACS_INT fix_position (Lisp_Object);
+#define CHECK_FIXNUM_COERCE_MARKER(x) ((x) = make_fixnum (fix_position (x)))
extern void delete_all_overlays (struct buffer *);
extern void reset_buffer (struct buffer *);
extern void compact_buffer (struct buffer *);
}
else
{
- CHECK_FIXNUM_COERCE_MARKER (position);
- if (XFIXNUM (position) < BEGV || XFIXNUM (position) >= ZV)
+ EMACS_INT fixed_pos = fix_position (position);
+ if (! (BEGV <= fixed_pos && fixed_pos < ZV))
args_out_of_range_3 (position, make_fixnum (BEGV), make_fixnum (ZV));
- pos = XFIXNAT (position);
+ pos = fixed_pos;
p = CHAR_POS_ADDR (pos);
}
if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
}
else
{
- CHECK_FIXNUM_COERCE_MARKER (start);
- CHECK_FIXNUM_COERCE_MARKER (end);
- if (XFIXNUM (start) < BEG || XFIXNUM (end) > Z || XFIXNUM (start) > XFIXNUM (end))
+ EMACS_INT s = fix_position (start);
+ EMACS_INT e = fix_position (end);
+ if (! (BEG <= s && s <= e && e <= Z))
args_out_of_range (start, end);
if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
return Qt;
- start_byte = CHAR_TO_BYTE (XFIXNUM (start));
- end_byte = CHAR_TO_BYTE (XFIXNUM (end));
- if (XFIXNUM (end) - XFIXNUM (start) == end_byte - start_byte)
+ start_byte = CHAR_TO_BYTE (s);
+ end_byte = CHAR_TO_BYTE (e);
+ if (e - s == end_byte - start_byte)
return Qt;
- if (XFIXNUM (start) < GPT && XFIXNUM (end) > GPT)
+ if (s < GPT && GPT < e)
{
- if ((GPT - XFIXNUM (start)) < (XFIXNUM (end) - GPT))
- move_gap_both (XFIXNUM (start), start_byte);
+ if (GPT - s < e - GPT)
+ move_gap_both (s, start_byte);
else
- move_gap_both (XFIXNUM (end), end_byte);
+ move_gap_both (e, end_byte);
}
}
}
else
{
- CHECK_FIXNUM_COERCE_MARKER (start);
- CHECK_FIXNUM_COERCE_MARKER (end);
- if (XFIXNUM (start) < BEG || XFIXNUM (end) > Z || XFIXNUM (start) > XFIXNUM (end))
+ EMACS_INT s = fix_position (start);
+ EMACS_INT e = fix_position (end);
+ if (! (BEG <= s && s <= e && e <= Z))
args_out_of_range (start, end);
if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
return Qnil;
- start_byte = CHAR_TO_BYTE (XFIXNUM (start));
- end_byte = CHAR_TO_BYTE (XFIXNUM (end));
- if (XFIXNUM (end) - XFIXNUM (start) == end_byte - start_byte)
+ start_byte = CHAR_TO_BYTE (s);
+ end_byte = CHAR_TO_BYTE (e);
+ if (e - s == end_byte - start_byte)
return Qnil;
- if (XFIXNUM (start) < GPT && XFIXNUM (end) > GPT)
+ if (s < GPT && GPT < e)
{
- if ((GPT - XFIXNUM (start)) < (XFIXNUM (end) - GPT))
- move_gap_both (XFIXNUM (start), start_byte);
+ if (GPT - s < e - GPT)
+ move_gap_both (s, start_byte);
else
- move_gap_both (XFIXNUM (end), end_byte);
+ move_gap_both (e, end_byte);
}
- pos = XFIXNUM (start);
+ pos = s;
}
list = Qnil;
ptrdiff_t start, end, from, to;
int id;
- CHECK_FIXNUM_COERCE_MARKER (pos);
+ EMACS_INT fixed_pos = fix_position (pos);
if (!NILP (limit))
- {
- CHECK_FIXNUM_COERCE_MARKER (limit);
- to = min (XFIXNUM (limit), ZV);
- }
+ to = clip_to_bounds (PTRDIFF_MIN, fix_position (limit), ZV);
else
to = -1;
if (!NILP (string))
{
CHECK_STRING (string);
- if (XFIXNUM (pos) < 0 || XFIXNUM (pos) > SCHARS (string))
+ if (! (0 <= fixed_pos && fixed_pos <= SCHARS (string)))
args_out_of_range (string, pos);
}
else
{
- if (XFIXNUM (pos) < BEGV || XFIXNUM (pos) > ZV)
+ if (! (BEGV <= fixed_pos && fixed_pos <= ZV))
args_out_of_range (Fcurrent_buffer (), pos);
}
- from = XFIXNUM (pos);
+ from = fixed_pos;
if (!find_composition (from, to, &start, &end, &prop, string))
{
return list3 (make_fixnum (start), make_fixnum (end), gstring);
return Qnil;
}
- if ((end <= XFIXNUM (pos) || start > XFIXNUM (pos)))
+ if (! (start <= fixed_pos && fixed_pos < end))
{
ptrdiff_t s, e;
if (find_automatic_composition (from, to, &s, &e, &gstring, string)
- && (e <= XFIXNUM (pos) ? e > end : s < start))
+ && (e <= fixed_pos ? e > end : s < start))
return list3 (make_fixnum (s), make_fixnum (e), gstring);
}
if (!composition_valid_p (start, end, prop))
If POSITION is out of range, the value is nil. */)
(Lisp_Object position)
{
- CHECK_FIXNUM_COERCE_MARKER (position);
- if (XFIXNUM (position) < BEG || XFIXNUM (position) > Z)
+ EMACS_INT pos = fix_position (position);
+ if (! (BEG <= pos && pos <= Z))
return Qnil;
- return make_fixnum (CHAR_TO_BYTE (XFIXNUM (position)));
+ return make_fixnum (CHAR_TO_BYTE (pos));
}
DEFUN ("byte-to-position", Fbyte_to_position, Sbyte_to_position, 1, 1, 0,
}
else
{
- CHECK_FIXNUM_COERCE_MARKER (pos);
- if (XFIXNUM (pos) < BEGV || XFIXNUM (pos) >= ZV)
+ EMACS_INT p = fix_position (pos);
+ if (! (BEGV <= p && p < ZV))
return Qnil;
- pos_byte = CHAR_TO_BYTE (XFIXNUM (pos));
+ pos_byte = CHAR_TO_BYTE (p);
}
return make_fixnum (FETCH_CHAR (pos_byte));
}
else
{
- CHECK_FIXNUM_COERCE_MARKER (pos);
+ EMACS_INT p = fix_position (pos);
- if (XFIXNUM (pos) <= BEGV || XFIXNUM (pos) > ZV)
+ if (! (BEGV < p && p <= ZV))
return Qnil;
- pos_byte = CHAR_TO_BYTE (XFIXNUM (pos));
+ pos_byte = CHAR_TO_BYTE (p);
}
if (!NILP (BVAR (current_buffer, enable_multibyte_characters)))
if (!BUFFER_LIVE_P (bp))
error ("Selecting deleted buffer");
- if (NILP (start))
- b = BUF_BEGV (bp);
- else
- {
- CHECK_FIXNUM_COERCE_MARKER (start);
- b = XFIXNUM (start);
- }
- if (NILP (end))
- e = BUF_ZV (bp);
- else
- {
- CHECK_FIXNUM_COERCE_MARKER (end);
- e = XFIXNUM (end);
- }
-
+ b = !NILP (start) ? fix_position (start) : BUF_BEGV (bp);
+ e = !NILP (end) ? fix_position (end) : BUF_ZV (bp);
if (b > e)
temp = b, b = e, e = temp;
error ("Selecting deleted buffer");
}
- if (NILP (start1))
- begp1 = BUF_BEGV (bp1);
- else
- {
- CHECK_FIXNUM_COERCE_MARKER (start1);
- begp1 = XFIXNUM (start1);
- }
- if (NILP (end1))
- endp1 = BUF_ZV (bp1);
- else
- {
- CHECK_FIXNUM_COERCE_MARKER (end1);
- endp1 = XFIXNUM (end1);
- }
-
+ begp1 = !NILP (start1) ? fix_position (start1) : BUF_BEGV (bp1);
+ endp1 = !NILP (end1) ? fix_position (end1) : BUF_ZV (bp1);
if (begp1 > endp1)
temp = begp1, begp1 = endp1, endp1 = temp;
error ("Selecting deleted buffer");
}
- if (NILP (start2))
- begp2 = BUF_BEGV (bp2);
- else
- {
- CHECK_FIXNUM_COERCE_MARKER (start2);
- begp2 = XFIXNUM (start2);
- }
- if (NILP (end2))
- endp2 = BUF_ZV (bp2);
- else
- {
- CHECK_FIXNUM_COERCE_MARKER (end2);
- endp2 = XFIXNUM (end2);
- }
-
+ begp2 = !NILP (start2) ? fix_position (start2) : BUF_BEGV (bp2);
+ endp2 = !NILP (end2) ? fix_position (end2) : BUF_ZV (bp2);
if (begp2 > endp2)
temp = begp2, begp2 = endp2, endp2 = temp;
When calling from Lisp, pass two arguments START and END:
positions (integers or markers) bounding the text that should
remain visible. */)
- (register Lisp_Object start, Lisp_Object end)
+ (Lisp_Object start, Lisp_Object end)
{
- CHECK_FIXNUM_COERCE_MARKER (start);
- CHECK_FIXNUM_COERCE_MARKER (end);
+ EMACS_INT s = fix_position (start), e = fix_position (end);
- if (XFIXNUM (start) > XFIXNUM (end))
+ if (e < s)
{
- Lisp_Object tem;
- tem = start; start = end; end = tem;
+ EMACS_INT tem = s; s = e; e = tem;
}
- if (!(BEG <= XFIXNUM (start) && XFIXNUM (start) <= XFIXNUM (end) && XFIXNUM (end) <= Z))
+ if (!(BEG <= s && s <= e && e <= Z))
args_out_of_range (start, end);
- if (BEGV != XFIXNAT (start) || ZV != XFIXNAT (end))
+ if (BEGV != s || ZV != e)
current_buffer->clip_changed = 1;
- SET_BUF_BEGV (current_buffer, XFIXNAT (start));
- SET_BUF_ZV (current_buffer, XFIXNAT (end));
- if (PT < XFIXNAT (start))
- SET_PT (XFIXNAT (start));
- if (PT > XFIXNAT (end))
- SET_PT (XFIXNAT (end));
+ SET_BUF_BEGV (current_buffer, s);
+ SET_BUF_ZV (current_buffer, e);
+ if (PT < s)
+ SET_PT (s);
+ if (e < PT)
+ SET_PT (e);
/* Changing the buffer bounds invalidates any recorded current column. */
invalidate_current_column ();
return Qnil;
struct buffer *bp = XBUFFER (object);
set_buffer_internal (bp);
- if (NILP (start))
- b = BEGV;
- else
- {
- CHECK_FIXNUM_COERCE_MARKER (start);
- b = XFIXNUM (start);
- }
-
- if (NILP (end))
- e = ZV;
- else
- {
- CHECK_FIXNUM_COERCE_MARKER (end);
- e = XFIXNUM (end);
- }
-
+ b = !NILP (start) ? fix_position (start) : BEGV;
+ e = !NILP (end) ? fix_position (end) : ZV;
if (b > e)
{
EMACS_INT temp = b;
Lisp_Object window;
struct window *w;
- CHECK_FIXNUM_COERCE_MARKER (position);
- if (! (BEGV <= XFIXNUM (position) && XFIXNUM (position) < ZV))
+ EMACS_INT fixed_pos = fix_position (position);
+ if (! (BEGV <= fixed_pos && fixed_pos < ZV))
args_out_of_range_3 (position, make_fixnum (BEGV), make_fixnum (ZV));
- pos = XFIXNUM (position);
+ pos = fixed_pos;
pos_byte = CHAR_TO_BYTE (pos);
if (NILP (ch))
c = FETCH_CHAR (pos_byte);
(Lisp_Object position, Lisp_Object window, Lisp_Object string)
{
struct window *w = decode_live_window (window);
+ EMACS_INT pos;
if (NILP (string))
{
if (XBUFFER (w->contents) != current_buffer)
error ("Specified window is not displaying the current buffer");
- CHECK_FIXNUM_COERCE_MARKER (position);
- if (! (BEGV <= XFIXNUM (position) && XFIXNUM (position) < ZV))
+ pos = fix_position (position);
+ if (! (BEGV <= pos && pos < ZV))
args_out_of_range_3 (position, make_fixnum (BEGV), make_fixnum (ZV));
}
else
{
CHECK_FIXNUM (position);
CHECK_STRING (string);
- if (! (0 <= XFIXNUM (position) && XFIXNUM (position) < SCHARS (string)))
+ pos = XFIXNUM (position);
+ if (! (0 <= pos && pos < SCHARS (string)))
args_out_of_range (string, position);
}
- return font_at (-1, XFIXNUM (position), NULL, w, string);
+ return font_at (-1, pos, NULL, w, string);
}
#if 0
if (!NILP (pos))
{
- CHECK_FIXNUM_COERCE_MARKER (pos);
- if (! (BEGV <= XFIXNUM (pos) && XFIXNUM (pos) <= ZV))
+ EMACS_INT p = fix_position (pos);
+ if (! (BEGV <= p && p <= ZV))
args_out_of_range (window, pos);
- textpos = XFIXNUM (pos);
+ textpos = p;
}
else if (w == XWINDOW (selected_window))
textpos = PT;
CHECK_RANGED_INTEGER (x, 0, TYPE_MAXIMUM (type)); \
} while (false)
-#define CHECK_FIXNUM_COERCE_MARKER(x) \
- do { \
- if (MARKERP ((x))) \
- XSETFASTINT (x, marker_position (x)); \
- else \
- CHECK_TYPE (FIXNUMP (x), Qinteger_or_marker_p, x); \
- } while (false)
-
INLINE double
XFLOATINT (Lisp_Object n)
{
}
else
{
- CHECK_FIXNUM_COERCE_MARKER (bound);
- lim = XFIXNUM (bound);
+ lim = fix_position (bound);
if (n > 0 ? lim < PT : lim > PT)
error ("Invalid search bound (wrong side of point)");
if (lim > ZV)
{
INTERVAL i;
ptrdiff_t searchpos;
+ Lisp_Object begin0 = *begin, end0 = *end;
CHECK_STRING_OR_BUFFER (object);
CHECK_FIXNUM_COERCE_MARKER (*begin);
if (!(BUF_BEGV (b) <= XFIXNUM (*begin) && XFIXNUM (*begin) <= XFIXNUM (*end)
&& XFIXNUM (*end) <= BUF_ZV (b)))
- args_out_of_range (*begin, *end);
+ args_out_of_range (begin0, end0);
i = buffer_intervals (b);
/* If there's no text, there are no properties. */
if (! (0 <= XFIXNUM (*begin) && XFIXNUM (*begin) <= XFIXNUM (*end)
&& XFIXNUM (*end) <= len))
- args_out_of_range (*begin, *end);
+ args_out_of_range (begin0, end0);
i = string_intervals (object);
if (len == 0)
{
struct window *w = 0;
- CHECK_FIXNUM_COERCE_MARKER (position);
+ EMACS_INT pos = fix_position (position);
if (NILP (object))
XSETBUFFER (object, current_buffer);
Lisp_Object *overlay_vec;
struct buffer *obuf = current_buffer;
- if (XFIXNUM (position) < BUF_BEGV (XBUFFER (object))
- || XFIXNUM (position) > BUF_ZV (XBUFFER (object)))
+ if (! (BUF_BEGV (XBUFFER (object)) <= pos
+ && pos <= BUF_ZV (XBUFFER (object))))
xsignal1 (Qargs_out_of_range, position);
set_buffer_temp (XBUFFER (object));
USE_SAFE_ALLOCA;
- GET_OVERLAYS_AT (XFIXNUM (position), overlay_vec, noverlays, NULL, false);
+ GET_OVERLAYS_AT (pos, overlay_vec, noverlays, NULL, false);
noverlays = sort_overlays (overlay_vec, noverlays, w);
set_buffer_temp (obuf);
/* Not a buffer, or no appropriate overlay, so fall through to the
simpler case. */
- return Fget_text_property (position, prop, object);
+ return Fget_text_property (make_fixnum (pos), prop, object);
}
DEFUN ("get-char-property", Fget_char_property, Sget_char_property, 2, 3, 0,
if (EQ (pos, Qt))
posint = -1;
else if (!NILP (pos))
- {
- CHECK_FIXNUM_COERCE_MARKER (pos);
- posint = XFIXNUM (pos);
- }
+ posint = fix_position (pos);
else if (w == XWINDOW (selected_window))
posint = PT;
else
start = pos;
}
else
- {
- CHECK_FIXNUM_COERCE_MARKER (from);
- start = min (max (XFIXNUM (from), BEGV), ZV);
- }
+ start = clip_to_bounds (BEGV, fix_position (from), ZV);
if (NILP (to))
end = ZV;
end = pos;
}
else
- {
- CHECK_FIXNUM_COERCE_MARKER (to);
- end = max (start, min (XFIXNUM (to), ZV));
- }
+ end = clip_to_bounds (start, fix_position (to), ZV);
if (!NILP (x_limit) && RANGED_FIXNUMP (0, x_limit, INT_MAX))
max_x = XFIXNUM (x_limit);