From: "Stefan Monnier" <monnier+gnu/emacs@cs.yale.edu>
Cc: emacs-devel@gnu.org
Subject: mmm-mode needs (was: narrow-to-here-document)
Date: Tue, 08 Jul 2003 10:12:19 -0400 [thread overview]
Message-ID: <200307081412.h68ECKCD009746@rum.cs.yale.edu> (raw)
In-Reply-To: 20030707234541.GC11786@schilling.ugcs.caltech.edu
> Our current implementation is able to do reasonably well by using
> font-lock-fontify-region-function and font-lock-beginning-of-syntax-function,
> but we'd love to have better support from font-lock (and other
> packages) for this sort of thing. Thanks, Stefan, for crossposting to
> the mmm list, since I wasn't following emacs-devel.
I wish package developers were more proactive in requesting features.
Especially since oftentimes the feature already exists (although not
in your case, I'm afraid) but also because it gives us more information
about what direction Elisp should be heading into.
> Briefly, the way mmm-mode works is to parse the buffer for regions
> that it thinks (based on its configuration) ought to be edited using a
> different major mode, and create overlays to mark those positions.
Is the parsing done "eagerly" when opening a file, or is it done
on-demand, à la jit-lock ? If done eagerly, has the parsing time
ever been a problem (as in font-lock where the solution was to have
font-lock-maximum-size before jit-lock) ?
What kind of granularity has mmm-mode been used at ?
I.e. has it been used with hundreds of "regions" ?
What about treating strings and comments as separate regions ?
> (It's not currently as good as we'd like at updating these overlays
> dynamically as text is edited, but I believe this is just because no
> one has sat down to write good code to do it.)
I tend to think of strings and comments as being in the same category
as here-documents, C-in-yacc, javascript-in-html, ...
For strings and comments, the boundaries are recognized by the syntax-tables
and syntax-ppss can be used to efficiently determine the "current mode"
as well as the starting point of that mode (and together with
parse-partial-sexp is can also give you the end point). It doesn't use
overlays, but the dynamic updating works rather well.
What do you think about extending syntax-tables to recognize an extensible
set of "mode switch" markers (rather than just comment-start, comment-end,
and string).
> I don't mean to co-opt this disucssion for mmm, since it started on a
> somewhat different (though related) topic. But a "wish list" of
I'm highly interested in Emacs's support for language syntax and mmm-mode
is an important aspect of it.
> 1. Have a "registry" of some sort for major modes, where they can
> store enough information for mmm to turn them on effectively in small
> regions. Currently, the way mmm finds out what local variables and so
> on to set for each mode is to create temporary buffers and save the
> values of individual local variables. Among other things, this
> requires mmm mode knowing about all local variables that any major
> mode could want to set, and so we have a huge list of what variables
> to look for and what modes to look for them in. In addition, some
Why not use `buffer-local-variables' ?
[ Don't take that to mean I think you're an idiot or something:
I'm just trying to better understand where the current features
are failing. ]
> major modes expect things like a file name set in all buffers, so we
> have to do kludgy things to the temporary buffer to try to make them
> work.
Why do you have to use a temporary buffer rather than the current
buffer exactly ?
> 2. Have some sort of built-in support for variables that are localized
> to a text region within a buffer, such as an overlay or a text
> property. I'm not sure how or if this would work in general, but it's
> effectively what mmm does already to some extent.
Is there a particular problem with the way mmm-mode does it ?
> In particular, some
> variables want to keep different values in different regions even of
> the same major mode, in particular variables that store the state of
> syntax parsing. This leads to...
I don't understand this part. Since currently such region-local variables
don't exist, packages use other ways to store the info than a variable:
either in a list (that's what I use in syntax-ppss) or in overlays or
text-properties, ...
> 3. Better support in the syntax parsing routines allowing the caller
> to specify starting and ending positions and states. One of
That's generally between very difficult and impossible: many/most
indentation algorithms don't have an explicit notion of `state'
(they actually work backwards from the indentation-point trying to find
a place w.r.t which they can indent).
> our biggest problems is that submodes end up trying to parse their
> syntax beyond the beginning of their region and getting confused, so
> ideally we would be able to tell them where to start their parsing,
> and what state to start parsing in. Sometimes the start state needs
> to be a continuation of the end state of the previous region in that
> mode (as with some literate programming, PHP, etc.), but sometimes
> it ought to be an independent start for each region.
>
> This is similar to the 'syntactic realm' idea that David Kastrup
> suggested. I don't think we've tried using intangible properties, for
> the reasons mentioned and perhaps others, but Joe Kelsey has had some
> success using syntax-table text properties to make the text that's not
> supposed to be parsed be treated as a single word or as whitespace, as
> appropriate. Joe, want to comment?
I think making the "outside" text intangible or whitespace-like or word-like
or comment-like is indeed the best approach. Fiddling with syntax-tables
is not 100% because many indentation algorithms don't use syntax-tables or
at least not exclusively, so they may not always expect to have to jump over
a comment, or they use "[ \t]" rather than "\\s-" or ...
Has anybody tried to play with point-entered/point-left or with
intangible ?
In any case it seems difficult with the current Emacs to make it work
reliably without having to adjust the indentation code in a few places,
so the Joe's approach might indeed be the best option (together with
a bit of collaboration from the major mode).
> 4. Effectively the same thing for font-lock, which uses the syntax
> parsing functions but also its own parsing functions. In general
> we've had more success hacking around font-lock than around syntax,
> because font-lock provides more customization variables and its state
> is easier to understand.
Also font-lock doesn't keep much state between lines.
Is mmm-mode line-oriented as well ?
> If we want to continue this discussion, should it stay crossposted, or
> only on emacs-devel?
It should definitely be on emacs-devel. Whether it should be crossposted
to mmm-mode, I don't have an opinion.
Stefan
next prev parent reply other threads:[~2003-07-08 14:12 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-20 13:59 narrow-to-here-document Masatake YAMATO
2003-06-20 14:10 ` narrow-to-here-document Ilya Zakharevich
2003-06-20 16:26 ` narrow-to-here-document Masatake YAMATO
2003-06-21 7:15 ` narrow-to-here-document Stephen J. Turnbull
2003-06-21 8:01 ` narrow-to-here-document David Kastrup
2003-06-21 14:19 ` narrow-to-here-document Ilya Zakharevich
2003-06-21 14:48 ` narrow-to-here-document David Kastrup
2003-06-22 8:33 ` narrow-to-here-document Ilya Zakharevich
2003-06-23 17:10 ` narrow-to-here-document Kevin Rodgers
2003-06-25 6:10 ` narrow-to-here-document Masatake YAMATO
2003-06-25 8:04 ` narrow-to-here-document David Kastrup
2003-06-25 8:21 ` narrow-to-here-document Masatake YAMATO
2003-06-26 0:34 ` narrow-to-here-document Kim F. Storm
2003-06-26 5:30 ` narrow-to-here-document Richard Stallman
2003-06-25 23:18 ` narrow-to-here-document Stefan Daschek
2003-06-26 5:59 ` mmm-mode.el(Re: narrow-to-here-document) Masatake YAMATO
2003-06-26 6:12 ` narrow-to-here-document David Kastrup
2003-06-26 13:00 ` narrow-to-here-document Alan Shutko
2003-06-30 0:34 ` narrow-to-here-document Miles Bader
2003-06-30 6:13 ` narrow-to-here-document Kai Großjohann
2003-06-30 17:19 ` narrow-to-here-document David Kastrup
2003-06-30 20:11 ` narrow-to-here-document Kai Großjohann
2003-07-04 0:07 ` narrow-to-here-document Stefan Monnier
2003-07-04 6:46 ` narrow-to-here-document Kai Großjohann
2003-07-01 15:17 ` narrow-to-here-document Richard Stallman
2003-07-04 0:32 ` narrow-to-here-document Stefan Monnier
2003-07-07 23:45 ` [MMM] narrow-to-here-document Michael A. Shulman
2003-07-08 7:19 ` Kai Großjohann
2003-07-10 16:44 ` Richard Stallman
2003-07-08 14:12 ` Stefan Monnier [this message]
2003-07-08 20:02 ` Richard Stallman
2003-06-25 16:58 ` narrow-to-here-document Kevin Rodgers
[not found] ` <20030625.143750.116352160.jet@gyve.org>
2003-06-26 5:29 ` narrow-to-here-document Richard Stallman
2003-06-26 7:19 ` narrow-to-here-document Miles Bader
2003-06-26 17:45 ` narrow-to-here-document Tak Ota
2003-06-26 23:10 ` narrow-to-here-document David Kastrup
2003-06-27 2:07 ` narrow-to-here-document Miles Bader
2003-06-27 2:49 ` narrow-to-here-document Richard Stallman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200307081412.h68ECKCD009746@rum.cs.yale.edu \
--to=monnier+gnu/emacs@cs.yale.edu \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).