all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: Alan Mackenzie <acm@muc.de>
Cc: "Vitalie Spinu" <spinuvit@gmail.com>,
	"Andreas Röhler" <andreas.roehler@online.de>,
	emacs-devel@gnu.org, "Stefan Monnier" <monnier@iro.umontreal.ca>,
	"Eli Zaretskii" <eliz@gnu.org>,
	"Drew Adams" <drew.adams@oracle.com>
Subject: Re: A vision for multiple major modes [was: Re: [Emacs-diffs] widen-limits c331b66:]
Date: Fri, 1 Apr 2016 04:15:18 +0300	[thread overview]
Message-ID: <654b8ea3-84ea-60d9-6fe1-b088d52579c3@yandex.ru> (raw)
In-Reply-To: <20160329000720.GC5095@acm.fritz.box>

On 03/29/2016 03:07 AM, Alan Mackenzie wrote:

>> E.g. (goto-char (match-end n)) is a common
>> idiom for syntax highlighting and indentation code.
>
> Yes, but that match is going to be in the same island, or at the very
> least, in the chain of islands containing the current one.

Would looking-at skip over intermediate islands? Basically, I wonder if

  (= (+ (match-beginning 0) (length (match-string 0))
     (match-end 0))

is going to always hold in that new world.

> Are you thinking more that `forward-char' should move from the end of an
> island to the beginning of the next island in a chain?

As one option, yes. Let's call it option A, and it entails renumerating 
buffer positions to avoid gaps.

>> True. I'm more worried about gaps. But they could be treated like
>> whitespace, I suppose.
>
> For example, by `forward-char'?  What primitives were you thinking of,
> here?

This would be option B. forward-char doesn't care if the characters are 
whitespace or not. I don't know if e.g. search-forward would see the 
contents of the intermediate islands as a bunch of actual space 
characters (it's something to consider).

Most importantly, the contents of intermediate islands would match 
"\\s-", and parse-partial-sexp would similarly skip over them.

>> Right. So then, some yet-unknown body of code has to become
>> island-aware, and the improvement is not that seamless anymore.
>
> The way I see it, the super modes would have to be totally aware of the
> island mechanism, but the major modes would be largely, it not totally,
> unaware of it.  `syntax-ppss' seems more part of the super mode
> mechanism.

At the very least, that does sound somewhat complicated.

>> What if var has an island-local binding? And my function has this:
>
>> (setq var 1)
>> (goto-char xx) ; where xx is in a different island
>
>> will its value change mid-program? What if xx is in the same island?
>> Will the value change then?
>
> A different island local binding would become current, so yes its value
> would thereby change.  Much like if var had a buffer local binding, and
> you do (set-buffer "foo"), the value of var you'd just set would no
> longer be in the current binding.  if xx is in the same island, the
> binding just setq'd would remain the same.

That might be something to look out for. Changing a buffer is an 
operation with big consequences, we know that already, but using 
goto-char didn't have too many implications until now (aside from 
point-entered hooks, I guess, which are being phased out).

>> I don't think either should be true. Then, the "adequate" model would
>> amount to changing them in post-command-hook anyway.
>
> What sort of variables are you thinking about here?  [ Some time later:]
> Could it be that it might be better to have "island chain local"
> variables rather than merely "island local" ones?

mmm-mode has both kinds.

> So that the three ruby
> lines in your example below would be three islands in a chain, and would
> thus all share a set of "island chain local" bindings rather than each
> line having its own binding?

Yes, probably. But that doesn't solve the above concern.

>> So making it seem, to the Lisp code, like the multiple related islands
>> don't have anything (for some definition of "anything") between them is
>> not a priority?
>
> By "related", I think you mean the same thing I meaan by "chained" - the
> three ruby mode lines enclosed in <%...%> in your example below, would be
> chained together by the super mode.

Yes, we can call them chained. As long as it doesn't imply anything 
about any presence of islands of other types between them.

>> Here's an example of ERB code Vitalie brought up recently:
>
>> <% if foo %>
>>    <%= bar(boo) %>
>> <% end %>
>
>> The parts of the buffer between %'s would be Ruby islands. The
>> suggestion was to use the value returned by the indentation function in
>> the second island (second line) to indent the "real" buffer contents.
>
> The question seems to be, are we indenting in the super mode or in each
> island?  The answer seems to be you'd want to indent in the super mode
> here, I think.

Indentation in the super mode would look like this:

   <% if foo %>
   <%= bar(boo) %>
   <% end %>

which is not what we'd really want. But yes, a good solution would take 
html-mode's indentation logic as a base, and modify it with the 
indentation offsets provided by the islands.

>> But: neither of the islands contains a newline. If they are combined in
>> the most straightforward way, the Ruby line will be 'if foo bar(boo)',
>> and its indentation would be not what we're looking for. I think the
>> current ways to look for a newline,
>
>>    (progn (skip-syntax-backward " ")
>>           (eq (char-before ?\n))
>
>> or
>
>>    (looking-at "\\s-$")
>
>> will fail to work. Also note that neither of the two islands in this
>> example contains the newline in question.
>
> Two?  Don't you mean three, here?  Is this a minor mistake in your
> counting or am I missing something important because I don't grok ruby?

The mistake would be mine, but really, I'm just talking about the first 
two. We're discussing the indentation of the second line. The third one 
is just here to make the example look more complete.

>> The "not chained" idea would require some explanation.
>
> For example, islands in a shell script which were individual AWK scripts
> would not be chained together.  But the three (?two) lines of ruby in the
> example above would be chained together.  I think we need to work this
> out more precisely.

Makes sense.

> For example, in the three ruby line scenario above, is there any variable
> you can think of for which it would be advantageous to have a binding
> for each island rather than a shared binding for the set of three (?two)?

Not off the top of my head. Maybe there's none.

> I'm kind of envisioning successive `forward-char's moving from the end
> of "<% if foo %>" to the beginning of "<%= bar(boo) %>", or even from
> the end of "if foo" to the beginning of "bar(boo)".  How does this sound?

Sounds like what I've calling option A above. Basically, my vague 
concerns are:

- Performance (checking islands boundaries in each primitive must incur 
overhead, even when there are no islands).
- Code complexity: new code paths that might be exercised not very often 
in the future. Hence, they could be prone to breakage. A dedicated test 
suite would help with that, though.

Also, think back to the problem of the absence of newlines in the Ruby 
islands in the above example. The indentation engine needs them, and it 
might be harder to make newlines appear both inside and outside of the 
Ruby islands (the html-mode indentation code needs them too, I'd wager). 
This is where option B has another advantage, aside from (probably) 
being easier to implement.



  reply	other threads:[~2016-04-01  1:15 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20160322022539.16038.77264@vcs.savannah.gnu.org>
     [not found] ` <E1aiC0q-0004DL-40@vcs.savannah.gnu.org>
2016-03-22 12:08   ` [Emacs-diffs] widen-limits c331b66: Implement buffer-widen-limits functionality Stefan Monnier
2016-03-22 19:44     ` Vitalie Spinu
2016-03-22 19:56       ` Drew Adams
2016-03-22 22:42         ` Vitalie Spinu
2016-03-23  0:44           ` Drew Adams
2016-03-23  7:16             ` Andreas Röhler
2016-03-23 11:58               ` Vitalie Spinu
2016-03-23 13:02                 ` Andreas Röhler
2016-03-23 14:17                   ` Vitalie Spinu
2016-03-23 15:34                     ` Eli Zaretskii
2016-03-23 17:24                       ` Andreas Röhler
2016-03-23 17:55                         ` Eli Zaretskii
2016-03-23 18:53                           ` Andreas Röhler
2016-03-23 21:57                             ` Drew Adams
2016-03-23 22:13                               ` Vitalie Spinu
2016-03-23 23:03                                 ` Drew Adams
2016-03-24  3:38                                 ` Eli Zaretskii
2016-03-24 12:24                                   ` Dmitry Gutov
2016-03-24 15:56                                     ` Eli Zaretskii
2016-03-24 18:55                                       ` Removing prog-indentation-context (was: [Emacs-diffs] widen-limits c331b66: Implement buffer-widen-limits functionality) Stefan Monnier
2016-03-25  0:53                                         ` Removing prog-indentation-context Dmitry Gutov
2016-03-25  1:29                                           ` Dmitry Gutov
2016-03-25  2:09                                           ` Stefan Monnier
2016-03-25 11:38                                             ` Dmitry Gutov
2016-03-26 22:29                                               ` John Wiegley
2016-03-28  1:03                                                 ` Dmitry Gutov
2016-03-25 15:45                                           ` Vitalie Spinu
2016-03-28 21:37                                             ` Dmitry Gutov
2016-03-28 22:08                                               ` Stefan Monnier
2016-03-28 22:55                                                 ` Dmitry Gutov
2016-03-28 23:24                                                   ` Stefan Monnier
2016-03-28  1:03                                       ` [Emacs-diffs] widen-limits c331b66: Implement buffer-widen-limits functionality Dmitry Gutov
2016-03-24  3:37                               ` Eli Zaretskii
2016-03-23 17:14                     ` Andreas Röhler
2016-03-24  0:03                       ` Vitalie Spinu
2016-03-24  0:37                         ` Drew Adams
2016-03-24  2:36                           ` Vitalie Spinu
2016-03-24 13:53                             ` Drew Adams
2016-03-24 13:57                               ` Dmitry Gutov
2016-03-24 14:31                                 ` Drew Adams
2016-03-24 14:56                                   ` Stefan Monnier
2016-03-24 15:13                                     ` Drew Adams
2016-03-24 15:20                                       ` Stefan Monnier
2016-03-24  7:00                         ` Andreas Röhler
2016-03-23 14:29                 ` Drew Adams
2016-03-23 21:16                 ` A vision for multiple major modes [was: Re: [Emacs-diffs] widen-limits c331b66:] Alan Mackenzie
2016-03-23 21:58                   ` Vitalie Spinu
2016-03-24 17:44                     ` Alan Mackenzie
2016-03-24 20:43                       ` Vitalie Spinu
2016-03-23 22:34                   ` Dmitry Gutov
2016-03-24 18:38                     ` Alan Mackenzie
2016-03-24 20:22                       ` Vitalie Spinu
2016-03-25  0:11                       ` Dmitry Gutov
2016-03-27 12:09                         ` Alan Mackenzie
2016-03-27 22:59                           ` Dmitry Gutov
2016-03-29  0:07                             ` Alan Mackenzie
2016-04-01  1:15                               ` Dmitry Gutov [this message]
2016-04-05 16:29                                 ` Alan Mackenzie
2016-04-05 22:52                                   ` Dmitry Gutov
2016-04-18 21:32                                     ` Alan Mackenzie
2016-03-28 13:00                       ` Filipp Gunbin
2016-03-25 18:20                   ` Phillip Lord

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=654b8ea3-84ea-60d9-6fe1-b088d52579c3@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=acm@muc.de \
    --cc=andreas.roehler@online.de \
    --cc=drew.adams@oracle.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=spinuvit@gmail.com \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.