annotate src/marker.c @ 15269:b6381b3a6c99

(make-backup-file-name): Check msdos-long-file-names. (basic-save-buffer-1, make-auto-save-file-name): Likewise.
author Karl Heuer <kwzh@gnu.org>
date Tue, 21 May 1996 17:21:25 +0000
parents ee40177f6c68
children cf4260218aec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /* Markers: examining, setting and killing.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2 Copyright (C) 1985 Free Software Foundation, Inc.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 This file is part of GNU Emacs.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
12244
ac7375e60931 Update GPL to version 2.
Karl Heuer <kwzh@gnu.org>
parents: 10999
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 any later version.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 GNU General Public License for more details.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14082
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14082
diff changeset
19 Boston, MA 02111-1307, USA. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 484
diff changeset
22 #include <config.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"
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 /* Operations on markers. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 DEFUN ("marker-buffer", Fmarker_buffer, Smarker_buffer, 1, 1, 0,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 "Return the buffer that MARKER points into, or nil if none.\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 Returns nil if MARKER points into a dead buffer.")
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 (marker)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 register Lisp_Object marker;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 register Lisp_Object buf;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 CHECK_MARKER (marker, 0);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 if (XMARKER (marker)->buffer)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 {
9275
bb50d17f7441 (Fmarker_buffer): Use new accessor macros instead of calling XSET directly.
Karl Heuer <kwzh@gnu.org>
parents: 9121
diff changeset
38 XSETBUFFER (buf, XMARKER (marker)->buffer);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 /* Return marker's buffer only if it is not dead. */
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 118
diff changeset
40 if (!NILP (XBUFFER (buf)->name))
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 return buf;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 return Qnil;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 DEFUN ("marker-position", Fmarker_position, Smarker_position, 1, 1, 0,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 "Return the position MARKER points at, as a character number.")
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 (marker)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 Lisp_Object marker;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 register Lisp_Object pos;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 register int i;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 register struct buffer *buf;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 CHECK_MARKER (marker, 0);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 if (XMARKER (marker)->buffer)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 buf = XMARKER (marker)->buffer;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 i = XMARKER (marker)->bufpos;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 if (i > BUF_GPT (buf) + BUF_GAP_SIZE (buf))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 i -= BUF_GAP_SIZE (buf);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 else if (i > BUF_GPT (buf))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 i = BUF_GPT (buf);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 if (i < BUF_BEG (buf) || i > BUF_Z (buf))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 abort ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68
9315
77eba75a44a0 (Fmarker_position): Don't use XFASTINT as an lvalue.
Karl Heuer <kwzh@gnu.org>
parents: 9275
diff changeset
69 XSETFASTINT (pos, i);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 return pos;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 return Qnil;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 }
12999
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
74
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 DEFUN ("set-marker", Fset_marker, Sset_marker, 2, 3, 0,
14082
c6a1708f37d4 (Fset_marker): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 13327
diff changeset
76 "Position MARKER before character number POSITION in BUFFER.\n\
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 BUFFER defaults to the current buffer.\n\
14082
c6a1708f37d4 (Fset_marker): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 13327
diff changeset
78 If POSITION is nil, makes marker point nowhere.\n\
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 Then it no longer slows down editing in any buffer.\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 Returns MARKER.")
14082
c6a1708f37d4 (Fset_marker): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 13327
diff changeset
81 (marker, position, buffer)
c6a1708f37d4 (Fset_marker): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 13327
diff changeset
82 Lisp_Object marker, position, buffer;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 register int charno;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 register struct buffer *b;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 register struct Lisp_Marker *m;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 CHECK_MARKER (marker, 0);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 /* If position is nil or a marker that points nowhere,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 make this marker point nowhere. */
14082
c6a1708f37d4 (Fset_marker): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 13327
diff changeset
91 if (NILP (position)
c6a1708f37d4 (Fset_marker): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 13327
diff changeset
92 || (MARKERP (position) && !XMARKER (position)->buffer))
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 unchain_marker (marker);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 return marker;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97
14082
c6a1708f37d4 (Fset_marker): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 13327
diff changeset
98 CHECK_NUMBER_COERCE_MARKER (position, 1);
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 118
diff changeset
99 if (NILP (buffer))
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 b = current_buffer;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 else
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 CHECK_BUFFER (buffer, 1);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 b = XBUFFER (buffer);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 /* If buffer is dead, set marker to point nowhere. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 if (EQ (b->name, Qnil))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 unchain_marker (marker);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 return marker;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112
14082
c6a1708f37d4 (Fset_marker): Harmonize arguments with documentation.
Erik Naggum <erik@naggum.no>
parents: 13327
diff changeset
113 charno = XINT (position);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 m = XMARKER (marker);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 if (charno < BUF_BEG (b))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 charno = BUF_BEG (b);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 if (charno > BUF_Z (b))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 charno = BUF_Z (b);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 if (charno > BUF_GPT (b)) charno += BUF_GAP_SIZE (b);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 m->bufpos = charno;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 if (m->buffer != b)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 unchain_marker (marker);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 m->buffer = b;
10315
c78d0bb85d30 Use BUF_MARKERS throughout.
Richard M. Stallman <rms@gnu.org>
parents: 9315
diff changeset
127 m->chain = BUF_MARKERS (b);
c78d0bb85d30 Use BUF_MARKERS throughout.
Richard M. Stallman <rms@gnu.org>
parents: 9315
diff changeset
128 BUF_MARKERS (b) = marker;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 return marker;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 /* This version of Fset_marker won't let the position
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 be outside the visible part. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 Lisp_Object
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 set_marker_restricted (marker, pos, buffer)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 Lisp_Object marker, pos, buffer;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 register int charno;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 register struct buffer *b;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 register struct Lisp_Marker *m;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 CHECK_MARKER (marker, 0);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 /* If position is nil or a marker that points nowhere,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 make this marker point nowhere. */
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 118
diff changeset
148 if (NILP (pos) ||
9121
faecbbbcceb4 (Fset_marker, set_marker_restricted, Fcopy_marker): Use type test macros.
Karl Heuer <kwzh@gnu.org>
parents: 8829
diff changeset
149 (MARKERP (pos) && !XMARKER (pos)->buffer))
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 unchain_marker (marker);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 return marker;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 CHECK_NUMBER_COERCE_MARKER (pos, 1);
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 118
diff changeset
156 if (NILP (buffer))
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 b = current_buffer;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 else
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 CHECK_BUFFER (buffer, 1);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 b = XBUFFER (buffer);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 /* If buffer is dead, set marker to point nowhere. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 if (EQ (b->name, Qnil))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 unchain_marker (marker);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 return marker;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 charno = XINT (pos);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 m = XMARKER (marker);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 if (charno < BUF_BEGV (b))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 charno = BUF_BEGV (b);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 if (charno > BUF_ZV (b))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 charno = BUF_ZV (b);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 if (charno > BUF_GPT (b))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 charno += BUF_GAP_SIZE (b);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 m->bufpos = charno;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 if (m->buffer != b)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 unchain_marker (marker);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 m->buffer = b;
10315
c78d0bb85d30 Use BUF_MARKERS throughout.
Richard M. Stallman <rms@gnu.org>
parents: 9315
diff changeset
185 m->chain = BUF_MARKERS (b);
c78d0bb85d30 Use BUF_MARKERS throughout.
Richard M. Stallman <rms@gnu.org>
parents: 9315
diff changeset
186 BUF_MARKERS (b) = marker;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 return marker;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 /* This is called during garbage collection,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 so we must be careful to ignore and preserve mark bits,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 including those in chain fields of markers. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 unchain_marker (marker)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 register Lisp_Object marker;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 register Lisp_Object tail, prev, next;
8829
6f0d48241807 (unchain_marker): Use EMACS_INT.
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
200 register EMACS_INT omark;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 register struct buffer *b;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 b = XMARKER (marker)->buffer;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 if (b == 0)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 return;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 if (EQ (b->name, Qnil))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 abort ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209
10315
c78d0bb85d30 Use BUF_MARKERS throughout.
Richard M. Stallman <rms@gnu.org>
parents: 9315
diff changeset
210 tail = BUF_MARKERS (b);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 prev = Qnil;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 while (XSYMBOL (tail) != XSYMBOL (Qnil))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 next = XMARKER (tail)->chain;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 XUNMARK (next);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 if (XMARKER (marker) == XMARKER (tail))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 {
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 118
diff changeset
219 if (NILP (prev))
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 {
10315
c78d0bb85d30 Use BUF_MARKERS throughout.
Richard M. Stallman <rms@gnu.org>
parents: 9315
diff changeset
221 BUF_MARKERS (b) = next;
c78d0bb85d30 Use BUF_MARKERS throughout.
Richard M. Stallman <rms@gnu.org>
parents: 9315
diff changeset
222 /* Deleting first marker from the buffer's chain. Crash
c78d0bb85d30 Use BUF_MARKERS throughout.
Richard M. Stallman <rms@gnu.org>
parents: 9315
diff changeset
223 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
224 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
225 base buffer. */
84076f6a1f1b (unchain_marker): Allow differing buffers
Richard M. Stallman <rms@gnu.org>
parents: 10315
diff changeset
226 if (!NILP (next) && b->text != XMARKER (next)->buffer->text)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 abort ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 else
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 omark = XMARKBIT (XMARKER (prev)->chain);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 XMARKER (prev)->chain = next;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 XSETMARKBIT (XMARKER (prev)->chain, omark);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 break;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 else
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 prev = tail;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 tail = next;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 XMARKER (marker)->buffer = 0;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243
10315
c78d0bb85d30 Use BUF_MARKERS throughout.
Richard M. Stallman <rms@gnu.org>
parents: 9315
diff changeset
244 /* Return the buffer position of marker MARKER, as a C integer. */
c78d0bb85d30 Use BUF_MARKERS throughout.
Richard M. Stallman <rms@gnu.org>
parents: 9315
diff changeset
245
c78d0bb85d30 Use BUF_MARKERS throughout.
Richard M. Stallman <rms@gnu.org>
parents: 9315
diff changeset
246 int
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 marker_position (marker)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 Lisp_Object marker;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 register struct Lisp_Marker *m = XMARKER (marker);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 register struct buffer *buf = m->buffer;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 register int i = m->bufpos;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 if (!buf)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 error ("Marker does not point anywhere");
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 if (i > BUF_GPT (buf) + BUF_GAP_SIZE (buf))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 i -= BUF_GAP_SIZE (buf);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 else if (i > BUF_GPT (buf))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 i = BUF_GPT (buf);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 if (i < BUF_BEG (buf) || i > BUF_Z (buf))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 abort ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 return i;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 }
12999
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
267
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
268 DEFUN ("copy-marker", Fcopy_marker, Scopy_marker, 1, 2, 0,
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 "Return a new marker pointing at the same place as MARKER.\n\
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 If argument is a number, makes a new marker pointing\n\
12999
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
271 at that position in the current buffer.\n\
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
272 The optional argument TYPE specifies the insertion type of the new marker;\n\
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
273 see `marker-insertion-type'.")
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
274 (marker, type)
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
275 register Lisp_Object marker, type;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 register Lisp_Object new;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278
12999
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
279 if (INTEGERP (marker) || MARKERP (marker))
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 {
12999
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
281 new = Fmake_marker ();
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
282 Fset_marker (new, marker,
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
283 (MARKERP (marker) ? Fmarker_buffer (marker) : Qnil));
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
284 XMARKER (new)->insertion_type = !NILP (type);
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
285 return new;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 }
12999
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
287 else
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
288 marker = wrong_type_argument (Qinteger_or_marker_p, marker);
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
289 }
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
290
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
291 DEFUN ("marker-insertion-type", Fmarker_insertion_type,
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
292 Smarker_insertion_type, 1, 1, 0,
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
293 "Return insertion type of MARKER: t if it stays after inserted text.\n\
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
294 nil means the marker stays before text inserted there.")
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
295 (marker)
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
296 register Lisp_Object marker;
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
297 {
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
298 register Lisp_Object buf;
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
299 CHECK_MARKER (marker, 0);
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
300 return XMARKER (marker)->insertion_type ? Qt : Qnil;
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
301 }
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
302
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
303 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
304 Sset_marker_insertion_type, 2, 2, 0,
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
305 "Set the insertion-type of MARKER to TYPE.\n\
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
306 If TYPE is t, it means the marker advances when you insert text at it.\n\
13327
e518c2be8d7b (Fset_marker_insertion_type): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 12999
diff changeset
307 If TYPE is nil, it means the marker stays behind when you insert text at it.")
12999
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
308 (marker, type)
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
309 Lisp_Object marker, type;
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
310 {
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
311 CHECK_MARKER (marker, 0);
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
312
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
313 XMARKER (marker)->insertion_type = ! NILP (type);
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
314 return type;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 syms_of_marker ()
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 defsubr (&Smarker_position);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 defsubr (&Smarker_buffer);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 defsubr (&Sset_marker);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 defsubr (&Scopy_marker);
12999
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
323 defsubr (&Smarker_insertion_type);
b889a50f71db (Fcopy_marker): New arg TYPE.
Richard M. Stallman <rms@gnu.org>
parents: 12244
diff changeset
324 defsubr (&Sset_marker_insertion_type);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 }