From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.devel Subject: Re: [Emacs-diffs] scratch/widen-less a4ba846: Replace prog-widen with consolidating widen calls Date: Sat, 16 Dec 2017 19:34:16 +0200 Message-ID: <8e5adcd7-e085-e8d2-085f-398c660cd34d@yandex.ru> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------6B73E527967D96732749178C" X-Trace: blaine.gmane.org 1513445681 32019 195.159.176.226 (16 Dec 2017 17:34:41 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 16 Dec 2017 17:34:41 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:58.0) Gecko/20100101 Thunderbird/58.0 To: "Wedler, Christoph" , Eli Zaretskii , "monnier@iro.umontreal.ca" , "emacs-devel@gnu.org" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Dec 16 18:34:33 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eQGM4-0007mt-RZ for ged-emacs-devel@m.gmane.org; Sat, 16 Dec 2017 18:34:33 +0100 Original-Received: from localhost ([::1]:51471 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQGMC-0004GG-1s for ged-emacs-devel@m.gmane.org; Sat, 16 Dec 2017 12:34:40 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44151) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQGLz-0004Ew-So for emacs-devel@gnu.org; Sat, 16 Dec 2017 12:34:29 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eQGLv-0007B9-3X for emacs-devel@gnu.org; Sat, 16 Dec 2017 12:34:27 -0500 Original-Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]:35209) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eQGLu-0007AS-Oy; Sat, 16 Dec 2017 12:34:23 -0500 Original-Received: by mail-wm0-x22b.google.com with SMTP id f9so22896570wmh.0; Sat, 16 Dec 2017 09:34:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=w7F/ZiENBXD8lqDqm85Ki1kjXQRvDaUWeZcoVYwALFc=; b=GDAQ03/NqwGC/X7rzFRhe8FsDMy1+gVBhSZ9r2awpkz2Uqt3l0vJXb++d9rRkQOGXb WKw9G20VRf531Crg4Y6XiNJddPk2RQ+XWly0KWIBA/HMKinVTavNjjeT1DmUksXxPZLo z1u3hLNGioHoy+ymfqGKnJ5mhYZs4ehP/sWuUvjz+8b5bnP1+Q02AZxIsCopQh+y/h3F hAK0PVf1VOOZcb9K5/OEEIChBt7b5WhUNqpLJ4G882fkGZi7Oz28OTaZzcaIVnFyrlMg 5eZiMQPwylSJdNmdktZ7ibSbC/Has7yz8vC91eJj3unrgd5r/2w5uTm0IDWQHfPbndTV evfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language; bh=w7F/ZiENBXD8lqDqm85Ki1kjXQRvDaUWeZcoVYwALFc=; b=GFFkFOrlgnyTX/dVRfkXOzIECiU6tyP53f1tSYSCHKoU1fowl7wVaW6iKrWE4DID+0 ZYRRy1nunkWtjoWoNrnfcWLi2kLQl3BAWNxiInj2nhQ037pMqinZJ+dKgeuKJ/L2EH/1 urlOdUB2UrpFeClOtNjOIuiNR0/c9jr9QhY74BLgV/905FxdvubZIKP/Z0RGRIkivl9h WFRlOMBGRPJaDvSSfdIgjvgUr7ZoXpQOnlPgQ+RAm21U+FEJQQN59e4QM4o36tfRRW9Q xYF9fky0ue3BP+c2L9VOlucVkwcXTMVsHG919KXbZd5cDkK25qKOhww6uMGwup6gdvqY g5Fw== X-Gm-Message-State: AKGB3mLPwKY8g+KP+nJFWLNEz8nXe4fAmpKcMWGDgOVVmIbBjB0HYUMV MrFY1I+n6d8jQU8GY7jNHSpSm+jZ X-Google-Smtp-Source: ACJfBotUl2c0ZNslTO7ZCU3br8EZAMTpyfvm5EXiJqOKuchfe0DfSCWv+cKx+FgW0Ec4DrIWlgA/5Q== X-Received: by 10.80.190.135 with SMTP id b7mr22766871edk.282.1513445660798; Sat, 16 Dec 2017 09:34:20 -0800 (PST) Original-Received: from [192.168.1.3] ([185.105.174.193]) by smtp.googlemail.com with ESMTPSA id g20sm8747136edb.75.2017.12.16.09.34.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 Dec 2017 09:34:18 -0800 (PST) In-Reply-To: Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22b X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.devel:221140 Archived-At: This is a multi-part message in MIME format. --------------6B73E527967D96732749178C Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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? --------------6B73E527967D96732749178C Content-Type: text/x-patch; name="antlr-mode-cleanup.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="antlr-mode-cleanup.diff" diff -u --label /home/dgutov/examples/antlr/antlr-mode.el --label \#\ /home/dgutov/examples/antlr/antlr-mode.el /tmp/buffer-content-4j5MsU --- /home/dgutov/examples/antlr/antlr-mode.el +++ # @@ -3408,12 +3408,10 @@ (when (and boa (eq antlr-indent-comment t) ; indent-region (boundp 'prog-indentation-context)) ; Emacs 24.5 or later - (let ((syntax-ppss-cache nil) ;#dynamic - (syntax-ppss-last nil) ;#dynamic - ;; TODO: do we also need to call `syntax-propertize'? - ;; and/or bind `syntax-propertize-function'? - (prog-indentation-context ;#dynamic - (list (+ leftouter c-basic-offset) (list (1+ boa))))) + (let ((prog-indentation-context ;#dynamic + (list (+ leftouter c-basic-offset)))) + ;; TODO: do we also need to call `syntax-propertize'? + ;; and/or bind `syntax-propertize-function'? (narrow-to-region (1+ boa) (point-max)) (python-indent-line (eq this-command 'antlr-indent-command)))))) Diff finished. Sat Dec 16 19:27:17 2017 --------------6B73E527967D96732749178C--