aboutsummaryrefslogtreecommitdiffstats
path: root/src/marker.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/marker.c')
-rw-r--r--src/marker.c52
1 files changed, 31 insertions, 21 deletions
diff --git a/src/marker.c b/src/marker.c
index 69be4faec3a..63027d3be5e 100644
--- a/src/marker.c
+++ b/src/marker.c
@@ -1,5 +1,6 @@
1/* Markers: examining, setting and deleting. 1/* Markers: examining, setting and deleting.
2 Copyright (C) 1985, 1997-1998, 2001-2012 Free Software Foundation, Inc. 2 Copyright (C) 1985, 1997-1998, 2001-2013 Free Software Foundation,
3 Inc.
3 4
4This file is part of GNU Emacs. 5This file is part of GNU Emacs.
5 6
@@ -82,9 +83,7 @@ clear_charpos_cache (struct buffer *b)
82 and everywhere there is a marker. So we find the one of these places 83 and everywhere there is a marker. So we find the one of these places
83 that is closest to the specified position, and scan from there. */ 84 that is closest to the specified position, and scan from there. */
84 85
85/* charpos_to_bytepos returns the byte position corresponding to CHARPOS. */ 86/* This macro is a subroutine of buf_charpos_to_bytepos.
86
87/* This macro is a subroutine of charpos_to_bytepos.
88 Note that it is desirable that BYTEPOS is not evaluated 87 Note that it is desirable that BYTEPOS is not evaluated
89 except when we really want its value. */ 88 except when we really want its value. */
90 89
@@ -128,11 +127,7 @@ clear_charpos_cache (struct buffer *b)
128 } \ 127 } \
129} 128}
130 129
131ptrdiff_t 130/* Return the byte position corresponding to CHARPOS in B. */
132charpos_to_bytepos (ptrdiff_t charpos)
133{
134 return buf_charpos_to_bytepos (current_buffer, charpos);
135}
136 131
137ptrdiff_t 132ptrdiff_t
138buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos) 133buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos)
@@ -141,8 +136,7 @@ buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos)
141 ptrdiff_t best_above, best_above_byte; 136 ptrdiff_t best_above, best_above_byte;
142 ptrdiff_t best_below, best_below_byte; 137 ptrdiff_t best_below, best_below_byte;
143 138
144 if (charpos < BUF_BEG (b) || charpos > BUF_Z (b)) 139 eassert (BUF_BEG (b) <= charpos && charpos <= BUF_Z (b));
145 emacs_abort ();
146 140
147 best_above = BUF_Z (b); 141 best_above = BUF_Z (b);
148 best_above_byte = BUF_Z_BYTE (b); 142 best_above_byte = BUF_Z_BYTE (b);
@@ -242,9 +236,6 @@ buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos)
242 236
243#undef CONSIDER 237#undef CONSIDER
244 238
245/* buf_bytepos_to_charpos returns the char position corresponding to
246 BYTEPOS. */
247
248/* This macro is a subroutine of buf_bytepos_to_charpos. 239/* This macro is a subroutine of buf_bytepos_to_charpos.
249 It is used when BYTEPOS is actually the byte position. */ 240 It is used when BYTEPOS is actually the byte position. */
250 241
@@ -288,6 +279,8 @@ buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos)
288 } \ 279 } \
289} 280}
290 281
282/* Return the character position corresponding to BYTEPOS in B. */
283
291ptrdiff_t 284ptrdiff_t
292buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos) 285buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos)
293{ 286{
@@ -295,8 +288,7 @@ buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos)
295 ptrdiff_t best_above, best_above_byte; 288 ptrdiff_t best_above, best_above_byte;
296 ptrdiff_t best_below, best_below_byte; 289 ptrdiff_t best_below, best_below_byte;
297 290
298 if (bytepos < BUF_BEG_BYTE (b) || bytepos > BUF_Z_BYTE (b)) 291 eassert (BUF_BEG_BYTE (b) <= bytepos && bytepos <= BUF_Z_BYTE (b));
299 emacs_abort ();
300 292
301 best_above = BUF_Z (b); 293 best_above = BUF_Z (b);
302 best_above_byte = BUF_Z_BYTE (b); 294 best_above_byte = BUF_Z_BYTE (b);
@@ -507,11 +499,29 @@ set_marker_internal (Lisp_Object marker, Lisp_Object position,
507 { 499 {
508 register ptrdiff_t charpos, bytepos; 500 register ptrdiff_t charpos, bytepos;
509 501
510 CHECK_NUMBER_COERCE_MARKER (position); 502 /* Do not use CHECK_NUMBER_COERCE_MARKER because we
511 charpos = clip_to_bounds (restricted ? BUF_BEGV (b) : BUF_BEG (b), 503 don't want to call buf_charpos_to_bytepos if POSITION
512 XINT (position), 504 is a marker and so we know the bytepos already. */
513 restricted ? BUF_ZV (b) : BUF_Z (b)); 505 if (INTEGERP (position))
514 bytepos = buf_charpos_to_bytepos (b, charpos); 506 charpos = XINT (position), bytepos = -1;
507 else if (MARKERP (position))
508 {
509 charpos = XMARKER (position)->charpos;
510 bytepos = XMARKER (position)->bytepos;
511 }
512 else
513 wrong_type_argument (Qinteger_or_marker_p, position);
514
515 charpos = clip_to_bounds
516 (restricted ? BUF_BEGV (b) : BUF_BEG (b), charpos,
517 restricted ? BUF_ZV (b) : BUF_Z (b));
518 if (bytepos == -1)
519 bytepos = buf_charpos_to_bytepos (b, charpos);
520 else
521 bytepos = clip_to_bounds
522 (restricted ? BUF_BEGV_BYTE (b) : BUF_BEG_BYTE (b),
523 bytepos, restricted ? BUF_ZV_BYTE (b) : BUF_Z_BYTE (b));
524
515 attach_marker (m, b, charpos, bytepos); 525 attach_marker (m, b, charpos, bytepos);
516 } 526 }
517 return marker; 527 return marker;