unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Vitalie Spinu <spinuvit@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Alan Mackenzie <acm@muc.de>, emacs-devel <emacs-devel@gnu.org>,
	Dmitry Gutov <dgutov@yandex.ru>
Subject: Re: Syntax tables for multiple modes [was: bug#22983: syntax-ppss returns wrong result.]
Date: Mon, 21 Mar 2016 17:45:38 +0100	[thread overview]
Message-ID: <87bn67eq4t.fsf@gmail.com> (raw)
In-Reply-To: <jwvlh5bx6bc.fsf-monnier+Inbox@gnu.org> (Stefan Monnier's message of "Mon, 21 Mar 2016 10:43:56 -0400")


I have split the answer in two separate conceptually distinct parts. This one is
about indentation complexities of generic multi-modes.

>> On Mon, Mar 21 2016 10:43, Stefan Monnier wrote:

>> Current prog-indentation-context allows for possibility of a string to be
>> inserted before begging in of current chunk.  STRING-BEFORE is more more
>> general than that because of the arbitrary POS that it can be applied to.

> Good point.  I didn't think of that.  Do you make use of that
> possibility, and/or can you give an example where it's useful?

Please see example of erb mode below.

>> Here is a simple example when inner mode cannot decide by itself on
>> the indentation.  Assume for concreteness a noweb header with some code
>> immediately following the header:
>>
>>   <<foo, some_arg=4>>= some_call(blabla) 
>>       some_other_call(blabla) ## indented by offset 2 with respect to header or prev_chunk
>>
>> How do you indent the some_call(blabal) after the header? The most
>> meaningful way is to keep it untouched just as user defined it. If
>> inner mode would indent it by itself it would give offset of 4. This
>> is a simple example of header dependence.

> Maybe it's because I'm not familiar with noweb, but I didn't understand this
> example.  It looks like a very interesting example, so could you go over it
> again in much more detail?


Noweb is not essential here. The story will hold for pretty much all multi-modes
with non-full-line headers. In noweb `<<foo, some_arg=4>>=` is a header of a
chunk. Polymode places heads and tail in their own modes because they are not
conceptually part of nor host or sub-mode. You can specify arbitrary parameters
in the head which might even instruct how to indent the chunk. The first code
line `some_call(blabla)` is placed on the same line with the head. This is
uncommon but it's the simplest real case I can think of.

There are two issues here.

First one is how do you indent the head itself? Let's assume the point is after
`foo`. If you follow the naive prog-indentation-context the indentation should
be handled by the mode in the head chunk, right? Let's call it
noweb-head-mode. This mode is the same for many noweb host-mode/inner-mode
combinations and defaults to poly-head-tail-mode. Host mode is commonly LaTeX
but it can be anything. One reasonable way to indent it is to use the host mode
indentation engine. Note that this is in contrast of the
prog-indentation-context assumption for which PREVIOUS-CHUNK is assumed to be of
the same mode type as the current type.

The second issue is with respect to the first line immediately after the
header. If you naively call inner mode indentation engine on that line in a
narrowed buffer starting after >>= you will get it indented to FIRST-COLUMN,
which in the above case is the indentation of the head, plus noweb chunk offset
which is a polymode specific thing and it is customizable per inner mode. Do you
really want to insert that space after >>=? Probably not. So the code following
the header is special. That means that you will either have to take care of that
in multi-mode engine or extend prog-indentation-context.

Think of markdown simple code spans `this = is(a, codes, span)` which can occur
anywhere in the buffer. Indentation is not meaningful within the span at all,
the whole chunk should be indented by the outer mode just before the opening `.

Real trouble comes with continuation chunks. You might need to have a completely
reversed indentation logic - in outer/host spans MM engine needs to call inner
mode for indentation. Consider this example of erb mode taken from
https://github.com/fxbois/web-mode/blob/master/tests/demo.erb.

    <div id='header'>
      <% if signed_in? -%>
        <%= link_to t('.sign_out'), sign_out_path, :method => :delete %>
      <% else -%>
        <%= link_to t('.sign_in'), sign_in_path %>
      <% end -%>
    </div>

One meaningful approach here is to indent if-else-end block using inner mode
rules, right? This is what web-mode seems to be currently doing. Assume you are
just in front of `<%= link_to`. This is host hmtl mode. But you need to indent
according to inner mode construct. So what do you do? You go to the end of
previous code chunk and call prog-indentation-function of inner mode with
STRING-BEFORE = "\n" and STRING-AFTER="link_to t('.sign_out'), sign_out_path,
:method => :delete". Simple isn't it? That's precisely my proposal.

The message is that whatever you try you will not be able to completely leave
all the work to inner mode or capture it with naive constructs like
prog-indentation-context. Quite the opposite, new complexities are likely to
make multi-mode authors life harder.


  Vitalie




  parent reply	other threads:[~2016-03-21 16:45 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20160311151512.GD2888@acm.fritz.box>
     [not found] ` <b158555f-e014-ed7b-23eb-d80d2d77a6f4@yandex.ru>
     [not found]   ` <20160311212410.GG2888@acm.fritz.box>
     [not found]     ` <73903215-f94b-e194-7bfe-0d6350c95769@yandex.ru>
     [not found]       ` <20160311221540.GH2888@acm.fritz.box>
     [not found]         ` <2c301ec9-041d-9172-d628-479062314b23@yandex.ru>
2016-03-14 15:16           ` Syntax tables for multiple modes [was: bug#22983: syntax-ppss returns wrong result.] Alan Mackenzie
2016-03-14 17:34             ` Andreas Röhler
2016-03-14 20:06             ` Dmitry Gutov
2016-03-19 22:51               ` Vitalie Spinu
2016-03-20  2:19                 ` Dmitry Gutov
2016-03-20 12:15                   ` Vitalie Spinu
2016-03-20 15:58                     ` Dmitry Gutov
2016-03-21  1:05                       ` Vitalie Spinu
2016-03-21  3:11                         ` Stefan Monnier
2016-03-21  5:05                           ` Vitalie Spinu
2016-03-21  7:13                             ` Andreas Röhler
2016-03-21 12:26                             ` Stefan Monnier
2016-03-21 14:13                               ` Vitalie Spinu
2016-03-21 14:43                                 ` Stefan Monnier
2016-03-21 16:42                                   ` Vitalie Spinu
2016-03-21 18:31                                     ` Stefan Monnier
2016-03-21 19:16                                       ` Vitalie Spinu
2016-03-21 20:47                                         ` Stefan Monnier
2016-03-21 20:33                                     ` Alan Mackenzie
2016-03-21 20:49                                       ` Stefan Monnier
2016-03-21 21:03                                       ` Drew Adams
2016-03-21 21:12                                       ` Dmitry Gutov
2016-03-21 16:45                                   ` Vitalie Spinu [this message]
2016-03-21 22:55                                     ` Dmitry Gutov
2016-03-22 14:51                                     ` Stefan Monnier
2016-03-22 18:17                                       ` Vitalie Spinu
2016-03-23  1:18                                         ` Dmitry Gutov
2016-03-23 13:18                                         ` Stefan Monnier
2016-03-22 18:26                                       ` Vitalie Spinu
2016-03-23  2:07                                         ` Stefan Monnier
2016-03-23 10:56                                           ` Vitalie Spinu
2016-03-23 11:41                                             ` Stefan Monnier
2016-03-23 12:39                                               ` Vitalie Spinu
2016-03-23 13:23                                                 ` Stefan Monnier
2016-03-23 15:28                                                   ` Dmitry Gutov
2016-03-23 21:51                                                     ` Vitalie Spinu
2016-03-24  7:30                                               ` Andreas Röhler
2016-03-21 11:56                           ` Dmitry Gutov
2016-03-21  5:08                         ` [Patch] hard-widen-limits [was Re: Syntax tables for multiple modes [was: bug#22983: syntax-ppss returns wrong result.]] Vitalie Spinu
2016-03-21 12:39                           ` Stefan Monnier
2016-03-21 12:54                             ` Vitalie Spinu
2016-03-21 14:07                               ` Stefan Monnier
2016-03-21 14:14                                 ` Vitalie Spinu
2016-03-21 14:04                             ` Stefan Monnier
2016-03-21 14:33                               ` Vitalie Spinu
2016-03-21 14:54                                 ` Stefan Monnier
2016-03-21 17:16                                   ` Vitalie Spinu
2016-03-21 18:36                                     ` Stefan Monnier
2016-03-21 19:18                                       ` Vitalie Spinu
2016-03-22  3:17                                         ` Vitalie Spinu
2016-03-22  9:57                                           ` Vitalie Spinu
2016-03-22 10:05                                             ` Vitalie Spinu
2016-03-22 11:57                                               ` Stefan Monnier
2016-03-22 16:28                                                 ` Vitalie Spinu
2016-03-22 16:44                                                   ` Stefan Monnier
2016-03-22 19:36                                                     ` Vitalie Spinu
2016-03-23  2:22                                                       ` Stefan Monnier
2016-03-23 11:41                                                         ` Vitalie Spinu
2016-03-23 12:34                                                           ` Stefan Monnier
2016-03-23 12:41                                                             ` Vitalie Spinu
2016-03-29 21:43                                                               ` Vitalie Spinu
2016-04-22 14:34                                                                 ` Dmitry Gutov
2016-04-24  7:22                                                                   ` Vitalie Spinu
2016-04-24  7:28                                                                     ` Achim Gratz
2016-04-24 11:33                                                                       ` Vitalie Spinu
2016-04-24 13:20                                                                         ` Andreas Schwab
2016-04-24 16:11                                                                           ` Vitalie Spinu
2016-04-24 16:19                                                                             ` Andreas Schwab
2016-04-24 16:41                                                                               ` Vitalie Spinu
2016-04-24 16:48                                                                                 ` Andreas Schwab
2016-04-24 18:01                                                                                   ` Vitalie Spinu
2016-04-24 19:05                                                                                     ` Andreas Schwab
2016-04-28 13:29                                                 ` Vitalie Spinu
2016-04-30 14:06                                                   ` Stefan Monnier
2016-03-22 20:08                                               ` Richard Stallman
2016-03-22 22:45                                                 ` Vitalie Spinu
2016-03-21 11:47                         ` Syntax tables for multiple modes [was: bug#22983: syntax-ppss returns wrong result.] Dmitry Gutov
2016-03-21 12:40                           ` Vitalie Spinu
2016-03-21 13:07                             ` Dmitry Gutov
2016-03-21 14:20                               ` Vitalie Spinu
2016-03-21 14:29                                 ` Dmitry Gutov
2016-03-21 14:42                                   ` Vitalie Spinu
2016-03-21 14:56                                     ` Dmitry Gutov
2016-03-21 16:52                                       ` Vitalie Spinu
2016-03-21 21:30                                         ` Dmitry Gutov
2016-04-03 23:34                                           ` John Wiegley
2016-03-21 14:02                             ` Stefan Monnier
2016-03-21 14:31                               ` Vitalie Spinu
2016-03-21 15:06                                 ` Stefan Monnier
2016-03-21 17:15                                   ` Andreas Röhler

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=87bn67eq4t.fsf@gmail.com \
    --to=spinuvit@gmail.com \
    --cc=acm@muc.de \
    --cc=dgutov@yandex.ru \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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).