emacs-devel
[Top][All Lists]
Advanced

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

RE: antlr-mode.el - need some support by python.el


From: Wedler, Christoph
Subject: RE: antlr-mode.el - need some support by python.el
Date: Fri, 13 Feb 2015 10:56:45 +0000

> I'd use prog-indentation-context.

OK, I append a patch for prog-mode.el below.

 >> The values are provided by the outer mode.  But the inner mode decides
 >> what it expects in <future> (that's why I called it SUBMODE-SPECIFIC in
 >> the "real doc").

 > That requires some cross-knowledge of the two modes.  It's not ideal,
 > but I guess it's OK.

You are right, it is not ideal.  I do not think it requires cross-knowledge,
just some knowledge by the outer mode about the inner (bad for me ;-))

What I deduce from your text is that you do not like to have this
variable "polluted" by some sub-mode specific stuff - and I do agree.

In the patch below I have now deleted SUBMODE-SPECIFIC.  It has the
advantage that we could extend the variable with some future generic
context info in a compatible manner.

Instead, I added a paragraph in the doc string that sub modes can define
their own `SUB-extra-indentation-context', which would have the
additional advantage that the variable content is documented.

 >> [...] that would require them to create a temporary buffer for the
 >> indent calculation.

 > Not necessarily: the submode can just go to the end of the previous
 > chunk, compute some state at that position and use that state as initial
 > context at MIN.

... if scan-lists, mode-specific skip-comments etc are prepared for this.

It would also not help me as the previous chunks are not part of the
ANTLR grammar buffer (but of the ANTLR code generation code) - I could
just fake some context _string_. (Providing the context as a string
would be actually the easiest for me.)

        Christoph

diff -c prog-mode.el.\~24.4\~ prog-mode.el
*** prog-mode.el.~24.4~ 2014-04-27 19:41:16.000000000 +0000
--- prog-mode.el        2015-02-13 09:19:26.285457000 +0000
***************
*** 41,46 ****
--- 41,76 ----
      map)
    "Keymap used for programming modes.")
  
+ (defvar prog-indentation-context nil
+   "Non-nil while indenting lines considered as belonging to a sub mode.
+ There are languages where part of the code is actually written in
+ a sub language, e.g., a Yacc/Bison or ANTLR grammar also consists
+ of plain C code.  This variables enables the major mode of the
+ main language to use the indentation function of the sub language
+ for lines belonging the code of the sub language.
+ 
+ When a major mode of such a main language decides to propagate the
+ indentation of a line/region to the indentation engine of the sub
+ mode, it is supposed to bind this variable to non-nil around the call.
+ 
+ The non-nil value looks as follows
+    ((MIN . MAX) LEFTMOST-COL)
+ 
+ MIN to MAX is the region consisting of code of the sub mode.
+ LEFTMOST-COL is the minimum column the indentation engine of the
+ sub mode should choose (instead of 0).
+ 
+ It is the task of the calling main mode to (temporary) set the
+ syntax table and related variables to values suitable for the sub
+ mode, and to call `syntax-ppss-flush-cache' if necessary.
+ 
+ If the indentation engine of the sub mode SUB depends on some
+ global context, it may introduce a variable named
+ `SUB-extra-indentation-context', which is to be bound like this
+ variable by the main major mode.  For example, cc-mode might
+ define `c-extra-indentation-context' which is to be bound to a
+ list of SYNTACTIC-SYMBOL as explained in `c-offsets-alist'.")
+ 
  (defun prog-indent-sexp (&optional defun)
    "Indent the expression after point.
  When interactively called with prefix, indent the enclosing defun

Diff finished.  Fri Feb 13 10:19:56 2015



reply via email to

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