From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#21526: 24.5; prolog-mode: broken indentation for if-then-else construct Date: Sun, 20 Sep 2015 23:03:34 -0400 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1442804662 10765 80.91.229.3 (21 Sep 2015 03:04:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 21 Sep 2015 03:04:22 +0000 (UTC) Cc: 21526@debbugs.gnu.org To: Markus Triska Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Sep 21 05:04: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 1ZdrOk-0001yl-MH for geb-bug-gnu-emacs@m.gmane.org; Mon, 21 Sep 2015 05:04:10 +0200 Original-Received: from localhost ([::1]:55128 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZdrOk-0001Sh-0m for geb-bug-gnu-emacs@m.gmane.org; Sun, 20 Sep 2015 23:04:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36811) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZdrOg-0001SX-CB for bug-gnu-emacs@gnu.org; Sun, 20 Sep 2015 23:04:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZdrOd-0005fX-2o for bug-gnu-emacs@gnu.org; Sun, 20 Sep 2015 23:04:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:47145) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZdrOc-0005fT-VV for bug-gnu-emacs@gnu.org; Sun, 20 Sep 2015 23:04:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1ZdrOc-0003vc-GF for bug-gnu-emacs@gnu.org; Sun, 20 Sep 2015 23:04:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 21 Sep 2015 03:04: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: Original-Received: via spool by 21526-submit@debbugs.gnu.org id=B21526.144280461815068 (code B ref 21526); Mon, 21 Sep 2015 03:04:02 +0000 Original-Received: (at 21526) by debbugs.gnu.org; 21 Sep 2015 03:03:38 +0000 Original-Received: from localhost ([127.0.0.1]:39355 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZdrOD-0003uy-RU for submit@debbugs.gnu.org; Sun, 20 Sep 2015 23:03:38 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:41728) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZdrOB-0003up-9v for 21526@debbugs.gnu.org; Sun, 20 Sep 2015 23:03:35 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0A5FgA731xV/2yixEVcgxCEAoVVwD6CTQQCAoE8PBEBAQEBAQEBgQpBBYNdAQEEJy8jEAs0EhQYDSSIP88jAQEBAQEBBAEBAQEeizqFBQeELQWGZYRfk1OSFIIUgUUjhBQigngBAQE X-IPAS-Result: A0A5FgA731xV/2yixEVcgxCEAoVVwD6CTQQCAoE8PBEBAQEBAQEBgQpBBYNdAQEEJy8jEAs0EhQYDSSIP88jAQEBAQEBBAEBAQEeizqFBQeELQWGZYRfk1OSFIIUgUUjhBQigngBAQE X-IronPort-AV: E=Sophos;i="5.13,465,1427774400"; d="scan'208";a="165395705" Original-Received: from 69-196-162-108.dsl.teksavvy.com (HELO ceviche.home) ([69.196.162.108]) by ironport2-out.teksavvy.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 20 Sep 2015 23:03:35 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id 3D39A6614D; Sun, 20 Sep 2015 23:03:34 -0400 (EDT) In-Reply-To: (Markus Triska's message of "Sun, 20 Sep 2015 21:33:00 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) 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:106756 Archived-At: I installed the patch below which should fix many of your problems. IIUC the only remaining issue is the indentation we get when the line is empty. Stefan diff --git a/lisp/progmodes/prolog.el b/lisp/progmodes/prolog.el index b36df21..24ac8d7 100644 --- a/lisp/progmodes/prolog.el +++ b/lisp/progmodes/prolog.el @@ -925,12 +925,30 @@ This is really kludgy, and unneeded (i.e. obsolete) in Emacs>=24." (`(:after . ".") '(column . 0)) ;; To work around smie-closer-alist. ;; Allow indentation of if-then-else as: ;; ( test - ;; -> thenrule - ;; ; elserule + ;; -> thenrule + ;; ; elserule ;; ) (`(:before . ,(or `"->" `";")) - (and (smie-rule-bolp) (smie-rule-parent-p "(") (smie-rule-parent 1))) - (`(:after . ,(or `":-" `"->" `"-->")) prolog-indent-width))) + (and (smie-rule-bolp) (smie-rule-parent-p "(") (smie-rule-parent 0))) + (`(:after . ,(or `"->" `"*->")) + ;; We distinguish + ;; + ;; (a -> + ;; b; + ;; c) + ;; and + ;; ( a -> + ;; b + ;; ; c) + ;; + ;; based on the space between the open paren and the "a". + (unless (and (smie-rule-parent-p "(") + (save-excursion + (smie-indent-forward-token) + (smie-backward-sexp 'halfsexp) + (not (eq ?\( (char-before))))) + prolog-indent-width)) + (`(:after . ,(or `":-" `"-->")) prolog-indent-width))) ;;------------------------------------------------------------------- @@ -1121,6 +1139,9 @@ Commands: (dolist (ar prolog-align-rules) (add-to-list 'align-rules-list ar)) (add-hook 'post-self-insert-hook #'prolog-post-self-insert nil t) ;; `imenu' entry moved to the appropriate hook for consistency. + (when prolog-electric-dot-flag + (setq-local electric-indent-chars + (cons ?\. electric-indent-chars))) ;; Load SICStus debugger if suitable (if (and (eq prolog-system 'sicstus) @@ -2078,6 +2099,7 @@ whitespace characters, parentheses, or then/else branches." (when prolog-electric-if-then-else-flag (save-excursion (let ((regexp (concat "(\\|" prolog-left-indent-regexp)) + (pos (point)) level) (beginning-of-line) (skip-chars-forward " \t") @@ -2087,6 +2109,9 @@ whitespace characters, parentheses, or then/else branches." ;; prolog-paren-indent)) ;; work on all subsequent "->", "(", ";" + (and (looking-at regexp) + (= pos (match-end 0)) + (indent-according-to-mode)) (while (looking-at regexp) (goto-char (match-end 0)) (setq level (+ (prolog-find-unmatched-paren) prolog-paren-indent)) diff --git a/test/indent/prolog.prolog b/test/indent/prolog.prolog index 5b5d272..ca4d2c9 100644 --- a/test/indent/prolog.prolog +++ b/test/indent/prolog.prolog @@ -1,5 +1,27 @@ %% -*- mode: prolog; coding: utf-8; fill-column: 78 -*- +%% bug#21526 +test1 :- + ( a -> + b + ; c + ). + +test2 :- + ( a + -> b1, + b2 + ; c1, + c2 + ) + +test3 :- + ( a, + b + ; c + ). + + %% Testing correct tokenizing. foo(X) :- 0'= = X. foo(X) :- 8'234 = X. @@ -50,9 +72,9 @@ subst(X, V, FV, lambda(Y, Ti, Bi), lambda(Y1, To, Bo)) :- %% Perform substitution on the body. subst(X, V, FV, Bi1, Bo)), ( X = Y - %% If X is equal to Y, X is shadowed, so no subst can take place. - -> Y1 = Y, Bo = Bi - ; (member((Y, _), FV) + %% If X is equal to Y, X is shadowed, so no subst can take place. + -> Y1 = Y, Bo = Bi + ; (member((Y, _), FV) %% If Y appears in FV, it can appear in V, so we need to %% rename it to avoid name capture. -> new_atom(Y, Y1),