unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: "Wedler, Christoph" <christoph.wedler@sap.com>,
	Eli Zaretskii <eliz@gnu.org>,
	"monnier@iro.umontreal.ca" <monnier@iro.umontreal.ca>,
	"emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: Re: [Emacs-diffs] scratch/widen-less a4ba846: Replace prog-widen with consolidating widen calls
Date: Sat, 16 Dec 2017 19:34:16 +0200	[thread overview]
Message-ID: <8e5adcd7-e085-e8d2-085f-398c660cd34d@yandex.ru> (raw)
In-Reply-To: <BEE4F6ED-B90A-4767-BA60-64758E37F642@sap.com>

[-- Attachment #1: Type: text/plain, Size: 3421 bytes --]

Hi Christoph,

On 12/15/17 5:48 PM, Wedler, Christoph wrote:
> Sorry for not having followed this discussion earlier - as the one who
> has somehow introduced `prog-indentation-context', I probably should have...

You checked out early from the previous discussion, so I didn't want to 
drag you in again. Hope that's okay.

> If it works and you tell me how to do it, I have no issues with an
> alternative way to make the indentation function of a "sub mode" work
> for code chunks inside an "outer language" (like ANTLR grammar files).

Is there a reason why you called narrow-to-region in 
antlr-python-indent-action-line anyway, even when using 
prog-indentation-context?

Because you do that, though, the "new way" should work with your code 
automatically. I'm attaching a patch with some minor cleanup, though.

Please try it with a build of Emacs from the 'widen-less' branch. Do you 
know how to build it?

> I you want to try some ANTLR grammar examples yourself, I would
> recommend:
> 
>   - antlr-mode 3.1.4
>     from https://sourceforge.net/projects/antlr-mode/files/
> 
>   - example grammar files, especially lines 46 to 51 in
>     https://github.com/antlr/examples-v3/blob/master/Python/C/C.g
> 
>   - and others in that repo (mentioned in line 100 of antlr-mode.el)

antlr-mode.el says these examples are to see the syntax highlighting. 
Any particular file and place to see how indentation works out? I 
couldn't find one from a cursory search.

> Now to the elements in `prog-indentation-context':
> 
>   - FIRST-COLUMN: I understood that you want to keep (s/th like) that...
> 
>   - (START . END) = the region of the code chunk: well, some indentation
>     engines got confused to see unknown code before code written in the
>     "sub-modes" - for some I could do `narrow-to-region' myself, other
>     engines did widen, like python.  IMHO, modes with widening provide a
>     better indentation experience than those without, see below.
> 
>   - PREVIOUS-CHUNKS: well, I was told to introduce this to be more
>     general... - some modes (like cc-mode) could be told that the code is
>     not some usual "top-level" code, but just some "normal statement".
>     (antlr-mode includes some ugly hack for cc-mode).
> 
> If all this is covered by a better way - fine with me!  Even if does not cover
> PREVIOUS-CHUNKS…

Yup.

> Now to a mode with non-widening indentation function: emacs-lisp mode:
> 
> Consider the following code
>      (defun foo ()
>        (+ 1 3))
> 
> I would assume that the indentation of line 2 does not change
> when I narrow to line 2 - but Emacs-25.1.1 now deletes the first 2
> spaces of line 2...  (yes; I also need to update to a newer Emacs)

Try out the widen-less branch!

And also, can we get your help with the manual? It still says:

Examples include
  @dfn{literate programming} source files that combine documentation and
  snippets of source code, Yacc/Bison programs that include snippets of
  plain C code, etc.  To correctly indent the embedded chunks, the primary
  mode needs to delegate the indentation to another mode's indentation
  engine (e.g., call @code{c-indent-defun} for C code or
  @code{python-indent-line} for Python)

I.e., it still mentions C and c-indent-defun (?). But c-indent-defun 
does not work for embedded chunks (yet)!

Can we replace that mentions with JS and js-indent-line, for instance? 
Would that still make sense?

[-- Attachment #2: antlr-mode-cleanup.diff --]
[-- Type: text/x-patch, Size: 1135 bytes --]

diff -u --label /home/dgutov/examples/antlr/antlr-mode.el --label \#\<buffer\ antlr-mode.el\> /home/dgutov/examples/antlr/antlr-mode.el /tmp/buffer-content-4j5MsU
--- /home/dgutov/examples/antlr/antlr-mode.el
+++ #<buffer antlr-mode.el>
@@ -3408,12 +3408,10 @@
     (when (and boa
                (eq antlr-indent-comment t) ; indent-region
                (boundp 'prog-indentation-context)) ; Emacs 24.5 or later
-      (let ((syntax-ppss-cache nil) ;#dynamic
-            (syntax-ppss-last nil) ;#dynamic
-            ;; TODO: do we also need to call `syntax-propertize'?
-            ;; and/or bind `syntax-propertize-function'?
-            (prog-indentation-context ;#dynamic
-             (list (+ leftouter c-basic-offset) (list (1+ boa)))))
+      (let ((prog-indentation-context ;#dynamic
+             (list (+ leftouter c-basic-offset))))
+        ;; TODO: do we also need to call `syntax-propertize'?
+        ;; and/or bind `syntax-propertize-function'?
         (narrow-to-region (1+ boa) (point-max))
         (python-indent-line (eq this-command 'antlr-indent-command))))))
 

Diff finished.  Sat Dec 16 19:27:17 2017

  parent reply	other threads:[~2017-12-16 17:34 UTC|newest]

Thread overview: 115+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-15 15:48 [Emacs-diffs] scratch/widen-less a4ba846: Replace prog-widen with consolidating widen calls Wedler, Christoph
2017-12-16 15:00 ` Stefan Monnier
2017-12-16 17:34 ` Dmitry Gutov [this message]
2017-12-18 12:39   ` Wedler, Christoph
2017-12-18 14:50     ` Dmitry Gutov
2017-12-18 17:41       ` Wedler, Christoph
2017-12-19  0:27         ` Dmitry Gutov
2017-12-19 11:27           ` Wedler, Christoph
2017-12-20  0:07             ` Dmitry Gutov
     [not found] <20171129233237.27462.23351@vcs0.savannah.gnu.org>
     [not found] ` <20171129233238.504B5204F1@vcs0.savannah.gnu.org>
2017-11-30  1:53   ` Stefan Monnier
2017-11-30  8:59     ` Dmitry Gutov
2017-11-30 10:58       ` Dmitry Gutov
2017-11-30 15:31         ` Tom Tromey
2017-11-30 21:28           ` Dmitry Gutov
2017-11-30 21:46         ` Alan Mackenzie
2017-11-30 23:09           ` Dmitry Gutov
2017-12-01 15:49             ` Alan Mackenzie
2017-12-01 16:26               ` Stefan Monnier
2017-12-01 18:20                 ` Alan Mackenzie
2017-12-01 18:59                 ` Dmitry Gutov
2017-12-01 19:51                   ` Stefan Monnier
2017-12-01 20:50                     ` Dmitry Gutov
2017-12-02  2:24                       ` Stefan Monnier
2017-12-02 20:01                         ` Dmitry Gutov
2017-12-02 23:47                           ` Stefan Monnier
2017-12-03  3:38                             ` Eli Zaretskii
2017-12-03 23:43                               ` Dmitry Gutov
2017-12-04  3:38                                 ` Eli Zaretskii
2017-12-04 11:53                                   ` Dmitry Gutov
2017-12-04 16:41                                     ` Eli Zaretskii
2017-12-04 17:45                                       ` Stefan Monnier
2017-12-05  0:10                                       ` Dmitry Gutov
2017-12-03 16:42                             ` Dmitry Gutov
2017-12-03 21:23                               ` Stefan Monnier
2017-12-03 23:58                                 ` Dmitry Gutov
2017-12-01 17:06               ` Drew Adams
2017-12-01 18:03               ` Stefan Monnier
2017-12-01 21:27                 ` Vitalie Spinu
2017-12-01 21:38                   ` Dmitry Gutov
2017-12-01 22:45                 ` Alan Mackenzie
2017-12-02  2:53                   ` Stefan Monnier
2017-12-02 14:02                     ` Tom Tromey
2017-12-02 23:48                   ` Richard Stallman
2017-12-01 19:13               ` Dmitry Gutov
2017-12-01 22:35                 ` Alan Mackenzie
2017-12-01 23:24                   ` Dmitry Gutov
2017-12-02  2:47                     ` Stefan Monnier
2017-12-02 20:28                       ` Alan Mackenzie
2017-12-03  0:03                         ` Stefan Monnier
2017-12-03 12:18                           ` Alan Mackenzie
2017-12-03 16:02                             ` Dmitry Gutov
2017-12-03  3:52                         ` Dmitry Gutov
2017-12-03 14:54                           ` Alan Mackenzie
2017-12-03 18:40                             ` Stefan Monnier
2017-12-03 22:26                               ` Alan Mackenzie
2017-12-03 23:42                                 ` Stefan Monnier
2017-12-03 23:53                             ` Dmitry Gutov
2017-12-02  8:27                     ` Eli Zaretskii
2017-12-02 10:50                       ` Dmitry Gutov
2017-12-02 11:10                         ` Eli Zaretskii
2017-12-02 16:41                           ` Stefan Monnier
2017-12-02 17:13                             ` Eli Zaretskii
2017-12-02 17:53                               ` Stefan Monnier
2017-12-02 18:33                                 ` Eli Zaretskii
2017-12-02 20:18                               ` Dmitry Gutov
2017-12-02 20:14                           ` Dmitry Gutov
2017-12-02 20:58                             ` Eli Zaretskii
2017-12-02 21:35                               ` Dmitry Gutov
2017-12-03 15:28                                 ` Eli Zaretskii
2017-12-03 16:35                                   ` Dmitry Gutov
2017-12-03 17:20                                     ` Eli Zaretskii
2017-12-03 19:43                                       ` Dmitry Gutov
2017-12-04 15:52                                         ` Eli Zaretskii
2017-12-04 16:35                                           ` Stefan Monnier
2017-12-04 16:56                                             ` Eli Zaretskii
2017-12-04 22:57                                               ` Dmitry Gutov
2017-12-04 23:27                                           ` Dmitry Gutov
2017-12-03 18:59                                     ` Alan Mackenzie
2017-12-03 19:25                                       ` Eli Zaretskii
2017-12-03 21:20                                         ` Alan Mackenzie
2017-12-04 16:10                                           ` Eli Zaretskii
2017-12-04 16:23                                             ` Alan Mackenzie
2017-12-04 16:48                                               ` Eli Zaretskii
2017-12-03 22:01                                       ` Stefan Monnier
2017-12-04  0:37                                       ` Dmitry Gutov
2017-12-04 15:52                                         ` Alan Mackenzie
2017-12-04 16:46                                           ` Eli Zaretskii
2017-12-05 13:08                                           ` Dmitry Gutov
2017-12-03 21:52                                   ` Stefan Monnier
2017-12-04  0:03                                     ` Dmitry Gutov
2017-12-04 16:12                                     ` Eli Zaretskii
2017-12-04 16:49                                       ` Stefan Monnier
2017-12-04 17:28                                         ` Eli Zaretskii
2017-12-04 21:52                                           ` Dmitry Gutov
2017-12-05  5:08                                             ` Eli Zaretskii
2017-12-05  5:33                                               ` Eli Zaretskii
2017-12-05 10:55                                                 ` Dmitry Gutov
2017-12-05 17:53                                                   ` Eli Zaretskii
2017-12-05 18:40                                                     ` Dmitry Gutov
2017-12-05 20:49                                                       ` Eli Zaretskii
2017-12-05 23:16                                                         ` Dmitry Gutov
2017-12-06  9:28                                                           ` Eli Zaretskii
2017-12-06 13:36                                                             ` Dmitry Gutov
2017-12-08 16:41                                                               ` Eli Zaretskii
2017-12-09 15:17                                                                 ` Dmitry Gutov
2017-12-09 15:43                                                                   ` Eli Zaretskii
2017-12-10 19:59                                                                     ` Dmitry Gutov
2017-12-10 20:04                                                                       ` Eli Zaretskii
2017-12-05 12:55                                               ` Dmitry Gutov
2017-12-05 17:57                                                 ` Eli Zaretskii
2017-12-05 18:54                                                   ` Dmitry Gutov
2017-12-05 20:48                                                     ` Eli Zaretskii
2017-12-05 21:08                                                       ` Ingo Lohmar
2017-12-06  9:26                                                         ` Eli Zaretskii
2017-12-06 13:37                                                       ` Dmitry Gutov

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=8e5adcd7-e085-e8d2-085f-398c660cd34d@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=christoph.wedler@sap.com \
    --cc=eliz@gnu.org \
    --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).