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 14:04:01 -0400 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1442772321 18503 80.91.229.3 (20 Sep 2015 18:05:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 20 Sep 2015 18:05:21 +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 Sun Sep 20 20:05: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 1Zdiz8-0006IB-57 for geb-bug-gnu-emacs@m.gmane.org; Sun, 20 Sep 2015 20:05:10 +0200 Original-Received: from localhost ([::1]:53032 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zdiz7-0001f0-CS for geb-bug-gnu-emacs@m.gmane.org; Sun, 20 Sep 2015 14:05:09 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54883) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zdiz3-0001dL-JY for bug-gnu-emacs@gnu.org; Sun, 20 Sep 2015 14:05:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zdiz0-0000T1-Dv for bug-gnu-emacs@gnu.org; Sun, 20 Sep 2015 14:05:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:46856) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zdiz0-0000QR-9a for bug-gnu-emacs@gnu.org; Sun, 20 Sep 2015 14:05:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Zdiyz-0008KY-Pm for bug-gnu-emacs@gnu.org; Sun, 20 Sep 2015 14:05:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 20 Sep 2015 18:05: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.144277224631952 (code B ref 21526); Sun, 20 Sep 2015 18:05:01 +0000 Original-Received: (at 21526) by debbugs.gnu.org; 20 Sep 2015 18:04:06 +0000 Original-Received: from localhost ([127.0.0.1]:39066 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Zdiy5-0008JH-8h for submit@debbugs.gnu.org; Sun, 20 Sep 2015 14:04:05 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:58896) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Zdiy2-0008J8-St for 21526@debbugs.gnu.org; Sun, 20 Sep 2015 14:04:04 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0AwEwA731xV/2yixEVcgxCEAoVVuzcJhH6CTQQCAoE8ORQBAQEBAQEBgQpBBYNdAQEDAScvIwULCzQSFBgNJIg3CM8jAQEBAQEBBAEBAQEeizqFBQeELQWQNI5jkhSCFIFFI4Fmgi4igngBAQE X-IPAS-Result: A0AwEwA731xV/2yixEVcgxCEAoVVuzcJhH6CTQQCAoE8ORQBAQEBAQEBgQpBBYNdAQEDAScvIwULCzQSFBgNJIg3CM8jAQEBAQEBBAEBAQEeizqFBQeELQWQNI5jkhSCFIFFI4Fmgi4igngBAQE X-IronPort-AV: E=Sophos;i="5.13,465,1427774400"; d="scan'208";a="165376478" 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 14:04:01 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id 1C1456614D; Sun, 20 Sep 2015 14:04:01 -0400 (EDT) In-Reply-To: (Markus Triska's message of "Sun, 20 Sep 2015 15:02:59 +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:106739 Archived-At: > (setq prolog-indent-width 8 > prolog-electric-tab-flag nil > prolog-electric-if-then-else-flag t > prolog-paren-indent 4 > prolog-electric-dot-flag nil > prolog-paren-indent-p t > prolog-char-quote-workaround nil) Thanks. We indeed have some problems with the new indentation code, and I hope you can help me figure out what it should do. Could you give me some examples of what prolog-paren-indent-p should do? Currently it's simply unused :-( > t e s t SPC : - RET ( a SPC - > RET b RET ; c RET ) . > then I get the following indentation (shown in untabified form): > 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. - 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 current code also tries to accommodate ( a -> b1, b2 ; c1, c2) so I'm not sure how to combine this with your use case. E.g. would you prefer ( a -> b1, b2 ; c1, c2) or do you only want the ; at paren-level in the case where -> was not at the beginning of the line? - 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. The patch below fixes some of those problems. After this patch, you should hopefully see something more like ( a -> b ; c ). in your buffer. Stefan diff --git a/lisp/progmodes/prolog.el b/lisp/progmodes/prolog.el index b36df21..2f4c03e 100644 --- a/lisp/progmodes/prolog.el +++ b/lisp/progmodes/prolog.el @@ -1121,6 +1121,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 +2081,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 +2091,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))