annotate src/buffer.h @ 793:e38acbeb1cae

[xemacs-hg @ 2002-03-29 04:46:17 by ben] lots o' fixes etc/ChangeLog: New file. Separated out all entries for etc/ into their own ChangeLog. Includes entries for the following files: etc/BABYL, etc/BETA, etc/CHARSETS, etc/DISTRIB, etc/Emacs.ad, etc/FTP, etc/GNUS-NEWS, etc/GOATS, etc/HELLO, etc/INSTALL, etc/MACHINES, etc/MAILINGLISTS, etc/MSDOS, etc/MYTHOLOGY, etc/NEWS, etc/OXYMORONS, etc/PACKAGES, etc/README, etc/TUTORIAL, etc/TUTORIAL.de, etc/TUTORIAL.ja, etc/TUTORIAL.ko, etc/TUTORIAL.se, etc/aliases.ksh, etc/altrasoft-logo.xpm, etc/check_cygwin_setup.sh, etc/custom/example-themes/europe-theme.el, etc/custom/example-themes/ex-custom-file, etc/custom/example-themes/example-theme.el, etc/e/eterm.ti, etc/edt-user.doc, etc/enriched.doc, etc/etags.1, etc/gnuserv.1, etc/gnuserv.README, etc/package-index.LATEST.gpg, etc/package-index.LATEST.pgp, etc/photos/jan.png, etc/recycle.xpm, etc/refcard.tex, etc/sample.Xdefaults, etc/sample.emacs, etc/sgml/CATALOG, etc/sgml/HTML32.dtd, etc/skk/SKK.tut.E, etc/smilies/Face_ase.xbm, etc/smilies/Face_ase2.xbm, etc/smilies/Face_ase3.xbm, etc/smilies/Face_smile.xbm, etc/smilies/Face_weep.xbm, etc/sounds, etc/toolbar, etc/toolbar/workshop-cap-up.xpm, etc/xemacs-ja.1, etc/xemacs.1, etc/yow.lines, etc\BETA, etc\NEWS, etc\README, etc\TUTORIAL, etc\TUTORIAL.de, etc\check_cygwin_setup.sh, etc\sample.init.el, etc\unicode\README, etc\unicode\mule-ucs\*, etc\unicode\other\* unicode/unicode-consortium/8859-16.TXT: New file. mule/english.el: Define this charset now, since a bug was fixed that formerly prevented it. mule/ethio-util.el: Fix compile errors involving Unicode `characters', which should be integers. Makefile.in.in: Always include gui.c, to fix compile error when TTY-only. EmacsFrame.c, abbrev.c, alloc.c, buffer.c, buffer.h, bytecode.c, bytecode.h, callint.c, callproc.c, casetab.c, casetab.h, charset.h, chartab.c, chartab.h, cmds.c, console-msw.c, console-msw.h, console-tty.c, console-x.c, console-x.h, console.c, console.h, data.c, database.c, device-gtk.c, device-msw.c, device-x.c, device.c, device.h, dialog-msw.c, doc.c, doprnt.c, dumper.c, dynarr.c, editfns.c, eldap.c, eldap.h, elhash.c, elhash.h, emacs.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, event-tty.c, event-unixoid.c, events.c, events.h, extents.c, extents.h, faces.c, faces.h, file-coding.c, file-coding.h, fileio.c, filelock.c, fns.c, frame-gtk.c, frame-msw.c, frame-tty.c, frame-x.c, frame.c, frame.h, free-hook.c, general-slots.h, glyphs-eimage.c, glyphs-gtk.c, glyphs-msw.c, glyphs-widget.c, glyphs-x.c, glyphs.c, glyphs.h, gpmevent.c, gtk-xemacs.c, gui-msw.c, gui-x.c, gui-x.h, gui.c, gui.h, gutter.c, gutter.h, indent.c, input-method-xlib.c, insdel.c, keymap.c, keymap.h, lisp-disunion.h, lisp-union.h, lisp.h, lread.c, lrecord.h, lstream.c, lstream.h, marker.c, menubar-gtk.c, menubar-msw.c, menubar-x.c, menubar.c, minibuf.c, mule-canna.c, mule-ccl.c, mule-charset.c, mule-wnnfns.c, native-gtk-toolbar.c, objects-msw.c, objects-tty.c, objects-x.c, objects.c, objects.h, opaque.c, opaque.h, postgresql.c, postgresql.h, print.c, process-unix.c, process.c, process.h, rangetab.c, rangetab.h, redisplay-gtk.c, redisplay-msw.c, redisplay-output.c, redisplay-tty.c, redisplay-x.c, redisplay.c, scrollbar-gtk.c, scrollbar-msw.c, scrollbar-x.c, scrollbar.c, scrollbar.h, search.c, select-gtk.c, select-x.c, sound.c, specifier.c, specifier.h, strftime.c, symbols.c, symeval.h, syntax.h, text.c, text.h, toolbar-common.c, toolbar-msw.c, toolbar.c, toolbar.h, tooltalk.c, tooltalk.h, ui-gtk.c, ui-gtk.h, undo.c, vm-limit.c, window.c, window.h: Eliminate XSETFOO. Replace all usages with wrap_foo(). Make symbol->name a Lisp_Object, not Lisp_String *. Eliminate nearly all uses of Lisp_String * in favor of Lisp_Object, and correct macros so most of them favor Lisp_Object. Create new error-behavior ERROR_ME_DEBUG_WARN -- output warnings, but at level `debug' (usually ignored). Use it when instantiating specifiers, so problems can be debugged. Move log-warning-minimum-level into C so that we can optimize ERROR_ME_DEBUG_WARN. Fix warning levels consistent with new definitions. Add default_ and parent fields to char table; not yet implemented. New fun Dynarr_verify(); use for further error checking on Dynarrs. Rearrange code at top of lisp.h in conjunction with dynarr changes. Fix eifree(). Use Eistrings in various places (format_event_object(), where_is_to_char(), and callers thereof) to avoid fixed-size strings buffers. New fun write_eistring(). Reindent and fix GPM code to follow standards. Set default MS Windows font to Lucida Console (same size as Courier New but less interline spacing, so more lines fit). Increase default frame size on Windows to 50 lines. (If that's too big for the workspace, the frame will be shrunk as necessary.) Fix problem with text files with no newlines (). (Change `convert-eol' coding system to use `nil' for autodetect, consistent with make-coding-system.) Correct compile warnings in vm-limit.c. Fix handling of reverse-direction charsets to avoid errors when opening (e.g.) mule-ucs/lisp/reldata/uiso8859-6.el. Recode some object printing methods to use write_fmt_string() instead of a fixed buffer and sprintf. Turn on display of png comments as warnings (level `info'), now that they're unobtrusive. Revamped the sound documentation. Fixed bug in redisplay w.r.t. hscroll/truncation/continuation glyphs causing jumping up and down of the lines, since they're bigger than the line size. (It was seen most obviously when there's a horizontal scroll bar, e.g. do C-h a glyph or something like that.) The problem was that the glyph-contrib-p setting on glyphs was ignored even if it was set properly, which it wasn't until now.
author ben
date Fri, 29 Mar 2002 04:49:13 +0000
parents 943eaba38521
children a5954632b187
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Header file for the buffer manipulation primitives.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1992, 1993, 1994, 1995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 Copyright (C) 1995 Sun Microsystems, Inc.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5 Copyright (C) 2001, 2002 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 /* Synched up with: FSF 19.30. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 /* Authorship:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 FSF: long ago.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 JWZ: separated out bufslots.h, early in Lemacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 Ben Wing: almost completely rewritten for Mule, 19.12.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
33 #ifndef INCLUDED_buffer_h_
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
34 #define INCLUDED_buffer_h_
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
36 #include "casetab.h"
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
37 #include "chartab.h"
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
38
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 /* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 /* definition of Lisp buffer object */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 /* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
45 /* Note: we keep both Bytebpos and Charbpos versions of some of the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 important buffer positions because they are accessed so much.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 If we didn't do this, we would constantly be invalidating the
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
48 charbpos<->bytebpos cache under Mule.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 Note that under non-Mule, both versions will always be the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 same so we don't really need to keep track of them. But it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 simplifies the logic to go ahead and do so all the time and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 the memory loss is insignificant. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 /* Formerly, it didn't much matter what went inside the struct buffer_text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 and what went outside it. Now it does, with the advent of "indirect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 buffers" that share text with another buffer. An indirect buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 shares the same *text* as another buffer, but has its own buffer-local
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 variables, its own accessible region, and its own markers and extents.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 (Due to the nature of markers, it doesn't actually matter much whether
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 we stick them inside or out of the struct buffer_text -- the user won't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 notice any difference -- but we go ahead and put them outside for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 consistency and overall saneness of algorithm.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 FSFmacs gets away with not maintaining any "children" pointers from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 a buffer to the indirect buffers that refer to it by putting the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 markers inside of the struct buffer_text, using markers to keep track
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 of BEGV and ZV in indirect buffers, and relying on the fact that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 all intervals (text properties and overlays) use markers for their
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 start and end points. We don't do this for extents (markers are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 inefficient anyway and take up space), so we have to maintain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 children pointers. This is not terribly hard, though, and the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 code to maintain this is just like the code already present in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 extent-parent and extent-children.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 struct buffer_text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
79 Intbyte *beg; /* Actual address of buffer contents. */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
80 Bytebpos gpt; /* Index of gap in buffer. */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
81 Bytebpos z; /* Index of end of buffer. */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
82 Charbpos bufz; /* Equivalent as a Charbpos. */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
83 Bytecount gap_size;/* Size of buffer's gap */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
84 Bytecount end_gap_size;/* Size of buffer's end gap */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 long modiff; /* This counts buffer-modification events
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 for this buffer. It is incremented for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 each such event, and never otherwise
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 changed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 long save_modiff; /* Previous value of modiff, as of last
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 time buffer visited or saved a file. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 #ifdef MULE
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
93 /* We keep track of a "known" region for very fast access. This
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
94 information is text-only so it goes here. We update this at each
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
95 change to the buffer, so if it's entirely ASCII, these will always
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
96 contain the minimum and maximum positions of the buffer. */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
97 Charbpos mule_bufmin, mule_bufmax;
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
98 Bytebpos mule_bytmin, mule_bytmax;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 int mule_shifter, mule_three_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 /* And we also cache 16 positions for fairly fast access near those
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 positions. */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
103 Charbpos mule_charbpos_cache[16];
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
104 Bytebpos mule_bytebpos_cache[16];
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
105
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
106 int entirely_ascii_p;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 /* Similar to the above, we keep track of positions for which line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 number has last been calculated. See line-number.c. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 Lisp_Object line_number_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 /* Change data that goes with the text. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 struct buffer_text_change_data *changes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 struct buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 struct lcrecord_header header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 /* This structure holds the coordinates of the buffer contents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 in ordinary buffers. In indirect buffers, this is not used. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 struct buffer_text own_text;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 /* This points to the `struct buffer_text' that is used for this buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 In an ordinary buffer, this is the own_text field above.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 In an indirect buffer, this is the own_text field of another buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 struct buffer_text *text;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
130 Bytebpos pt; /* Position of point in buffer. */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
131 Charbpos bufpt; /* Equivalent as a Charbpos. */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
132 Bytebpos begv; /* Index of beginning of accessible range. */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
133 Charbpos bufbegv; /* Equivalent as a Charbpos. */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
134 Bytebpos zv; /* Index of end of accessible range. */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
135 Charbpos bufzv; /* Equivalent as a Charbpos. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 int face_change; /* This is set when a change in how the text should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 be displayed (e.g., font, color) is made. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
140 /* Whether buffer specific face is specified. */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
141 int buffer_local_face_property;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
142
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 /* change data indicating what portion of the text has changed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 since the last time this was reset. Used by redisplay.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 Logically we should keep this with the text structure, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 redisplay resets it for each buffer individually and we don't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 want interference between an indirect buffer and its base
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 struct each_buffer_change_data *changes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 #ifdef REGION_CACHE_NEEDS_WORK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 /* If the long line scan cache is enabled (i.e. the buffer-local
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 variable cache-long-line-scans is non-nil), newline_cache
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 points to the newline cache, and width_run_cache points to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 width run cache.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 The newline cache records which stretches of the buffer are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 known *not* to contain newlines, so that they can be skipped
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 quickly when we search for newlines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 The width run cache records which stretches of the buffer are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 known to contain characters whose widths are all the same. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 the width run cache maps a character to a value > 0, that value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 is the character's width; if it maps a character to zero, we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 don't know what its width is. This allows compute_motion to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 process such regions very quickly, using algebra instead of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 inspecting each character. See also width_table, below. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 struct region_cache *newline_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 struct region_cache *width_run_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 #endif /* REGION_CACHE_NEEDS_WORK */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 /* The markers that refer to this buffer. This is actually a single
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 marker -- successive elements in its marker `chain' are the other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 markers referring to this buffer */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
175 Lisp_Marker *markers;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 /* The buffer's extent info. This is its own type, an extent-info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 object (done this way for ease in marking / finalizing). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 Lisp_Object extent_info;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 /* ----------------------------------------------------------------- */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 /* All the stuff above this line is the responsibility of insdel.c,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 with some help from marker.c and extents.c.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 All the stuff below this line is the responsibility of buffer.c. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 /* In an indirect buffer, this points to the base buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 In an ordinary buffer, it is 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 We DO mark through this slot. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 struct buffer *base_buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 /* List of indirect buffers whose base is this buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 If we are an indirect buffer, this will be nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 Do NOT mark through this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 Lisp_Object indirect_children;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 /* Flags saying which DEFVAR_PER_BUFFER variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 are local to this buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 int local_var_flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 /* Set to the modtime of the visited file when read or written.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 -1 means visited file was nonexistent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 0 means visited file modtime unknown; in no case complain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 about any mismatch on next save attempt. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 int modtime;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 /* the value of text->modiff at the last auto-save. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
207 long auto_save_modified;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 /* The time at which we detected a failure to auto-save,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 Or -1 if we didn't have a failure. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 int auto_save_failure_time;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 /* Position in buffer at which display started
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 the last time this buffer was displayed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 int last_window_start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 /* Everything from here down must be a Lisp_Object */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 #define MARKED_SLOT(x) Lisp_Object x
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 #include "bufslots.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 #undef MARKED_SLOT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 DECLARE_LRECORD (buffer, struct buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 #define XBUFFER(x) XRECORD (x, buffer, struct buffer)
617
af57a77cbc92 [xemacs-hg @ 2001-06-18 07:09:50 by ben]
ben
parents: 616
diff changeset
226 #define wrap_buffer(p) wrap_record (p, buffer)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 #define BUFFERP(x) RECORDP (x, buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 #define CHECK_BUFFER(x) CHECK_RECORD (x, buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 #define CONCHECK_BUFFER(x) CONCHECK_RECORD (x, buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 #define BUFFER_LIVE_P(b) (!NILP ((b)->name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 #define CHECK_LIVE_BUFFER(x) do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 CHECK_BUFFER (x); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 if (!BUFFER_LIVE_P (XBUFFER (x))) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 dead_wrong_type_argument (Qbuffer_live_p, (x)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 #define CONCHECK_LIVE_BUFFER(x) do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 CONCHECK_BUFFER (x); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 if (!BUFFER_LIVE_P (XBUFFER (x))) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 x = wrong_type_argument (Qbuffer_live_p, (x)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 #define BUFFER_BASE_BUFFER(b) ((b)->base_buffer ? (b)->base_buffer : (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 /* Map over buffers sharing the same text as MPS_BUF. MPS_BUFVAR is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 variable that gets the buffer values (beginning with the base
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 buffer, then the children), and MPS_BUFCONS should be a temporary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 Lisp_Object variable. */
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 617
diff changeset
252 #define MAP_INDIRECT_BUFFERS(mps_buf, mps_bufvar, mps_bufcons) \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 617
diff changeset
253 for (mps_bufcons = Qunbound, \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 617
diff changeset
254 mps_bufvar = BUFFER_BASE_BUFFER (mps_buf); \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 617
diff changeset
255 UNBOUNDP (mps_bufcons) ? \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 617
diff changeset
256 (mps_bufcons = mps_bufvar->indirect_children, \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 617
diff changeset
257 1) \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 617
diff changeset
258 : (!NILP (mps_bufcons) \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 617
diff changeset
259 && (mps_bufvar = XBUFFER (XCAR (mps_bufcons)), 1) \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 617
diff changeset
260 && (mps_bufcons = XCDR (mps_bufcons), 1)); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 /* Accessor macros for important positions in a buffer */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 /* We put them here because some stuff below wants them before the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 place where we would normally put them. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 /* None of these are lvalues. Use the settor macros below to change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 the positions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 /* Beginning of buffer. */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
275 #define BI_BUF_BEG(buf) ((Bytebpos) 1)
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
276 #define BUF_BEG(buf) ((Charbpos) 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 /* Beginning of accessible range of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 #define BI_BUF_BEGV(buf) ((buf)->begv + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 #define BUF_BEGV(buf) ((buf)->bufbegv + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 /* End of accessible range of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 #define BI_BUF_ZV(buf) ((buf)->zv + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 #define BUF_ZV(buf) ((buf)->bufzv + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 /* End of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 #define BI_BUF_Z(buf) ((buf)->text->z + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 #define BUF_Z(buf) ((buf)->text->bufz + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 /* Point. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 #define BI_BUF_PT(buf) ((buf)->pt + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 #define BUF_PT(buf) ((buf)->bufpt + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 /* Converting between positions and addresses */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 /* Convert the address of a byte in the buffer into a position. */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
299 INLINE_HEADER Bytebpos BI_BUF_PTR_BYTE_POS (struct buffer *buf, Intbyte *ptr);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
300 INLINE_HEADER Bytebpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
301 BI_BUF_PTR_BYTE_POS (struct buffer *buf, Intbyte *ptr)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 return (ptr - buf->text->beg + 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 - ((ptr - buf->text->beg + 1) > buf->text->gpt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 ? buf->text->gap_size : 0));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 #define BUF_PTR_BYTE_POS(buf, ptr) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
309 bytebpos_to_charbpos (buf, BI_BUF_PTR_BYTE_POS (buf, ptr))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 /* Address of byte at position POS in buffer. */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
312 INLINE_HEADER Intbyte * BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytebpos pos);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
313 INLINE_HEADER Intbyte *
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
314 BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytebpos pos)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 return (buf->text->beg +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 ((pos >= buf->text->gpt ? (pos + buf->text->gap_size) : pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 - 1));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 #define BUF_BYTE_ADDRESS(buf, pos) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
322 BI_BUF_BYTE_ADDRESS (buf, charbpos_to_bytebpos (buf, pos))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 /* Address of byte before position POS in buffer. */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
325 INLINE_HEADER Intbyte * BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytebpos pos);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
326 INLINE_HEADER Intbyte *
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
327 BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytebpos pos)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 return (buf->text->beg +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 ((pos > buf->text->gpt ? (pos + buf->text->gap_size) : pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 - 2));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 #define BUF_BYTE_ADDRESS_BEFORE(buf, pos) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
335 BI_BUF_BYTE_ADDRESS_BEFORE (buf, charbpos_to_bytebpos (buf, pos))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 /* Converting between byte indices and memory indices */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
341 INLINE_HEADER int valid_membpos_p (struct buffer *buf, Membpos x);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
342 INLINE_HEADER int
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
343 valid_membpos_p (struct buffer *buf, Membpos x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
345 return ((x >= 1 && x <= (Membpos) buf->text->gpt) ||
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
346 (x > (Membpos) (buf->text->gpt + buf->text->gap_size) &&
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
347 x <= (Membpos) (buf->text->z + buf->text->gap_size)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
350 INLINE_HEADER Membpos bytebpos_to_membpos (struct buffer *buf, Bytebpos x);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
351 INLINE_HEADER Membpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
352 bytebpos_to_membpos (struct buffer *buf, Bytebpos x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
354 return (Membpos) ((x > buf->text->gpt) ? (x + buf->text->gap_size) : x);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
358 INLINE_HEADER Bytebpos membpos_to_bytebpos (struct buffer *buf, Membpos x);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
359 INLINE_HEADER Bytebpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
360 membpos_to_bytebpos (struct buffer *buf, Membpos x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
362 #ifdef ERROR_CHECK_CHARBPOS
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
363 assert (valid_membpos_p (buf, x));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 #endif
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
365 return (Bytebpos) ((x > (Membpos) buf->text->gpt) ?
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 x - buf->text->gap_size :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 x);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
370 #define membpos_to_charbpos(buf, x) \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
371 bytebpos_to_charbpos (buf, membpos_to_bytebpos (buf, x))
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
372 #define charbpos_to_membpos(buf, x) \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
373 bytebpos_to_membpos (buf, charbpos_to_bytebpos (buf, x))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 /* These macros generalize many standard buffer-position functions to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 either a buffer or a string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
378 /* Converting between Membposs and Bytebposs, for a buffer-or-string.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 For strings, this is a no-op. For buffers, this resolves
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
380 to the standard membpos<->bytebpos converters. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
382 #define buffer_or_string_bytebpos_to_membpos(obj, ind) \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
383 (BUFFERP (obj) ? bytebpos_to_membpos (XBUFFER (obj), ind) : (Membpos) ind)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
385 #define buffer_or_string_membpos_to_bytebpos(obj, ind) \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
386 (BUFFERP (obj) ? membpos_to_bytebpos (XBUFFER (obj), ind) : (Bytebpos) ind)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
388 /* Converting between Charbpos's and Bytebposs, for a buffer-or-string.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 For strings, this maps to the bytecount<->charcount converters. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
391 #define buffer_or_string_charbpos_to_bytebpos(obj, pos) \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
392 (BUFFERP (obj) ? charbpos_to_bytebpos (XBUFFER (obj), pos) : \
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
393 (Bytebpos) string_index_char_to_byte (obj, pos))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
395 #define buffer_or_string_bytebpos_to_charbpos(obj, ind) \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
396 (BUFFERP (obj) ? bytebpos_to_charbpos (XBUFFER (obj), ind) : \
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
397 (Charbpos) string_index_byte_to_char (obj, ind))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
399 /* Similar for Charbpos's and Membposs. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
401 #define buffer_or_string_charbpos_to_membpos(obj, pos) \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
402 (BUFFERP (obj) ? charbpos_to_membpos (XBUFFER (obj), pos) : \
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
403 (Membpos) string_index_char_to_byte (obj, pos))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
405 #define buffer_or_string_membpos_to_charbpos(obj, ind) \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
406 (BUFFERP (obj) ? membpos_to_charbpos (XBUFFER (obj), ind) : \
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
407 (Charbpos) string_index_byte_to_char (obj, ind))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 /* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 /* working with buffer-level data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 /* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 (A) Working with byte indices:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 ------------------------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
420 VALID_BYTEBPOS_P(buf, bi):
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 Given a byte index, does it point to the beginning of a character?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
423 ASSERT_VALID_BYTEBPOS_UNSAFE(buf, bi):
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 If error-checking is enabled, assert that the given byte index
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 is within range and points to the beginning of a character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 or to the end of the buffer. Otherwise, do nothing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
428 ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE(buf, bi):
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 If error-checking is enabled, assert that the given byte index
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
430 is within range and satisfies ASSERT_VALID_BYTEBPOS() and also
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 does not refer to the beginning of the buffer. (i.e. movement
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 backwards is OK.) Otherwise, do nothing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
434 ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE(buf, bi):
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 If error-checking is enabled, assert that the given byte index
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
436 is within range and satisfies ASSERT_VALID_BYTEBPOS() and also
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 does not refer to the end of the buffer. (i.e. movement
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 forwards is OK.) Otherwise, do nothing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
440 VALIDATE_BYTEBPOS_BACKWARD(buf, bi):
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 Make sure that the given byte index is pointing to the beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 of a character. If not, back up until this is the case. Note
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 that there are not too many places where it is legitimate to do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 this sort of thing. It's an error if you're passed an "invalid"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 byte index.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
447 VALIDATE_BYTEBPOS_FORWARD(buf, bi):
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 Make sure that the given byte index is pointing to the beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 of a character. If not, move forward until this is the case.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 Note that there are not too many places where it is legitimate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 to do this sort of thing. It's an error if you're passed an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 "invalid" byte index.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
454 INC_BYTEBPOS(buf, bi):
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 Given a byte index (assumed to point at the beginning of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 character), modify that value so it points to the beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 of the next character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
459 DEC_BYTEBPOS(buf, bi):
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 Given a byte index (assumed to point at the beginning of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 character), modify that value so it points to the beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 of the previous character. Unlike for DEC_CHARPTR(), we can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 do all the assert()s because there are sentinels at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 beginning of the gap and the end of the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
466 BYTEBPOS_INVALID:
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
467 A constant representing an invalid Bytebpos. Valid Bytebposs
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 can never have this value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
471 (B) Converting between Charbpos's and Bytebposs:
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 --------------------------------------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
474 charbpos_to_bytebpos(buf, bu):
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
475 Given a Charbpos, return the equivalent Bytebpos.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
477 bytebpos_to_charbpos(buf, bi):
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
478 Given a Bytebpos, return the equivalent Charbpos.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
480 make_charbpos(buf, bi):
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
481 Given a Bytebpos, return the equivalent Charbpos as a Lisp Object.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 /* working with byte indices */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 #ifdef MULE
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
490 # define VALID_BYTEBPOS_P(buf, x) \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
491 INTBYTE_FIRST_BYTE_P (*BI_BUF_BYTE_ADDRESS (buf, x))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 #else
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
493 # define VALID_BYTEBPOS_P(buf, x) 1
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
496 #ifdef ERROR_CHECK_CHARBPOS
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
498 # define ASSERT_VALID_BYTEBPOS_UNSAFE(buf, x) do { \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 assert (BUFFER_LIVE_P (buf)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 assert ((x) >= BI_BUF_BEG (buf) && x <= BI_BUF_Z (buf)); \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
501 assert (VALID_BYTEBPOS_P (buf, x)); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 } while (0)
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
503 # define ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE(buf, x) do { \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 assert (BUFFER_LIVE_P (buf)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 assert ((x) > BI_BUF_BEG (buf) && x <= BI_BUF_Z (buf)); \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
506 assert (VALID_BYTEBPOS_P (buf, x)); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 } while (0)
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
508 # define ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE(buf, x) do { \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 assert (BUFFER_LIVE_P (buf)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 assert ((x) >= BI_BUF_BEG (buf) && x < BI_BUF_Z (buf)); \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
511 assert (VALID_BYTEBPOS_P (buf, x)); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
514 #else /* not ERROR_CHECK_CHARBPOS */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
515 # define ASSERT_VALID_BYTEBPOS_UNSAFE(buf, x)
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
516 # define ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE(buf, x)
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
517 # define ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE(buf, x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
519 #endif /* not ERROR_CHECK_CHARBPOS */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 /* Note that, although the Mule version will work fine for non-Mule
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 as well (it should reduce down to nothing), we provide a separate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 version to avoid compilation warnings and possible non-optimal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 results with stupid compilers. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 #ifdef MULE
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
527 # define VALIDATE_BYTEBPOS_BACKWARD(buf, x) do { \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
528 Intbyte *VBB_ptr = BI_BUF_BYTE_ADDRESS (buf, x); \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
529 while (!INTBYTE_FIRST_BYTE_P (*VBB_ptr)) \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 VBB_ptr--, (x)--; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 #else
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
533 # define VALIDATE_BYTEBPOS_BACKWARD(buf, x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 /* Note that, although the Mule version will work fine for non-Mule
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 as well (it should reduce down to nothing), we provide a separate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 version to avoid compilation warnings and possible non-optimal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 results with stupid compilers. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 #ifdef MULE
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
542 # define VALIDATE_BYTEBPOS_FORWARD(buf, x) do { \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
543 Intbyte *VBF_ptr = BI_BUF_BYTE_ADDRESS (buf, x); \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
544 while (!INTBYTE_FIRST_BYTE_P (*VBF_ptr)) \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 VBF_ptr++, (x)++; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 #else
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
548 # define VALIDATE_BYTEBPOS_FORWARD(buf, x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
551 /* Note that in the simplest case (no MULE, no ERROR_CHECK_CHARBPOS),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 this crap reduces down to simply (x)++. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
554 #define INC_BYTEBPOS(buf, x) do \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 { \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
556 ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE (buf, x); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 /* Note that we do the increment first to \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 make sure that the pointer in \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
559 VALIDATE_BYTEBPOS_FORWARD() ends up on \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 the correct side of the gap */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 (x)++; \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
562 VALIDATE_BYTEBPOS_FORWARD (buf, x); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
565 /* Note that in the simplest case (no MULE, no ERROR_CHECK_CHARBPOS),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 this crap reduces down to simply (x)--. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
568 #define DEC_BYTEBPOS(buf, x) do \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 { \
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
570 ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE (buf, x); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 /* Note that we do the decrement first to \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 make sure that the pointer in \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
573 VALIDATE_BYTEBPOS_BACKWARD() ends up on \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 the correct side of the gap */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 (x)--; \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
576 VALIDATE_BYTEBPOS_BACKWARD (buf, x); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
579 INLINE_HEADER Bytebpos prev_bytebpos (struct buffer *buf, Bytebpos x);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
580 INLINE_HEADER Bytebpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
581 prev_bytebpos (struct buffer *buf, Bytebpos x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
583 DEC_BYTEBPOS (buf, x);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 return x;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
587 INLINE_HEADER Bytebpos next_bytebpos (struct buffer *buf, Bytebpos x);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
588 INLINE_HEADER Bytebpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
589 next_bytebpos (struct buffer *buf, Bytebpos x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
591 INC_BYTEBPOS (buf, x);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 return x;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
595 #define BYTEBPOS_INVALID ((Bytebpos) -1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 /* Converting between buffer positions and byte indices */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
603 Bytebpos charbpos_to_bytebpos_func (struct buffer *buf, Charbpos x);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
604 Charbpos bytebpos_to_charbpos_func (struct buffer *buf, Bytebpos x);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 /* The basic algorithm we use is to keep track of a known region of
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
607 characters in each buffer, all of which are of the same width. We keep
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
608 track of the boundaries of the region in both Charbpos and Bytebpos
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
609 coordinates and also keep track of the char width, which is 1 - 4 bytes.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
610 If the position we're translating is not in the known region, then we
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
611 invoke a function to update the known region to surround the position in
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
612 question. This assumes locality of reference, which is usually the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
613 case.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
614
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
615 Note that the function to update the known region can be simple or
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
616 complicated depending on how much information we cache. In addition to
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
617 the known region, we always cache the correct conversions for point,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
618 BEGV, and ZV, and in addition to this we cache 16 positions where the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
619 conversion is known. We only look in the cache or update it when we
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
620 need to move the known region more than a certain amount (currently 50
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
621 chars), and then we throw away a "random" value and replace it with the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
622 newly calculated value.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
623
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
624 Finally, we maintain an extra flag that tracks whether the buffer is
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
625 entirely ASCII, to speed up the conversions even more. This flag is
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
626 actually of dubious value because in an entirely-ASCII buffer the known
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
627 region will always span the entire buffer (in fact, we update the flag
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
628 based on this fact), and so all we're saving is a few machine cycles.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
630 A potentially smarter method than what we do with known regions and
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
631 cached positions would be to keep some sort of pseudo-extent layer over
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
632 the buffer; maybe keep track of the charbpos/bytebpos correspondence at the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
633 beginning of each line, which would allow us to do a binary search over
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
634 the pseudo-extents to narrow things down to the correct line, at which
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
635 point you could use a linear movement method. This would also mesh well
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
636 with efficiently implementing a line-numbering scheme. However, you
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
637 have to weigh the amount of time spent updating the cache vs. the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
638 savings that result from it. In reality, we modify the buffer far less
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
639 often than we access it, so a cache of this sort that provides
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
640 guaranteed LOG (N) performance (or perhaps N * LOG (N), if we set a
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
641 maximum on the cache size) would indeed be a win, particularly in very
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
642 large buffers. If we ever implement this, we should probably set a
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
643 reasonably high minimum below which we use the old method, because the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
644 time spent updating the fancy cache would likely become dominant when
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
645 making buffer modifications in smaller buffers.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
647 Note also that we have to multiply or divide by the char width in order
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
648 to convert the positions. We do some tricks to avoid ever actually
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
649 having to do a multiply or divide, because that is typically an
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
650 expensive operation (esp. divide). Multiplying or dividing by 1, 2, or
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
651 4 can be implemented simply as a shift left or shift right, and we keep
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
652 track of a shifter value (0, 1, or 2) indicating how much to shift.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
653 Multiplying by 3 can be implemented by doubling and then adding the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
654 original value. Dividing by 3, alas, cannot be implemented in any
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
655 simple shift/subtract method, as far as I know; so we just do a table
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
656 lookup. For simplicity, we use a table of size 128K, which indexes the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
657 "divide-by-3" values for the first 64K non-negative numbers. (Note that
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
658 we can increase the size up to 384K, i.e. indexing the first 192K
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
659 non-negative numbers, while still using shorts in the array.) This also
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
660 means that the size of the known region can be at most 64K for
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
661 width-three characters.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
662
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
663 !!#### We should investigate the algorithm in GNU Emacs. I think it
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
664 does something similar, but it may differ in some details, and it's
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
665 worth seeing if anything can be gleaned.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 extern short three_to_one_table[];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
670 INLINE_HEADER Bytebpos real_charbpos_to_bytebpos (struct buffer *buf, Charbpos x);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
671 INLINE_HEADER Bytebpos
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
672 real_charbpos_to_bytebpos (struct buffer *buf, Charbpos x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
674 if (buf->text->entirely_ascii_p)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
675 return (Bytebpos) x;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 if (x >= buf->text->mule_bufmin && x <= buf->text->mule_bufmax)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 return (buf->text->mule_bytmin +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 ((x - buf->text->mule_bufmin) << buf->text->mule_shifter) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 (buf->text->mule_three_p ? (x - buf->text->mule_bufmin) : 0));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 else
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
681 return charbpos_to_bytebpos_func (buf, x);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
684 INLINE_HEADER Charbpos real_bytebpos_to_charbpos (struct buffer *buf, Bytebpos x);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
685 INLINE_HEADER Charbpos
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
686 real_bytebpos_to_charbpos (struct buffer *buf, Bytebpos x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
688 if (buf->text->entirely_ascii_p)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
689 return (Charbpos) x;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 if (x >= buf->text->mule_bytmin && x <= buf->text->mule_bytmax)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 return (buf->text->mule_bufmin +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 ((buf->text->mule_three_p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 ? three_to_one_table[x - buf->text->mule_bytmin]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 : (x - buf->text->mule_bytmin) >> buf->text->mule_shifter)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 else
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
696 return bytebpos_to_charbpos_func (buf, x);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 #else /* not MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
701 # define real_charbpos_to_bytebpos(buf, x) ((Bytebpos) x)
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
702 # define real_bytebpos_to_charbpos(buf, x) ((Charbpos) x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 #endif /* not MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
706 #ifdef ERROR_CHECK_CHARBPOS
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
708 Bytebpos charbpos_to_bytebpos (struct buffer *buf, Charbpos x);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
709 Charbpos bytebpos_to_charbpos (struct buffer *buf, Bytebpos x);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
711 #else /* not ERROR_CHECK_CHARBPOS */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
713 #define charbpos_to_bytebpos real_charbpos_to_bytebpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
714 #define bytebpos_to_charbpos real_bytebpos_to_charbpos
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
716 #endif /* not ERROR_CHECK_CHARBPOS */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
718 #define make_charbpos(buf, ind) make_int (bytebpos_to_charbpos (buf, ind))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 /* Converting between buffer bytes and Emacs characters */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 /* The character at position POS in buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 #define BI_BUF_FETCH_CHAR(buf, pos) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 charptr_emchar (BI_BUF_BYTE_ADDRESS (buf, pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 #define BUF_FETCH_CHAR(buf, pos) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
728 BI_BUF_FETCH_CHAR (buf, charbpos_to_bytebpos (buf, pos))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 /* The character at position POS in buffer, as a string. This is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 equivalent to set_charptr_emchar (str, BUF_FETCH_CHAR (buf, pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 but is faster for Mule. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 # define BI_BUF_CHARPTR_COPY_CHAR(buf, pos, str) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 charptr_copy_char (BI_BUF_BYTE_ADDRESS (buf, pos), str)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 #define BUF_CHARPTR_COPY_CHAR(buf, pos, str) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
737 BI_BUF_CHARPTR_COPY_CHAR (buf, charbpos_to_bytebpos (buf, pos), str)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 /************************************************************************/
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
741 /* */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 /* higher-level buffer-position functions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 /* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 /* Settor macros for important positions in a buffer */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 /* Set beginning of accessible range of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 #define SET_BOTH_BUF_BEGV(buf, val, bival) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 do \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 (buf)->begv = (bival); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 (buf)->bufbegv = (val); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 /* Set end of accessible range of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 #define SET_BOTH_BUF_ZV(buf, val, bival) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 do \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 (buf)->zv = (bival); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 (buf)->bufzv = (val); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 /* Set point. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 /* Since BEGV and ZV are almost never set, it's reasonable to enforce
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
768 the restriction that the Charbpos and Bytebpos values must both be
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 specified. However, point is set in lots and lots of places. So
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 we provide the ability to specify both (for efficiency) or just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 one. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 #define BOTH_BUF_SET_PT(buf, val, bival) set_buffer_point (buf, val, bival)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 #define BI_BUF_SET_PT(buf, bival) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
774 BOTH_BUF_SET_PT (buf, bytebpos_to_charbpos (buf, bival), bival)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 #define BUF_SET_PT(buf, value) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
776 BOTH_BUF_SET_PT (buf, value, charbpos_to_bytebpos (buf, value))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 #if 0 /* FSFmacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 /* These macros exist in FSFmacs because SET_PT() in FSFmacs incorrectly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 does too much stuff, such as moving out of invisible extents. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 #define TEMP_SET_PT(position) (temp_set_point ((position), current_buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 #define SET_BUF_PT(buf, value) ((buf)->pt = (value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 #endif /* FSFmacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 /* Miscellaneous buffer values */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 /* Number of characters in buffer */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 #define BUF_SIZE(buf) (BUF_Z (buf) - BUF_BEG (buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 /* Is this buffer narrowed? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 #define BUF_NARROWED(buf) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 ((BI_BUF_BEGV (buf) != BI_BUF_BEG (buf)) || \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 (BI_BUF_ZV (buf) != BI_BUF_Z (buf)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 /* Modification count. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 #define BUF_MODIFF(buf) ((buf)->text->modiff)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 /* Saved modification count. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 #define BUF_SAVE_MODIFF(buf) ((buf)->text->save_modiff)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 /* Face changed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 #define BUF_FACECHANGE(buf) ((buf)->face_change)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 #define POINT_MARKER_P(marker) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 (XMARKER (marker)->buffer != 0 && \
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
809 EQ (marker, XMARKER (marker)->buffer->point_marker))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 #define BUF_MARKERS(buf) ((buf)->markers)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 /* WARNING:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 The new definitions of CEILING_OF() and FLOOR_OF() differ semantically
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 from the old ones (in FSF Emacs and XEmacs 19.11 and before).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 Conversion is as follows:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 OLD_BI_CEILING_OF(n) = NEW_BI_CEILING_OF(n) - 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 OLD_BI_FLOOR_OF(n) = NEW_BI_FLOOR_OF(n + 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 The definitions were changed because the new definitions are more
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
823 consistent with the way everything else works in XEmacs.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 /* Properties of CEILING_OF and FLOOR_OF (also apply to BI_ variants):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 1) FLOOR_OF (CEILING_OF (n)) = n
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 CEILING_OF (FLOOR_OF (n)) = n
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 2) CEILING_OF (n) = n if and only if n = ZV
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 FLOOR_OF (n) = n if and only if n = BEGV
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 3) CEILING_OF (CEILING_OF (n)) = ZV
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 FLOOR_OF (FLOOR_OF (n)) = BEGV
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 4) The bytes in the regions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 [BYTE_ADDRESS (n), BYTE_ADDRESS_BEFORE (CEILING_OF (n))]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 [BYTE_ADDRESS (FLOOR_OF (n)), BYTE_ADDRESS_BEFORE (n)]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 are contiguous.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
846
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
847 A typical loop using CEILING_OF to process contiguous ranges of text
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
848 between [from, to) looks like this:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
849
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
850 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
851 Bytebpos pos = from;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
852
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
853 while (pos < to)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
854 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
855 Bytebpos ceil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
856
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
857 ceil = BI_BUF_CEILING_OF (buf, pos);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
858 ceil = min (to, ceil);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
859 process_intbyte_string (BI_BUF_BYTE_ADDRESS (buf, pos), ceil - pos);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
860 pos = ceil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
861 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
862 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
863
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
864 Currently there will be at most two iterations in the loop, but it is
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
865 written in such a way that it will still work if the buffer
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
866 representation is changed to have multiple gaps in it.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
867 */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 /* Return the maximum index in the buffer it is safe to scan forwards
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 past N to. This is used to prevent buffer scans from running into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 the gap (e.g. search.c). All characters between N and CEILING_OF(N)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 are located contiguous in memory. Note that the character *at*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 CEILING_OF(N) is not contiguous in memory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 #define BI_BUF_CEILING_OF(b, n) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 ((n) < (b)->text->gpt && (b)->text->gpt < BI_BUF_ZV (b) ? \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 (b)->text->gpt : BI_BUF_ZV (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 #define BUF_CEILING_OF(b, n) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
879 bytebpos_to_charbpos (b, BI_BUF_CEILING_OF (b, charbpos_to_bytebpos (b, n)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 /* Return the minimum index in the buffer it is safe to scan backwards
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 past N to. All characters between FLOOR_OF(N) and N are located
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 contiguous in memory. Note that the character *at* N may not be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 contiguous in memory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 #define BI_BUF_FLOOR_OF(b, n) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 (BI_BUF_BEGV (b) < (b)->text->gpt && (b)->text->gpt < (n) ? \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 (b)->text->gpt : BI_BUF_BEGV (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 #define BUF_FLOOR_OF(b, n) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
889 bytebpos_to_charbpos (b, BI_BUF_FLOOR_OF (b, charbpos_to_bytebpos (b, n)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 #define BI_BUF_CEILING_OF_IGNORE_ACCESSIBLE(b, n) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 ((n) < (b)->text->gpt && (b)->text->gpt < BI_BUF_Z (b) ? \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 (b)->text->gpt : BI_BUF_Z (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 #define BUF_CEILING_OF_IGNORE_ACCESSIBLE(b, n) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
895 bytebpos_to_charbpos \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
896 (b, BI_BUF_CEILING_OF_IGNORE_ACCESSIBLE (b, charbpos_to_bytebpos (b, n)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 #define BI_BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 (BI_BUF_BEG (b) < (b)->text->gpt && (b)->text->gpt < (n) ? \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 (b)->text->gpt : BI_BUF_BEG (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 #define BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
902 bytebpos_to_charbpos \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
903 (b, BI_BUF_FLOOR_OF_IGNORE_ACCESSIBLE (b, charbpos_to_bytebpos (b, n)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 /* This structure marks which slots in a buffer have corresponding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 default values in Vbuffer_defaults.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 Each such slot has a nonzero value in this structure.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 The value has only one nonzero bit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 When a buffer has its own local value for a slot,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 the bit for that slot (found in the same slot in this structure)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 is turned on in the buffer's local_var_flags slot.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 If a slot in this structure is zero, then even though there may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 be a DEFVAR_BUFFER_LOCAL for the slot, there is no default value for it;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 and the corresponding slot in Vbuffer_defaults is not used. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 extern struct buffer buffer_local_flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 /* Allocation of buffer data. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 #ifdef REL_ALLOC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
925 char *r_alloc (unsigned char **, size_t);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
926 char *r_re_alloc (unsigned char **, size_t);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 void r_alloc_free (unsigned char **);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 #define BUFFER_ALLOC(data, size) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
930 ((Intbyte *) r_alloc ((unsigned char **) &data, (size) * sizeof(Intbyte)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 #define BUFFER_REALLOC(data, size) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
932 ((Intbyte *) r_re_alloc ((unsigned char **) &data, (size) * sizeof(Intbyte)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 #define BUFFER_FREE(data) r_alloc_free ((unsigned char **) &(data))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 #define R_ALLOC_DECLARE(var,data) r_alloc_declare (&(var), data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 #else /* !REL_ALLOC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 #define BUFFER_ALLOC(data,size)\
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
939 (data = xnew_array (Intbyte, size))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 #define BUFFER_REALLOC(data,size)\
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
941 ((Intbyte *) xrealloc (data, (size) * sizeof(Intbyte)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 /* Avoid excess parentheses, or syntax errors may rear their heads. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 #define BUFFER_FREE(data) xfree (data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 #define R_ALLOC_DECLARE(var,data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 #endif /* !REL_ALLOC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 /* Case conversion */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 /* A "trt" table is a mapping from characters to other characters,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 typically used to convert between uppercase and lowercase. For
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 compatibility reasons, trt tables are currently in the form of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 a Lisp string of 256 characters, specifying the conversion for each
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 of the first 256 Emacs characters (i.e. the 256 Latin-1 characters).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 This should be generalized at some point to support conversions for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 all of the allowable Mule characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 /* The _1 macros are named as such because they assume that you have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 already guaranteed that the character values are all in the range
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 0 - 255. Bad lossage will happen otherwise. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
966 #define MAKE_TRT_TABLE() Fmake_char_table (Qgeneric)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
967 INLINE_HEADER Emchar TRT_TABLE_CHAR_1 (Lisp_Object table, Emchar c);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
968 INLINE_HEADER Emchar
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
969 TRT_TABLE_CHAR_1 (Lisp_Object table, Emchar ch)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
970 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
971 Lisp_Object TRT_char;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
972 TRT_char = get_char_table (ch, XCHAR_TABLE (table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
973 if (NILP (TRT_char))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
974 return ch;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
975 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
976 return XCHAR (TRT_char);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
977 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
978 #define SET_TRT_TABLE_CHAR_1(table, ch1, ch2) \
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
979 Fput_char_table (make_char (ch1), make_char (ch2), table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
981 INLINE_HEADER Emchar TRT_TABLE_OF (Lisp_Object trt, Emchar c);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
982 INLINE_HEADER Emchar
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 TRT_TABLE_OF (Lisp_Object trt, Emchar c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
985 return TRT_TABLE_CHAR_1 (trt, c);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
988 INLINE_HEADER Lisp_Object BUFFER_CASE_TABLE (struct buffer *buf);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
989 INLINE_HEADER Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
990 BUFFER_CASE_TABLE (struct buffer *buf)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
991 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
992 return buf ? buf->case_table : Vstandard_case_table;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
993 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
994
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 /* Macros used below. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
996 #define DOWNCASE_TABLE_OF(buf, c) \
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
997 TRT_TABLE_OF (XCASE_TABLE_DOWNCASE (BUFFER_CASE_TABLE (buf)), c)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
998 #define UPCASE_TABLE_OF(buf, c) \
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
999 TRT_TABLE_OF (XCASE_TABLE_UPCASE (BUFFER_CASE_TABLE (buf)), c)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 /* 1 if CH is upper case. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1003 INLINE_HEADER int UPPERCASEP (struct buffer *buf, Emchar ch);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1004 INLINE_HEADER int
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 UPPERCASEP (struct buffer *buf, Emchar ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 return DOWNCASE_TABLE_OF (buf, ch) != ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 /* 1 if CH is lower case. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1012 INLINE_HEADER int LOWERCASEP (struct buffer *buf, Emchar ch);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1013 INLINE_HEADER int
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 LOWERCASEP (struct buffer *buf, Emchar ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 return (UPCASE_TABLE_OF (buf, ch) != ch &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 DOWNCASE_TABLE_OF (buf, ch) == ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 /* 1 if CH is neither upper nor lower case. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1022 INLINE_HEADER int NOCASEP (struct buffer *buf, Emchar ch);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1023 INLINE_HEADER int
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 NOCASEP (struct buffer *buf, Emchar ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 return UPCASE_TABLE_OF (buf, ch) == ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 /* Upcase a character, or make no change if that cannot be done. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1031 INLINE_HEADER Emchar UPCASE (struct buffer *buf, Emchar ch);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1032 INLINE_HEADER Emchar
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 UPCASE (struct buffer *buf, Emchar ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 return (DOWNCASE_TABLE_OF (buf, ch) == ch) ? UPCASE_TABLE_OF (buf, ch) : ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 /* Upcase a character known to be not upper case. Unused. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 #define UPCASE1(buf, ch) UPCASE_TABLE_OF (buf, ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 /* Downcase a character, or make no change if that cannot be done. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 #define DOWNCASE(buf, ch) DOWNCASE_TABLE_OF (buf, ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1046 #endif /* INCLUDED_buffer_h_ */