emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Emacs-diffs] scratch/widen-less a4ba846: Replace prog-widen with co


From: Dmitry Gutov
Subject: Re: [Emacs-diffs] scratch/widen-less a4ba846: Replace prog-widen with consolidating widen calls
Date: Sat, 16 Dec 2017 19:34:16 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:58.0) Gecko/20100101 Thunderbird/58.0

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: antlr-mode-cleanup.diff
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]