Mercurial > hg > xemacs-beta
view src/buffer.h @ 2367:ecf1ebac70d8
[xemacs-hg @ 2004-11-04 23:05:23 by ben]
commit mega-patch
configure.in: Turn off -Winline and -Wchar-subscripts.
Use the right set of cflags when compiling modules.
Rewrite ldap configuration to separate the inclusion of lber
(needed in recent Cygwin) from the basic checks for the
needed libraries.
add a function for MAKE_JUNK_C; initially code was added to
generate xemacs.def using this, but it will need to be rewritten.
add an rm -f for junk.c to avoid weird Cygwin bug with cp -f onto
an existing file.
Sort list of auto-detected functions and eliminate unused checks for
stpcpy, setlocale and getwd.
Add autodetection of Cygwin scanf problems
BETA: Rewrite section on configure to indicate what flags are important
and what not.
digest-doc.c, make-dump-id.c, profile.c, sorted-doc.c: Add proper decls for main().
make-msgfile.c: Document that this is old junk.
Move proposal to text.c.
make-msgfile.lex: Move proposal to text.c.
make-mswin-unicode.pl: Convert error-generating code so that the entire message will
be seen as a single unrecognized token.
mule/mule-ccl.el: Update docs.
lispref/mule.texi: Update CCL docs.
ldap/eldap.c: Mule-ize.
Use EXTERNAL_LIST_LOOP_2 instead of deleted EXTERNAL_LIST_LOOP.
* XEmacs 21.5.18 "chestnut" is released.
---------------------------------------------------------------
MULE-RELATED WORK:
---------------------------------------------------------------
---------------------------
byte-char conversion
---------------------------
buffer.c, buffer.h, insdel.c, text.c: Port FSF algorithm for byte-char conversion, replacing broken
previous version. Track the char position of the gap. Add
functions to do char-byte conversion downwards as well as upwards.
Move comments about algorithm workings to internals manual.
---------------------------
work on types
---------------------------
alloc.c, console-x-impl.h, dump-data.c, dump-data.h, dumper.c, dialog-msw.c, dired-msw.c, doc.c, editfns.c, esd.c, event-gtk.h, event-msw.c, events.c, file-coding.c, file-coding.h, fns.c, glyphs-eimage.c, glyphs-gtk.c, glyphs-msw.c, glyphs-shared.c, glyphs-x.c, glyphs.c, glyphs.h, gui.c, hpplay.c, imgproc.c, intl-win32.c, lrecord.h, lstream.c, keymap.c, lisp.h, libsst.c, linuxplay.c, miscplay.c, miscplay.h, mule-coding.c, nas.c, nt.c, ntheap.c, ntplay.c, objects-msw.c, objects-tty.c, objects-x.c, print.c, process-nt.c, process.c, redisplay.h, select-common.h, select-gtk.c, select-x.c, sgiplay.c, sound.c, sound.h, sunplay.c, sysfile.h, sysdep.c, syswindows.h, text.c, unexnt.c, win32.c, xgccache.c: Further work on types. This creates a full set of types for all
the basic semantics of `char' that I have so far identified, so that
its semantics can always be identified for the purposes of proper
Mule-safe code, and the raw use of `char' always avoided.
(1) More type renaming, for consistency of naming.
Char_ASCII -> Ascbyte
UChar_ASCII -> UAscbyte
Char_Binary -> CBinbyte
UChar_Binary -> Binbyte
SChar_Binary -> SBinbyte
(2) Introduce Rawbyte, CRawbyte, Boolbyte, Chbyte, UChbyte, and
Bitbyte and use them.
(3) New types Itext, Wexttext and Textcount for separating out
the concepts of bytes and textual units (different under UTF-16
and UTF-32, which are potential internal encodings).
(4) qxestr*_c -> qxestr*_ascii.
lisp.h: New; goes with other qxe() functions. #### Maybe goes in a
different section.
lisp.h: Group generic int-type defs together with EMACS_INT defs.
lisp.h: * lisp.h (WEXTTEXT_IS_WIDE)
New defns.
lisp.h: New type to replace places where int occurs as a boolean.
It's signed because occasionally people may want to use -1 as
an error value, and because unsigned ints are viral -- see comments
in the internals manual against using them.
dynarr.c: int -> Bytecount.
---------------------------
Mule-izing
---------------------------
device-x.c: Partially Mule-ize.
dumper.c, dumper.h: Mule-ize. Use Rawbyte. Use stderr_out not printf. Use wext_*().
sysdep.c, syswindows.h, text.c: New Wexttext API for manipulation of external text that may be
Unicode (e.g. startup code under Windows).
emacs.c: Mule-ize. Properly deal with argv in external encoding.
Use wext_*() and Wexttext. Use Rawbyte.
#if 0 some old junk on SCO that is unlikely to be correct.
Rewrite allocation code in run-temacs.
emacs.c, symsinit.h, win32.c: Rename win32 init function and call it even earlier, to
initialize mswindows_9x_p even earlier, for use in startup code
(XEUNICODE_P).
process.c: Use _wenviron not environ under Windows, to get Unicode environment
variables.
event-Xt.c: Mule-ize drag-n-drop related stuff.
dragdrop.c, dragdrop.h, frame-x.c: Mule-ize.
text.h: Add some more stand-in defines for particular kinds of conversion;
use in Mule-ization work in frame-x.c etc.
---------------------------
Freshening
---------------------------
intl-auto-encap-win32.c, intl-auto-encap-win32.h: Regenerate.
---------------------------
Unicode-work
---------------------------
intl-win32.c, syswindows.h: Factor out common options to MultiByteToWideChar and
WideCharToMultiByte. Add convert_unicode_to_multibyte_malloc()
and convert_unicode_to_multibyte_dynarr() and use. Add stuff for
alloca() conversion of multibyte/unicode.
alloc.c: Use dfc_external_data_len() in case of unicode coding system.
alloc.c, mule-charset.c: Don't zero out and reinit charset Unicode tables. This fucks up
dump-time loading. Anyway, either we load them at dump time or
run time, never both.
unicode.c: Dump the blank tables as well.
---------------------------------------------------------------
DOCUMENTATION, MOSTLY MULE-RELATED:
---------------------------------------------------------------
EmacsFrame.c, emodules.c, event-Xt.c, fileio.c, input-method-xlib.c, mule-wnnfns.c, redisplay-gtk.c, redisplay-tty.c, redisplay-x.c, regex.c, sysdep.c: Add comment about Mule work needed.
text.h: Add more documentation describing why DFC routines were not written
to return their value. Add some other DFC documentation.
console-msw.c, console-msw.h: Add pointer to docs in win32.c.
emacs.c: Add comments on sources of doc info.
text.c, charset.h, unicode.c, intl-win32.c, intl-encap-win32.c, text.h, file-coding.c, mule-coding.c: Collect background comments and related to text matters and
internationalization, and proposals for work to be done, in text.c
or Internals manual, stuff related to specific textual API's in
text.h, and stuff related to internal implementation of Unicode
conversion in unicode.c. Put lots of pointers to the comments to
make them easier to find.
s/mingw32.h, s/win32-common.h, s/win32-native.h, s/windowsnt.h, win32.c: Add bunches of new documentation on the different kinds of
builds and environments under Windows and how they work.
Collect this info in win32.c. Add pointers to these docs in
the relevant s/* files.
emacs.c: Document places with long comments.
Remove comment about exiting, move to internals manual, put
in pointer.
event-stream.c: Move docs about event queues and focus to internals manual, put
in pointer.
events.h: Move docs about event stream callbacks to internals manual, put
in pointer.
profile.c, redisplay.c, signal.c: Move documentation to the Internals manual.
process-nt.c: Add pointer to comment in win32-native.el.
lisp.h: Add comments about some comment conventions.
lisp.h: Add comment about the second argument.
device-msw.c, redisplay-msw.c: @@#### comments are out-of-date.
---------------------------------------------------------------
PDUMP WORK (MOTIVATED BY UNICODE CHANGES)
---------------------------------------------------------------
alloc.c, buffer.c, bytecode.c, console-impl.h, console.c, device.c, dumper.c, lrecord.h, elhash.c, emodules.h, events.c, extents.c, frame.c, glyphs.c, glyphs.h, mule-charset.c, mule-coding.c, objects.c, profile.c, rangetab.c, redisplay.c, specifier.c, specifier.h, window.c, lstream.c, file-coding.h, file-coding.c: PDUMP:
Properly implement dump_add_root_block(), which never worked before,
and is necessary for dumping Unicode tables.
Pdump name changes for accuracy:
XD_STRUCT_PTR -> XD_BLOCK_PTR.
XD_STRUCT_ARRAY -> XD_BLOCK_ARRAY.
XD_C_STRING -> XD_ASCII_STRING.
*_structure_* -> *_block_*.
lrecord.h: some comments added about
dump_add_root_block() vs dump_add_root_block_ptr().
extents.c: remove incorrect comment about pdump problems with gap array.
---------------------------------------------------------------
ALLOCATION
---------------------------------------------------------------
abbrev.c, alloc.c, bytecode.c, casefiddle.c, device-msw.c, device-x.c, dired-msw.c, doc.c, doprnt.c, dragdrop.c, editfns.c, emodules.c, file-coding.c, fileio.c, filelock.c, fns.c, glyphs-eimage.c, glyphs-gtk.c, glyphs-msw.c, glyphs-x.c, gui-msw.c, gui-x.c, imgproc.c, intl-win32.c, lread.c, menubar-gtk.c, menubar.c, nt.c, objects-msw.c, objects-x.c, print.c, process-nt.c, process-unix.c, process.c, realpath.c, redisplay.c, search.c, select-common.c, symbols.c, sysdep.c, syswindows.h, text.c, text.h, ui-byhand.c: New macros {alloca,xnew}_{itext,{i,ext,raw,bin,asc}bytes} for
more convenient allocation of these commonly requested items.
Modify functions to use alloca_ibytes, alloca_array, alloca_extbytes,
xnew_ibytes, etc. also XREALLOC_ARRAY, xnew.
alloc.c: Rewrite the allocation functions to factor out repeated code.
Add assertions for freeing dumped data.
lisp.h: Moved down and consolidated with other allocation stuff.
lisp.h, dynarr.c: New functions for allocation that's very efficient when mostly in
LIFO order.
lisp.h, text.c, text.h: Factor out some stuff for general use by alloca()-conversion funs.
text.h, lisp.h: Fill out convenience routines for allocating various kinds of
bytes and put them in lisp.h. Use them in place of xmalloc(),
ALLOCA().
text.h: Fill out the convenience functions so the _MALLOC() kinds match
the alloca() kinds.
---------------------------------------------------------------
ERROR-CHECKING
---------------------------------------------------------------
text.h: Create ASSERT_ASCTEXT_ASCII() and ASSERT_ASCTEXT_ASCII_LEN()
from similar Eistring checkers and change the Eistring checkers to
use them instead.
---------------------------------------------------------------
MACROS IN LISP.H
---------------------------------------------------------------
lisp.h: Redo GCPRO declarations. Create a "base" set of functions that can
be used to generate any kind of gcpro sets -- regular, ngcpro,
nngcpro, private ones used in GC_EXTERNAL_LIST_LOOP_2.
buffer.c, callint.c, chartab.c, console-msw.c, device-x.c, dialog-msw.c, dired.c, extents.c, ui-gtk.c, rangetab.c, nt.c, mule-coding.c, minibuf.c, menubar-msw.c, menubar.c, menubar-gtk.c, lread.c, lisp.h, gutter.c, glyphs.c, glyphs-widget.c, fns.c, fileio.c, file-coding.c, specifier.c: Eliminate EXTERNAL_LIST_LOOP, which does not check for circularities.
Use EXTERNAL_LIST_LOOP_2 instead or EXTERNAL_LIST_LOOP_3
or EXTERNAL_PROPERTY_LIST_LOOP_3 or GC_EXTERNAL_LIST_LOOP_2
(new macro). Removed/redid comments on EXTERNAL_LIST_LOOP.
---------------------------------------------------------------
SPACING FIXES
---------------------------------------------------------------
callint.c, hftctl.c, number-gmp.c, process-unix.c: Spacing fixes.
---------------------------------------------------------------
FIX FOR GEOMETRY PROBLEM IN FIRST FRAME
---------------------------------------------------------------
unicode.c: Add workaround for newlib bug in sscanf() [should be fixed by
release 1.5.12 of Cygwin].
toolbar.c: bug fix for problem of initial frame being 77 chars wide on Windows.
will be overridden by my other ws.
---------------------------------------------------------------
FIX FOR LEAKING PROCESS HANDLES:
---------------------------------------------------------------
process-nt.c: Fixes for leaking handles. Inspired by work done by Adrian Aichner
<adrian@xemacs.org>.
---------------------------------------------------------------
FIX FOR CYGWIN BUG (Unicode-related):
---------------------------------------------------------------
unicode.c: Add workaround for newlib bug in sscanf() [should be fixed by
release 1.5.12 of Cygwin].
---------------------------------------------------------------
WARNING FIXES:
---------------------------------------------------------------
console-stream.c: `reinit' is unused.
compiler.h, event-msw.c, frame-msw.c, intl-encap-win32.c, text.h: Add stuff to deal with ANSI-aliasing warnings I got.
regex.c: Gather includes together to avoid warning.
---------------------------------------------------------------
CHANGES TO INITIALIZATION ROUTINES:
---------------------------------------------------------------
buffer.c, emacs.c, console.c, debug.c, device-x.c, device.c, dragdrop.c, emodules.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, event-tty.c, events.c, extents.c, faces.c, file-coding.c, fileio.c, font-lock.c, frame-msw.c, glyphs-widget.c, glyphs.c, gui-x.c, insdel.c, lread.c, lstream.c, menubar-gtk.c, menubar-x.c, minibuf.c, mule-wnnfns.c, objects-msw.c, objects.c, print.c, scrollbar-x.c, search.c, select-x.c, text.c, undo.c, unicode.c, window.c, symsinit.h: Call reinit_*() functions directly from emacs.c, for clarity.
Factor out some redundant init code. Move disallowed stuff
that had crept into vars_of_glyphs() into complex_vars_of_glyphs().
Call init_eval_semi_early() from eval.c not in the middle of
vars_of_() in emacs.c since there should be no order dependency
in the latter calls.
---------------------------------------------------------------
ARMAGEDDON:
---------------------------------------------------------------
alloc.c, emacs.c, lisp.h, print.c: Rename inhibit_non_essential_printing_operations to
inhibit_non_essential_conversion_operations.
text.c: Assert on !inhibit_non_essential_conversion_operations.
console-msw.c, print.c: Don't do conversion in SetConsoleTitle or FindWindow to avoid
problems during armageddon. Put #errors for NON_ASCII_INTERNAL_FORMAT
in places where problems would arise.
---------------------------------------------------------------
CHANGES TO THE BUILD PROCEDURE:
---------------------------------------------------------------
config.h.in, s/cxux.h, s/usg5-4-2.h, m/powerpc.h: Add comment about correct ordering of this file.
Rearrange everything to follow this -- put all #undefs together
and before the s&m files. Add undefs for HAVE_ALLOCA, C_ALLOCA,
BROKEN_ALLOCA_IN_FUNCTION_CALLS, STACK_DIRECTION. Remove unused
HAVE_STPCPY, HAVE_GETWD, HAVE_SETLOCALE.
m/gec63.h: Deleted; totally broken, not used at all, not in FSF.
m/7300.h, m/acorn.h, m/alliant-2800.h, m/alliant.h, m/altos.h, m/amdahl.h, m/apollo.h, m/att3b.h, m/aviion.h, m/celerity.h, m/clipper.h, m/cnvrgnt.h, m/convex.h, m/cydra5.h, m/delta.h, m/delta88k.h, m/dpx2.h, m/elxsi.h, m/ews4800r.h, m/gould.h, m/hp300bsd.h, m/hp800.h, m/hp9000s300.h, m/i860.h, m/ibmps2-aix.h, m/ibmrs6000.h, m/ibmrt-aix.h, m/ibmrt.h, m/intel386.h, m/iris4d.h, m/iris5d.h, m/iris6d.h, m/irist.h, m/isi-ov.h, m/luna88k.h, m/m68k.h, m/masscomp.h, m/mg1.h, m/mips-nec.h, m/mips-siemens.h, m/mips.h, m/news.h, m/nh3000.h, m/nh4000.h, m/ns32000.h, m/orion105.h, m/pfa50.h, m/plexus.h, m/pmax.h, m/powerpc.h, m/pyrmips.h, m/sequent-ptx.h, m/sequent.h, m/sgi-challenge.h, m/symmetry.h, m/tad68k.h, m/tahoe.h, m/targon31.h, m/tekxd88.h, m/template.h, m/tower32.h, m/tower32v3.h, m/ustation.h, m/vax.h, m/wicat.h, m/xps100.h: Delete C_ALLOCA, HAVE_ALLOCA, STACK_DIRECTION,
BROKEN_ALLOCA_IN_FUNCTION_CALLS. All of this is auto-detected.
When in doubt, I followed recent FSF sources, which also have
these things deleted.
author | ben |
---|---|
date | Thu, 04 Nov 2004 23:08:28 +0000 |
parents | ba4677f54a05 |
children | 6fa9919a9a0b |
line wrap: on
line source
/* Header file for the buffer manipulation primitives. Copyright (C) 1985, 1986, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. Copyright (C) 1995 Sun Microsystems, Inc. Copyright (C) 2001, 2002, 2004 Ben Wing. This file is part of XEmacs. XEmacs is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. XEmacs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with XEmacs; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Synched up with: FSF 19.30. */ /* Authorship: FSF: long ago. JWZ: separated out bufslots.h, early in Lemacs. Ben Wing: almost completely rewritten for Mule, 19.12. */ #ifndef INCLUDED_buffer_h_ #define INCLUDED_buffer_h_ #include "casetab.h" #include "chartab.h" /************************************************************************/ /* */ /* definition of Lisp buffer object */ /* */ /************************************************************************/ /* Note: we keep both Bytebpos and Charbpos versions of some of the important buffer positions because they are accessed so much. If we didn't do this, we would constantly be invalidating the charbpos<->bytebpos cache under Mule. Note that under non-Mule, both versions will always be the same so we don't really need to keep track of them. But it simplifies the logic to go ahead and do so all the time and the memory loss is insignificant. */ /* Formerly, it didn't much matter what went inside the struct buffer_text and what went outside it. Now it does, with the advent of "indirect buffers" that share text with another buffer. An indirect buffer shares the same *text* as another buffer, but has its own buffer-local variables, its own accessible region, and its own markers and extents. (Due to the nature of markers, it doesn't actually matter much whether we stick them inside or out of the struct buffer_text -- the user won't notice any difference -- but we go ahead and put them outside for consistency and overall saneness of algorithm.) FSFmacs gets away with not maintaining any "children" pointers from a buffer to the indirect buffers that refer to it by putting the markers inside of the struct buffer_text, using markers to keep track of BEGV and ZV in indirect buffers, and relying on the fact that all intervals (text properties and overlays) use markers for their start and end points. We don't do this for extents (markers are inefficient anyway and take up space), so we have to maintain children pointers. This is not terribly hard, though, and the code to maintain this is just like the code already present in extent-parent and extent-children. */ #define NUM_CACHED_POSITIONS 50 #define NUM_MOVED_POSITIONS 10 struct buffer_text { Ibyte *beg; /* Actual address of buffer contents. */ Bytebpos gpt; /* Index of gap in buffer. */ Charbpos bufgpt; /* Equivalent as a Charbpos. */ Bytebpos z; /* Index of end of buffer. */ Charbpos bufz; /* Equivalent as a Charbpos. */ Bytecount gap_size;/* Size of buffer's gap */ Bytecount end_gap_size;/* Size of buffer's end gap */ long modiff; /* This counts buffer-modification events for this buffer. It is incremented for each such event, and never otherwise changed. */ long save_modiff; /* Previous value of modiff, as of last time buffer visited or saved a file. */ #ifdef MULE #ifdef OLD_BYTE_CHAR /* We keep track of a "known" region for very fast access. This information is text-only so it goes here. We update this at each change to the buffer, so if it's entirely ASCII, these will always contain the minimum and maximum positions of the buffer. */ Charbpos mule_bufmin, mule_bufmax; Bytebpos mule_bytmin, mule_bytmax; int mule_shifter, mule_three_p; #endif /* And we also cache NUM_CACHED_POSITIONS positions for fairly fast access near those positions. */ Charbpos mule_charbpos_cache[NUM_CACHED_POSITIONS]; Bytebpos mule_bytebpos_cache[NUM_CACHED_POSITIONS]; int next_cache_pos; Charbpos cached_charpos; Bytebpos cached_bytepos; /* True if all chars fit into one byte; == (format == FORMAT_8_BIT_FIXED || (format == FORMAT_DEFAULT && num_ascii_chars == bufz - 1)) kept around to speed up (slightly?) the byte-char conversion routines. */ int entirely_one_byte_p; /* Number of ASCII chars in buffer (0 - 127) */ Charcount num_ascii_chars; /* Number of chars in buffer that would fit in an 8-bit-fixed buffer. */ Charcount num_8_bit_fixed_chars; /* Number of chars in buffer that would fit in an 16-bit-fixed buffer. */ Charcount num_16_bit_fixed_chars; /* Currently we only handle 8 bit fixed and default */ Internal_Format format; #endif /* MULE */ /* Similar to the above, we keep track of positions for which line number has last been calculated. See line-number.c. */ Lisp_Object line_number_cache; /* Change data that goes with the text. */ struct buffer_text_change_data *changes; }; struct buffer { struct lcrecord_header header; /* This structure holds the coordinates of the buffer contents in ordinary buffers. In indirect buffers, this is not used. */ struct buffer_text own_text; /* This points to the `struct buffer_text' that is used for this buffer. In an ordinary buffer, this is the own_text field above. In an indirect buffer, this is the own_text field of another buffer. */ struct buffer_text *text; Bytebpos pt; /* Position of point in buffer. */ Charbpos bufpt; /* Equivalent as a Charbpos. */ Bytebpos begv; /* Index of beginning of accessible range. */ Charbpos bufbegv; /* Equivalent as a Charbpos. */ Bytebpos zv; /* Index of end of accessible range. */ Charbpos bufzv; /* Equivalent as a Charbpos. */ int face_change; /* This is set when a change in how the text should be displayed (e.g., font, color) is made. */ /* Whether buffer specific face is specified. */ int buffer_local_face_property; /* change data indicating what portion of the text has changed since the last time this was reset. Used by redisplay. Logically we should keep this with the text structure, but redisplay resets it for each buffer individually and we don't want interference between an indirect buffer and its base buffer. */ struct each_buffer_change_data *changes; #ifdef REGION_CACHE_NEEDS_WORK /* If the long line scan cache is enabled (i.e. the buffer-local variable cache-long-line-scans is non-nil), newline_cache points to the newline cache, and width_run_cache points to the width run cache. The newline cache records which stretches of the buffer are known *not* to contain newlines, so that they can be skipped quickly when we search for newlines. The width run cache records which stretches of the buffer are known to contain characters whose widths are all the same. If the width run cache maps a character to a value > 0, that value is the character's width; if it maps a character to zero, we don't know what its width is. This allows compute_motion to process such regions very quickly, using algebra instead of inspecting each character. See also width_table, below. */ struct region_cache *newline_cache; struct region_cache *width_run_cache; #endif /* REGION_CACHE_NEEDS_WORK */ /* The markers that refer to this buffer. This is actually a single marker -- successive elements in its marker `chain' are the other markers referring to this buffer */ Lisp_Marker *markers; /* The buffer's extent info. This is its own type, an extent-info object (done this way for ease in marking / finalizing). */ Lisp_Object extent_info; /* The buffer's syntax cache. This caches a known region where the `syntax-table' property is unchanged, for quick lookup in the routines that scan a buffer looking for a particular syntax (regex routines, parse-partial-sexp, etc.). */ struct syntax_cache *syntax_cache; /* ----------------------------------------------------------------- */ /* All the stuff above this line is the responsibility of insdel.c, with some help from marker.c, extents.c and syntax.c. All the stuff below this line is the responsibility of buffer.c. */ /* In an indirect buffer, this points to the base buffer. In an ordinary buffer, it is 0. We DO mark through this slot. */ struct buffer *base_buffer; /* List of indirect buffers whose base is this buffer. If we are an indirect buffer, this will be nil. Do NOT mark through this. */ Lisp_Object indirect_children; /* Flags saying which DEFVAR_PER_BUFFER variables are local to this buffer. */ int local_var_flags; /* Set to the modtime of the visited file when read or written. -1 means visited file was nonexistent. 0 means visited file modtime unknown; in no case complain about any mismatch on next save attempt. */ int modtime; /* the value of text->modiff at the last auto-save. */ long auto_save_modified; /* The time at which we detected a failure to auto-save, Or -1 if we didn't have a failure. */ int auto_save_failure_time; /* Position in buffer at which display started the last time this buffer was displayed. */ int last_window_start; /* Everything from here down must be a Lisp_Object */ #define MARKED_SLOT(x) Lisp_Object x; #include "bufslots.h" #undef MARKED_SLOT }; DECLARE_LRECORD (buffer, struct buffer); #define XBUFFER(x) XRECORD (x, buffer, struct buffer) #define wrap_buffer(p) wrap_record (p, buffer) #define BUFFERP(x) RECORDP (x, buffer) #define CHECK_BUFFER(x) CHECK_RECORD (x, buffer) #define CONCHECK_BUFFER(x) CONCHECK_RECORD (x, buffer) #define BUFFER_LIVE_P(b) (!NILP ((b)->name)) #define CHECK_LIVE_BUFFER(x) do { \ CHECK_BUFFER (x); \ if (!BUFFER_LIVE_P (XBUFFER (x))) \ dead_wrong_type_argument (Qbuffer_live_p, (x)); \ } while (0) #define CONCHECK_LIVE_BUFFER(x) do { \ CONCHECK_BUFFER (x); \ if (!BUFFER_LIVE_P (XBUFFER (x))) \ x = wrong_type_argument (Qbuffer_live_p, (x)); \ } while (0) #define BUFFER_BASE_BUFFER(b) ((b)->base_buffer ? (b)->base_buffer : (b)) /* Map over buffers sharing the same text as MPS_BUF. MPS_BUFVAR is a variable that gets the buffer values (beginning with the base buffer, then the children), and MPS_BUFCONS should be a temporary Lisp_Object variable. */ #define MAP_INDIRECT_BUFFERS(mps_buf, mps_bufvar, mps_bufcons) \ for (mps_bufcons = Qunbound, \ mps_bufvar = BUFFER_BASE_BUFFER (mps_buf); \ UNBOUNDP (mps_bufcons) ? \ (mps_bufcons = mps_bufvar->indirect_children, \ 1) \ : (!NILP (mps_bufcons) \ && (mps_bufvar = XBUFFER (XCAR (mps_bufcons)), 1) \ && (mps_bufcons = XCDR (mps_bufcons), 1)); \ ) /* All macros below follow the three golden rules of macros (see text.h), with the following exception: -- 'struct buffer *' arguments can be evaluated more than once. */ /*----------------------------------------------------------------------*/ /* Accessor macros for important positions in a buffer */ /*----------------------------------------------------------------------*/ /* We put them here because some stuff below wants them before the place where we would normally put them. */ /* None of these are lvalues. Use the settor macros below to change the positions. */ /* Beginning of buffer. */ #define BYTE_BUF_BEG(buf) ((Bytebpos) 1) #define BUF_BEG(buf) ((Charbpos) 1) /* Beginning of accessible range of buffer. */ #define BYTE_BUF_BEGV(buf) ((buf)->begv + 0) #define BUF_BEGV(buf) ((buf)->bufbegv + 0) /* End of accessible range of buffer. */ #define BYTE_BUF_ZV(buf) ((buf)->zv + 0) #define BUF_ZV(buf) ((buf)->bufzv + 0) /* End of buffer. */ #define BYTE_BUF_Z(buf) ((buf)->text->z + 0) #define BUF_Z(buf) ((buf)->text->bufz + 0) /* Gap location. */ #define BYTE_BUF_GPT(buf) ((buf)->text->gpt + 0) #define BUF_GPT(buf) ((buf)->text->bufgpt + 0) /* Point. */ #define BYTE_BUF_PT(buf) ((buf)->pt + 0) #define BUF_PT(buf) ((buf)->bufpt + 0) /* Internal format of buffer. */ #ifdef MULE #define BUF_FORMAT(buf) ((buf)->text->format) #else #define BUF_FORMAT(buf) FORMAT_DEFAULT #endif /*----------------------------------------------------------------------*/ /* Validating byte positions */ /*----------------------------------------------------------------------*/ /* Address of byte at position POS in buffer, no error checking. */ DECLARE_INLINE_HEADER ( Ibyte * BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (struct buffer *buf, Bytebpos pos) ) { return (buf->text->beg + ((pos >= buf->text->gpt ? (pos + buf->text->gap_size) : pos) - 1)); } /* Given a byte position, does it point to the beginning of a character? */ #ifdef MULE DECLARE_INLINE_HEADER ( int VALID_BYTEBPOS_P (struct buffer *buf, Bytebpos x) ) { switch (BUF_FORMAT (buf)) { case FORMAT_DEFAULT: return ibyte_first_byte_p (*BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, x)); case FORMAT_16_BIT_FIXED: return ((x - 1) & 1) == 0; case FORMAT_32_BIT_FIXED: return ((x - 1) & 3) == 0; default: return 1; } } #else # define VALID_BYTEBPOS_P(buf, x) 1 #endif /* If error-checking is enabled, assert that the given char position is within range. Otherwise, do nothing. */ # define ASSERT_VALID_CHARBPOS_UNSAFE(buf, x) do { \ text_checking_assert (BUFFER_LIVE_P (buf)); \ text_checking_assert ((x) >= BUF_BEG (buf) && x <= BUF_Z (buf)); \ } while (0) /* If error-checking is enabled, assert that the given byte position is within range and points to the beginning of a character or to the end of the buffer. Otherwise, do nothing. */ # define ASSERT_VALID_BYTEBPOS_UNSAFE(buf, x) do { \ text_checking_assert (BUFFER_LIVE_P (buf)); \ text_checking_assert ((x) >= BYTE_BUF_BEG (buf) && x <= BYTE_BUF_Z (buf)); \ text_checking_assert (VALID_BYTEBPOS_P (buf, x)); \ } while (0) /* If error-checking is enabled, assert that the given byte position is within range and satisfies ASSERT_VALID_BYTEBPOS() and also does not refer to the beginning of the buffer. (i.e. movement backwards is OK.) Otherwise, do nothing. */ # define ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE(buf, x) do { \ text_checking_assert (BUFFER_LIVE_P (buf)); \ text_checking_assert ((x) > BYTE_BUF_BEG (buf) && x <= BYTE_BUF_Z (buf)); \ text_checking_assert (VALID_BYTEBPOS_P (buf, x)); \ } while (0) /* If error-checking is enabled, assert that the given byte position is within range and satisfies ASSERT_VALID_BYTEBPOS() and also does not refer to the end of the buffer. (i.e. movement forwards is OK.) Otherwise, do nothing. */ # define ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE(buf, x) do { \ text_checking_assert (BUFFER_LIVE_P (buf)); \ text_checking_assert ((x) >= BYTE_BUF_BEG (buf) && x < BYTE_BUF_Z (buf)); \ text_checking_assert (VALID_BYTEBPOS_P (buf, x)); \ } while (0) #ifdef MULE /* Make sure that the given byte position is pointing to the beginning of a character. If not, back up until this is the case. Note that there are not too many places where it is legitimate to do this sort of thing. It's an error if you're passed an "invalid" byte position. */ # define VALIDATE_BYTEBPOS_BACKWARD(buf, x) do { \ switch (BUF_FORMAT (buf)) \ { \ case FORMAT_DEFAULT: \ { \ Ibyte *VBB_ptr = BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, x); \ while (!ibyte_first_byte_p (*VBB_ptr)) \ VBB_ptr--, (x)--; \ } \ break; \ case FORMAT_16_BIT_FIXED: \ if (((x - 1) & 1) != 0) \ x--; \ break; \ case FORMAT_32_BIT_FIXED: \ while (((x - 1) & 3) != 0) \ x--; \ break; \ default: \ break; \ } \ } while (0) #else # define VALIDATE_BYTEBPOS_BACKWARD(buf, x) #endif #ifdef MULE /* Make sure that the given byte position is pointing to the beginning of a character. If not, move forward until this is the case. Note that there are not too many places where it is legitimate to do this sort of thing. It's an error if you're passed an "invalid" byte position. */ # define VALIDATE_BYTEBPOS_FORWARD(buf, x) do { \ switch (BUF_FORMAT (buf)) \ { \ case FORMAT_DEFAULT: \ { \ Ibyte *VBF_ptr = BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, x); \ while (!ibyte_first_byte_p (*VBF_ptr)) \ VBF_ptr++, (x)++; \ } \ break; \ case FORMAT_16_BIT_FIXED: \ if (((x - 1) & 1) != 0) \ x++; \ break; \ case FORMAT_32_BIT_FIXED: \ while (((x - 1) & 3) != 0) \ x++; \ break; \ default: \ break; \ } \ } while (0) #else # define VALIDATE_BYTEBPOS_FORWARD(buf, x) #endif /*----------------------------------------------------------------------*/ /* Working with byte positions */ /*----------------------------------------------------------------------*/ /* Given a byte position (assumed to point at the beginning of a character), modify that value so it points to the beginning of the next character. Note that in the simplest case (no MULE, no ERROR_CHECK_TEXT), this crap reduces down to simply (x)++. */ #define INC_BYTEBPOS(buf, x) do \ { \ ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE (buf, x); \ /* Note that we do the increment first to \ make sure that the pointer in \ VALIDATE_BYTEBPOS_FORWARD() ends up on \ the correct side of the gap */ \ (x)++; \ VALIDATE_BYTEBPOS_FORWARD (buf, x); \ } while (0) /* Given a byte position (assumed to point at the beginning of a character), modify that value so it points to the beginning of the previous character. Unlike for DEC_IBYTEPTR(), we can do all the assert()s because there are sentinels at the beginning of the gap and the end of the buffer. Note that in the simplest case (no MULE, no ERROR_CHECK_TEXT), this crap reduces down to simply (x)--. */ #define DEC_BYTEBPOS(buf, x) do \ { \ ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE (buf, x); \ /* Note that we do the decrement first to \ make sure that the pointer in \ VALIDATE_BYTEBPOS_BACKWARD() ends up on \ the correct side of the gap */ \ (x)--; \ VALIDATE_BYTEBPOS_BACKWARD (buf, x); \ } while (0) DECLARE_INLINE_HEADER ( Bytebpos prev_bytebpos (struct buffer *USED_IF_MULE_OR_CHECK_TEXT (buf), Bytebpos x) ) { DEC_BYTEBPOS (buf, x); return x; } DECLARE_INLINE_HEADER ( Bytebpos next_bytebpos (struct buffer *USED_IF_MULE_OR_CHECK_TEXT (buf), Bytebpos x) ) { INC_BYTEBPOS (buf, x); return x; } /* A constant representing an invalid Bytebpos. Valid Bytebposes can never have this value. */ #define BYTEBPOS_INVALID ((Bytebpos) -1) /*----------------------------------------------------------------------*/ /* Converting between byte and character positions */ /*----------------------------------------------------------------------*/ /* Info on Byte-Char conversion: (Info-goto-node "(internals)Byte-Char Position Conversion") */ #ifdef MULE Bytebpos charbpos_to_bytebpos_func (struct buffer *buf, Charbpos x); Charbpos bytebpos_to_charbpos_func (struct buffer *buf, Bytebpos x); extern short three_to_one_table[]; #endif /* MULE */ /* Given a Charbpos, return the equivalent Bytebpos. */ DECLARE_INLINE_HEADER ( Bytebpos charbpos_to_bytebpos (struct buffer *USED_IF_MULE_OR_CHECK_TEXT (buf), Charbpos x) ) { Bytebpos retval; ASSERT_VALID_CHARBPOS_UNSAFE (buf, x); #ifdef MULE if (buf->text->entirely_one_byte_p) retval = (Bytebpos) x; else if (BUF_FORMAT (buf) == FORMAT_16_BIT_FIXED) retval = (Bytebpos) (x << 1); else if (BUF_FORMAT (buf) == FORMAT_32_BIT_FIXED) retval = (Bytebpos) (x << 2); #ifdef OLD_BYTE_CHAR else if (x >= buf->text->mule_bufmin && x <= buf->text->mule_bufmax) retval = (buf->text->mule_bytmin + ((x - buf->text->mule_bufmin) << buf->text->mule_shifter) + (buf->text->mule_three_p ? (x - buf->text->mule_bufmin) : (Bytebpos) 0)); #endif /* OLD_BYTE_CHAR */ else retval = charbpos_to_bytebpos_func (buf, x); #else retval = (Bytebpos) x; #endif ASSERT_VALID_BYTEBPOS_UNSAFE (buf, retval); return retval; } /* Given a Bytebpos, return the equivalent Charbpos. */ DECLARE_INLINE_HEADER ( Charbpos bytebpos_to_charbpos (struct buffer *USED_IF_MULE_OR_CHECK_TEXT (buf), Bytebpos x) ) { Charbpos retval; ASSERT_VALID_BYTEBPOS_UNSAFE (buf, x); #ifdef MULE if (buf->text->entirely_one_byte_p) retval = (Charbpos) x; else if (BUF_FORMAT (buf) == FORMAT_16_BIT_FIXED) retval = (Charbpos) (x >> 1); else if (BUF_FORMAT (buf) == FORMAT_32_BIT_FIXED) retval = (Charbpos) (x >> 2); #ifdef OLD_BYTE_CHAR else if (x >= buf->text->mule_bytmin && x <= buf->text->mule_bytmax) retval = (buf->text->mule_bufmin + ((buf->text->mule_three_p ? three_to_one_table[x - buf->text->mule_bytmin] : (x - buf->text->mule_bytmin) >> buf->text->mule_shifter))); #endif /* OLD_BYTE_CHAR */ else retval = bytebpos_to_charbpos_func (buf, x); #else retval = (Charbpos) x; #endif ASSERT_VALID_CHARBPOS_UNSAFE (buf, retval); return retval; } /* Given a Bytebpos, return the equivalent Charbpos as a Lisp Object. */ #define make_charbpos(buf, ind) make_int (bytebpos_to_charbpos (buf, ind)) /*----------------------------------------------------------------------*/ /* Converting between byte and memory positions */ /*----------------------------------------------------------------------*/ DECLARE_INLINE_HEADER ( int valid_membpos_p (struct buffer *buf, Membpos x) ) { return ((x >= 1 && x <= (Membpos) buf->text->gpt) || (x > (Membpos) (buf->text->gpt + buf->text->gap_size) && x <= (Membpos) (buf->text->z + buf->text->gap_size))); } DECLARE_INLINE_HEADER ( Membpos bytebpos_to_membpos (struct buffer *buf, Bytebpos x) ) { ASSERT_VALID_BYTEBPOS_UNSAFE (buf, x); return (Membpos) ((x > buf->text->gpt) ? (x + buf->text->gap_size) : x); } DECLARE_INLINE_HEADER ( Bytebpos membpos_to_bytebpos (struct buffer *buf, Membpos x) ) { Bytebpos retval; text_checking_assert (valid_membpos_p (buf, x)); retval = (Bytebpos) ((x > (Membpos) buf->text->gpt) ? x - buf->text->gap_size : x); ASSERT_VALID_BYTEBPOS_UNSAFE (buf, retval); return retval; } DECLARE_INLINE_HEADER ( Charbpos membpos_to_charbpos (struct buffer *buf, Membpos x) ) { return bytebpos_to_charbpos (buf, membpos_to_bytebpos (buf, x)); } DECLARE_INLINE_HEADER ( Membpos charbpos_to_membpos (struct buffer *buf, Charbpos x) ) { return bytebpos_to_membpos (buf, charbpos_to_bytebpos (buf, x)); } /*----------------------------------------------------------------------*/ /* Generalized buffer/string position convertors */ /*----------------------------------------------------------------------*/ /* These macros generalize many standard buffer-position functions to either a buffer or a string. */ /* Converting between Memxpos's and Bytexpos's, for a buffer-or-string. For strings, this is a no-op. For buffers, this resolves to the standard membpos<->bytebpos converters. */ DECLARE_INLINE_HEADER ( Memxpos buffer_or_string_bytexpos_to_memxpos (Lisp_Object obj, Bytexpos pos) ) { return (BUFFERP (obj) ? bytebpos_to_membpos (XBUFFER (obj), pos) : (Memxpos) pos); } DECLARE_INLINE_HEADER ( Bytexpos buffer_or_string_memxpos_to_bytexpos (Lisp_Object obj, Memxpos pos) ) { return (BUFFERP (obj) ? membpos_to_bytebpos (XBUFFER (obj), pos) : (Bytexpos) pos); } /* Converting between Charxpos's and Bytexpos's, for a buffer-or-string. For strings, this maps to the bytecount<->charcount converters. */ DECLARE_INLINE_HEADER ( Bytexpos buffer_or_string_charxpos_to_bytexpos (Lisp_Object obj, Charxpos pos) ) { return (BUFFERP (obj) ? charbpos_to_bytebpos (XBUFFER (obj), pos) : (Bytexpos) string_index_char_to_byte (obj, pos)); } DECLARE_INLINE_HEADER ( Charxpos buffer_or_string_bytexpos_to_charxpos (Lisp_Object obj, Bytexpos pos) ) { return (BUFFERP (obj) ? bytebpos_to_charbpos (XBUFFER (obj), pos) : (Charxpos) string_index_byte_to_char (obj, pos)); } /* Similar for Charxpos's and Memxpos's. */ DECLARE_INLINE_HEADER ( Memxpos buffer_or_string_charxpos_to_memxpos (Lisp_Object obj, Charxpos pos) ) { return (BUFFERP (obj) ? charbpos_to_membpos (XBUFFER (obj), pos) : (Memxpos) string_index_char_to_byte (obj, pos)); } DECLARE_INLINE_HEADER ( Charxpos buffer_or_string_memxpos_to_charxpos (Lisp_Object obj, Memxpos pos) ) { return (BUFFERP (obj) ? membpos_to_charbpos (XBUFFER (obj), pos) : (Charxpos) string_index_byte_to_char (obj, pos)); } DECLARE_INLINE_HEADER ( Internal_Format buffer_or_other_internal_format (Lisp_Object obj) ) { return BUFFERP (obj) ? BUF_FORMAT (XBUFFER (obj)) : FORMAT_DEFAULT; } /* Return the index to the character before the one at X, in a buffer or string. */ DECLARE_INLINE_HEADER ( Bytebpos prev_bytexpos (Lisp_Object obj, Bytebpos x) ) { return BUFFERP (obj) ? prev_bytebpos (XBUFFER (obj), x) : prev_string_index (obj, x); } /* Return the index to the character after the one at X, in a buffer or string. */ DECLARE_INLINE_HEADER ( Bytebpos next_bytexpos (Lisp_Object obj, Bytebpos x) ) { return BUFFERP (obj) ? next_bytebpos (XBUFFER (obj), x) : next_string_index (obj, x); } /*----------------------------------------------------------------------*/ /* Converting between positions and addresses */ /*----------------------------------------------------------------------*/ /* Convert the address of a byte in the buffer into a position. */ DECLARE_INLINE_HEADER ( Bytebpos BYTE_BUF_PTR_BYTE_POS (struct buffer *buf, Ibyte *ptr) ) { Bytebpos retval = (ptr - buf->text->beg + 1 - ((ptr - buf->text->beg + 1) > buf->text->gpt ? buf->text->gap_size : (Bytebpos) 0)); ASSERT_VALID_BYTEBPOS_UNSAFE (buf, retval); return retval; } #define BUF_PTR_BYTE_POS(buf, ptr) \ bytebpos_to_charbpos (buf, BYTE_BUF_PTR_BYTE_POS (buf, ptr)) /* Address of byte at position POS in buffer. */ DECLARE_INLINE_HEADER ( Ibyte * BYTE_BUF_BYTE_ADDRESS (struct buffer *buf, Bytebpos pos) ) { ASSERT_VALID_BYTEBPOS_UNSAFE (buf, pos); return BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, pos); } #define BUF_BYTE_ADDRESS(buf, pos) \ BYTE_BUF_BYTE_ADDRESS (buf, charbpos_to_bytebpos (buf, pos)) /* Address of byte before position POS in buffer. */ DECLARE_INLINE_HEADER ( Ibyte * BYTE_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytebpos pos) ) { ASSERT_VALID_BYTEBPOS_UNSAFE (buf, pos); return (buf->text->beg + ((pos > buf->text->gpt ? (pos + buf->text->gap_size) : pos) - 2)); } #define BUF_BYTE_ADDRESS_BEFORE(buf, pos) \ BYTE_BUF_BYTE_ADDRESS_BEFORE (buf, charbpos_to_bytebpos (buf, pos)) /*----------------------------------------------------------------------*/ /* Converting between buffer bytes and Emacs characters */ /*----------------------------------------------------------------------*/ /* The character at position POS in buffer. */ #define BYTE_BUF_FETCH_CHAR(buf, pos) \ itext_ichar_fmt (BYTE_BUF_BYTE_ADDRESS (buf, pos), BUF_FORMAT (buf), \ wrap_buffer (buf)) #define BUF_FETCH_CHAR(buf, pos) \ BYTE_BUF_FETCH_CHAR (buf, charbpos_to_bytebpos (buf, pos)) /* The "raw value" of the character at position POS in buffer. See ichar_to_raw(). */ #define BYTE_BUF_FETCH_CHAR_RAW(buf, pos) \ itext_ichar_raw_fmt (BYTE_BUF_BYTE_ADDRESS (buf, pos), BUF_FORMAT (buf)) #define BUF_FETCH_CHAR_RAW(buf, pos) \ BYTE_BUF_FETCH_CHAR_RAW (buf, charbpos_to_bytebpos (buf, pos)) /* The character at position POS in buffer, as a string. This is equivalent to set_itext_ichar (str, BUF_FETCH_CHAR (buf, pos)) but is faster for Mule. */ # define BYTE_BUF_ITEXT_COPY_ICHAR(buf, pos, str) \ (BUF_FORMAT (buf) == FORMAT_DEFAULT ? \ itext_copy_ichar (BYTE_BUF_BYTE_ADDRESS (buf, pos), str) : \ set_itext_ichar (str, BYTE_BUF_FETCH_CHAR (buf, pos))) #define BUF_ITEXT_COPY_ICHAR(buf, pos, str) \ BYTE_BUF_ITEXT_COPY_ICHAR (buf, charbpos_to_bytebpos (buf, pos), str) /************************************************************************/ /* */ /* higher-level buffer-position functions */ /* */ /************************************************************************/ /*----------------------------------------------------------------------*/ /* Settor macros for important positions in a buffer */ /*----------------------------------------------------------------------*/ /* Set beginning of accessible range of buffer. */ #define SET_BOTH_BUF_BEGV(buf, val, bpval) \ do \ { \ (buf)->begv = (bpval); \ (buf)->bufbegv = (val); \ } while (0) /* Set end of accessible range of buffer. */ #define SET_BOTH_BUF_ZV(buf, val, bpval) \ do \ { \ (buf)->zv = (bpval); \ (buf)->bufzv = (val); \ } while (0) /* Set point. */ /* Since BEGV and ZV are almost never set, it's reasonable to enforce the restriction that the Charbpos and Bytebpos values must both be specified. However, point is set in lots and lots of places. So we provide the ability to specify both (for efficiency) or just one. */ #define BOTH_BUF_SET_PT(buf, val, bpval) set_buffer_point (buf, val, bpval) #define BYTE_BUF_SET_PT(buf, bpval) \ do \ { \ Bytebpos __bpbsp_bpval = (bpval); \ BOTH_BUF_SET_PT (buf, bytebpos_to_charbpos (buf, __bpbsp_bpval), \ __bpbsp_bpval); \ } while (0) #define BUF_SET_PT(buf, value) \ do \ { \ Bytebpos __bsp_val = (value); \ BOTH_BUF_SET_PT (buf, __bsp_val, charbpos_to_bytebpos (buf, __bsp_val)); \ } while (0) #if 0 /* FSFmacs */ /* These macros exist in FSFmacs because SET_PT() in FSFmacs incorrectly does too much stuff, such as moving out of invisible extents. */ #define TEMP_SET_PT(position) (temp_set_point ((position), current_buffer)) #define SET_BUF_PT(buf, value) ((buf)->pt = (value)) #endif /* FSFmacs */ /*----------------------------------------------------------------------*/ /* Miscellaneous buffer values */ /*----------------------------------------------------------------------*/ /* Number of characters in buffer */ #define BUF_SIZE(buf) (BUF_Z (buf) - BUF_BEG (buf)) /* Is this buffer narrowed? */ #define BUF_NARROWED(buf) \ ((BYTE_BUF_BEGV (buf) != BYTE_BUF_BEG (buf)) || \ (BYTE_BUF_ZV (buf) != BYTE_BUF_Z (buf))) /* Modification count */ #define BUF_MODIFF(buf) ((buf)->text->modiff) /* Saved modification count */ #define BUF_SAVE_MODIFF(buf) ((buf)->text->save_modiff) /* Face changed. */ #define BUF_FACECHANGE(buf) ((buf)->face_change) DECLARE_INLINE_HEADER ( int POINT_MARKER_P (Lisp_Object marker) ) { return (XMARKER (marker)->buffer != 0 && EQ (marker, XMARKER (marker)->buffer->point_marker)); } #define BUF_MARKERS(buf) ((buf)->markers) #ifdef MULE DECLARE_INLINE_HEADER ( Lisp_Object BUFFER_CATEGORY_TABLE (struct buffer *buf) ) { return buf ? buf->category_table : Vstandard_category_table; } #endif /* MULE */ DECLARE_INLINE_HEADER ( Lisp_Object BUFFER_SYNTAX_TABLE (struct buffer *buf) ) { return buf ? buf->syntax_table : Vstandard_syntax_table; } DECLARE_INLINE_HEADER ( Lisp_Object BUFFER_MIRROR_SYNTAX_TABLE (struct buffer *buf) ) { return buf ? buf->mirror_syntax_table : XCHAR_TABLE (Vstandard_syntax_table)->mirror_table; } /* WARNING: The new definitions of CEILING_OF() and FLOOR_OF() differ semantically from the old ones (in FSF Emacs and XEmacs 19.11 and before). Conversion is as follows: OLD_BYTE_CEILING_OF(n) = NEW_BYTE_CEILING_OF(n) - 1 OLD_BYTE_FLOOR_OF(n) = NEW_BYTE_FLOOR_OF(n + 1) The definitions were changed because the new definitions are more consistent with the way everything else works in XEmacs. */ /* Properties of CEILING_OF and FLOOR_OF (also apply to BYTE_ variants): 1) FLOOR_OF (CEILING_OF (n)) = n CEILING_OF (FLOOR_OF (n)) = n 2) CEILING_OF (n) = n if and only if n = ZV FLOOR_OF (n) = n if and only if n = BEGV 3) CEILING_OF (CEILING_OF (n)) = ZV FLOOR_OF (FLOOR_OF (n)) = BEGV 4) The bytes in the regions [BYTE_ADDRESS (n), BYTE_ADDRESS_BEFORE (CEILING_OF (n))] and [BYTE_ADDRESS (FLOOR_OF (n)), BYTE_ADDRESS_BEFORE (n)] are contiguous. A typical loop using CEILING_OF to process contiguous ranges of text between [from, to) looks like this: { Bytebpos pos = from; while (pos < to) { Bytebpos ceil = BYTE_BUF_CEILING_OF (buf, pos); ceil = min (to, ceil); process_ibyte_string (BYTE_BUF_BYTE_ADDRESS (buf, pos), ceil - pos); pos = ceil; } } Currently there will be at most two iterations in the loop, but it is written in such a way that it will still work if the buffer representation is changed to have multiple gaps in it. */ /* Return the maximum position in the buffer it is safe to scan forwards past N to. This is used to prevent buffer scans from running into the gap (e.g. search.c). All characters between N and CEILING_OF(N) are located contiguous in memory. Note that the character *at* CEILING_OF(N) is not contiguous in memory. */ #define BYTE_BUF_CEILING_OF(b, n) \ ((n) < BYTE_BUF_GPT (b) && BYTE_BUF_GPT (b) < BYTE_BUF_ZV (b) ? \ BYTE_BUF_GPT (b) : BYTE_BUF_ZV (b)) #define BUF_CEILING_OF(b, n) \ ((n) < BUF_GPT (b) && BUF_GPT (b) < BUF_ZV (b) ? \ BUF_GPT (b) : BUF_ZV (b)) /* Return the minimum position in the buffer it is safe to scan backwards past N to. All characters between FLOOR_OF(N) and N are located contiguous in memory. Note that the character *at* N may not be contiguous in memory. */ #define BYTE_BUF_FLOOR_OF(b, n) \ (BYTE_BUF_BEGV (b) < BYTE_BUF_GPT (b) && BYTE_BUF_GPT (b) < (n) ? \ BYTE_BUF_GPT (b) : BYTE_BUF_BEGV (b)) #define BUF_FLOOR_OF(b, n) \ (BUF_BEGV (b) < BUF_GPT (b) && BUF_GPT (b) < (n) ? \ BUF_GPT (b) : BUF_BEGV (b)) #define BYTE_BUF_CEILING_OF_IGNORE_ACCESSIBLE(b, n) \ ((n) < BYTE_BUF_GPT (b) && BYTE_BUF_GPT (b) < BYTE_BUF_Z (b) ? \ BYTE_BUF_GPT (b) : BYTE_BUF_Z (b)) #define BUF_CEILING_OF_IGNORE_ACCESSIBLE(b, n) \ ((n) < BUF_GPT (b) && BUF_GPT (b) < BUF_Z (b) ? \ BUF_GPT (b) : BUF_Z (b)) #define BYTE_BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \ (BYTE_BUF_BEG (b) < BYTE_BUF_GPT (b) && BYTE_BUF_GPT (b) < (n) ? \ BYTE_BUF_GPT (b) : BYTE_BUF_BEG (b)) #define BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \ (BUF_BEG (b) < BUF_GPT (b) && BUF_GPT (b) < (n) ? \ BUF_GPT (b) : BUF_BEG (b)) /* Iterate over contiguous chunks of text in buffer BUF, starting at POS, of length LEN. Evaluates POS and LEN only once, but BUF multiply. In each iteration, store the current chunk into RUNPTR/RUNLEN, which will be automatically declared (don't declare them yourself). This does not respect the limits of accessibility (BUF_BEGV/BUF_ZV); if you want these limits respected, you need to impose them yourself. NOTE: This must be surrounded with braces! */ #define BUFFER_TEXT_LOOP(buf, pos, len, runptr, runlen) \ Ibyte *runptr; \ Bytecount runlen; \ Bytebpos BTL_pos = (pos); \ Bytebpos BTL_len = (len); \ for (runptr = BYTE_BUF_BYTE_ADDRESS (buf, BTL_pos), \ runlen = BYTE_BUF_CEILING_OF_IGNORE_ACCESSIBLE (buf, BTL_pos) - BTL_pos, \ runlen = min (BTL_len, runlen); \ BTL_len > 0; \ BTL_pos += runlen, \ BTL_len -= runlen, \ runptr = BYTE_BUF_BYTE_ADDRESS (buf, BTL_pos), \ runlen = BYTE_BUF_CEILING_OF_IGNORE_ACCESSIBLE (buf, BTL_pos) - BTL_pos, \ runlen = min (BTL_len, runlen)) /* This structure marks which slots in a buffer have corresponding default values in Vbuffer_defaults. Each such slot has a nonzero value in this structure. The value has only one nonzero bit. When a buffer has its own local value for a slot, the bit for that slot (found in the same slot in this structure) is turned on in the buffer's local_var_flags slot. If a slot in this structure is zero, then even though there may be a DEFVAR_BUFFER_LOCAL for the slot, there is no default value for it; and the corresponding slot in Vbuffer_defaults is not used. */ extern struct buffer buffer_local_flags; /* Allocation of buffer data. */ #ifdef REL_ALLOC char *r_alloc (unsigned char **, size_t); char *r_re_alloc (unsigned char **, size_t); void r_alloc_free (unsigned char **); #define BUFFER_ALLOC(data, size) \ ((Ibyte *) r_alloc ((unsigned char **) &data, (size) * sizeof(Ibyte))) #define BUFFER_REALLOC(data, size) \ ((Ibyte *) r_re_alloc ((unsigned char **) &data, (size) * sizeof(Ibyte))) #define BUFFER_FREE(data) r_alloc_free ((unsigned char **) &(data)) #define R_ALLOC_DECLARE(var,data) r_alloc_declare (&(var), data) #else /* !REL_ALLOC */ #define BUFFER_ALLOC(data,size)\ (data = xnew_array (Ibyte, size)) #define BUFFER_REALLOC(data,size)\ ((Ibyte *) xrealloc (data, (size) * sizeof(Ibyte))) /* Avoid excess parentheses, or syntax errors may rear their heads. */ #define BUFFER_FREE(data) xfree (data, Ibyte *) #define R_ALLOC_DECLARE(var,data) #endif /* !REL_ALLOC */ /************************************************************************/ /* Case conversion */ /************************************************************************/ /* A "trt" table is a mapping from characters to other characters, typically used to convert between uppercase and lowercase. */ /* The _1 macros are named as such because they assume that you have already guaranteed that the character values are all in the range 0 - 255. Bad lossage will happen otherwise. */ #define MAKE_TRT_TABLE() Fmake_char_table (Qgeneric) DECLARE_INLINE_HEADER ( Ichar TRT_TABLE_OF (Lisp_Object table, Ichar ch) ) { Lisp_Object TRT_char; TRT_char = get_char_table (ch, table); if (NILP (TRT_char)) return ch; else return XCHAR (TRT_char); } #define SET_TRT_TABLE_OF(table, ch1, ch2) \ Fput_char_table (make_char (ch1), make_char (ch2), table) DECLARE_INLINE_HEADER ( Lisp_Object BUFFER_CASE_TABLE (struct buffer *buf) ) { return buf ? buf->case_table : Vstandard_case_table; } /* Macros used below. */ #define DOWNCASE_TABLE_OF(buf, c) \ TRT_TABLE_OF (XCASE_TABLE_DOWNCASE (BUFFER_CASE_TABLE (buf)), c) #define UPCASE_TABLE_OF(buf, c) \ TRT_TABLE_OF (XCASE_TABLE_UPCASE (BUFFER_CASE_TABLE (buf)), c) /* 1 if CH is upper case. */ DECLARE_INLINE_HEADER ( int UPPERCASEP (struct buffer *buf, Ichar ch) ) { return DOWNCASE_TABLE_OF (buf, ch) != ch; } /* 1 if CH is lower case. */ DECLARE_INLINE_HEADER ( int LOWERCASEP (struct buffer *buf, Ichar ch) ) { return (UPCASE_TABLE_OF (buf, ch) != ch && DOWNCASE_TABLE_OF (buf, ch) == ch); } /* 1 if CH is neither upper nor lower case. */ DECLARE_INLINE_HEADER ( int NOCASEP (struct buffer *buf, Ichar ch) ) { return UPCASE_TABLE_OF (buf, ch) == ch; } /* Upcase a character, or make no change if that cannot be done. */ DECLARE_INLINE_HEADER ( Ichar UPCASE (struct buffer *buf, Ichar ch) ) { return (DOWNCASE_TABLE_OF (buf, ch) == ch) ? UPCASE_TABLE_OF (buf, ch) : ch; } /* Upcase a character known to be not upper case. Unused. */ #define UPCASE1(buf, ch) UPCASE_TABLE_OF (buf, ch) /* Downcase a character, or make no change if that cannot be done. */ #define DOWNCASE(buf, ch) DOWNCASE_TABLE_OF (buf, ch) #endif /* INCLUDED_buffer_h_ */