Mercurial > hg > xemacs-beta
comparison src/insdel.c @ 2367:ecf1ebac70d8
[xemacs-hg @ 2004-11-04 23:05:23 by ben]
commit mega-patch
configure.in: Turn off -Winline and -Wchar-subscripts.
Use the right set of cflags when compiling modules.
Rewrite ldap configuration to separate the inclusion of lber
(needed in recent Cygwin) from the basic checks for the
needed libraries.
add a function for MAKE_JUNK_C; initially code was added to
generate xemacs.def using this, but it will need to be rewritten.
add an rm -f for junk.c to avoid weird Cygwin bug with cp -f onto
an existing file.
Sort list of auto-detected functions and eliminate unused checks for
stpcpy, setlocale and getwd.
Add autodetection of Cygwin scanf problems
BETA: Rewrite section on configure to indicate what flags are important
and what not.
digest-doc.c, make-dump-id.c, profile.c, sorted-doc.c: Add proper decls for main().
make-msgfile.c: Document that this is old junk.
Move proposal to text.c.
make-msgfile.lex: Move proposal to text.c.
make-mswin-unicode.pl: Convert error-generating code so that the entire message will
be seen as a single unrecognized token.
mule/mule-ccl.el: Update docs.
lispref/mule.texi: Update CCL docs.
ldap/eldap.c: Mule-ize.
Use EXTERNAL_LIST_LOOP_2 instead of deleted EXTERNAL_LIST_LOOP.
* XEmacs 21.5.18 "chestnut" is released.
---------------------------------------------------------------
MULE-RELATED WORK:
---------------------------------------------------------------
---------------------------
byte-char conversion
---------------------------
buffer.c, buffer.h, insdel.c, text.c: Port FSF algorithm for byte-char conversion, replacing broken
previous version. Track the char position of the gap. Add
functions to do char-byte conversion downwards as well as upwards.
Move comments about algorithm workings to internals manual.
---------------------------
work on types
---------------------------
alloc.c, console-x-impl.h, dump-data.c, dump-data.h, dumper.c, dialog-msw.c, dired-msw.c, doc.c, editfns.c, esd.c, event-gtk.h, event-msw.c, events.c, file-coding.c, file-coding.h, fns.c, glyphs-eimage.c, glyphs-gtk.c, glyphs-msw.c, glyphs-shared.c, glyphs-x.c, glyphs.c, glyphs.h, gui.c, hpplay.c, imgproc.c, intl-win32.c, lrecord.h, lstream.c, keymap.c, lisp.h, libsst.c, linuxplay.c, miscplay.c, miscplay.h, mule-coding.c, nas.c, nt.c, ntheap.c, ntplay.c, objects-msw.c, objects-tty.c, objects-x.c, print.c, process-nt.c, process.c, redisplay.h, select-common.h, select-gtk.c, select-x.c, sgiplay.c, sound.c, sound.h, sunplay.c, sysfile.h, sysdep.c, syswindows.h, text.c, unexnt.c, win32.c, xgccache.c: Further work on types. This creates a full set of types for all
the basic semantics of `char' that I have so far identified, so that
its semantics can always be identified for the purposes of proper
Mule-safe code, and the raw use of `char' always avoided.
(1) More type renaming, for consistency of naming.
Char_ASCII -> Ascbyte
UChar_ASCII -> UAscbyte
Char_Binary -> CBinbyte
UChar_Binary -> Binbyte
SChar_Binary -> SBinbyte
(2) Introduce Rawbyte, CRawbyte, Boolbyte, Chbyte, UChbyte, and
Bitbyte and use them.
(3) New types Itext, Wexttext and Textcount for separating out
the concepts of bytes and textual units (different under UTF-16
and UTF-32, which are potential internal encodings).
(4) qxestr*_c -> qxestr*_ascii.
lisp.h: New; goes with other qxe() functions. #### Maybe goes in a
different section.
lisp.h: Group generic int-type defs together with EMACS_INT defs.
lisp.h: * lisp.h (WEXTTEXT_IS_WIDE)
New defns.
lisp.h: New type to replace places where int occurs as a boolean.
It's signed because occasionally people may want to use -1 as
an error value, and because unsigned ints are viral -- see comments
in the internals manual against using them.
dynarr.c: int -> Bytecount.
---------------------------
Mule-izing
---------------------------
device-x.c: Partially Mule-ize.
dumper.c, dumper.h: Mule-ize. Use Rawbyte. Use stderr_out not printf. Use wext_*().
sysdep.c, syswindows.h, text.c: New Wexttext API for manipulation of external text that may be
Unicode (e.g. startup code under Windows).
emacs.c: Mule-ize. Properly deal with argv in external encoding.
Use wext_*() and Wexttext. Use Rawbyte.
#if 0 some old junk on SCO that is unlikely to be correct.
Rewrite allocation code in run-temacs.
emacs.c, symsinit.h, win32.c: Rename win32 init function and call it even earlier, to
initialize mswindows_9x_p even earlier, for use in startup code
(XEUNICODE_P).
process.c: Use _wenviron not environ under Windows, to get Unicode environment
variables.
event-Xt.c: Mule-ize drag-n-drop related stuff.
dragdrop.c, dragdrop.h, frame-x.c: Mule-ize.
text.h: Add some more stand-in defines for particular kinds of conversion;
use in Mule-ization work in frame-x.c etc.
---------------------------
Freshening
---------------------------
intl-auto-encap-win32.c, intl-auto-encap-win32.h: Regenerate.
---------------------------
Unicode-work
---------------------------
intl-win32.c, syswindows.h: Factor out common options to MultiByteToWideChar and
WideCharToMultiByte. Add convert_unicode_to_multibyte_malloc()
and convert_unicode_to_multibyte_dynarr() and use. Add stuff for
alloca() conversion of multibyte/unicode.
alloc.c: Use dfc_external_data_len() in case of unicode coding system.
alloc.c, mule-charset.c: Don't zero out and reinit charset Unicode tables. This fucks up
dump-time loading. Anyway, either we load them at dump time or
run time, never both.
unicode.c: Dump the blank tables as well.
---------------------------------------------------------------
DOCUMENTATION, MOSTLY MULE-RELATED:
---------------------------------------------------------------
EmacsFrame.c, emodules.c, event-Xt.c, fileio.c, input-method-xlib.c, mule-wnnfns.c, redisplay-gtk.c, redisplay-tty.c, redisplay-x.c, regex.c, sysdep.c: Add comment about Mule work needed.
text.h: Add more documentation describing why DFC routines were not written
to return their value. Add some other DFC documentation.
console-msw.c, console-msw.h: Add pointer to docs in win32.c.
emacs.c: Add comments on sources of doc info.
text.c, charset.h, unicode.c, intl-win32.c, intl-encap-win32.c, text.h, file-coding.c, mule-coding.c: Collect background comments and related to text matters and
internationalization, and proposals for work to be done, in text.c
or Internals manual, stuff related to specific textual API's in
text.h, and stuff related to internal implementation of Unicode
conversion in unicode.c. Put lots of pointers to the comments to
make them easier to find.
s/mingw32.h, s/win32-common.h, s/win32-native.h, s/windowsnt.h, win32.c: Add bunches of new documentation on the different kinds of
builds and environments under Windows and how they work.
Collect this info in win32.c. Add pointers to these docs in
the relevant s/* files.
emacs.c: Document places with long comments.
Remove comment about exiting, move to internals manual, put
in pointer.
event-stream.c: Move docs about event queues and focus to internals manual, put
in pointer.
events.h: Move docs about event stream callbacks to internals manual, put
in pointer.
profile.c, redisplay.c, signal.c: Move documentation to the Internals manual.
process-nt.c: Add pointer to comment in win32-native.el.
lisp.h: Add comments about some comment conventions.
lisp.h: Add comment about the second argument.
device-msw.c, redisplay-msw.c: @@#### comments are out-of-date.
---------------------------------------------------------------
PDUMP WORK (MOTIVATED BY UNICODE CHANGES)
---------------------------------------------------------------
alloc.c, buffer.c, bytecode.c, console-impl.h, console.c, device.c, dumper.c, lrecord.h, elhash.c, emodules.h, events.c, extents.c, frame.c, glyphs.c, glyphs.h, mule-charset.c, mule-coding.c, objects.c, profile.c, rangetab.c, redisplay.c, specifier.c, specifier.h, window.c, lstream.c, file-coding.h, file-coding.c: PDUMP:
Properly implement dump_add_root_block(), which never worked before,
and is necessary for dumping Unicode tables.
Pdump name changes for accuracy:
XD_STRUCT_PTR -> XD_BLOCK_PTR.
XD_STRUCT_ARRAY -> XD_BLOCK_ARRAY.
XD_C_STRING -> XD_ASCII_STRING.
*_structure_* -> *_block_*.
lrecord.h: some comments added about
dump_add_root_block() vs dump_add_root_block_ptr().
extents.c: remove incorrect comment about pdump problems with gap array.
---------------------------------------------------------------
ALLOCATION
---------------------------------------------------------------
abbrev.c, alloc.c, bytecode.c, casefiddle.c, device-msw.c, device-x.c, dired-msw.c, doc.c, doprnt.c, dragdrop.c, editfns.c, emodules.c, file-coding.c, fileio.c, filelock.c, fns.c, glyphs-eimage.c, glyphs-gtk.c, glyphs-msw.c, glyphs-x.c, gui-msw.c, gui-x.c, imgproc.c, intl-win32.c, lread.c, menubar-gtk.c, menubar.c, nt.c, objects-msw.c, objects-x.c, print.c, process-nt.c, process-unix.c, process.c, realpath.c, redisplay.c, search.c, select-common.c, symbols.c, sysdep.c, syswindows.h, text.c, text.h, ui-byhand.c: New macros {alloca,xnew}_{itext,{i,ext,raw,bin,asc}bytes} for
more convenient allocation of these commonly requested items.
Modify functions to use alloca_ibytes, alloca_array, alloca_extbytes,
xnew_ibytes, etc. also XREALLOC_ARRAY, xnew.
alloc.c: Rewrite the allocation functions to factor out repeated code.
Add assertions for freeing dumped data.
lisp.h: Moved down and consolidated with other allocation stuff.
lisp.h, dynarr.c: New functions for allocation that's very efficient when mostly in
LIFO order.
lisp.h, text.c, text.h: Factor out some stuff for general use by alloca()-conversion funs.
text.h, lisp.h: Fill out convenience routines for allocating various kinds of
bytes and put them in lisp.h. Use them in place of xmalloc(),
ALLOCA().
text.h: Fill out the convenience functions so the _MALLOC() kinds match
the alloca() kinds.
---------------------------------------------------------------
ERROR-CHECKING
---------------------------------------------------------------
text.h: Create ASSERT_ASCTEXT_ASCII() and ASSERT_ASCTEXT_ASCII_LEN()
from similar Eistring checkers and change the Eistring checkers to
use them instead.
---------------------------------------------------------------
MACROS IN LISP.H
---------------------------------------------------------------
lisp.h: Redo GCPRO declarations. Create a "base" set of functions that can
be used to generate any kind of gcpro sets -- regular, ngcpro,
nngcpro, private ones used in GC_EXTERNAL_LIST_LOOP_2.
buffer.c, callint.c, chartab.c, console-msw.c, device-x.c, dialog-msw.c, dired.c, extents.c, ui-gtk.c, rangetab.c, nt.c, mule-coding.c, minibuf.c, menubar-msw.c, menubar.c, menubar-gtk.c, lread.c, lisp.h, gutter.c, glyphs.c, glyphs-widget.c, fns.c, fileio.c, file-coding.c, specifier.c: Eliminate EXTERNAL_LIST_LOOP, which does not check for circularities.
Use EXTERNAL_LIST_LOOP_2 instead or EXTERNAL_LIST_LOOP_3
or EXTERNAL_PROPERTY_LIST_LOOP_3 or GC_EXTERNAL_LIST_LOOP_2
(new macro). Removed/redid comments on EXTERNAL_LIST_LOOP.
---------------------------------------------------------------
SPACING FIXES
---------------------------------------------------------------
callint.c, hftctl.c, number-gmp.c, process-unix.c: Spacing fixes.
---------------------------------------------------------------
FIX FOR GEOMETRY PROBLEM IN FIRST FRAME
---------------------------------------------------------------
unicode.c: Add workaround for newlib bug in sscanf() [should be fixed by
release 1.5.12 of Cygwin].
toolbar.c: bug fix for problem of initial frame being 77 chars wide on Windows.
will be overridden by my other ws.
---------------------------------------------------------------
FIX FOR LEAKING PROCESS HANDLES:
---------------------------------------------------------------
process-nt.c: Fixes for leaking handles. Inspired by work done by Adrian Aichner
<adrian@xemacs.org>.
---------------------------------------------------------------
FIX FOR CYGWIN BUG (Unicode-related):
---------------------------------------------------------------
unicode.c: Add workaround for newlib bug in sscanf() [should be fixed by
release 1.5.12 of Cygwin].
---------------------------------------------------------------
WARNING FIXES:
---------------------------------------------------------------
console-stream.c: `reinit' is unused.
compiler.h, event-msw.c, frame-msw.c, intl-encap-win32.c, text.h: Add stuff to deal with ANSI-aliasing warnings I got.
regex.c: Gather includes together to avoid warning.
---------------------------------------------------------------
CHANGES TO INITIALIZATION ROUTINES:
---------------------------------------------------------------
buffer.c, emacs.c, console.c, debug.c, device-x.c, device.c, dragdrop.c, emodules.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, event-tty.c, events.c, extents.c, faces.c, file-coding.c, fileio.c, font-lock.c, frame-msw.c, glyphs-widget.c, glyphs.c, gui-x.c, insdel.c, lread.c, lstream.c, menubar-gtk.c, menubar-x.c, minibuf.c, mule-wnnfns.c, objects-msw.c, objects.c, print.c, scrollbar-x.c, search.c, select-x.c, text.c, undo.c, unicode.c, window.c, symsinit.h: Call reinit_*() functions directly from emacs.c, for clarity.
Factor out some redundant init code. Move disallowed stuff
that had crept into vars_of_glyphs() into complex_vars_of_glyphs().
Call init_eval_semi_early() from eval.c not in the middle of
vars_of_() in emacs.c since there should be no order dependency
in the latter calls.
---------------------------------------------------------------
ARMAGEDDON:
---------------------------------------------------------------
alloc.c, emacs.c, lisp.h, print.c: Rename inhibit_non_essential_printing_operations to
inhibit_non_essential_conversion_operations.
text.c: Assert on !inhibit_non_essential_conversion_operations.
console-msw.c, print.c: Don't do conversion in SetConsoleTitle or FindWindow to avoid
problems during armageddon. Put #errors for NON_ASCII_INTERNAL_FORMAT
in places where problems would arise.
---------------------------------------------------------------
CHANGES TO THE BUILD PROCEDURE:
---------------------------------------------------------------
config.h.in, s/cxux.h, s/usg5-4-2.h, m/powerpc.h: Add comment about correct ordering of this file.
Rearrange everything to follow this -- put all #undefs together
and before the s&m files. Add undefs for HAVE_ALLOCA, C_ALLOCA,
BROKEN_ALLOCA_IN_FUNCTION_CALLS, STACK_DIRECTION. Remove unused
HAVE_STPCPY, HAVE_GETWD, HAVE_SETLOCALE.
m/gec63.h: Deleted; totally broken, not used at all, not in FSF.
m/7300.h, m/acorn.h, m/alliant-2800.h, m/alliant.h, m/altos.h, m/amdahl.h, m/apollo.h, m/att3b.h, m/aviion.h, m/celerity.h, m/clipper.h, m/cnvrgnt.h, m/convex.h, m/cydra5.h, m/delta.h, m/delta88k.h, m/dpx2.h, m/elxsi.h, m/ews4800r.h, m/gould.h, m/hp300bsd.h, m/hp800.h, m/hp9000s300.h, m/i860.h, m/ibmps2-aix.h, m/ibmrs6000.h, m/ibmrt-aix.h, m/ibmrt.h, m/intel386.h, m/iris4d.h, m/iris5d.h, m/iris6d.h, m/irist.h, m/isi-ov.h, m/luna88k.h, m/m68k.h, m/masscomp.h, m/mg1.h, m/mips-nec.h, m/mips-siemens.h, m/mips.h, m/news.h, m/nh3000.h, m/nh4000.h, m/ns32000.h, m/orion105.h, m/pfa50.h, m/plexus.h, m/pmax.h, m/powerpc.h, m/pyrmips.h, m/sequent-ptx.h, m/sequent.h, m/sgi-challenge.h, m/symmetry.h, m/tad68k.h, m/tahoe.h, m/targon31.h, m/tekxd88.h, m/template.h, m/tower32.h, m/tower32v3.h, m/ustation.h, m/vax.h, m/wicat.h, m/xps100.h: Delete C_ALLOCA, HAVE_ALLOCA, STACK_DIRECTION,
BROKEN_ALLOCA_IN_FUNCTION_CALLS. All of this is auto-detected.
When in doubt, I followed recent FSF sources, which also have
these things deleted.
author | ben |
---|---|
date | Thu, 04 Nov 2004 23:08:28 +0000 |
parents | a8d8f419b459 |
children | 3d8143fc88e1 |
comparison
equal
deleted
inserted
replaced
2366:2a392e0c390a | 2367:ecf1ebac70d8 |
---|---|
1 /* Buffer insertion/deletion and gap motion for XEmacs. | 1 /* Buffer insertion/deletion and gap motion for XEmacs. |
2 Copyright (C) 1985, 1986, 1991, 1992, 1993, 1994, 1995 | 2 Copyright (C) 1985, 1986, 1991, 1992, 1993, 1994, 1995 |
3 Free Software Foundation, Inc. | 3 Free Software Foundation, Inc. |
4 Copyright (C) 1995 Sun Microsystems, Inc. | 4 Copyright (C) 1995 Sun Microsystems, Inc. |
5 Copyright (C) 2001, 2002, 2003 Ben Wing. | 5 Copyright (C) 2001, 2002, 2003, 2004 Ben Wing. |
6 | 6 |
7 This file is part of XEmacs. | 7 This file is part of XEmacs. |
8 | 8 |
9 XEmacs is free software; you can redistribute it and/or modify it | 9 XEmacs is free software; you can redistribute it and/or modify it |
10 under the terms of the GNU General Public License as published by the | 10 under the terms of the GNU General Public License as published by the |
63 #define SET_BUF_GAP_SIZE(buf, value) \ | 63 #define SET_BUF_GAP_SIZE(buf, value) \ |
64 do { (buf)->text->gap_size = (value); } while (0) | 64 do { (buf)->text->gap_size = (value); } while (0) |
65 #define SET_BUF_END_GAP_SIZE(buf, value) \ | 65 #define SET_BUF_END_GAP_SIZE(buf, value) \ |
66 do { (buf)->text->end_gap_size = (value); } while (0) | 66 do { (buf)->text->end_gap_size = (value); } while (0) |
67 | 67 |
68 /* Gap location. */ | |
69 #define BYTE_BUF_GPT(buf) ((buf)->text->gpt + 0) | |
70 #define BUF_GPT_ADDR(buf) (BUF_BEG_ADDR (buf) + BYTE_BUF_GPT (buf) - 1) | 68 #define BUF_GPT_ADDR(buf) (BUF_BEG_ADDR (buf) + BYTE_BUF_GPT (buf) - 1) |
71 | 69 |
72 /* Set gap location. */ | 70 /* Set gap location. */ |
73 #define SET_BYTE_BUF_GPT(buf, value) do { (buf)->text->gpt = (value); } while (0) | 71 #define SET_BOTH_BUF_GPT(buf, cval, bval) \ |
74 | |
75 /* Set end of buffer. */ | |
76 #define SET_BOTH_BUF_Z(buf, val, bival) \ | |
77 do \ | 72 do \ |
78 { \ | 73 { \ |
79 (buf)->text->z = (bival); \ | 74 (buf)->text->gpt = (bval); \ |
80 (buf)->text->bufz = (val); \ | 75 (buf)->text->bufgpt = (cval); \ |
76 } while (0) | |
77 | |
78 /* Set end of buffer. */ | |
79 #define SET_BOTH_BUF_Z(buf, cval, bval) \ | |
80 do \ | |
81 { \ | |
82 (buf)->text->z = (bval); \ | |
83 (buf)->text->bufz = (cval); \ | |
81 } while (0) | 84 } while (0) |
82 | 85 |
83 /* Under Mule, we maintain two sentinels in the buffer: one at the | 86 /* Under Mule, we maintain two sentinels in the buffer: one at the |
84 beginning of the gap, and one at the end of the buffer. This | 87 beginning of the gap, and one at the end of the buffer. This |
85 allows us to move forward, examining bytes looking for the | 88 allows us to move forward, examining bytes looking for the |
252 value improves gap-motion efficiency but decreases QUIT responsiveness | 255 value improves gap-motion efficiency but decreases QUIT responsiveness |
253 time. Was 32000 but today's processors are faster and files are | 256 time. Was 32000 but today's processors are faster and files are |
254 bigger. --ben */ | 257 bigger. --ben */ |
255 #define GAP_MOVE_CHUNK 300000 | 258 #define GAP_MOVE_CHUNK 300000 |
256 | 259 |
257 /* Move the gap to POS, which is less than the current GPT. */ | 260 /* Move the gap to CPOS/BPOS, which is less than the current GPT. */ |
258 | 261 |
259 static void | 262 static void |
260 gap_left (struct buffer *buf, Bytebpos pos) | 263 gap_left (struct buffer *buf, Charbpos cpos, Bytebpos bpos) |
261 { | 264 { |
262 Ibyte *to, *from; | 265 Ibyte *to, *from; |
263 Bytecount i; | 266 Bytecount i; |
264 Bytebpos new_s1; | 267 Bytebpos new_s1; |
265 struct buffer *mbuf; | 268 struct buffer *mbuf; |
273 copy characters up. */ | 276 copy characters up. */ |
274 | 277 |
275 while (1) | 278 while (1) |
276 { | 279 { |
277 /* I gets number of characters left to copy. */ | 280 /* I gets number of characters left to copy. */ |
278 i = new_s1 - pos; | 281 i = new_s1 - bpos; |
279 if (i == 0) | 282 if (i == 0) |
280 break; | 283 break; |
281 /* If a quit is requested, stop copying now. | 284 /* If a quit is requested, stop copying now. |
282 Change POS to be where we have actually moved the gap to. */ | 285 Change BPOS to be where we have actually moved the gap to. */ |
283 if (QUITP) | 286 if (QUITP) |
284 { | 287 { |
285 pos = new_s1; | 288 bpos = new_s1; |
289 cpos = bytebpos_to_charbpos (buf, bpos); | |
286 break; | 290 break; |
287 } | 291 } |
288 /* Move at most GAP_MOVE_CHUNK chars before checking again for a quit. */ | 292 /* Move at most GAP_MOVE_CHUNK chars before checking again for a quit. */ |
289 if (i > GAP_MOVE_CHUNK) | 293 if (i > GAP_MOVE_CHUNK) |
290 i = GAP_MOVE_CHUNK; | 294 i = GAP_MOVE_CHUNK; |
291 | 295 |
292 if (i >= 128) | 296 if (i >= 10) /* was 128 but memmove() should be extremely efficient |
297 nowadays */ | |
293 { | 298 { |
294 new_s1 -= i; | 299 new_s1 -= i; |
295 from -= i; | 300 from -= i; |
296 to -= i; | 301 to -= i; |
297 memmove (to, from, i); | 302 memmove (to, from, i); |
302 while (--i >= 0) | 307 while (--i >= 0) |
303 *--to = *--from; | 308 *--to = *--from; |
304 } | 309 } |
305 } | 310 } |
306 | 311 |
307 /* Adjust markers, and buffer data structure, to put the gap at POS. | 312 /* Adjust markers, and buffer data structure, to put the gap at BPOS. |
308 POS is where the loop above stopped, which may be what was specified | 313 BPOS is where the loop above stopped, which may be what was specified |
309 or may be where a quit was detected. */ | 314 or may be where a quit was detected. */ |
310 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | 315 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
311 { | 316 { |
312 adjust_markers (mbuf, pos, BYTE_BUF_GPT (mbuf), BUF_GAP_SIZE (mbuf)); | 317 adjust_markers (mbuf, bpos, BYTE_BUF_GPT (mbuf), BUF_GAP_SIZE (mbuf)); |
313 } | 318 } |
314 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | 319 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
315 { | 320 { |
316 adjust_extents (wrap_buffer (mbuf), pos, BYTE_BUF_GPT (mbuf), | 321 adjust_extents (wrap_buffer (mbuf), bpos, BYTE_BUF_GPT (mbuf), |
317 BUF_GAP_SIZE (mbuf)); | 322 BUF_GAP_SIZE (mbuf)); |
318 } | 323 } |
319 SET_BYTE_BUF_GPT (buf, pos); | 324 SET_BOTH_BUF_GPT (buf, cpos, bpos); |
320 SET_GAP_SENTINEL (buf); | 325 SET_GAP_SENTINEL (buf); |
321 #ifdef ERROR_CHECK_EXTENTS | 326 #ifdef ERROR_CHECK_EXTENTS |
322 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | 327 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
323 { | 328 { |
324 sledgehammer_extent_check (wrap_buffer (mbuf)); | 329 sledgehammer_extent_check (wrap_buffer (mbuf)); |
326 #endif | 331 #endif |
327 QUIT; | 332 QUIT; |
328 } | 333 } |
329 | 334 |
330 static void | 335 static void |
331 gap_right (struct buffer *buf, Bytebpos pos) | 336 gap_right (struct buffer *buf, Charbpos cpos, Bytebpos bpos) |
332 { | 337 { |
333 Ibyte *to, *from; | 338 Ibyte *to, *from; |
334 Bytecount i; | 339 Bytecount i; |
335 Bytebpos new_s1; | 340 Bytebpos new_s1; |
336 struct buffer *mbuf; | 341 struct buffer *mbuf; |
344 copy characters down. */ | 349 copy characters down. */ |
345 | 350 |
346 while (1) | 351 while (1) |
347 { | 352 { |
348 /* I gets number of characters left to copy. */ | 353 /* I gets number of characters left to copy. */ |
349 i = pos - new_s1; | 354 i = bpos - new_s1; |
350 if (i == 0) | 355 if (i == 0) |
351 break; | 356 break; |
352 /* If a quit is requested, stop copying now. | 357 /* If a quit is requested, stop copying now. |
353 Change POS to be where we have actually moved the gap to. */ | 358 Change BPOS to be where we have actually moved the gap to. */ |
354 if (QUITP) | 359 if (QUITP) |
355 { | 360 { |
356 pos = new_s1; | 361 bpos = new_s1; |
362 cpos = bytebpos_to_charbpos (buf, bpos); | |
357 break; | 363 break; |
358 } | 364 } |
359 /* Move at most GAP_MOVE_CHUNK chars before checking again for a quit. */ | 365 /* Move at most GAP_MOVE_CHUNK chars before checking again for a quit. */ |
360 if (i > GAP_MOVE_CHUNK) | 366 if (i > GAP_MOVE_CHUNK) |
361 i = GAP_MOVE_CHUNK; | 367 i = GAP_MOVE_CHUNK; |
362 | 368 |
363 if (i >= 128) | 369 if (i >= 10) /* was 128 but memmove() should be extremely efficient |
370 nowadays */ | |
364 { | 371 { |
365 new_s1 += i; | 372 new_s1 += i; |
366 memmove (to, from, i); | 373 memmove (to, from, i); |
367 from += i; | 374 from += i; |
368 to += i; | 375 to += i; |
377 | 384 |
378 { | 385 { |
379 int gsize = BUF_GAP_SIZE (buf); | 386 int gsize = BUF_GAP_SIZE (buf); |
380 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | 387 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
381 { | 388 { |
382 adjust_markers (mbuf, BYTE_BUF_GPT (mbuf) + gsize, pos + gsize, - gsize); | 389 adjust_markers (mbuf, BYTE_BUF_GPT (mbuf) + gsize, bpos + gsize, - gsize); |
383 } | 390 } |
384 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | 391 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
385 { | 392 { |
386 adjust_extents (wrap_buffer (mbuf), BYTE_BUF_GPT (mbuf) + gsize, | 393 adjust_extents (wrap_buffer (mbuf), BYTE_BUF_GPT (mbuf) + gsize, |
387 pos + gsize, - gsize); | 394 bpos + gsize, - gsize); |
388 } | 395 } |
389 SET_BYTE_BUF_GPT (buf, pos); | 396 SET_BOTH_BUF_GPT (buf, cpos, bpos); |
390 SET_GAP_SENTINEL (buf); | 397 SET_GAP_SENTINEL (buf); |
391 #ifdef ERROR_CHECK_EXTENTS | 398 #ifdef ERROR_CHECK_EXTENTS |
392 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | 399 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
393 { | 400 { |
394 sledgehammer_extent_check (wrap_buffer (mbuf)); | 401 sledgehammer_extent_check (wrap_buffer (mbuf)); |
395 } | 402 } |
396 #endif | 403 #endif |
397 } | 404 } |
398 if (pos == BYTE_BUF_Z (buf)) | 405 if (bpos == BYTE_BUF_Z (buf)) |
399 { | 406 { |
400 /* merge gap with end gap */ | 407 /* merge gap with end gap */ |
401 | 408 |
402 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) + BUF_END_GAP_SIZE (buf)); | 409 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) + BUF_END_GAP_SIZE (buf)); |
403 SET_BUF_END_GAP_SIZE (buf, 0); | 410 SET_BUF_END_GAP_SIZE (buf, 0); |
405 } | 412 } |
406 | 413 |
407 QUIT; | 414 QUIT; |
408 } | 415 } |
409 | 416 |
410 /* Move gap to position `pos'. | 417 /* Move gap to position `bpos'. |
411 Note that this can quit! */ | 418 Note that this can quit! */ |
412 | 419 |
413 static void | 420 static void |
414 move_gap (struct buffer *buf, Bytebpos pos) | 421 move_gap (struct buffer *buf, Charbpos cpos, Bytebpos bpos) |
415 { | 422 { |
416 if (! BUF_BEG_ADDR (buf)) | 423 if (! BUF_BEG_ADDR (buf)) |
417 abort (); | 424 abort (); |
418 if (pos < BYTE_BUF_GPT (buf)) | 425 if (bpos < BYTE_BUF_GPT (buf)) |
419 gap_left (buf, pos); | 426 gap_left (buf, cpos, bpos); |
420 else if (pos > BYTE_BUF_GPT (buf)) | 427 else if (bpos > BYTE_BUF_GPT (buf)) |
421 gap_right (buf, pos); | 428 gap_right (buf, cpos, bpos); |
422 } | 429 } |
423 | 430 |
424 /* Merge the end gap into the gap */ | 431 /* Merge the end gap into the gap */ |
425 | 432 |
426 static void | 433 static void |
427 merge_gap_with_end_gap (struct buffer *buf) | 434 merge_gap_with_end_gap (struct buffer *buf) |
428 { | 435 { |
429 Lisp_Object tem; | 436 Lisp_Object tem; |
430 Bytebpos real_gap_loc; | 437 Charbpos real_gap_loc_char; |
438 Bytebpos real_gap_loc_byte; | |
431 Bytecount old_gap_size; | 439 Bytecount old_gap_size; |
432 Bytecount increment; | 440 Bytecount increment; |
433 | 441 |
434 increment = BUF_END_GAP_SIZE (buf); | 442 increment = BUF_END_GAP_SIZE (buf); |
435 SET_BUF_END_GAP_SIZE (buf, 0); | 443 SET_BUF_END_GAP_SIZE (buf, 0); |
438 { | 446 { |
439 /* Prevent quitting in move_gap. */ | 447 /* Prevent quitting in move_gap. */ |
440 tem = Vinhibit_quit; | 448 tem = Vinhibit_quit; |
441 Vinhibit_quit = Qt; | 449 Vinhibit_quit = Qt; |
442 | 450 |
443 real_gap_loc = BYTE_BUF_GPT (buf); | 451 real_gap_loc_char = BUF_GPT (buf); |
452 real_gap_loc_byte = BYTE_BUF_GPT (buf); | |
444 old_gap_size = BUF_GAP_SIZE (buf); | 453 old_gap_size = BUF_GAP_SIZE (buf); |
445 | 454 |
446 /* Pretend the end gap is the gap */ | 455 /* Pretend the end gap is the gap */ |
447 SET_BYTE_BUF_GPT (buf, BYTE_BUF_Z (buf) + BUF_GAP_SIZE (buf)); | 456 SET_BOTH_BUF_GPT (buf, BUF_Z (buf) + BUF_GAP_SIZE (buf), |
457 BYTE_BUF_Z (buf) + BUF_GAP_SIZE (buf)); | |
448 SET_BUF_GAP_SIZE (buf, increment); | 458 SET_BUF_GAP_SIZE (buf, increment); |
449 | 459 |
450 /* Move the new gap down to be consecutive with the end of the old one. | 460 /* Move the new gap down to be consecutive with the end of the old one. |
451 This adjusts the markers properly too. */ | 461 This adjusts the markers properly too. */ |
452 gap_left (buf, real_gap_loc + old_gap_size); | 462 gap_left (buf, real_gap_loc_char + old_gap_size, |
463 real_gap_loc_byte + old_gap_size); | |
453 | 464 |
454 /* Now combine the two into one large gap. */ | 465 /* Now combine the two into one large gap. */ |
455 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) + old_gap_size); | 466 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) + old_gap_size); |
456 SET_BYTE_BUF_GPT (buf, real_gap_loc); | 467 SET_BOTH_BUF_GPT (buf, real_gap_loc_char, real_gap_loc_byte); |
457 SET_GAP_SENTINEL (buf); | 468 SET_GAP_SENTINEL (buf); |
458 | 469 |
459 /* We changed the total size of the buffer (including gap), | 470 /* We changed the total size of the buffer (including gap), |
460 so we need to fix up the end sentinel. */ | 471 so we need to fix up the end sentinel. */ |
461 SET_END_SENTINEL (buf); | 472 SET_END_SENTINEL (buf); |
469 static void | 480 static void |
470 make_gap (struct buffer *buf, Bytecount increment) | 481 make_gap (struct buffer *buf, Bytecount increment) |
471 { | 482 { |
472 Ibyte *result; | 483 Ibyte *result; |
473 Lisp_Object tem; | 484 Lisp_Object tem; |
474 Bytebpos real_gap_loc; | 485 Charbpos real_gap_loc_char; |
486 Bytebpos real_gap_loc_byte; | |
475 Bytecount old_gap_size; | 487 Bytecount old_gap_size; |
476 | 488 |
477 /* If we have to get more space, get enough to last a while. We use | 489 /* If we have to get more space, get enough to last a while. We use |
478 a geometric progression that saves on realloc space. */ | 490 a geometric progression that saves on realloc space. */ |
479 increment += 2000 + ((BYTE_BUF_Z (buf) - BYTE_BUF_BEG (buf)) / 8); | 491 increment += 2000 + ((BYTE_BUF_Z (buf) - BYTE_BUF_BEG (buf)) / 8); |
506 | 518 |
507 /* Prevent quitting in move_gap. */ | 519 /* Prevent quitting in move_gap. */ |
508 tem = Vinhibit_quit; | 520 tem = Vinhibit_quit; |
509 Vinhibit_quit = Qt; | 521 Vinhibit_quit = Qt; |
510 | 522 |
511 real_gap_loc = BYTE_BUF_GPT (buf); | 523 real_gap_loc_char = BUF_GPT (buf); |
524 real_gap_loc_byte = BYTE_BUF_GPT (buf); | |
512 old_gap_size = BUF_GAP_SIZE (buf); | 525 old_gap_size = BUF_GAP_SIZE (buf); |
513 | 526 |
514 /* Call the newly allocated space a gap at the end of the whole space. */ | 527 /* Call the newly allocated space a gap at the end of the whole space. */ |
515 SET_BYTE_BUF_GPT (buf, BYTE_BUF_Z (buf) + BUF_GAP_SIZE (buf)); | 528 SET_BOTH_BUF_GPT (buf, BUF_Z (buf) + BUF_GAP_SIZE (buf), |
529 BYTE_BUF_Z (buf) + BUF_GAP_SIZE (buf)); | |
516 SET_BUF_GAP_SIZE (buf, increment); | 530 SET_BUF_GAP_SIZE (buf, increment); |
517 | 531 |
518 SET_BUF_END_GAP_SIZE (buf, 0); | 532 SET_BUF_END_GAP_SIZE (buf, 0); |
519 | 533 |
520 /* Move the new gap down to be consecutive with the end of the old one. | 534 /* Move the new gap down to be consecutive with the end of the old one. |
521 This adjusts the markers properly too. */ | 535 This adjusts the markers properly too. */ |
522 gap_left (buf, real_gap_loc + old_gap_size); | 536 gap_left (buf, real_gap_loc_char + old_gap_size, |
537 real_gap_loc_byte + old_gap_size); | |
523 | 538 |
524 /* Now combine the two into one large gap. */ | 539 /* Now combine the two into one large gap. */ |
525 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) + old_gap_size); | 540 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) + old_gap_size); |
526 SET_BYTE_BUF_GPT (buf, real_gap_loc); | 541 SET_BOTH_BUF_GPT (buf, real_gap_loc_char, real_gap_loc_byte); |
527 SET_GAP_SENTINEL (buf); | 542 SET_GAP_SENTINEL (buf); |
528 | 543 |
529 /* We changed the total size of the buffer (including gap), | 544 /* We changed the total size of the buffer (including gap), |
530 so we need to fix up the end sentinel. */ | 545 so we need to fix up the end sentinel. */ |
531 SET_END_SENTINEL (buf); | 546 SET_END_SENTINEL (buf); |
1128 | 1143 |
1129 if (bytepos != BYTE_BUF_GPT (buf)) | 1144 if (bytepos != BYTE_BUF_GPT (buf)) |
1130 /* #### if debug-on-quit is invoked and the user changes the | 1145 /* #### if debug-on-quit is invoked and the user changes the |
1131 buffer, bad things can happen. This is a rampant problem | 1146 buffer, bad things can happen. This is a rampant problem |
1132 in Emacs. */ | 1147 in Emacs. */ |
1133 move_gap (buf, bytepos); /* may QUIT */ | 1148 move_gap (buf, pos, bytepos); /* may QUIT */ |
1134 if (! GAP_CAN_HOLD_SIZE_P (buf, length_in_buffer)) | 1149 if (! GAP_CAN_HOLD_SIZE_P (buf, length_in_buffer)) |
1135 { | 1150 { |
1136 if (BUF_END_GAP_SIZE (buf) >= length_in_buffer) | 1151 if (BUF_END_GAP_SIZE (buf) >= length_in_buffer) |
1137 merge_gap_with_end_gap (buf); | 1152 merge_gap_with_end_gap (buf); |
1138 else | 1153 else |
1164 STRINGP (reloc) ? reloc : Qnil, | 1179 STRINGP (reloc) ? reloc : Qnil, |
1165 BUF_GPT_ADDR (buf), length_in_buffer, | 1180 BUF_GPT_ADDR (buf), length_in_buffer, |
1166 BUF_FORMAT (buf), wrap_buffer (buf), NULL); | 1181 BUF_FORMAT (buf), wrap_buffer (buf), NULL); |
1167 | 1182 |
1168 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) - length_in_buffer); | 1183 SET_BUF_GAP_SIZE (buf, BUF_GAP_SIZE (buf) - length_in_buffer); |
1169 SET_BYTE_BUF_GPT (buf, BYTE_BUF_GPT (buf) + length_in_buffer); | 1184 SET_BOTH_BUF_GPT (buf, BUF_GPT (buf) + cclen, |
1185 BYTE_BUF_GPT (buf) + length_in_buffer); | |
1170 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | 1186 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
1171 { | 1187 { |
1172 SET_BOTH_BUF_ZV (mbuf, BUF_ZV (mbuf) + cclen, | 1188 SET_BOTH_BUF_ZV (mbuf, BUF_ZV (mbuf) + cclen, |
1173 BYTE_BUF_ZV (mbuf) + length_in_buffer); | 1189 BYTE_BUF_ZV (mbuf) + length_in_buffer); |
1174 } | 1190 } |
1387 else | 1403 else |
1388 { | 1404 { |
1389 /* Make sure the gap is somewhere in or next to what we are deleting. */ | 1405 /* Make sure the gap is somewhere in or next to what we are deleting. */ |
1390 /* NOTE: Can QUIT! */ | 1406 /* NOTE: Can QUIT! */ |
1391 if (byte_to < BYTE_BUF_GPT (buf)) | 1407 if (byte_to < BYTE_BUF_GPT (buf)) |
1392 gap_left (buf, byte_to); | 1408 gap_left (buf, to, byte_to); |
1393 if (byte_from > BYTE_BUF_GPT (buf)) | 1409 if (byte_from > BYTE_BUF_GPT (buf)) |
1394 gap_right (buf, byte_from); | 1410 gap_right (buf, from, byte_from); |
1395 do_move_gap = 1; | 1411 do_move_gap = 1; |
1396 } | 1412 } |
1397 | 1413 |
1398 /* At this point, no more QUITting or processing of Lisp code. Buffer is | 1414 /* At this point, no more QUITting or processing of Lisp code. Buffer is |
1399 in a consistent state. Following code puts buffer in an inconsistent | 1415 in a consistent state. Following code puts buffer in an inconsistent |
1509 SET_BOTH_BUF_ZV (mbuf, BUF_ZV (mbuf) - numdel, | 1525 SET_BOTH_BUF_ZV (mbuf, BUF_ZV (mbuf) - numdel, |
1510 BYTE_BUF_ZV (mbuf) - byte_numdel); | 1526 BYTE_BUF_ZV (mbuf) - byte_numdel); |
1511 } | 1527 } |
1512 SET_BOTH_BUF_Z (buf, BUF_Z (buf) - numdel, BYTE_BUF_Z (buf) - byte_numdel); | 1528 SET_BOTH_BUF_Z (buf, BUF_Z (buf) - numdel, BYTE_BUF_Z (buf) - byte_numdel); |
1513 if (do_move_gap) | 1529 if (do_move_gap) |
1514 SET_BYTE_BUF_GPT (buf, byte_from); | 1530 SET_BOTH_BUF_GPT (buf, from, byte_from); |
1515 SET_GAP_SENTINEL (buf); | 1531 SET_GAP_SENTINEL (buf); |
1516 | 1532 |
1517 #ifdef MULE | 1533 #ifdef MULE |
1518 buffer_mule_signal_deleted_region (buf, from, to, byte_from, byte_to); | 1534 buffer_mule_signal_deleted_region (buf, from, to, byte_from, byte_to); |
1519 buf->text->entirely_one_byte_p = | 1535 buf->text->entirely_one_byte_p = |
1751 } | 1767 } |
1752 | 1768 |
1753 void | 1769 void |
1754 vars_of_insdel (void) | 1770 vars_of_insdel (void) |
1755 { | 1771 { |
1756 reinit_vars_of_insdel (); | |
1757 } | 1772 } |
1758 | 1773 |
1759 void | 1774 void |
1760 init_buffer_text (struct buffer *b) | 1775 init_buffer_text (struct buffer *b) |
1761 { | 1776 { |
1765 BUFFER_ALLOC (b->text->beg, BUF_GAP_SIZE (b) + BUF_END_SENTINEL_SIZE); | 1780 BUFFER_ALLOC (b->text->beg, BUF_GAP_SIZE (b) + BUF_END_SENTINEL_SIZE); |
1766 if (! BUF_BEG_ADDR (b)) | 1781 if (! BUF_BEG_ADDR (b)) |
1767 memory_full (); | 1782 memory_full (); |
1768 | 1783 |
1769 SET_BUF_END_GAP_SIZE (b, 0); | 1784 SET_BUF_END_GAP_SIZE (b, 0); |
1770 SET_BYTE_BUF_GPT (b, 1); | 1785 SET_BOTH_BUF_GPT (b, 1, 1); |
1771 SET_BOTH_BUF_Z (b, 1, 1); | 1786 SET_BOTH_BUF_Z (b, 1, 1); |
1772 SET_GAP_SENTINEL (b); | 1787 SET_GAP_SENTINEL (b); |
1773 SET_END_SENTINEL (b); | 1788 SET_END_SENTINEL (b); |
1789 | |
1774 #ifdef MULE | 1790 #ifdef MULE |
1775 { | 1791 b->text->entirely_one_byte_p = 1; |
1776 int i; | 1792 |
1777 | 1793 #ifdef OLD_BYTE_CHAR |
1778 b->text->mule_bufmin = b->text->mule_bufmax = 1; | 1794 b->text->mule_bufmin = b->text->mule_bufmax = 1; |
1779 b->text->mule_bytmin = b->text->mule_bytmax = 1; | 1795 b->text->mule_bytmin = b->text->mule_bytmax = 1; |
1780 b->text->entirely_one_byte_p = 1; | 1796 #endif |
1781 | 1797 |
1782 for (i = 0; i < 16; i++) | 1798 b->text->cached_charpos = 1; |
1783 { | 1799 b->text->cached_bytepos = 1; |
1784 b->text->mule_charbpos_cache[i] = 1; | 1800 |
1785 b->text->mule_bytebpos_cache[i] = 1; | |
1786 } | |
1787 } | |
1788 /* &&#### Set to FORMAT_8_BIT_FIXED when that code is working */ | 1801 /* &&#### Set to FORMAT_8_BIT_FIXED when that code is working */ |
1789 BUF_FORMAT (b) = FORMAT_DEFAULT; | 1802 BUF_FORMAT (b) = FORMAT_DEFAULT; |
1790 #endif /* MULE */ | 1803 #endif /* MULE */ |
1791 b->text->line_number_cache = Qnil; | 1804 b->text->line_number_cache = Qnil; |
1792 | 1805 |