[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: |
Wed, 3 Jun 2015 14:14:49 +0000 |
Hi Stefan,
finally, I prepared a patch (vs master fetched this morning ca 06:10 UTC).
I incorporated the things we had in the mail discussions earlier
Remarks / corrections welcome.
I hope the format is correct.
Regards,
Christoph
5102d1d513d82d7a34851411494c29624c50ae47 HEAD master
Author: Christoph Wedler <address@hidden>
Date: Wed Jun 3 13:54:31 2015 +0000
Some generic support for multi-mode indentation.
2 files changed, 63 insertions(+)
ChangeLog.2 | 7 ++++++
lisp/progmodes/prog-mode.el | 56 +++++++++++++++++++++++++++++++++++++++++++++
Modified ChangeLog.2
diff --git a/ChangeLog.2 b/ChangeLog.2
index 115ccda..e110ea0 100644
--- a/ChangeLog.2
+++ b/ChangeLog.2
@@ -1,3 +1,10 @@
+2015-06-03 Christoph Wedler <address@hidden>
+
+ Some generic support for multi-mode indentation.
+ * lisp/progmodes/prog-mode.el (prog-indentation-context): New
+ variable.
+ (prog-first-column, prog-widen): New convenience functions.
+
2015-05-30 Dmitry Gutov <address@hidden>
Make sure there's no explicit tag name
Modified lisp/progmodes/prog-mode.el
diff --git a/lisp/progmodes/prog-mode.el b/lisp/progmodes/prog-mode.el
index 0d9fabd..33abb6d 100644
--- a/lisp/progmodes/prog-mode.el
+++ b/lisp/progmodes/prog-mode.el
@@ -48,6 +48,43 @@
map)
"Keymap used for programming modes.")
+(defvar prog-indentation-context nil
+ "Non-nil while indenting embedded code chunks.
+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 variable enables the major mode of the
+main language to use the indentation engine of the sub mode for
+lines in code chunks written in the sub language.
+
+When a major mode of such a main language decides to delegate 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
+ \(FIRST-COLUMN (START . END) PREVIOUS-CHUNKS)
+
+FIRST-COLUMN is the column the indentation engine of the sub mode
+should usually choose for top-level language constructs inside
+the code chunk (instead of 0).
+
+START to END is the region of the code chunk. See function
+`prog-widen' for additional info.
+
+PREVIOUS-CHUNKS, if non-nil, provides the indentation engine of
+the sub mode with the virtual context of the code chunk. Valid
+values are:
+
+ - A string containing code which the indentation engine can
+ consider as standing in front of the code chunk. For example,
+ it can contain a function header to make the code chunk
+ being correctly indented as a function body.
+
+ - A function called with the start position of the current
+ chunk. It will return either the region of the previous chunk
+ as \(PREV-START . PREV-END) or nil if there is no further
+ previous chunk.")
+
+
(defun prog-indent-sexp (&optional defun)
"Indent the expression after point.
When interactively called with prefix, indent the enclosing defun
@@ -61,6 +98,25 @@ instead."
(end (progn (forward-sexp 1) (point))))
(indent-region start end nil))))
+(defun prog-first-column ()
+ "Return the indentation column normally used for top-level constructs."
+ (or (car prog-indentation-context) 0))
+
+(defun prog-widen ()
+ "Remove restrictions (narrowing) from current code chunk or buffer.
+This function should be used instead of `widen' in any function
+used by the indentation engine to make it respect the value
+`prog-indentation-context'.
+
+This function (like 'widen') is useful inside a
+`save-restriction' to make the indentation correctly work when
+narrowing is in effect."
+ (widen)
+ (let ((chunk (cadr prog-indentation-context)))
+ (when chunk
+ (narrow-to-region (car chunk) (or (cdr chunk) (point-max))))))
+
+
(defvar-local prettify-symbols-alist nil
"Alist of symbol prettifications.
Each element looks like (SYMBOL . CHARACTER), where the symbol
- RE: antlr-mode.el - need some support by python.el,
Wedler, Christoph <=
- Re: antlr-mode.el - need some support by python.el, Stefan Monnier, 2015/06/03
- RE: antlr-mode.el - need some support by python.el, Wedler, Christoph, 2015/06/05
- Re: antlr-mode.el - need some support by python.el, Dmitry Gutov, 2015/06/05
- RE: antlr-mode.el - need some support by python.el, Wedler, Christoph, 2015/06/08
- Re: antlr-mode.el - need some support by python.el, Stefan Monnier, 2015/06/08
- Re: antlr-mode.el - need some support by python.el, Dmitry Gutov, 2015/06/08
- Re: antlr-mode.el - need some support by python.el, Stefan Monnier, 2015/06/08
- Re: antlr-mode.el - need some support by python.el, Dmitry Gutov, 2015/06/08
- RE: antlr-mode.el - need some support by python.el, Wedler, Christoph, 2015/06/09
- Re: antlr-mode.el - need some support by python.el, Stefan Monnier, 2015/06/09