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: Wed, 30 Sep 2015 20:35:40 +0200 Message-ID: <87vbarwy9v.fsf@metalevel.at> References: <87y4fo9zt6.fsf@metalevel.at> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1443685028 26336 80.91.229.3 (1 Oct 2015 07:37:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 1 Oct 2015 07:37:08 +0000 (UTC) Cc: 21526@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Oct 01 09:36:59 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 1ZhYQD-0003Ik-Bp for geb-bug-gnu-emacs@m.gmane.org; Thu, 01 Oct 2015 09:36:57 +0200 Original-Received: from localhost ([::1]:39893 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhYQC-0000pC-O9 for geb-bug-gnu-emacs@m.gmane.org; Thu, 01 Oct 2015 03:36:56 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53736) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhMEb-0002tr-K4 for bug-gnu-emacs@gnu.org; Wed, 30 Sep 2015 14:36:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZhMEU-0006jX-3a for bug-gnu-emacs@gnu.org; Wed, 30 Sep 2015 14:36:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:60579) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZhMEU-0006jT-0g for bug-gnu-emacs@gnu.org; Wed, 30 Sep 2015 14:36:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1ZhMET-0003b1-LH for bug-gnu-emacs@gnu.org; Wed, 30 Sep 2015 14:36:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Markus Triska Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 30 Sep 2015 18:36:01 +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: Original-Received: via spool by 21526-submit@debbugs.gnu.org id=B21526.144363814413798 (code B ref 21526); Wed, 30 Sep 2015 18:36:01 +0000 Original-Received: (at 21526) by debbugs.gnu.org; 30 Sep 2015 18:35:44 +0000 Original-Received: from localhost ([127.0.0.1]:49550 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZhMEB-0003aT-Rt for submit@debbugs.gnu.org; Wed, 30 Sep 2015 14:35:44 -0400 Original-Received: from static.59.150.47.78.clients.your-server.de ([78.47.150.59]:53541 helo=metalevel.at) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZhME9-0003aL-9B for 21526@debbugs.gnu.org; Wed, 30 Sep 2015 14:35:42 -0400 Original-Received: by metalevel.at (Postfix, from userid 1000) id BA78EEC0FF; Wed, 30 Sep 2015 20:35:40 +0200 (CEST) In-Reply-To: (Stefan Monnier's message of "Wed, 30 Sep 2015 05:23:38 -0400") 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:107102 Archived-At: Stefan Monnier writes: > I don't understand. You say you want > > :- multifile > pred1, > pred2, > pred3. Yes, exactly. The most frequent such directives are: discontiguous dynamic meta_predicate module_transparent multifile Their unary argument is always a valid Prolog term itself, and the whole directive is, like everything that appears in a Prolog file (except comments), also a valid Prolog term, and ends with a '.'. As a good approximation, you can expect these directives to have the form: :- pred1, pred2, ..., pred_n. Where pred_k is a predicate indicator of the form Name/Arity, where Name is a Prolog atom and Arity is an integer. The atom may of course also contain a '.', for example, the directive may look like: :- multifile 'unusual.predicate'/1. This situation is very rare, but at least it should not produce errors. > whereas clearly you'd like > > multifile > (pred1, > pred2, > pred3) Yes, this is because of the built-in precedences: multifile has precedence 1150, and thus (,)/2 with arity 1000 binds more tightly. > what should happen if "multifile" appears elsewhere? what other keyword > can appear where you have "multifile" and do they all use this > same syntax? The term above is just like any other Prolog term, so if multifile appears elsewhere then, from a purely semantic point of view, I would expect it to also indent just according to the structure of the resulting Prolog term. However, not even Stefan Bruda's mode goes so far as to ensure this kind of semantic indentation. For example, from a purely semantic view, in the following example, the atom 'x' is an argument of the operator multifile: test :- multifile x. However, as a first approximation, it would already be great to handle this indentation of multifile just in directives (= lines where (:-)/1 is the primary functor). This is also what Stefan Bruda's mode does. The same goes for the other keywords shown above. The ability to define custom operators makes Prolog code harder to parse and indent semantically than other languages. If you are interested in truly pushing this to its ultimate conclusion, you will have to dynamically take operator precedences into account, using Prolog's current_op/3 predicate to look up the current precedences. Independently of all this, would you please consider to set the default value of prolog-electric-if-then-else-flag to t in Emacs? I find this behaviour extremely useful, and other modes like C also have electric indentation turned on by default in recent Emacs versions. Thank you and all the best! Markus