annotate src/marker.c @ 112442:76fa839f455e

* Makefile.in (MAKEINFO): Now controlled by `configure'. (MAKEINFO_OPTS): New variable. Use it where appropriate. (ENVADD): New variable to control texi2dvi and texi2pdf.
author Werner Lemberg <wl@gnu.org>
date Sun, 23 Jan 2011 11:22:21 +0100
parents 42e22c4f06b7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
1 /* Markers: examining, setting and deleting.
94963
8971ddf55736 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 91327
diff changeset
2 Copyright (C) 1985, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006,
112218
376148b31b5e Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents: 106815
diff changeset
3 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5 This file is part of GNU Emacs.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6
94963
8971ddf55736 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 91327
diff changeset
7 GNU Emacs is free software: you can redistribute it and/or modify
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
94963
8971ddf55736 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 91327
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
8971ddf55736 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 91327
diff changeset
10 (at your option) any later version.
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 GNU Emacs is distributed in the hope that it will be useful,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 GNU General Public License for more details.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
94963
8971ddf55736 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 91327
diff changeset
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 484
diff changeset
21 #include <config.h>
105669
68dd71358159 * alloc.c: Do not define struct catchtag.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 100951
diff changeset
22 #include <setjmp.h>
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 #include "lisp.h"
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 #include "buffer.h"
88351
aac41b50c875 Include "character.h" instead of "charset.h".
Kenichi Handa <handa@m17n.org>
parents: 41235
diff changeset
25 #include "character.h"
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
27 /* Record one cached position found recently by
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
28 buf_charpos_to_bytepos or buf_bytepos_to_charpos. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
29
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
30 static EMACS_INT cached_charpos;
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
31 static EMACS_INT cached_bytepos;
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
32 static struct buffer *cached_buffer;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
33 static int cached_modiff;
20678
4c69e3503cfc (clear_charpos_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20563
diff changeset
34
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
35 static void byte_char_debug_check (struct buffer *, EMACS_INT, EMACS_INT);
31830
cf1b4094811a Avoid some more compiler warnings.
Gerd Moellmann <gerd@gnu.org>
parents: 28417
diff changeset
36
21514
fa9ff387d260 Fix -Wimplicit warnings.
Andreas Schwab <schwab@suse.de>
parents: 21497
diff changeset
37 void
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
38 clear_charpos_cache (struct buffer *b)
20678
4c69e3503cfc (clear_charpos_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20563
diff changeset
39 {
4c69e3503cfc (clear_charpos_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20563
diff changeset
40 if (cached_buffer == b)
4c69e3503cfc (clear_charpos_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20563
diff changeset
41 cached_buffer = 0;
4c69e3503cfc (clear_charpos_cache): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20563
diff changeset
42 }
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
43
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
44 /* Converting between character positions and byte positions. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
45
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
46 /* There are several places in the buffer where we know
44651
392bc50108e8 Fix typo in comment.
Juanma Barranquero <lekktu@gmail.com>
parents: 44560
diff changeset
47 the correspondence: BEG, BEGV, PT, GPT, ZV and Z,
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
48 and everywhere there is a marker. So we find the one of these places
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
49 that is closest to the specified position, and scan from there. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
50
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
51 /* charpos_to_bytepos returns the byte position corresponding to CHARPOS. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
52
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
53 /* This macro is a subroutine of charpos_to_bytepos.
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
54 Note that it is desirable that BYTEPOS is not evaluated
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
55 except when we really want its value. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
56
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
57 #define CONSIDER(CHARPOS, BYTEPOS) \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
58 { \
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
59 EMACS_INT this_charpos = (CHARPOS); \
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
60 int changed = 0; \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
61 \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
62 if (this_charpos == charpos) \
20872
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
63 { \
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
64 EMACS_INT value = (BYTEPOS); \
20872
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
65 if (byte_debug_flag) \
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
66 byte_char_debug_check (b, charpos, value); \
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
67 return value; \
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
68 } \
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
69 else if (this_charpos > charpos) \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
70 { \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
71 if (this_charpos < best_above) \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
72 { \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
73 best_above = this_charpos; \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
74 best_above_byte = (BYTEPOS); \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
75 changed = 1; \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
76 } \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
77 } \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
78 else if (this_charpos > best_below) \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
79 { \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
80 best_below = this_charpos; \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
81 best_below_byte = (BYTEPOS); \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
82 changed = 1; \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
83 } \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
84 \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
85 if (changed) \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
86 { \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
87 if (best_above - best_below == best_above_byte - best_below_byte) \
20872
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
88 { \
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
89 EMACS_INT value = best_below_byte + (charpos - best_below); \
20872
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
90 if (byte_debug_flag) \
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
91 byte_char_debug_check (b, charpos, value); \
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
92 return value; \
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
93 } \
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
94 } \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
95 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
96
31830
cf1b4094811a Avoid some more compiler warnings.
Gerd Moellmann <gerd@gnu.org>
parents: 28417
diff changeset
97 static void
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
98 byte_char_debug_check (struct buffer *b, EMACS_INT charpos, EMACS_INT bytepos)
20872
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
99 {
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
100 EMACS_INT nchars = 0;
20872
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
101
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
102 if (bytepos > BUF_GPT_BYTE (b))
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
103 {
21219
29d2cf14040a (byte_char_debug_check): Call multibyte_chars_in_text
Kenichi Handa <handa@m17n.org>
parents: 20872
diff changeset
104 nchars = multibyte_chars_in_text (BUF_BEG_ADDR (b),
29d2cf14040a (byte_char_debug_check): Call multibyte_chars_in_text
Kenichi Handa <handa@m17n.org>
parents: 20872
diff changeset
105 BUF_GPT_BYTE (b) - BUF_BEG_BYTE (b));
29d2cf14040a (byte_char_debug_check): Call multibyte_chars_in_text
Kenichi Handa <handa@m17n.org>
parents: 20872
diff changeset
106 nchars += multibyte_chars_in_text (BUF_GAP_END_ADDR (b),
29d2cf14040a (byte_char_debug_check): Call multibyte_chars_in_text
Kenichi Handa <handa@m17n.org>
parents: 20872
diff changeset
107 bytepos - BUF_GPT_BYTE (b));
20872
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
108 }
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
109 else
21219
29d2cf14040a (byte_char_debug_check): Call multibyte_chars_in_text
Kenichi Handa <handa@m17n.org>
parents: 20872
diff changeset
110 nchars = multibyte_chars_in_text (BUF_BEG_ADDR (b),
29d2cf14040a (byte_char_debug_check): Call multibyte_chars_in_text
Kenichi Handa <handa@m17n.org>
parents: 20872
diff changeset
111 bytepos - BUF_BEG_BYTE (b));
20872
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
112
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
113 if (charpos - 1 != nchars)
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
114 abort ();
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
115 }
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
116
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
117 EMACS_INT
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
118 charpos_to_bytepos (EMACS_INT charpos)
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
119 {
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
120 return buf_charpos_to_bytepos (current_buffer, charpos);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
121 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
122
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
123 EMACS_INT
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
124 buf_charpos_to_bytepos (struct buffer *b, EMACS_INT charpos)
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
125 {
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
126 struct Lisp_Marker *tail;
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
127 EMACS_INT best_above, best_above_byte;
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
128 EMACS_INT best_below, best_below_byte;
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
129
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
130 if (charpos < BUF_BEG (b) || charpos > BUF_Z (b))
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
131 abort ();
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
132
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
133 best_above = BUF_Z (b);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
134 best_above_byte = BUF_Z_BYTE (b);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
135
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
136 /* If this buffer has as many characters as bytes,
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
137 each character must be one byte.
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
138 This takes care of the case where enable-multibyte-characters is nil. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
139 if (best_above == best_above_byte)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
140 return charpos;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
141
44328
ed296e71aa64 (buf_charpos_to_bytepos, buf_bytepos_to_charpos): Use BEG and BEG_BYTE.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41235
diff changeset
142 best_below = BEG;
ed296e71aa64 (buf_charpos_to_bytepos, buf_bytepos_to_charpos): Use BEG and BEG_BYTE.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41235
diff changeset
143 best_below_byte = BEG_BYTE;
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
144
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
145 /* We find in best_above and best_above_byte
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
146 the closest known point above CHARPOS,
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
147 and in best_below and best_below_byte
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
148 the closest known point below CHARPOS,
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
149
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
150 If at any point we can tell that the space between those
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
151 two best approximations is all single-byte,
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
152 we interpolate the result immediately. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
153
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
154 CONSIDER (BUF_PT (b), BUF_PT_BYTE (b));
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
155 CONSIDER (BUF_GPT (b), BUF_GPT_BYTE (b));
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
156 CONSIDER (BUF_BEGV (b), BUF_BEGV_BYTE (b));
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
157 CONSIDER (BUF_ZV (b), BUF_ZV_BYTE (b));
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
158
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
159 if (b == cached_buffer && BUF_MODIFF (b) == cached_modiff)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
160 CONSIDER (cached_charpos, cached_bytepos);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
161
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
162 for (tail = BUF_MARKERS (b); tail; tail = tail->next)
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
163 {
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
164 CONSIDER (tail->charpos, tail->bytepos);
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
165
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
166 /* If we are down to a range of 50 chars,
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
167 don't bother checking any other markers;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
168 scan the intervening chars directly now. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
169 if (best_above - best_below < 50)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
170 break;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
171 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
172
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
173 /* We get here if we did not exactly hit one of the known places.
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
174 We have one known above and one known below.
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
175 Scan, counting characters, from whichever one is closer. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
176
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
177 if (charpos - best_below < best_above - charpos)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
178 {
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
179 int record = charpos - best_below > 5000;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
180
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
181 while (best_below != charpos)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
182 {
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
183 best_below++;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
184 BUF_INC_POS (b, best_below_byte);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
185 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
186
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
187 /* If this position is quite far from the nearest known position,
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
188 cache the correspondence by creating a marker here.
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
189 It will last until the next GC. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
190 if (record)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
191 {
21497
837148a1541f (buf_charpos_to_bytepos, buf_bytepos_to_charpos):
Karl Heuer <kwzh@gnu.org>
parents: 21458
diff changeset
192 Lisp_Object marker, buffer;
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
193 marker = Fmake_marker ();
21497
837148a1541f (buf_charpos_to_bytepos, buf_bytepos_to_charpos):
Karl Heuer <kwzh@gnu.org>
parents: 21458
diff changeset
194 XSETBUFFER (buffer, b);
837148a1541f (buf_charpos_to_bytepos, buf_bytepos_to_charpos):
Karl Heuer <kwzh@gnu.org>
parents: 21458
diff changeset
195 set_marker_both (marker, buffer, best_below, best_below_byte);
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
196 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
197
20872
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
198 if (byte_debug_flag)
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
199 byte_char_debug_check (b, charpos, best_below_byte);
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
200
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
201 cached_buffer = b;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
202 cached_modiff = BUF_MODIFF (b);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
203 cached_charpos = best_below;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
204 cached_bytepos = best_below_byte;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
205
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
206 return best_below_byte;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
207 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
208 else
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
209 {
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
210 int record = best_above - charpos > 5000;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
211
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
212 while (best_above != charpos)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
213 {
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
214 best_above--;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
215 BUF_DEC_POS (b, best_above_byte);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
216 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
217
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
218 /* If this position is quite far from the nearest known position,
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
219 cache the correspondence by creating a marker here.
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
220 It will last until the next GC. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
221 if (record)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
222 {
21497
837148a1541f (buf_charpos_to_bytepos, buf_bytepos_to_charpos):
Karl Heuer <kwzh@gnu.org>
parents: 21458
diff changeset
223 Lisp_Object marker, buffer;
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
224 marker = Fmake_marker ();
21497
837148a1541f (buf_charpos_to_bytepos, buf_bytepos_to_charpos):
Karl Heuer <kwzh@gnu.org>
parents: 21458
diff changeset
225 XSETBUFFER (buffer, b);
837148a1541f (buf_charpos_to_bytepos, buf_bytepos_to_charpos):
Karl Heuer <kwzh@gnu.org>
parents: 21458
diff changeset
226 set_marker_both (marker, buffer, best_above, best_above_byte);
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
227 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
228
20872
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
229 if (byte_debug_flag)
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
230 byte_char_debug_check (b, charpos, best_above_byte);
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
231
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
232 cached_buffer = b;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
233 cached_modiff = BUF_MODIFF (b);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
234 cached_charpos = best_above;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
235 cached_bytepos = best_above_byte;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
236
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
237 return best_above_byte;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
238 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
239 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
240
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
241 #undef CONSIDER
50472
674bfa5d582d (verify_bytepos): New function.
Richard M. Stallman <rms@gnu.org>
parents: 49600
diff changeset
242
674bfa5d582d (verify_bytepos): New function.
Richard M. Stallman <rms@gnu.org>
parents: 49600
diff changeset
243 /* Used for debugging: recompute the bytepos corresponding to CHARPOS
674bfa5d582d (verify_bytepos): New function.
Richard M. Stallman <rms@gnu.org>
parents: 49600
diff changeset
244 in the simplest, most reliable way. */
674bfa5d582d (verify_bytepos): New function.
Richard M. Stallman <rms@gnu.org>
parents: 49600
diff changeset
245
110560
3b57f0a3b766 Fix int/EMACS_INT use in lread.c, marker.c, minibuf.c, print.c
Eli Zaretskii <eliz@gnu.org>
parents: 110511
diff changeset
246 EMACS_INT
3b57f0a3b766 Fix int/EMACS_INT use in lread.c, marker.c, minibuf.c, print.c
Eli Zaretskii <eliz@gnu.org>
parents: 110511
diff changeset
247 verify_bytepos (EMACS_INT charpos)
50472
674bfa5d582d (verify_bytepos): New function.
Richard M. Stallman <rms@gnu.org>
parents: 49600
diff changeset
248 {
110560
3b57f0a3b766 Fix int/EMACS_INT use in lread.c, marker.c, minibuf.c, print.c
Eli Zaretskii <eliz@gnu.org>
parents: 110511
diff changeset
249 EMACS_INT below = 1;
3b57f0a3b766 Fix int/EMACS_INT use in lread.c, marker.c, minibuf.c, print.c
Eli Zaretskii <eliz@gnu.org>
parents: 110511
diff changeset
250 EMACS_INT below_byte = 1;
50472
674bfa5d582d (verify_bytepos): New function.
Richard M. Stallman <rms@gnu.org>
parents: 49600
diff changeset
251
674bfa5d582d (verify_bytepos): New function.
Richard M. Stallman <rms@gnu.org>
parents: 49600
diff changeset
252 while (below != charpos)
674bfa5d582d (verify_bytepos): New function.
Richard M. Stallman <rms@gnu.org>
parents: 49600
diff changeset
253 {
674bfa5d582d (verify_bytepos): New function.
Richard M. Stallman <rms@gnu.org>
parents: 49600
diff changeset
254 below++;
674bfa5d582d (verify_bytepos): New function.
Richard M. Stallman <rms@gnu.org>
parents: 49600
diff changeset
255 BUF_INC_POS (current_buffer, below_byte);
674bfa5d582d (verify_bytepos): New function.
Richard M. Stallman <rms@gnu.org>
parents: 49600
diff changeset
256 }
674bfa5d582d (verify_bytepos): New function.
Richard M. Stallman <rms@gnu.org>
parents: 49600
diff changeset
257
674bfa5d582d (verify_bytepos): New function.
Richard M. Stallman <rms@gnu.org>
parents: 49600
diff changeset
258 return below_byte;
674bfa5d582d (verify_bytepos): New function.
Richard M. Stallman <rms@gnu.org>
parents: 49600
diff changeset
259 }
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
260
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
261 /* bytepos_to_charpos returns the char position corresponding to BYTEPOS. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
262
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
263 /* This macro is a subroutine of bytepos_to_charpos.
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
264 It is used when BYTEPOS is actually the byte position. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
265
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
266 #define CONSIDER(BYTEPOS, CHARPOS) \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
267 { \
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
268 EMACS_INT this_bytepos = (BYTEPOS); \
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
269 int changed = 0; \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
270 \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
271 if (this_bytepos == bytepos) \
20872
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
272 { \
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
273 EMACS_INT value = (CHARPOS); \
20872
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
274 if (byte_debug_flag) \
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
275 byte_char_debug_check (b, value, bytepos); \
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
276 return value; \
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
277 } \
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
278 else if (this_bytepos > bytepos) \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
279 { \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
280 if (this_bytepos < best_above_byte) \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
281 { \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
282 best_above = (CHARPOS); \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
283 best_above_byte = this_bytepos; \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
284 changed = 1; \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
285 } \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
286 } \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
287 else if (this_bytepos > best_below_byte) \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
288 { \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
289 best_below = (CHARPOS); \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
290 best_below_byte = this_bytepos; \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
291 changed = 1; \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
292 } \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
293 \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
294 if (changed) \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
295 { \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
296 if (best_above - best_below == best_above_byte - best_below_byte) \
20872
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
297 { \
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
298 EMACS_INT value = best_below + (bytepos - best_below_byte); \
20872
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
299 if (byte_debug_flag) \
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
300 byte_char_debug_check (b, value, bytepos); \
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
301 return value; \
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
302 } \
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
303 } \
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
304 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
305
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
306 EMACS_INT
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
307 bytepos_to_charpos (EMACS_INT bytepos)
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
308 {
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
309 return buf_bytepos_to_charpos (current_buffer, bytepos);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
310 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
311
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
312 EMACS_INT
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
313 buf_bytepos_to_charpos (struct buffer *b, EMACS_INT bytepos)
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
314 {
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
315 struct Lisp_Marker *tail;
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
316 EMACS_INT best_above, best_above_byte;
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
317 EMACS_INT best_below, best_below_byte;
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
318
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
319 if (bytepos < BUF_BEG_BYTE (b) || bytepos > BUF_Z_BYTE (b))
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
320 abort ();
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
321
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
322 best_above = BUF_Z (b);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
323 best_above_byte = BUF_Z_BYTE (b);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
324
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
325 /* If this buffer has as many characters as bytes,
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
326 each character must be one byte.
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
327 This takes care of the case where enable-multibyte-characters is nil. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
328 if (best_above == best_above_byte)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
329 return bytepos;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
330
44328
ed296e71aa64 (buf_charpos_to_bytepos, buf_bytepos_to_charpos): Use BEG and BEG_BYTE.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41235
diff changeset
331 best_below = BEG;
ed296e71aa64 (buf_charpos_to_bytepos, buf_bytepos_to_charpos): Use BEG and BEG_BYTE.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 41235
diff changeset
332 best_below_byte = BEG_BYTE;
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
333
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
334 CONSIDER (BUF_PT_BYTE (b), BUF_PT (b));
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
335 CONSIDER (BUF_GPT_BYTE (b), BUF_GPT (b));
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
336 CONSIDER (BUF_BEGV_BYTE (b), BUF_BEGV (b));
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
337 CONSIDER (BUF_ZV_BYTE (b), BUF_ZV (b));
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
338
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
339 if (b == cached_buffer && BUF_MODIFF (b) == cached_modiff)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
340 CONSIDER (cached_bytepos, cached_charpos);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
341
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
342 for (tail = BUF_MARKERS (b); tail; tail = tail->next)
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
343 {
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
344 CONSIDER (tail->bytepos, tail->charpos);
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
345
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
346 /* If we are down to a range of 50 chars,
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
347 don't bother checking any other markers;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
348 scan the intervening chars directly now. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
349 if (best_above - best_below < 50)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
350 break;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
351 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
352
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
353 /* We get here if we did not exactly hit one of the known places.
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
354 We have one known above and one known below.
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
355 Scan, counting characters, from whichever one is closer. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
356
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
357 if (bytepos - best_below_byte < best_above_byte - bytepos)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
358 {
22022
64ac294567a6 (unchain_marker): Abort if the marker is not in its buffer's chain.
Richard M. Stallman <rms@gnu.org>
parents: 21528
diff changeset
359 int record = bytepos - best_below_byte > 5000;
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
360
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
361 while (best_below_byte < bytepos)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
362 {
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
363 best_below++;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
364 BUF_INC_POS (b, best_below_byte);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
365 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
366
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
367 /* If this position is quite far from the nearest known position,
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
368 cache the correspondence by creating a marker here.
22022
64ac294567a6 (unchain_marker): Abort if the marker is not in its buffer's chain.
Richard M. Stallman <rms@gnu.org>
parents: 21528
diff changeset
369 It will last until the next GC.
64ac294567a6 (unchain_marker): Abort if the marker is not in its buffer's chain.
Richard M. Stallman <rms@gnu.org>
parents: 21528
diff changeset
370 But don't do it if BUF_MARKERS is nil;
64ac294567a6 (unchain_marker): Abort if the marker is not in its buffer's chain.
Richard M. Stallman <rms@gnu.org>
parents: 21528
diff changeset
371 that is a signal from Fset_buffer_multibyte. */
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
372 if (record && BUF_MARKERS (b))
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
373 {
21497
837148a1541f (buf_charpos_to_bytepos, buf_bytepos_to_charpos):
Karl Heuer <kwzh@gnu.org>
parents: 21458
diff changeset
374 Lisp_Object marker, buffer;
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
375 marker = Fmake_marker ();
21497
837148a1541f (buf_charpos_to_bytepos, buf_bytepos_to_charpos):
Karl Heuer <kwzh@gnu.org>
parents: 21458
diff changeset
376 XSETBUFFER (buffer, b);
837148a1541f (buf_charpos_to_bytepos, buf_bytepos_to_charpos):
Karl Heuer <kwzh@gnu.org>
parents: 21458
diff changeset
377 set_marker_both (marker, buffer, best_below, best_below_byte);
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
378 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
379
20872
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
380 if (byte_debug_flag)
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
381 byte_char_debug_check (b, best_below, bytepos);
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
382
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
383 cached_buffer = b;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
384 cached_modiff = BUF_MODIFF (b);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
385 cached_charpos = best_below;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
386 cached_bytepos = best_below_byte;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
387
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
388 return best_below;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
389 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
390 else
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
391 {
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
392 int record = best_above_byte - bytepos > 5000;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
393
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
394 while (best_above_byte > bytepos)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
395 {
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
396 best_above--;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
397 BUF_DEC_POS (b, best_above_byte);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
398 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
399
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
400 /* If this position is quite far from the nearest known position,
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
401 cache the correspondence by creating a marker here.
22022
64ac294567a6 (unchain_marker): Abort if the marker is not in its buffer's chain.
Richard M. Stallman <rms@gnu.org>
parents: 21528
diff changeset
402 It will last until the next GC.
64ac294567a6 (unchain_marker): Abort if the marker is not in its buffer's chain.
Richard M. Stallman <rms@gnu.org>
parents: 21528
diff changeset
403 But don't do it if BUF_MARKERS is nil;
64ac294567a6 (unchain_marker): Abort if the marker is not in its buffer's chain.
Richard M. Stallman <rms@gnu.org>
parents: 21528
diff changeset
404 that is a signal from Fset_buffer_multibyte. */
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
405 if (record && BUF_MARKERS (b))
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
406 {
21497
837148a1541f (buf_charpos_to_bytepos, buf_bytepos_to_charpos):
Karl Heuer <kwzh@gnu.org>
parents: 21458
diff changeset
407 Lisp_Object marker, buffer;
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
408 marker = Fmake_marker ();
21497
837148a1541f (buf_charpos_to_bytepos, buf_bytepos_to_charpos):
Karl Heuer <kwzh@gnu.org>
parents: 21458
diff changeset
409 XSETBUFFER (buffer, b);
837148a1541f (buf_charpos_to_bytepos, buf_bytepos_to_charpos):
Karl Heuer <kwzh@gnu.org>
parents: 21458
diff changeset
410 set_marker_both (marker, buffer, best_above, best_above_byte);
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
411 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
412
20872
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
413 if (byte_debug_flag)
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
414 byte_char_debug_check (b, best_above, bytepos);
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
415
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
416 cached_buffer = b;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
417 cached_modiff = BUF_MODIFF (b);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
418 cached_charpos = best_above;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
419 cached_bytepos = best_above_byte;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
420
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
421 return best_above;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
422 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
423 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
424
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
425 #undef CONSIDER
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
426
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 /* Operations on markers. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 DEFUN ("marker-buffer", Fmarker_buffer, Smarker_buffer, 1, 1, 0,
40553
440be654a370 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 34972
diff changeset
430 doc: /* Return the buffer that MARKER points into, or nil if none.
440be654a370 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 34972
diff changeset
431 Returns nil if MARKER points into a dead buffer. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109126
diff changeset
432 (register Lisp_Object marker)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
434 register Lisp_Object buf;
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40553
diff changeset
435 CHECK_MARKER (marker);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436 if (XMARKER (marker)->buffer)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437 {
9275
bb50d17f7441 (Fmarker_buffer): Use new accessor macros instead of calling XSET directly.
Karl Heuer <kwzh@gnu.org>
parents: 9121
diff changeset
438 XSETBUFFER (buf, XMARKER (marker)->buffer);
85014
ad5045db16f7 (Fmarker_buffer): Make test for odd case into a failure.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78260
diff changeset
439 /* If the buffer is dead, we're in trouble: the buffer pointer here
ad5045db16f7 (Fmarker_buffer): Make test for odd case into a failure.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78260
diff changeset
440 does not preserve the buffer from being GC'd (it's weak), so
ad5045db16f7 (Fmarker_buffer): Make test for odd case into a failure.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78260
diff changeset
441 markers have to be unlinked from their buffer as soon as the buffer
ad5045db16f7 (Fmarker_buffer): Make test for odd case into a failure.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78260
diff changeset
442 is killed. */
ad5045db16f7 (Fmarker_buffer): Make test for odd case into a failure.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78260
diff changeset
443 eassert (!NILP (XBUFFER (buf)->name));
ad5045db16f7 (Fmarker_buffer): Make test for odd case into a failure.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78260
diff changeset
444 return buf;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
445 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
446 return Qnil;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
447 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449 DEFUN ("marker-position", Fmarker_position, Smarker_position, 1, 1, 0,
72625
b7e16dcc0668 (Fmarker_position): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 71840
diff changeset
450 doc: /* Return the position MARKER points at, as a character number.
b7e16dcc0668 (Fmarker_position): Doc fix.
Juri Linkov <juri@jurta.org>
parents: 71840
diff changeset
451 Returns nil if MARKER points nowhere. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109126
diff changeset
452 (Lisp_Object marker)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453 {
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40553
diff changeset
454 CHECK_MARKER (marker);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455 if (XMARKER (marker)->buffer)
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
456 return make_number (XMARKER (marker)->charpos);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458 return Qnil;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 }
12999
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
460
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
461 DEFUN ("set-marker", Fset_marker, Sset_marker, 2, 3, 0,
40553
440be654a370 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 34972
diff changeset
462 doc: /* Position MARKER before character number POSITION in BUFFER.
440be654a370 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 34972
diff changeset
463 BUFFER defaults to the current buffer.
440be654a370 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 34972
diff changeset
464 If POSITION is nil, makes marker point nowhere.
440be654a370 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 34972
diff changeset
465 Then it no longer slows down editing in any buffer.
440be654a370 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 34972
diff changeset
466 Returns MARKER. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109126
diff changeset
467 (Lisp_Object marker, Lisp_Object position, Lisp_Object buffer)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
468 {
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
469 register EMACS_INT charno, bytepos;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470 register struct buffer *b;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471 register struct Lisp_Marker *m;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
472
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40553
diff changeset
473 CHECK_MARKER (marker);
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
474 m = XMARKER (marker);
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
475
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
476 /* If position is nil or a marker that points nowhere,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
477 make this marker point nowhere. */
14082
c6a1708f37d4 (Fset_marker): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 13327
diff changeset
478 if (NILP (position)
c6a1708f37d4 (Fset_marker): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 13327
diff changeset
479 || (MARKERP (position) && !XMARKER (position)->buffer))
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
480 {
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
481 unchain_marker (m);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
482 return marker;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
483 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
484
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 118
diff changeset
485 if (NILP (buffer))
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
486 b = current_buffer;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
487 else
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
488 {
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40553
diff changeset
489 CHECK_BUFFER (buffer);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
490 b = XBUFFER (buffer);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
491 /* If buffer is dead, set marker to point nowhere. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
492 if (EQ (b->name, Qnil))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
493 {
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
494 unchain_marker (m);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
495 return marker;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
496 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
497 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
498
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
499 /* Optimize the special case where we are copying the position
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
500 of an existing marker, and MARKER is already in the same buffer. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
501 if (MARKERP (position) && b == XMARKER (position)->buffer
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
502 && b == m->buffer)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
503 {
20563
d4de7ffb567d (buf_bytepos_to_charpos): Use marker bytepos, not bufpos.
Richard M. Stallman <rms@gnu.org>
parents: 20537
diff changeset
504 m->bytepos = XMARKER (position)->bytepos;
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
505 m->charpos = XMARKER (position)->charpos;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
506 return marker;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
507 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
508
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40553
diff changeset
509 CHECK_NUMBER_COERCE_MARKER (position);
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
510
14082
c6a1708f37d4 (Fset_marker): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 13327
diff changeset
511 charno = XINT (position);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
512
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
513 if (charno < BUF_BEG (b))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
514 charno = BUF_BEG (b);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
515 if (charno > BUF_Z (b))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
516 charno = BUF_Z (b);
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
517
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
518 bytepos = buf_charpos_to_bytepos (b, charno);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
519
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
520 /* Every character is at least one byte. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
521 if (charno > bytepos)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
522 abort ();
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
523
20563
d4de7ffb567d (buf_bytepos_to_charpos): Use marker bytepos, not bufpos.
Richard M. Stallman <rms@gnu.org>
parents: 20537
diff changeset
524 m->bytepos = bytepos;
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
525 m->charpos = charno;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
526
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
527 if (m->buffer != b)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
528 {
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
529 unchain_marker (m);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
530 m->buffer = b;
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
531 m->next = BUF_MARKERS (b);
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
532 BUF_MARKERS (b) = m;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
533 }
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 44651
diff changeset
534
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
535 return marker;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
536 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
537
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
538 /* This version of Fset_marker won't let the position
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
539 be outside the visible part. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
540
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 44651
diff changeset
541 Lisp_Object
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
542 set_marker_restricted (Lisp_Object marker, Lisp_Object pos, Lisp_Object buffer)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
543 {
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
544 register EMACS_INT charno, bytepos;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
545 register struct buffer *b;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
546 register struct Lisp_Marker *m;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
547
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40553
diff changeset
548 CHECK_MARKER (marker);
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
549 m = XMARKER (marker);
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
550
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
551 /* If position is nil or a marker that points nowhere,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
552 make this marker point nowhere. */
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
553 if (NILP (pos)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
554 || (MARKERP (pos) && !XMARKER (pos)->buffer))
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
555 {
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
556 unchain_marker (m);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
557 return marker;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
558 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
559
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 118
diff changeset
560 if (NILP (buffer))
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
561 b = current_buffer;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
562 else
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
563 {
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40553
diff changeset
564 CHECK_BUFFER (buffer);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
565 b = XBUFFER (buffer);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
566 /* If buffer is dead, set marker to point nowhere. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
567 if (EQ (b->name, Qnil))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
568 {
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
569 unchain_marker (m);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
570 return marker;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
571 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
572 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
573
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
574 /* Optimize the special case where we are copying the position
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
575 of an existing marker, and MARKER is already in the same buffer. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
576 if (MARKERP (pos) && b == XMARKER (pos)->buffer
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
577 && b == m->buffer)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
578 {
20563
d4de7ffb567d (buf_bytepos_to_charpos): Use marker bytepos, not bufpos.
Richard M. Stallman <rms@gnu.org>
parents: 20537
diff changeset
579 m->bytepos = XMARKER (pos)->bytepos;
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
580 m->charpos = XMARKER (pos)->charpos;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
581 return marker;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
582 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
583
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40553
diff changeset
584 CHECK_NUMBER_COERCE_MARKER (pos);
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
585
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
586 charno = XINT (pos);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
587
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
588 if (charno < BUF_BEGV (b))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
589 charno = BUF_BEGV (b);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
590 if (charno > BUF_ZV (b))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
591 charno = BUF_ZV (b);
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
592
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
593 bytepos = buf_charpos_to_bytepos (b, charno);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
594
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
595 /* Every character is at least one byte. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
596 if (charno > bytepos)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
597 abort ();
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
598
20563
d4de7ffb567d (buf_bytepos_to_charpos): Use marker bytepos, not bufpos.
Richard M. Stallman <rms@gnu.org>
parents: 20537
diff changeset
599 m->bytepos = bytepos;
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
600 m->charpos = charno;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
601
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
602 if (m->buffer != b)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
603 {
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
604 unchain_marker (m);
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
605 m->buffer = b;
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
606 m->next = BUF_MARKERS (b);
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
607 BUF_MARKERS (b) = m;
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
608 }
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 44651
diff changeset
609
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
610 return marker;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
611 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
612
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
613 /* Set the position of MARKER, specifying both the
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
614 character position and the corresponding byte position. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
615
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 44651
diff changeset
616 Lisp_Object
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
617 set_marker_both (Lisp_Object marker, Lisp_Object buffer, EMACS_INT charpos, EMACS_INT bytepos)
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
618 {
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
619 register struct buffer *b;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
620 register struct Lisp_Marker *m;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
621
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40553
diff changeset
622 CHECK_MARKER (marker);
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
623 m = XMARKER (marker);
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
624
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
625 if (NILP (buffer))
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
626 b = current_buffer;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
627 else
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
628 {
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40553
diff changeset
629 CHECK_BUFFER (buffer);
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
630 b = XBUFFER (buffer);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
631 /* If buffer is dead, set marker to point nowhere. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
632 if (EQ (b->name, Qnil))
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
633 {
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
634 unchain_marker (m);
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
635 return marker;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
636 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
637 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
638
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
639 /* In a single-byte buffer, the two positions must be equal. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
640 if (BUF_Z (b) == BUF_Z_BYTE (b)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
641 && charpos != bytepos)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
642 abort ();
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
643 /* Every character is at least one byte. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
644 if (charpos > bytepos)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
645 abort ();
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
646
20563
d4de7ffb567d (buf_bytepos_to_charpos): Use marker bytepos, not bufpos.
Richard M. Stallman <rms@gnu.org>
parents: 20537
diff changeset
647 m->bytepos = bytepos;
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
648 m->charpos = charpos;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
649
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
650 if (m->buffer != b)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
651 {
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
652 unchain_marker (m);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
653 m->buffer = b;
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
654 m->next = BUF_MARKERS (b);
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
655 BUF_MARKERS (b) = m;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
656 }
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 44651
diff changeset
657
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
658 return marker;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
659 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
660
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
661 /* This version of set_marker_both won't let the position
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
662 be outside the visible part. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
663
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 44651
diff changeset
664 Lisp_Object
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
665 set_marker_restricted_both (Lisp_Object marker, Lisp_Object buffer, EMACS_INT charpos, EMACS_INT bytepos)
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
666 {
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
667 register struct buffer *b;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
668 register struct Lisp_Marker *m;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
669
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40553
diff changeset
670 CHECK_MARKER (marker);
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
671 m = XMARKER (marker);
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
672
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
673 if (NILP (buffer))
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
674 b = current_buffer;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
675 else
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
676 {
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40553
diff changeset
677 CHECK_BUFFER (buffer);
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
678 b = XBUFFER (buffer);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
679 /* If buffer is dead, set marker to point nowhere. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
680 if (EQ (b->name, Qnil))
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
681 {
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
682 unchain_marker (m);
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
683 return marker;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
684 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
685 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
686
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
687 if (charpos < BUF_BEGV (b))
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
688 charpos = BUF_BEGV (b);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
689 if (charpos > BUF_ZV (b))
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
690 charpos = BUF_ZV (b);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
691 if (bytepos < BUF_BEGV_BYTE (b))
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
692 bytepos = BUF_BEGV_BYTE (b);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
693 if (bytepos > BUF_ZV_BYTE (b))
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
694 bytepos = BUF_ZV_BYTE (b);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
695
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
696 /* In a single-byte buffer, the two positions must be equal. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
697 if (BUF_Z (b) == BUF_Z_BYTE (b)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
698 && charpos != bytepos)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
699 abort ();
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
700 /* Every character is at least one byte. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
701 if (charpos > bytepos)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
702 abort ();
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
703
20563
d4de7ffb567d (buf_bytepos_to_charpos): Use marker bytepos, not bufpos.
Richard M. Stallman <rms@gnu.org>
parents: 20537
diff changeset
704 m->bytepos = bytepos;
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
705 m->charpos = charpos;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
706
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
707 if (m->buffer != b)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
708 {
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
709 unchain_marker (m);
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
710 m->buffer = b;
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
711 m->next = BUF_MARKERS (b);
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
712 BUF_MARKERS (b) = m;
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
713 }
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 44651
diff changeset
714
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
715 return marker;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
716 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
717
41235
23d7de34a596 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
718 /* Remove MARKER from the chain of whatever buffer it is in.
23d7de34a596 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
719 Leave it "in no buffer".
23d7de34a596 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
720
23d7de34a596 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 40656
diff changeset
721 This is called during garbage collection,
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
722 so we must be careful to ignore and preserve mark bits,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
723 including those in chain fields of markers. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
724
20301
6e2ea54ad704 (unchain_marker): Define as returning nothing.
Andreas Schwab <schwab@suse.de>
parents: 16418
diff changeset
725 void
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
726 unchain_marker (register struct Lisp_Marker *marker)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
727 {
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
728 register struct Lisp_Marker *tail, *prev, *next;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
729 register struct buffer *b;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
730
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
731 b = marker->buffer;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
732 if (b == 0)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
733 return;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
734
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
735 if (EQ (b->name, Qnil))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
736 abort ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
737
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
738 marker->buffer = 0;
22022
64ac294567a6 (unchain_marker): Abort if the marker is not in its buffer's chain.
Richard M. Stallman <rms@gnu.org>
parents: 21528
diff changeset
739
10315
c78d0bb85d30 Use BUF_MARKERS throughout.
Richard M. Stallman <rms@gnu.org>
parents: 9315
diff changeset
740 tail = BUF_MARKERS (b);
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
741 prev = NULL;
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
742 while (tail)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
743 {
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
744 next = tail->next;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
745
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
746 if (marker == tail)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
747 {
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
748 if (!prev)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
749 {
10315
c78d0bb85d30 Use BUF_MARKERS throughout.
Richard M. Stallman <rms@gnu.org>
parents: 9315
diff changeset
750 BUF_MARKERS (b) = next;
c78d0bb85d30 Use BUF_MARKERS throughout.
Richard M. Stallman <rms@gnu.org>
parents: 9315
diff changeset
751 /* Deleting first marker from the buffer's chain. Crash
c78d0bb85d30 Use BUF_MARKERS throughout.
Richard M. Stallman <rms@gnu.org>
parents: 9315
diff changeset
752 if new first marker in chain does not say it belongs
10999
84076f6a1f1b (unchain_marker): Allow differing buffers
Richard M. Stallman <rms@gnu.org>
parents: 10315
diff changeset
753 to the same buffer, or at least that they have the same
84076f6a1f1b (unchain_marker): Allow differing buffers
Richard M. Stallman <rms@gnu.org>
parents: 10315
diff changeset
754 base buffer. */
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
755 if (next && b->text != next->buffer->text)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
756 abort ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
757 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
758 else
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
759 prev->next = next;
22022
64ac294567a6 (unchain_marker): Abort if the marker is not in its buffer's chain.
Richard M. Stallman <rms@gnu.org>
parents: 21528
diff changeset
760 /* We have removed the marker from the chain;
64ac294567a6 (unchain_marker): Abort if the marker is not in its buffer's chain.
Richard M. Stallman <rms@gnu.org>
parents: 21528
diff changeset
761 no need to scan the rest of the chain. */
64ac294567a6 (unchain_marker): Abort if the marker is not in its buffer's chain.
Richard M. Stallman <rms@gnu.org>
parents: 21528
diff changeset
762 return;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
763 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
764 else
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
765 prev = tail;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
766 tail = next;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
767 }
22022
64ac294567a6 (unchain_marker): Abort if the marker is not in its buffer's chain.
Richard M. Stallman <rms@gnu.org>
parents: 21528
diff changeset
768
64ac294567a6 (unchain_marker): Abort if the marker is not in its buffer's chain.
Richard M. Stallman <rms@gnu.org>
parents: 21528
diff changeset
769 /* Marker was not in its chain. */
64ac294567a6 (unchain_marker): Abort if the marker is not in its buffer's chain.
Richard M. Stallman <rms@gnu.org>
parents: 21528
diff changeset
770 abort ();
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
771 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
772
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
773 /* Return the char position of marker MARKER, as a C integer. */
10315
c78d0bb85d30 Use BUF_MARKERS throughout.
Richard M. Stallman <rms@gnu.org>
parents: 9315
diff changeset
774
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
775 EMACS_INT
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
776 marker_position (Lisp_Object marker)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
777 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
778 register struct Lisp_Marker *m = XMARKER (marker);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
779 register struct buffer *buf = m->buffer;
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
780
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
781 if (!buf)
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
782 error ("Marker does not point anywhere");
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
783
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
784 return m->charpos;
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
785 }
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
786
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
787 /* Return the byte position of marker MARKER, as a C integer. */
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
788
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
789 EMACS_INT
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
790 marker_byte_position (Lisp_Object marker)
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
791 {
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
792 register struct Lisp_Marker *m = XMARKER (marker);
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
793 register struct buffer *buf = m->buffer;
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
794 register EMACS_INT i = m->bytepos;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
795
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
796 if (!buf)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
797 error ("Marker does not point anywhere");
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
798
20537
cc87b03bad13 (marker_byte_position): Renamed from marker_position.
Richard M. Stallman <rms@gnu.org>
parents: 20301
diff changeset
799 if (i < BUF_BEG_BYTE (buf) || i > BUF_Z_BYTE (buf))
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
800 abort ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
801
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
802 return i;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
803 }
12999
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
804
110033
2c9ea5d32862 * src/marker.c (Fcopy_marker): Make the first arg optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 109179
diff changeset
805 DEFUN ("copy-marker", Fcopy_marker, Scopy_marker, 0, 2, 0,
40553
440be654a370 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 34972
diff changeset
806 doc: /* Return a new marker pointing at the same place as MARKER.
440be654a370 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 34972
diff changeset
807 If argument is a number, makes a new marker pointing
440be654a370 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 34972
diff changeset
808 at that position in the current buffer.
110033
2c9ea5d32862 * src/marker.c (Fcopy_marker): Make the first arg optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 109179
diff changeset
809 If MARKER is not specified, the new marker does not point anywhere.
40553
440be654a370 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 34972
diff changeset
810 The optional argument TYPE specifies the insertion type of the new marker;
440be654a370 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 34972
diff changeset
811 see `marker-insertion-type'. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109126
diff changeset
812 (register Lisp_Object marker, Lisp_Object type)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
813 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
814 register Lisp_Object new;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
815
110033
2c9ea5d32862 * src/marker.c (Fcopy_marker): Make the first arg optional.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 109179
diff changeset
816 if (!NILP (marker))
71840
96e9b3cb9809 (Fcopy_marker): Use CHECK_TYPE.
Kim F. Storm <storm@cua.dk>
parents: 68651
diff changeset
817 CHECK_TYPE (INTEGERP (marker) || MARKERP (marker), Qinteger_or_marker_p, marker);
22744
79ca732d9740 (Fcopy_marker): Make return from wrong_type_argument
Karl Heuer <kwzh@gnu.org>
parents: 22022
diff changeset
818
79ca732d9740 (Fcopy_marker): Make return from wrong_type_argument
Karl Heuer <kwzh@gnu.org>
parents: 22022
diff changeset
819 new = Fmake_marker ();
79ca732d9740 (Fcopy_marker): Make return from wrong_type_argument
Karl Heuer <kwzh@gnu.org>
parents: 22022
diff changeset
820 Fset_marker (new, marker,
79ca732d9740 (Fcopy_marker): Make return from wrong_type_argument
Karl Heuer <kwzh@gnu.org>
parents: 22022
diff changeset
821 (MARKERP (marker) ? Fmarker_buffer (marker) : Qnil));
79ca732d9740 (Fcopy_marker): Make return from wrong_type_argument
Karl Heuer <kwzh@gnu.org>
parents: 22022
diff changeset
822 XMARKER (new)->insertion_type = !NILP (type);
79ca732d9740 (Fcopy_marker): Make return from wrong_type_argument
Karl Heuer <kwzh@gnu.org>
parents: 22022
diff changeset
823 return new;
12999
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
824 }
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
825
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
826 DEFUN ("marker-insertion-type", Fmarker_insertion_type,
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
827 Smarker_insertion_type, 1, 1, 0,
40553
440be654a370 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 34972
diff changeset
828 doc: /* Return insertion type of MARKER: t if it stays after inserted text.
74568
21b2a6ce1aa9 (Fmarker_insertion_type): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents: 72625
diff changeset
829 The value nil means the marker stays before text inserted there. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109126
diff changeset
830 (register Lisp_Object marker)
12999
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
831 {
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40553
diff changeset
832 CHECK_MARKER (marker);
12999
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
833 return XMARKER (marker)->insertion_type ? Qt : Qnil;
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
834 }
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
835
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
836 DEFUN ("set-marker-insertion-type", Fset_marker_insertion_type,
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
837 Sset_marker_insertion_type, 2, 2, 0,
40553
440be654a370 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 34972
diff changeset
838 doc: /* Set the insertion-type of MARKER to TYPE.
440be654a370 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 34972
diff changeset
839 If TYPE is t, it means the marker advances when you insert text at it.
440be654a370 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 34972
diff changeset
840 If TYPE is nil, it means the marker stays behind when you insert text at it. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109126
diff changeset
841 (Lisp_Object marker, Lisp_Object type)
12999
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
842 {
40656
cdfd4d09b79a Update usage of CHECK_ macros (remove unused second argument).
Pavel Janík <Pavel@Janik.cz>
parents: 40553
diff changeset
843 CHECK_MARKER (marker);
12999
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
844
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
845 XMARKER (marker)->insertion_type = ! NILP (type);
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
846 return type;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
847 }
16418
cf4260218aec (Fbuffer_has_markers_at): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
848
cf4260218aec (Fbuffer_has_markers_at): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
849 DEFUN ("buffer-has-markers-at", Fbuffer_has_markers_at, Sbuffer_has_markers_at,
40553
440be654a370 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 34972
diff changeset
850 1, 1, 0,
440be654a370 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 34972
diff changeset
851 doc: /* Return t if there are markers pointing at POSITION in the current buffer. */)
109179
8cfee7d2955f Convert DEFUNs to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109126
diff changeset
852 (Lisp_Object position)
16418
cf4260218aec (Fbuffer_has_markers_at): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
853 {
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
854 register struct Lisp_Marker *tail;
110511
5746a646bb03 Fix EMACS_INT/int conversion errors in marker.c.
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents: 110033
diff changeset
855 register EMACS_INT charno;
16418
cf4260218aec (Fbuffer_has_markers_at): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
856
cf4260218aec (Fbuffer_has_markers_at): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
857 charno = XINT (position);
cf4260218aec (Fbuffer_has_markers_at): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
858
cf4260218aec (Fbuffer_has_markers_at): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
859 if (charno < BEG)
cf4260218aec (Fbuffer_has_markers_at): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
860 charno = BEG;
cf4260218aec (Fbuffer_has_markers_at): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
861 if (charno > Z)
cf4260218aec (Fbuffer_has_markers_at): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
862 charno = Z;
cf4260218aec (Fbuffer_has_markers_at): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
863
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
864 for (tail = BUF_MARKERS (current_buffer); tail; tail = tail->next)
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
865 if (tail->charpos == charno)
16418
cf4260218aec (Fbuffer_has_markers_at): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
866 return Qt;
cf4260218aec (Fbuffer_has_markers_at): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
867
cf4260218aec (Fbuffer_has_markers_at): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
868 return Qnil;
cf4260218aec (Fbuffer_has_markers_at): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
869 }
44560
0fddc27db9ae (count_markers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 44328
diff changeset
870
0fddc27db9ae (count_markers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 44328
diff changeset
871 /* For debugging -- count the markers in buffer BUF. */
0fddc27db9ae (count_markers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 44328
diff changeset
872
0fddc27db9ae (count_markers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 44328
diff changeset
873 int
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
874 count_markers (struct buffer *buf)
44560
0fddc27db9ae (count_markers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 44328
diff changeset
875 {
0fddc27db9ae (count_markers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 44328
diff changeset
876 int total = 0;
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
877 struct Lisp_Marker *tail;
44560
0fddc27db9ae (count_markers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 44328
diff changeset
878
51672
018c85ec9a1e (buf_charpos_to_bytepos, buf_bytepos_to_charpos)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 50472
diff changeset
879 for (tail = BUF_MARKERS (buf); tail; tail = tail->next)
44560
0fddc27db9ae (count_markers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 44328
diff changeset
880 total++;
0fddc27db9ae (count_markers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 44328
diff changeset
881
0fddc27db9ae (count_markers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 44328
diff changeset
882 return total;
0fddc27db9ae (count_markers): New function.
Richard M. Stallman <rms@gnu.org>
parents: 44328
diff changeset
883 }
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
884
20301
6e2ea54ad704 (unchain_marker): Define as returning nothing.
Andreas Schwab <schwab@suse.de>
parents: 16418
diff changeset
885 void
109126
aec1143e8d85 Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109100
diff changeset
886 syms_of_marker (void)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
887 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
888 defsubr (&Smarker_position);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
889 defsubr (&Smarker_buffer);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
890 defsubr (&Sset_marker);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
891 defsubr (&Scopy_marker);
12999
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
892 defsubr (&Smarker_insertion_type);
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
893 defsubr (&Sset_marker_insertion_type);
16418
cf4260218aec (Fbuffer_has_markers_at): New function.
Richard M. Stallman <rms@gnu.org>
parents: 14186
diff changeset
894 defsubr (&Sbuffer_has_markers_at);
20872
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
895
112364
42e22c4f06b7 Move all DEFVAR'd globals into a structure -- threading infrastructure
Tom Tromey <tromey@redhat.com>
parents: 112278
diff changeset
896 DEFVAR_BOOL ("byte-debug-flag", byte_debug_flag,
40553
440be654a370 Change doc-string comments to `new style' [w/`doc:' keyword].
Pavel Janík <Pavel@Janik.cz>
parents: 34972
diff changeset
897 doc: /* Non-nil enables debugging checks in byte/char position conversions. */);
20872
431f875501a6 (byte_char_debug_check): New function.
Richard M. Stallman <rms@gnu.org>
parents: 20706
diff changeset
898 byte_debug_flag = 0;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
899 }
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 51672
diff changeset
900