From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Markus Triska Newsgroups: gmane.emacs.bugs Subject: bug#21526: 24.5; prolog-mode: broken indentation for if-then-else construct Date: Sun, 20 Sep 2015 21:33:00 +0200 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1442778383 8116 80.91.229.3 (20 Sep 2015 19:46:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 20 Sep 2015 19:46:23 +0000 (UTC) To: 21526@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Sep 20 21:46:11 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1ZdkYs-0004BG-Is for geb-bug-gnu-emacs@m.gmane.org; Sun, 20 Sep 2015 21:46:10 +0200 Original-Received: from localhost ([::1]:53389 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZdkYr-0007D5-FB for geb-bug-gnu-emacs@m.gmane.org; Sun, 20 Sep 2015 15:46:09 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49626) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZdkYn-0007Cl-IZ for bug-gnu-emacs@gnu.org; Sun, 20 Sep 2015 15:46:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZdkYk-0007Ey-Bx for bug-gnu-emacs@gnu.org; Sun, 20 Sep 2015 15:46:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:46996) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZdkYk-0007EO-9D for bug-gnu-emacs@gnu.org; Sun, 20 Sep 2015 15:46:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1ZdkYk-0002I4-4X for bug-gnu-emacs@gnu.org; Sun, 20 Sep 2015 15:46:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Markus Triska Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 20 Sep 2015 19:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 21526 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.14427783168683 (code B ref -1); Sun, 20 Sep 2015 19:46:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 20 Sep 2015 19:45:16 +0000 Original-Received: from localhost ([127.0.0.1]:39176 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZdkXz-0002Fy-OD for submit@debbugs.gnu.org; Sun, 20 Sep 2015 15:45:16 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:39399) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZdkXw-0002Fp-LX for submit@debbugs.gnu.org; Sun, 20 Sep 2015 15:45:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZdkXv-0006on-8e for submit@debbugs.gnu.org; Sun, 20 Sep 2015 15:45:12 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:53901) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZdkXv-0006oe-64 for submit@debbugs.gnu.org; Sun, 20 Sep 2015 15:45:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49396) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZdkXu-00070a-2K for bug-gnu-emacs@gnu.org; Sun, 20 Sep 2015 15:45:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZdkXq-0006je-Qj for bug-gnu-emacs@gnu.org; Sun, 20 Sep 2015 15:45:10 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:43759) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZdkXq-0006dE-HZ for bug-gnu-emacs@gnu.org; Sun, 20 Sep 2015 15:45:06 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1ZdkXn-0002Qx-Ea for bug-gnu-emacs@gnu.org; Sun, 20 Sep 2015 21:45:03 +0200 Original-Received: from 178.115.130.183.wireless.dyn.drei.com ([178.115.130.183]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 20 Sep 2015 21:45:03 +0200 Original-Received: from triska by 178.115.130.183.wireless.dyn.drei.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 20 Sep 2015 21:45:03 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 175 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 178.115.130.183.wireless.dyn.drei.com Cancel-Lock: sha1:k3O3CVSuq2tfFpoS4i/WiCPnZe4= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:106750 Archived-At: Stefan Monnier writes: > Thanks. We indeed have some problems with the new indentation code, and > I hope you can help me figure out what it should do. Thank you for looking into this! I will help in every way I can to achieve the excellent indentation of Stefan Bruda's original version. > Could you give me some examples of what prolog-paren-indent-p > should do? Currently it's simply unused :-( Basically, when I set prolog-paren-indent-p to t (and the other settings I posted), then, after I have already typed a Prolog clause like: test :- HERE (throughout the following, "HERE" is a placeholder that only denotes the location of point, with point at the "H"), and then I press "(", then I expect to get: test :- ( HERE with point again being at the "H". In other words, the electric parenthesis indents `prolog-paren-indent', which is typically 4. This way, you spare users having to enter spaces manually to achieve the typical indentation of the if-then-else construct. >> test :- >> ( a -> >> b >> ;c >> ). > > I see a few different problems: > - The indentation of ) is wrong simply because nothing caused it to be > reindented (hitting TAB or RET at the end brings the close paren to > the right spot). I guess "." should cause re-indentation. Adding it > to electric-indent-chars should do the trick. In Stefan Bruda's original version, after I typed: test :- ( a -> b, cHERE with point again at the "H", and then I press RET, I get: test :- ( a -> b, c HERE That is, notice in particular that this new line is NOT indented the same amount as the immediately preceding Prolog goals. There is a clear reason for this: The immediately preceding Prolog goal, namely c, is NOT followed by a comma. This means that where HERE appears, only two things can realistically follow: 1) ";", denoting a further disjunct 2) ")", the closing parenthesis for the whole construct For example, the preceding block can either end with: test :- ( a -> b, c ; HERE (notice the next indentation), or with: test :- ( a -> b, c ) after which the whole construct is finished. This is exactly the behaviour users expect from a good indentation engine for Prolog, like PceEmacs that ships with SWI-Prolog, and also Stefan Bruda's prolog.el. To (unexpectedly) first indent the block and then only re-indent it when "." is pressed would in my view be a regression compared to that. > > - there are two desired indentations for "b". IIUC You want > > (a -> > b1, > b2 > ;c1, > c2) > > whereas the current code tries to accommodate > > (a -> > b1, > b2; > c1, > c2) The two most common ways to indent Prolog's if-then-else are: ( a -> b, c ; d, e ), and: ( a -> b, c ; d, e ) Notice that only the placement of the arrow is different. I am using the first style throughout all Prolog code I write. The second version is also common in the Prolog community, and notably a lot of library code of SWI-Prolog is written in that style. I made sure (via patches that are integrated as of version 1.15) that both styles are well supported in the prolog.el supplied directly by Stefan Bruda, even in the same program and predicate, if you set electric parentheses and the other settings I posted. Please try it for reference to see the expected indentation of Prolog code written in either style. Relatedly, notice that the indentation must also work for disjunctions: ( a, b ; c, d ) i.e., in such cases, there is no arrow at all. > > - After hitting "b RET" you get indented to a bogus column. This is > because SMIE thinks that > > predicate > (arg2, arg2) > > is a possibility, so after "b RET" it thinks you might be about to > enter a list of arguments to "b". This is a general problem with > SMIE's handling of empty lines (where it's often valid but unlikely), > and even more so here in Prolog where such things aren't even valid. Exactly, the main point here is that this would be invalid. > The patch below fixes some of those problems. After this patch, you > should hopefully see something more like > > ( a -> > b > ; c > ). I've never seen this indentation style in a decade of heavy Prolog use including publishing, so my guess is that this will not help many users. Many thanks for looking into this! All the best, Markus