annotate src/font-lock.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 87084e8445a7
children 3d8143fc88e1
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 /* Routines to compute the current syntactic context, for font-lock mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Copyright (C) 1995 Sun Microsystems, Inc.
1296
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
4 Copyright (C) 2002, 2003 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 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
10 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 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
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 /* Synched up with: Not in FSF. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 /* This code computes the syntactic context of the current point, that is,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 whether point is within a comment, a string, what have you. It does
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 this by picking a point "known" to be outside of any syntactic constructs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 and moving forward, examining the syntax of each character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 Two caches are used: one caches the last point computed, and the other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 caches the last point at the beginning of a line. This makes there
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 be little penalty for moving left-to-right on a line a character at a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 time; makes starting over on a line be cheap; and makes random-accessing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 within a line relatively cheap.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 When we move to a different line farther down in the file (but within the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 current top-level form) we simply continue computing forward. If we move
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 backward more than a line, or move beyond the end of the current tlf, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 switch buffers, then we call `beginning-of-defun' and start over from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 #### We should really rewrite this to keep extents over the buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 that hold the current syntactic information. This would be a big win.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 This way there would be no guessing or incorrect results.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46
838
bf645ed7cfe3 [xemacs-hg @ 2002-05-14 09:28:06 by ben]
ben
parents: 826
diff changeset
47 #include <config.h>
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 665
diff changeset
48
838
bf645ed7cfe3 [xemacs-hg @ 2002-05-14 09:28:06 by ben]
ben
parents: 826
diff changeset
49 #ifdef USE_C_FONT_LOCK
bf645ed7cfe3 [xemacs-hg @ 2002-05-14 09:28:06 by ben]
ben
parents: 826
diff changeset
50
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 #include "insdel.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 #include "syntax.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 Lisp_Object Qcomment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 Lisp_Object Qblock_comment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 Lisp_Object Qbeginning_of_defun;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 enum syntactic_context
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 context_none,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 context_string,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 context_comment,
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
66 context_block_comment,
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
67 context_generic_comment,
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
68 context_generic_string
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 enum block_comment_context
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 ccontext_none,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 ccontext_start1,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 ccontext_start2,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 ccontext_end1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 enum comment_style
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 comment_style_none,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 comment_style_a,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 comment_style_b
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 struct context_cache
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
88 Charbpos start_point; /* beginning of defun */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
89 Charbpos cur_point; /* cache location */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
90 Charbpos end_point; /* end of defun */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 struct buffer *buffer; /* does this need to be staticpro'd? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 enum syntactic_context context; /* single-char-syntax state */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 enum block_comment_context ccontext; /* block-comment state */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 enum comment_style style; /* which comment group */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 844
diff changeset
95 Ichar scontext; /* active string delimiter */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 int depth; /* depth in parens */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 int backslash_p; /* just read a backslash */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 int needs_its_head_reexamined; /* we're apparently outside of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 a top level form, and far away
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 from it. This is a bad situation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 because it will lead to constant
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 slowness as we keep going way
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 back to that form and moving
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 forward again. In this case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 we try to compute a "pseudo-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 top-level-form" where the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 depth is 0 and the context
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 is none at both ends. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 /* We have two caches; one for the current point and one for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 the beginning of line. We used to rely on the caller to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 tell us when to invalidate them, but now we do it ourselves;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 it lets us be smarter. */
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 static struct context_cache context_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 static struct context_cache bol_context_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 int font_lock_debug;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 #define reset_context_cache(cc) memset (cc, 0, sizeof (struct context_cache))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 /* This function is called from signal_after_change() to tell us when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 textual changes are made so we can flush our caches when necessary.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 We make the following somewhat heuristic assumptions:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 (remember that current_point is always >= start_point, but may be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 less than or greater than end_point (we might not be inside any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 top-level form)).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 1) Textual changes before the beginning of the current top-level form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 don't affect anything; all we need to do is offset the caches
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 appropriately.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 2) Textual changes right at the beginning of the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 top-level form messes things up and requires that we flush
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 the caches.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 3) Textual changes after the beginning of the current top-level form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 and before one or both or the caches invalidates the corresponding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 cache(s).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 4) Textual changes after the caches and before the end of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 current top-level form don't affect anything; all we need to do is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 offset the caches appropriately.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 5) Textual changes right at the end of the current top-level form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 necessitate recomputing that end value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 6) Textual changes after the end of the current top-level form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 are ignored. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149
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 void
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
152 font_lock_maybe_update_syntactic_caches (struct buffer *buf, Charbpos start,
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
153 Charbpos orig_end, Charbpos new_end)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 /* Note: either both context_cache and bol_context_cache are valid and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 point to the same buffer, or both are invalid. If we have to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 invalidate just context_cache, we recopy it from bol_context_cache.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 if (context_cache.buffer != buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 /* caches don't apply */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 /* NOTE: The order of the if statements below is important. If you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 change them around unthinkingly, you will probably break something. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 if (orig_end <= context_cache.start_point - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 /* case 1: before the beginning of the current top-level form */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 Charcount diff = new_end - orig_end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 stderr_out ("font-lock; Case 1\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 context_cache.start_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 context_cache.cur_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 context_cache.end_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 bol_context_cache.start_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 bol_context_cache.cur_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 bol_context_cache.end_point += diff;
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 else if (start <= context_cache.start_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 stderr_out ("font-lock; Case 2\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 /* case 2: right at the current top-level form (paren that starts
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 top level form got deleted or moved away from the newline it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 was touching) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 reset_context_cache (&context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 reset_context_cache (&bol_context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 /* OK, now we know that the start is after the beginning of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 current top-level form. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 else if (start < bol_context_cache.cur_point)
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 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 stderr_out ("font-lock; Case 3 (1)\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 /* case 3: after the beginning of the current top-level form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 and before both of the caches */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 reset_context_cache (&context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 reset_context_cache (&bol_context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 else if (start < context_cache.cur_point)
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 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 stderr_out ("font-lock; Case 3 (2)\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 /* case 3: but only need to invalidate one cache */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 context_cache = bol_context_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 /* OK, now we know that the start is after the caches. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 else if (start >= context_cache.end_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 stderr_out ("font-lock; Case 6\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 /* case 6: after the end of the current top-level form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 and after the caches. */
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 else if (orig_end <= context_cache.end_point - 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 /* case 4: after the caches and before the end of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 current top-level form */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 Charcount diff = new_end - orig_end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 stderr_out ("font-lock; Case 4\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 context_cache.end_point += diff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 bol_context_cache.end_point += diff;
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 stderr_out ("font-lock; Case 5\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 /* case 5: right at the end of the current top-level form */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 context_cache.end_point = context_cache.start_point - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 bol_context_cache.end_point = context_cache.start_point - 1;
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 }
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 /* This function is called from Fkill_buffer(). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 font_lock_buffer_was_killed (struct buffer *buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 if (context_cache.buffer == buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 reset_context_cache (&context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 reset_context_cache (&bol_context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
245 static Charbpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
246 beginning_of_defun (struct buffer *buf, Charbpos pt)
428
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 /* This function can GC */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
249 Charbpos opt = BUF_PT (buf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 if (pt == BUF_BEGV (buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 return pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 BUF_SET_PT (buf, pt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 /* There used to be some kludginess to call c++-beginning-of-defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 if we're in C++ mode. There's no point in this any more;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 we're using cc-mode. If you really want to get the old c++
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 mode working, fix it rather than the C code. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 call0_in_buffer (buf, Qbeginning_of_defun);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 pt = BUF_PT (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 BUF_SET_PT (buf, opt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 return pt;
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
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
263 static Charbpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
264 end_of_defun (struct buffer *buf, Charbpos pt)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 Lisp_Object retval = scan_lists (buf, pt, 1, 0, 0, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 if (NILP (retval))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 return BUF_ZV (buf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 return XINT (retval);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 /* Set up context_cache for attempting to determine the syntactic context
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 in buffer BUF at point PT. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 static void
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
277 setup_context_cache (struct buffer *buf, Charbpos pt)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 int recomputed_start_point = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 if (context_cache.buffer != buf || pt < context_cache.start_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 start_over:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 stderr_out ("reset context cache\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 /* OK, completely invalid. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 reset_context_cache (&context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 reset_context_cache (&bol_context_cache);
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 if (!context_cache.buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 /* Need to recompute the start point. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 stderr_out ("recompute start\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 context_cache.start_point = beginning_of_defun (buf, pt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 recomputed_start_point = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 bol_context_cache.start_point = context_cache.start_point;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 bol_context_cache.buffer = context_cache.buffer = buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 if (context_cache.end_point < context_cache.start_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 /* Need to recompute the end point. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 stderr_out ("recompute end\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 context_cache.end_point = end_of_defun (buf, context_cache.start_point);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 bol_context_cache.end_point = context_cache.end_point;
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 if (bol_context_cache.cur_point == 0 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 pt < bol_context_cache.cur_point)
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 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 stderr_out ("reset to start\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 if (pt > context_cache.end_point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 /* 3000 is some arbitrary delta but seems reasonable;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 about the size of a reasonable function */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 && pt - context_cache.end_point > 3000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 /* If we're far past the end of the top level form,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 don't trust it; recompute it. */
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 /* But don't get in an infinite loop doing this.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 If we're really far past the end of the top level
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 form, try to compute a pseudo-top-level form. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 if (recomputed_start_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 context_cache.needs_its_head_reexamined = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 /* force recomputation */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 goto start_over;
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 /* Go to the nearest end of the top-level form that's before
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 us. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 if (pt > context_cache.end_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 pt = context_cache.end_point;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 pt = context_cache.start_point;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 /* Reset current point to start of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 context_cache.cur_point = pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 context_cache.context = context_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 context_cache.ccontext = ccontext_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 context_cache.style = comment_style_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 context_cache.scontext = '\000';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 context_cache.depth = 0;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
342 /* #### shouldn't this be checking the character's syntax instead of
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
343 explicitly testing for backslash characters? */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 context_cache.backslash_p = ((pt > 1) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 (BUF_FETCH_CHAR (buf, pt - 1) == '\\'));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 /* Note that the BOL context cache may not be at the beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 of the line, but that should be OK, nobody's checking. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 bol_context_cache = context_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 else if (pt < context_cache.cur_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 stderr_out ("reset to bol\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 /* bol cache is OK but current_cache is not. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 context_cache = bol_context_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 else if (pt <= context_cache.end_point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 stderr_out ("everything is OK\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 /* in same top-level form. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 /* OK, we're past the end of the top-level form. */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
368 Charbpos maxpt = max (context_cache.end_point, context_cache.cur_point);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 int shortage;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 if (font_lock_debug)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 stderr_out ("past end\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 if (pt <= maxpt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 /* OK, fine. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 #if 0
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
379 /* This appears to cause huge slowdowns in files which have no
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
380 top-level forms.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 In any case, it's not really necessary that we know for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 sure the top-level form we're in; if we're in a form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 but the form we have recorded is the previous one,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 it will be OK. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 scan_buffer (buf, '\n', maxpt, pt, 1, &shortage, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 if (!shortage)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 /* If there was a newline in the region past the known universe,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 we might be inside another top-level form, so start over.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 Otherwise, we're outside of any top-level forms and we know
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 the one directly before us, so it's OK. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 goto start_over;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
398 /* You'd think it wouldn't be necessary to cast something to the type
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
399 it's already defined is, but if you're GCC, you apparently think
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
400 differently */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
401 #define SYNTAX_START_STYLE(c1, c2) \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
402 ((enum comment_style) \
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
403 (SYNTAX_CODES_MATCH_START_P (c1, c2, SYNTAX_COMMENT_STYLE_A) ? \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 comment_style_a : \
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
405 SYNTAX_CODES_MATCH_START_P (c1, c2, SYNTAX_COMMENT_STYLE_B) ? \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 comment_style_b : \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
407 comment_style_none))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
409 #define SYNTAX_END_STYLE(c1, c2) \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
410 ((enum comment_style) \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
411 (SYNTAX_CODES_MATCH_END_P (c1, c2, SYNTAX_COMMENT_STYLE_A) ? \
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
412 comment_style_a : \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
413 SYNTAX_CODES_MATCH_END_P (c1, c2, SYNTAX_COMMENT_STYLE_B) ? \
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
414 comment_style_b : \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
415 comment_style_none))
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
416
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
417 #define SINGLE_SYNTAX_STYLE(c) \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
418 ((enum comment_style) \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
419 (SYNTAX_CODE_MATCHES_1CHAR_P (c, SYNTAX_COMMENT_STYLE_A) ? \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 comment_style_a : \
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
421 SYNTAX_CODE_MATCHES_1CHAR_P (c, SYNTAX_COMMENT_STYLE_B) ? \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 comment_style_b : \
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
423 comment_style_none))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 /* Set up context_cache for position PT in BUF. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 static void
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
428 find_context (struct buffer *buf, Charbpos pt)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 /* This function can GC */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 844
diff changeset
431 Ichar prev_c, c;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
432 int prev_syncode, syncode;
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
433 Charbpos target = pt;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 665
diff changeset
434 struct syntax_cache *scache;
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 842
diff changeset
435 int spec = specpdl_depth ();
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 842
diff changeset
436
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 842
diff changeset
437 /* If we are narrowed, we will get confused. In fact, we are quite often
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 842
diff changeset
438 narrowed when this function is called. */
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 842
diff changeset
439 if (BUF_BEGV (buf) != BUF_BEG (buf) || BUF_ZV (buf) != BUF_Z (buf))
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 842
diff changeset
440 {
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 842
diff changeset
441 record_unwind_protect (save_restriction_restore,
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 842
diff changeset
442 save_restriction_save (buf));
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 842
diff changeset
443 Fwiden (wrap_buffer (buf));
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 842
diff changeset
444 }
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 665
diff changeset
445
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 setup_context_cache (buf, pt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 pt = context_cache.cur_point;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448
842
dc12269565c9 [xemacs-hg @ 2002-05-14 18:14:27 by ben]
ben
parents: 838
diff changeset
449 scache = setup_buffer_syntax_cache (buf, pt > BUF_BEGV (buf) ? pt - 1 : pt,
dc12269565c9 [xemacs-hg @ 2002-05-14 18:14:27 by ben]
ben
parents: 838
diff changeset
450 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 if (pt > BUF_BEGV (buf))
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
452 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
453 c = BUF_FETCH_CHAR (buf, pt - 1);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 665
diff changeset
454 syncode = SYNTAX_CODE_FROM_CACHE (scache, c);
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
455 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 else
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
457 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
458 c = '\n'; /* to get bol_context_cache at point-min */
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
459 syncode = Swhitespace;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
460 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 for (; pt < target; pt++, context_cache.cur_point = pt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 if (context_cache.needs_its_head_reexamined)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 if (context_cache.depth == 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 && context_cache.context == context_none)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 /* We've found an anchor spot.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 Try to put the start of defun within 6000 chars of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 the target, and the end of defun as close as possible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 6000 is also arbitrary but tries to strike a balance
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 between two conflicting pulls when dealing with a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 file that has lots of stuff sitting outside of a top-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 level form:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 a) If you move past the start of defun, you will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 have to recompute defun, which in this case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 means that start of defun goes all the way back
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 to the beginning of the file; so you want
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 to set start of defun a ways back from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 current point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 b) If you move a line backwards but within start of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 defun, you have to move back to start of defun;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 so you don't want start of defun too far from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 the current point.
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 if (target - context_cache.start_point > 6000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 context_cache.start_point = pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 context_cache.end_point = pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 bol_context_cache = context_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 665
diff changeset
495 UPDATE_SYNTAX_CACHE_FORWARD (scache, pt);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 prev_c = c;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
497 prev_syncode = syncode;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 c = BUF_FETCH_CHAR (buf, pt);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 665
diff changeset
499 syncode = SYNTAX_CODE_FROM_CACHE (scache, c);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 if (prev_c == '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 bol_context_cache = context_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 if (context_cache.backslash_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 context_cache.backslash_p = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 665
diff changeset
510 switch (SYNTAX_FROM_CODE (syncode))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 case Sescape:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 context_cache.backslash_p = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 case Sopen:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 if (context_cache.context == context_none)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 context_cache.depth++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 break;
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 case Sclose:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 if (context_cache.context == context_none)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 context_cache.depth--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 break;
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 case Scomment:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 if (context_cache.context == context_none)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 context_cache.context = context_comment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 context_cache.ccontext = ccontext_none;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
531 context_cache.style = SINGLE_SYNTAX_STYLE (syncode);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 if (context_cache.style == comment_style_none) abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 break;
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 case Sendcomment:
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
537 if (context_cache.style != SINGLE_SYNTAX_STYLE (syncode))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 else if (context_cache.context == context_comment)
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 context_cache.context = context_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 context_cache.style = comment_style_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 else if (context_cache.context == context_block_comment &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 (context_cache.ccontext == ccontext_start2 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 context_cache.ccontext == ccontext_end1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 context_cache.context = context_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 context_cache.ccontext = ccontext_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 context_cache.style = comment_style_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 case Sstring:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 if (context_cache.context == context_string &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 context_cache.scontext == c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 context_cache.context = context_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 context_cache.scontext = '\000';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 else if (context_cache.context == context_none)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
564 Lisp_Object stringtermobj =
1296
87084e8445a7 [xemacs-hg @ 2003-02-14 09:50:15 by ben]
ben
parents: 867
diff changeset
565 syntax_match (scache->syntax_table, c);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 844
diff changeset
566 Ichar stringterm;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 if (CHARP (stringtermobj))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 stringterm = XCHAR (stringtermobj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 stringterm = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 context_cache.context = context_string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 context_cache.scontext = stringterm;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 context_cache.ccontext = ccontext_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
578
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
579 case Scomment_fence:
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
580 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
581 if (context_cache.context == context_generic_comment)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
582 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
583 context_cache.context = context_none;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
584 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
585 else if (context_cache.context == context_none)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
586 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
587 context_cache.context = context_generic_comment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
588 context_cache.ccontext = ccontext_none;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
589 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
590 break;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
591 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
592
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
593 case Sstring_fence:
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
594 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
595 if (context_cache.context == context_generic_string)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
596 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
597 context_cache.context = context_none;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
598 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
599 else if (context_cache.context == context_none)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
600 {
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
601 context_cache.context = context_generic_string;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
602 context_cache.ccontext = ccontext_none;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
603 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
604 break;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
605 }
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
606
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 /* That takes care of the characters with manifest syntax.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 Now we've got to hack multi-char sequences that start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 and end block comments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 */
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
615 if ((SYNTAX_CODE_COMMENT_BITS (syncode) &
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 SYNTAX_SECOND_CHAR_START) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 context_cache.context == context_none &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 context_cache.ccontext == ccontext_start1 &&
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
619 SYNTAX_CODES_START_P (prev_syncode, syncode) /* the two chars match */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 context_cache.ccontext = ccontext_start2;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
623 context_cache.style = SYNTAX_START_STYLE (prev_syncode, syncode);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 if (context_cache.style == comment_style_none) abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
626 else if ((SYNTAX_CODE_COMMENT_BITS (syncode) &
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 SYNTAX_FIRST_CHAR_START) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 context_cache.context == context_none &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 (context_cache.ccontext == ccontext_none ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 context_cache.ccontext == ccontext_start1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 context_cache.ccontext = ccontext_start1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 context_cache.style = comment_style_none; /* should be this already*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
635 else if ((SYNTAX_CODE_COMMENT_BITS (syncode) &
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 SYNTAX_SECOND_CHAR_END) &&
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
637 context_cache.context ==
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
638 (enum syntactic_context) context_block_comment &&
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
639 context_cache.ccontext ==
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 563
diff changeset
640 (enum block_comment_context) ccontext_end1 &&
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
641 SYNTAX_CODES_END_P (prev_syncode, syncode) &&
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 /* the two chars match */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 context_cache.style ==
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
644 SYNTAX_END_STYLE (prev_syncode, syncode)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 context_cache.context = context_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 context_cache.ccontext = ccontext_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 context_cache.style = comment_style_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 }
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
651 else if ((SYNTAX_CODE_COMMENT_BITS (syncode) &
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 SYNTAX_FIRST_CHAR_END) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 context_cache.context == context_block_comment &&
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
654 context_cache.style == SINGLE_SYNTAX_STYLE (syncode) &&
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 (context_cache.ccontext == ccontext_start2 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 context_cache.ccontext == ccontext_end1))
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
657 /* #### is it right to check for end1 here??
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
658 yes, because this might be a repetition of the first char
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
659 of a comment-end sequence. ie, '/xxx foo xxx/' or
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
660 '/xxx foo x/', where 'x' = '*' -- mct */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 if (context_cache.style == comment_style_none) abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 context_cache.ccontext = ccontext_end1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 else if (context_cache.ccontext == ccontext_start1)
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 if (context_cache.context != context_none) abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 context_cache.ccontext = ccontext_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 else if (context_cache.ccontext == ccontext_end1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 if (context_cache.context != context_block_comment) abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 context_cache.context = context_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 context_cache.ccontext = ccontext_start2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 if (context_cache.ccontext == ccontext_start2 &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 context_cache.context == context_none)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 context_cache.context = context_block_comment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 if (context_cache.style == comment_style_none) abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 else if (context_cache.ccontext == ccontext_none &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 context_cache.context == context_block_comment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 context_cache.context = context_none;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 context_cache.needs_its_head_reexamined = 0;
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 842
diff changeset
692 unbind_to (spec);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 context_to_symbol (enum syntactic_context context)
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 switch (context)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 {
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
700 case context_none: return Qnil;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
701 case context_string: return Qstring;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
702 case context_comment: return Qcomment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
703 case context_block_comment: return Qblock_comment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
704 case context_generic_comment: return Qblock_comment;
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
705 case context_generic_string: return Qstring;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 default: abort (); return Qnil; /* suppress compiler warning */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 DEFUN ("buffer-syntactic-context", Fbuffer_syntactic_context, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 Return the syntactic context of BUFFER at point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 If BUFFER is nil or omitted, the current buffer is assumed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 The returned value is one of the following symbols:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 nil ; meaning no special interpretation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 string ; meaning point is within a string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 comment ; meaning point is within a line comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 block-comment ; meaning point is within a block comment
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 See also the function `buffer-syntactic-context-depth', which returns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 the current nesting-depth within all parenthesis-syntax delimiters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 and the function `syntactically-sectionize', which will map a function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 over each syntactic context in a region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 WARNING: this may alter match-data.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 find_context (buf, BUF_PT (buf));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 return context_to_symbol (context_cache.context);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 DEFUN ("buffer-syntactic-context-depth", Fbuffer_syntactic_context_depth,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 Return the depth within all parenthesis-syntax delimiters at point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 If BUFFER is nil or omitted, the current buffer is assumed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 WARNING: this may alter match-data.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 find_context (buf, BUF_PT (buf));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 return make_int (context_cache.depth);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 }
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 DEFUN ("syntactically-sectionize", Fsyntactically_sectionize, 3, 4, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 Call FUNCTION for each contiguous syntactic context in the region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 Call the given function with four arguments: the start and end of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 region, a symbol representing the syntactic context, and the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 depth (as returned by the functions `buffer-syntactic-context' and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 `buffer-syntactic-context-depth'). When this function is called, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 current buffer will be set to BUFFER.
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 WARNING: this may alter match-data.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 (function, start, end, buffer))
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 /* This function can GC */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
763 Charbpos s, pt, e;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 int edepth;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 enum syntactic_context this_context;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 Lisp_Object extent = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 struct gcpro gcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 get_buffer_range_char (buf, start, end, &s, &e, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 pt = s;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 find_context (buf, pt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 GCPRO1 (extent);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 while (pt < e)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
778 Charbpos estart, eend;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 /* skip over "blank" areas, and bug out at end-of-buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 while (context_cache.context == context_none)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 pt++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 if (pt >= e) goto DONE_LABEL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 find_context (buf, pt);
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 /* We've found a non-blank area; keep going until we reach its end */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 this_context = context_cache.context;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 estart = pt;
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 /* Minor kludge: consider the comment-start character(s) a part of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 the comment.
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 if (this_context == context_block_comment &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 context_cache.ccontext == ccontext_start2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 estart -= 2;
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
796 else if (this_context == context_comment
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
797 || this_context == context_generic_comment
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
798 )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 estart -= 1;
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 edepth = context_cache.depth;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 while (context_cache.context == this_context && pt < e)
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 pt++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 find_context (buf, pt);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 eend = pt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 /* Minor kludge: consider the character which terminated the comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 a part of the comment.
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 if ((this_context == context_block_comment ||
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
814 this_context == context_comment
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
815 || this_context == context_generic_comment
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 442
diff changeset
816 )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 && pt < e)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 eend++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 if (estart == eend)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 /* Make sure not to pass in values that are outside the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 actual bounds of this function. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 call4_in_buffer (buf, function, make_int (max (s, estart)),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 make_int (eend == e ? e : eend - 1),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 context_to_symbol (this_context),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 make_int (edepth));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 DONE_LABEL:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 }
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 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 syms_of_font_lock (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 460
diff changeset
837 DEFSYMBOL (Qcomment);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 460
diff changeset
838 DEFSYMBOL (Qblock_comment);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 460
diff changeset
839 DEFSYMBOL (Qbeginning_of_defun);
428
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 DEFSUBR (Fbuffer_syntactic_context);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 DEFSUBR (Fbuffer_syntactic_context_depth);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 DEFSUBR (Fsyntactically_sectionize);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 reinit_vars_of_font_lock (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 xzero (context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 xzero (bol_context_cache);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 vars_of_font_lock (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 }
838
bf645ed7cfe3 [xemacs-hg @ 2002-05-14 09:28:06 by ben]
ben
parents: 826
diff changeset
857
bf645ed7cfe3 [xemacs-hg @ 2002-05-14 09:28:06 by ben]
ben
parents: 826
diff changeset
858 #endif /* USE_C_FONT_LOCK */