diff options
| author | Eli Zaretskii | 2013-03-28 20:13:59 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2013-03-28 20:13:59 +0200 |
| commit | d76bf86f438d4f5f9fe493ab76f02ffc78f3ae2e (patch) | |
| tree | 04fa8bc7bd2058a316a7ee30f8741d25bfd0b060 /src/marker.c | |
| parent | 2ef26ceb192c7683754cf0b4aa3087f501254332 (diff) | |
| parent | e74aeda863cd6896e06e92586f87b45d63d67d15 (diff) | |
| download | emacs-d76bf86f438d4f5f9fe493ab76f02ffc78f3ae2e.tar.gz emacs-d76bf86f438d4f5f9fe493ab76f02ffc78f3ae2e.zip | |
Merge from trunk and resolve conflicts.
Diffstat (limited to 'src/marker.c')
| -rw-r--r-- | src/marker.c | 52 |
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 | ||
| 4 | This file is part of GNU Emacs. | 5 | This 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 | ||
| 131 | ptrdiff_t | 130 | /* Return the byte position corresponding to CHARPOS in B. */ |
| 132 | charpos_to_bytepos (ptrdiff_t charpos) | ||
| 133 | { | ||
| 134 | return buf_charpos_to_bytepos (current_buffer, charpos); | ||
| 135 | } | ||
| 136 | 131 | ||
| 137 | ptrdiff_t | 132 | ptrdiff_t |
| 138 | buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos) | 133 | buf_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 | |||
| 291 | ptrdiff_t | 284 | ptrdiff_t |
| 292 | buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos) | 285 | buf_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; |