From: "Wedler, Christoph" <christoph.wedler@sap.com>
To: Dmitry Gutov <dgutov@yandex.ru>,
Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: "Fabián E.Gallina" <fabian@anue.biz>,
"emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: RE: antlr-mode.el - need some support by python.el
Date: Tue, 9 Jun 2015 09:07:08 +0000 [thread overview]
Message-ID: <F9C2521BBF380A4A97379009991555E685B81C67@DEWDFEMB17C.global.corp.sap> (raw)
In-Reply-To: <55760A1D.5080908@yandex.ru>
Here as now a new version - changes to previous one:
- fetch/rebase this morning
- mention text-properties (good idea) and typical use cases in the
docstring of `prog-indentation-context'
- prog-widen: no widen for narrow-to-region case, docstring
"should"->"can" (you are right, "should" was meant for "make it
respect the value `prog-indentation-context'"
a1bd75f57b6d2c726a9c214536da9b63c9c67672 HEAD master
Author: Christoph Wedler <christoph.wedler@sap.com>
Date: Wed Jun 3 13:54:31 2015 +0000
Some generic support for multi-mode indentation.
2 files changed, 73 insertions(+)
ChangeLog.2 | 7 +++++
lisp/progmodes/prog-mode.el | 66 +++++++++++++++++++++++++++++++++++++++++++++
Modified ChangeLog.2
diff --git a/ChangeLog.2 b/ChangeLog.2
index 4d59b8f..22c4684 100644
--- a/ChangeLog.2
+++ b/ChangeLog.2
@@ -1,3 +1,10 @@
+2015-06-09 Christoph Wedler <christoph.wedler@sap.com>
+
+ 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-06-06 Paul Eggert <eggert@cs.ucla.edu>
Merge from gnulib
Modified lisp/progmodes/prog-mode.el
diff --git a/lisp/progmodes/prog-mode.el b/lisp/progmodes/prog-mode.el
index 0d9fabd..cb8aaad 100644
--- a/lisp/progmodes/prog-mode.el
+++ b/lisp/progmodes/prog-mode.el
@@ -48,6 +48,51 @@
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. To cache the
+ string's calculated syntactic information for repeated calls
+ with the same string, it is valid and expected for the inner
+ mode to add text-properties to the string.
+
+ A typical use case is for grammars with code chunks which are
+ to be indented like function bodies - the string would contain
+ a corresponding function header.
+
+ - 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.
+
+ A typical use case are literate programming sources - the
+ function would successively return the code chunks of the
+ previous macro definitions for the same name.")
+
(defun prog-indent-sexp (&optional defun)
"Indent the expression after point.
When interactively called with prefix, indent the enclosing defun
@@ -61,6 +106,27 @@ 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 can 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."
+ (let ((chunk (cadr prog-indentation-context)))
+ (if chunk
+ ;; no widen necessary here, as narrow-to-region changes (not
+ ;; just narrows) existing restrictions
+ (narrow-to-region (car chunk) (or (cdr chunk) (point-max)))
+ (widen))))
+
+
(defvar-local prettify-symbols-alist nil
"Alist of symbol prettifications.
Each element looks like (SYMBOL . CHARACTER), where the symbol
next prev parent reply other threads:[~2015-06-09 9:07 UTC|newest]
Thread overview: 79+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-16 19:50 antlr-mode.el - need some support by python.el Wedler, Christoph
2015-01-16 23:37 ` Stefan Monnier
2015-02-05 11:39 ` Wedler, Christoph
2015-02-05 14:27 ` Stefan Monnier
2015-02-06 15:14 ` Wedler, Christoph
2015-02-06 17:47 ` Stefan Monnier
2015-02-13 10:56 ` Wedler, Christoph
2015-02-13 19:40 ` Stefan Monnier
2015-02-16 14:38 ` Wedler, Christoph
2015-02-16 19:23 ` Stefan Monnier
2015-02-17 10:55 ` Wedler, Christoph
2015-02-18 0:00 ` Stefan Monnier
2015-02-18 14:27 ` Wedler, Christoph
2015-02-18 3:39 ` Dmitry Gutov
2015-02-18 5:48 ` Stefan Monnier
2015-02-18 14:13 ` Wedler, Christoph
2015-02-18 15:13 ` Dmitry Gutov
2015-02-18 15:41 ` Wedler, Christoph
2015-02-18 17:56 ` Stefan Monnier
2015-02-19 2:43 ` Dmitry Gutov
2015-02-19 3:20 ` Stefan Monnier
2015-02-19 3:30 ` Dmitry Gutov
2015-02-19 13:18 ` Stefan Monnier
2015-02-21 22:14 ` Dmitry Gutov
2015-02-25 11:05 ` Wedler, Christoph
2015-03-01 17:04 ` Stefan Monnier
2015-03-01 22:16 ` Dmitry Gutov
2015-03-02 5:23 ` Stefan Monnier
2015-03-02 15:08 ` Dmitry Gutov
2015-03-02 16:48 ` Stefan Monnier
2015-03-02 18:04 ` Dmitry Gutov
2015-03-02 18:51 ` Stefan Monnier
2015-03-02 19:31 ` Dmitry Gutov
2015-03-03 16:32 ` Stefan Monnier
2015-03-04 16:53 ` Wedler, Christoph
2015-03-04 17:20 ` Dmitry Gutov
2015-03-05 9:46 ` Wedler, Christoph
2015-03-05 12:29 ` Dmitry Gutov
2015-03-05 12:43 ` Dmitry Gutov
2015-04-02 14:10 ` Wedler, Christoph
2015-04-07 17:49 ` Stefan Monnier
2015-04-09 14:07 ` Wedler, Christoph
2015-04-09 18:13 ` Stefan Monnier
2015-06-03 14:14 ` Wedler, Christoph
2015-06-03 15:31 ` Stefan Monnier
2015-06-05 14:17 ` Wedler, Christoph
2015-06-05 17:46 ` Dmitry Gutov
2015-06-08 9:12 ` Wedler, Christoph
2015-06-08 13:26 ` Stefan Monnier
2015-06-08 16:02 ` Dmitry Gutov
2015-06-08 20:50 ` Stefan Monnier
2015-06-08 21:33 ` Dmitry Gutov
2015-06-09 9:07 ` Wedler, Christoph [this message]
2015-06-09 15:58 ` Stefan Monnier
2015-06-09 19:05 ` Wedler, Christoph
2015-06-15 11:02 ` Dmitry Gutov
2015-06-08 13:18 ` Stefan Monnier
2015-03-04 17:37 ` Dmitry Gutov
2015-03-04 22:26 ` Stefan Monnier
2015-03-04 22:59 ` Dmitry Gutov
2015-03-10 1:16 ` Stefan Monnier
2015-03-21 15:30 ` Dmitry Gutov
2015-03-21 17:08 ` Stefan Monnier
2015-03-21 23:41 ` Dmitry Gutov
2015-03-22 13:54 ` Stefan Monnier
2015-03-22 19:31 ` Dmitry Gutov
2015-03-22 21:59 ` Stefan Monnier
2015-03-23 14:03 ` Dmitry Gutov
2015-03-23 19:25 ` Stefan Monnier
2015-03-04 16:29 ` Wedler, Christoph
2015-03-04 17:16 ` Dmitry Gutov
2015-03-01 22:25 ` Dmitry Gutov
2015-02-18 12:22 ` Wedler, Christoph
2015-02-18 15:29 ` Dmitry Gutov
2015-02-18 16:10 ` Wedler, Christoph
2015-02-18 22:55 ` Dmitry Gutov
2015-02-25 11:16 ` Wedler, Christoph
2015-02-18 3:15 ` Dmitry Gutov
2015-02-22 7:52 ` 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=F9C2521BBF380A4A97379009991555E685B81C67@DEWDFEMB17C.global.corp.sap \
--to=christoph.wedler@sap.com \
--cc=dgutov@yandex.ru \
--cc=emacs-devel@gnu.org \
--cc=fabian@anue.biz \
--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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.