1 /* Header file for the buffer manipulation primitives.
2 Copyright (C) 1985, 1986, 1990, 1992 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #ifdef USE_TEXT_PROPERTIES
27 #define SET_PT(position) (set_point ((position), current_buffer))
28 #define TEMP_SET_PT(position) (temp_set_point ((position), current_buffer))
30 #define BUF_SET_PT(buffer, position) (set_point ((position), (buffer)))
31 #define BUF_TEMP_SET_PT(buffer, position) (temp_set_point ((position), (buffer)))
33 #else /* don't support text properties */
35 #define SET_PT(position) (current_buffer->text.pt = (position))
36 #define TEMP_SET_PT(position) (current_buffer->text.pt = (position))
38 #define BUF_SET_PT(buffer, position) (buffer->text.pt = (position))
39 #define BUF_TEMP_SET_PT(buffer, position) (buffer->text.pt = (position))
40 #endif /* don't support text properties */
42 /* Character position of beginning of buffer. */
45 /* Character position of beginning of accessible range of buffer. */
46 #define BEGV (current_buffer->text.begv)
48 /* Character position of point in buffer. The "+ 0" makes this
49 not an l-value, so you can't assign to it. Use SET_PT instead. */
50 #define PT (current_buffer->text.pt + 0)
52 /* Character position of gap in buffer. */
53 #define GPT (current_buffer->text.gpt)
55 /* Character position of end of accessible range of buffer. */
56 #define ZV (current_buffer->text.zv)
58 /* Character position of end of buffer. */
59 #define Z (current_buffer->text.z)
61 /* Modification count. */
62 #define MODIFF (current_buffer->text.modiff)
64 /* Address of beginning of buffer. */
65 #define BEG_ADDR (current_buffer->text.beg)
67 /* Address of beginning of accessible range of buffer. */
68 #define BEGV_ADDR (&FETCH_CHAR (current_buffer->text.begv))
70 /* Address of point in buffer. */
71 #define PT_ADDR (&FETCH_CHAR (current_buffer->text.pt))
73 /* Address of beginning of gap in buffer. */
74 #define GPT_ADDR (current_buffer->text.beg + current_buffer->text.gpt - 1)
76 /* Address of end of gap in buffer. */
77 #define GAP_END_ADDR (current_buffer->text.beg + current_buffer->text.gpt + current_buffer->text.gap_size - 1)
79 /* Address of end of accessible range of buffer. */
80 #define ZV_ADDR (&FETCH_CHAR (current_buffer->text.zv))
83 #define GAP_SIZE (current_buffer->text.gap_size)
85 /* Now similar macros for a specified buffer.
86 Note that many of these evaluate the buffer argument more than once. */
88 /* Character position of beginning of buffer. */
89 #define BUF_BEG(buf) (1)
91 /* Character position of beginning of accessible range of buffer. */
92 #define BUF_BEGV(buf) ((buf)->text.begv)
94 /* Character position of point in buffer. */
95 #define BUF_PT(buf) ((buf)->text.pt)
97 /* Character position of gap in buffer. */
98 #define BUF_GPT(buf) ((buf)->text.gpt)
100 /* Character position of end of accessible range of buffer. */
101 #define BUF_ZV(buf) ((buf)->text.zv)
103 /* Character position of end of buffer. */
104 #define BUF_Z(buf) ((buf)->text.z)
106 /* Modification count. */
107 #define BUF_MODIFF(buf) ((buf)->text.modiff)
109 /* Address of beginning of buffer. */
110 #define BUF_BEG_ADDR(buf) ((buf)->text.beg)
112 /* Macro for setting the value of BUF_ZV (BUF) to VALUE,
113 by varying the end of the accessible region. */
114 #define SET_BUF_ZV(buf, value) ((buf)->text.zv = (value))
115 #define SET_BUF_PT(buf, value) ((buf)->text.pt = (value))
118 #define BUF_GAP_SIZE(buf) ((buf)->text.gap_size)
120 /* Return the address of character at position POS in buffer BUF.
121 Note that both arguments can be computed more than once. */
122 #define BUF_CHAR_ADDRESS(buf, pos) \
123 ((buf)->text.beg + (pos) - 1 \
124 + ((pos) >= (buf)->text.gpt ? (buf)->text.gap_size : 0))
126 /* Convert the address of a char in the buffer into a character position. */
127 #define PTR_CHAR_POS(ptr) \
128 ((ptr) - (current_buffer)->text.beg \
129 - (ptr - (current_buffer)->text.beg < (unsigned) GPT ? 0 : GAP_SIZE) \
134 unsigned char *beg
; /* Actual address of buffer contents. */
135 int begv
; /* Index of beginning of accessible range. */
136 int pt
; /* Position of point in buffer. */
137 int gpt
; /* Index of gap in buffer. */
138 int zv
; /* Index of end of accessible range. */
139 int z
; /* Index of end of buffer. */
140 int gap_size
; /* Size of buffer's gap */
141 int modiff
; /* This counts buffer-modification events
142 for this buffer. It is incremented for
143 each such event, and never otherwise
149 /* Everything before the `name' slot must be of a non-Lisp_Object type,
150 and every slot after `name' must be a Lisp_Object.
152 Check out mark_buffer (alloc.c) to see why.
155 /* This structure holds the coordinates of the buffer contents. */
156 struct buffer_text text
;
157 /* Next buffer, in chain of all buffers including killed buffers.
158 This chain is used only for garbage collection, in order to
159 collect killed buffers properly. */
161 /* Flags saying which DEFVAR_PER_BUFFER variables
162 are local to this buffer. */
164 /* Value of text.modiff as of when visited file was read or written. */
166 /* Set to the modtime of the visited file when read or written.
167 -1 means visited file was nonexistent.
168 0 means visited file modtime unknown; in no case complain
169 about any mismatch on next save attempt. */
171 /* the value of text.modiff at the last auto-save. */
172 int auto_save_modified
;
173 /* Position in buffer at which display started
174 the last time this buffer was displayed */
175 int last_window_start
;
177 /* Properties of this buffer's text -- conditionally compiled. */
180 /* This is a special exception -- as this slot should not be
181 marked by gc_sweep, and as it is not lisp-accessible as
182 a local variable -- so we regard it as not really being of type
184 /* the markers that refer to this buffer.
185 This is actually a single marker ---
186 successive elements in its marker `chain'
187 are the other markers referring to this
192 /* Everything from here down must be a Lisp_Object */
195 /* the name of this buffer */
197 /* Nuked: buffer number, assigned when buffer made Lisp_Object number;*/
198 /* the name of the file associated with this buffer */
199 Lisp_Object filename
;
200 /* Dir for expanding relative pathnames */
201 Lisp_Object directory
;
202 /* true iff this buffer has been been backed
203 up (if you write to its associated file
204 and it hasn't been backed up, then a
205 backup will be made) */
206 /* This isn't really used by the C code, so could be deleted. */
207 Lisp_Object backed_up
;
208 /* Length of file when last read or saved. */
209 Lisp_Object save_length
;
210 /* file name used for auto-saving this buffer */
211 Lisp_Object auto_save_file_name
;
212 /* Non-nil if buffer read-only */
213 Lisp_Object read_only
;
214 /* "The mark"; no longer allowed to be nil */
217 /* Alist of elements (SYMBOL . VALUE-IN-THIS-BUFFER)
218 for all per-buffer variables of this buffer. */
219 Lisp_Object local_var_alist
;
222 /* Symbol naming major mode (eg lisp-mode) */
223 Lisp_Object major_mode
;
224 /* Pretty name of major mode (eg "Lisp") */
225 Lisp_Object mode_name
;
226 /* Format string for mode line */
227 Lisp_Object mode_line_format
;
229 /* Keys that are bound local to this buffer */
231 /* This buffer's local abbrev table */
232 Lisp_Object abbrev_table
;
233 /* This buffer's syntax table. */
234 Lisp_Object syntax_table
;
236 /* Values of several buffer-local variables */
237 /* tab-width is buffer-local so that redisplay can find it
238 in buffers that are not current */
239 Lisp_Object case_fold_search
;
240 Lisp_Object tab_width
;
241 Lisp_Object fill_column
;
242 Lisp_Object left_margin
;
243 /* Function to call when insert space past fill column */
244 Lisp_Object auto_fill_function
;
246 /* String of length 256 mapping each char to its lower-case version. */
247 Lisp_Object downcase_table
;
248 /* String of length 256 mapping each char to its upper-case version. */
249 Lisp_Object upcase_table
;
251 /* Non-nil means do not display continuation lines */
252 Lisp_Object truncate_lines
;
253 /* Non-nil means display ctl chars with uparrow */
254 Lisp_Object ctl_arrow
;
255 /* Non-nil means do selective display;
256 See doc string in syms_of_buffer (buffer.c) for details. */
257 Lisp_Object selective_display
;
259 /* Non-nil means show ... at end of line followed by invisible lines. */
260 Lisp_Object selective_display_ellipses
;
262 /* Alist of (FUNCTION . STRING) for each minor mode enabled in buffer. */
263 Lisp_Object minor_modes
;
264 /* t if "self-insertion" should overwrite */
265 Lisp_Object overwrite_mode
;
266 /* non-nil means abbrev mode is on. Expand abbrevs automatically. */
267 Lisp_Object abbrev_mode
;
268 /* Display table to use for text in this buffer. */
269 Lisp_Object display_table
;
270 /* Translate table for case-folding search. */
271 Lisp_Object case_canon_table
;
272 /* Inverse translate (equivalence class) table for case-folding search. */
273 Lisp_Object case_eqv_table
;
274 /* Changes in the buffer are recorded here for undo.
275 t means don't record anything. */
276 Lisp_Object undo_list
;
278 /* List of fields in this buffer. */
279 Lisp_Object fieldlist
;
282 extern struct buffer
*current_buffer
;
284 /* This structure holds the default values of the buffer-local variables
285 defined with DefBufferLispVar, that have special slots in each buffer.
286 The default value occupies the same slot in this structure
287 as an individual buffer's value occupies in that buffer.
288 Setting the default value also goes through the alist of buffers
289 and stores into each buffer that does not say it has a local value. */
291 extern struct buffer buffer_defaults
;
293 /* This structure marks which slots in a buffer have corresponding
294 default values in buffer_defaults.
295 Each such slot has a nonzero value in this structure.
296 The value has only one nonzero bit.
298 When a buffer has its own local value for a slot,
299 the bit for that slot (found in the same slot in this structure)
300 is turned on in the buffer's local_var_flags slot.
302 If a slot in this structure is zero, then even though there may
303 be a DefBufferLispVar for the slot, there is no default valuefeor it;
304 and the corresponding slot in buffer_defaults is not used. */
306 extern struct buffer buffer_local_flags
;
308 /* For each buffer slot, this points to the Lisp symbol name
309 for that slot in the current buffer. It is 0 for slots
310 that don't have such names. */
312 extern struct buffer buffer_local_symbols
;
314 /* This structure holds the required types for the values in the
315 buffer-local slots. If a slot contains Qnil, then the
316 corresponding buffer slot may contain a value of any type. If a
317 slot contains an integer, then prospective values' tags must be
318 equal to that integer. When a tag does not match, the function
319 buffer_slot_type_mismatch will signal an error. The value Qnil may
320 always be safely stored in any slot. */
321 extern struct buffer buffer_local_types
;
323 /* Point in the current buffer. */
325 #define point (current_buffer->text.pt + 0)
327 /* Return character at position n. No range checking */
328 #define FETCH_CHAR(n) *(((n)>= GPT ? GAP_SIZE : 0) + (n) + BEG_ADDR - 1)
330 /* BUFFER_CEILING_OF (resp. BUFFER_FLOOR_OF), when applied to n, return
331 the max (resp. min) p such that
333 &FETCH_CHAR (p) - &FETCH_CHAR (n) == p - n */
335 #define BUFFER_CEILING_OF(n) (((n) < GPT && GPT < ZV ? GPT : ZV) - 1)
336 #define BUFFER_FLOOR_OF(n) (BEGV <= GPT && GPT <= (n) ? GPT : BEGV)
338 extern void reset_buffer ();
340 /* Functions to call before and after each text change. */
341 extern Lisp_Object Vbefore_change_function
;
342 extern Lisp_Object Vafter_change_function
;
343 extern Lisp_Object Vfirst_change_hook
;
344 extern Lisp_Object Qfirst_change_hook
;
348 A field is like a marker but it defines a region rather than a
349 point. Like a marker, a field is asocated with a buffer.
350 The field mechanism uses the marker mechanism in the
351 sense that its start and end points are maintained as markers
352 updated in the usual way as the buffer changes.
354 A field can be protected or unprotected. If it is protected,
355 no modifications can be made that affect the field in its buffer,
356 when protected field checking is enabled.
358 Each field also contains an alist, in which you can store
359 whatever you like. */
361 /* Slots in a field: */
363 #define FIELD_BUFFER(f) (XVECTOR(f)->contents[1])
364 #define FIELD_START_MARKER(f) (XVECTOR(f)->contents[2])
365 #define FIELD_END_MARKER(f) (XVECTOR(f)->contents[3])
366 #define FIELD_PROTECTED_FLAG(f) (XVECTOR(f)->contents[4])
367 #define FIELD_ALIST(f) (XVECTOR(f)->contents[5])
369 /* Allocation of buffer data. */
371 #define BUFFER_ALLOC(data,size) ((unsigned char *) r_alloc (&data, (size)))
372 #define BUFFER_REALLOC(data,size) ((unsigned char *) r_re_alloc (&data, (size)))
373 #define BUFFER_FREE(data) (r_alloc_free (&data))
374 #define R_ALLOC_DECLARE(var,data) (r_alloc_declare (&var, (data)))
376 #define BUFFER_ALLOC(data,size) (data = (unsigned char *) malloc ((size)))
377 #define BUFFER_REALLOC(data,size) ((unsigned char *) realloc ((data), (size)))
378 #define BUFFER_FREE(data) (free ((data)))
379 #define R_ALLOC_DECLARE(var,data)
382 /* VAX C is non-ANSI wrt extern declarations and requires the struct
383 re_pattern_buffer to completely defined for searchbuf's declaration. */
388 /* A search buffer, with a fastmap allocated and ready to go. */
389 extern struct re_pattern_buffer searchbuf
;
391 extern Lisp_Object
Fbuffer_name ();
392 extern Lisp_Object
Fget_file_buffer ();