From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Wedler, Christoph" Newsgroups: gmane.emacs.devel Subject: RE: antlr-mode.el - need some support by python.el Date: Wed, 3 Jun 2015 14:14:49 +0000 Message-ID: References: <54E54DE7.1010807@yandex.ru> <54E558C8.9040600@yandex.ru> <54E90362.8070904@yandex.ru> <54F38FD3.1020307@yandex.ru> <54F47CD3.5080708@yandex.ru> <54F4A62F.3040403@yandex.ru> <54F4BA93.4000801@yandex.ru> <54F73EE0.9070306@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1433341076 3361 80.91.229.3 (3 Jun 2015 14:17:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 3 Jun 2015 14:17:56 +0000 (UTC) Cc: =?iso-8859-1?Q?Fabi=E1n_E=2EGallina?= , "emacs-devel@gnu.org" , Dmitry Gutov To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jun 03 16:17:50 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Z09U6-0006yl-RM for ged-emacs-devel@m.gmane.org; Wed, 03 Jun 2015 16:17:35 +0200 Original-Received: from localhost ([::1]:35811 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z09U0-0000S3-VO for ged-emacs-devel@m.gmane.org; Wed, 03 Jun 2015 10:17:28 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57109) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z09Ta-0000HD-UF for emacs-devel@gnu.org; Wed, 03 Jun 2015 10:17:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z09TW-0001Q1-OR for emacs-devel@gnu.org; Wed, 03 Jun 2015 10:17:02 -0400 Original-Received: from smtpgw04.sap-ag.de ([155.56.66.99]:41493 helo=smtpgw.sap-ag.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z09TW-0001PP-F7 for emacs-devel@gnu.org; Wed, 03 Jun 2015 10:16:58 -0400 Thread-Topic: antlr-mode.el - need some support by python.el Thread-Index: AQHQcvDw02VwMpjAIE6bq0LznyyOqJ2bJ+xA In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.21.40.114] X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 X-Received-From: 155.56.66.99 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:186983 Archived-At: 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 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 + + 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 =20 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.") =20 +(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)))) =20 +(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