From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#14593: 24.3; java-mode indentation of try-with-resources statement Date: Sat, 13 Jul 2013 19:19:36 +0000 Message-ID: <20130713191936.GA29736@acm.acm> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1373743278 20941 80.91.229.3 (13 Jul 2013 19:21:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 13 Jul 2013 19:21:18 +0000 (UTC) Cc: Patrick Brinich-Langlois To: 14593@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jul 13 21:21:19 2013 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 1Uy5Ne-0004f2-EU for geb-bug-gnu-emacs@m.gmane.org; Sat, 13 Jul 2013 21:21:18 +0200 Original-Received: from localhost ([::1]:46379 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uy5Nd-0002Wo-Ts for geb-bug-gnu-emacs@m.gmane.org; Sat, 13 Jul 2013 15:21:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uy5Na-0002W8-I0 for bug-gnu-emacs@gnu.org; Sat, 13 Jul 2013 15:21:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uy5NV-0003Fk-Ny for bug-gnu-emacs@gnu.org; Sat, 13 Jul 2013 15:21:14 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:58840) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uy5NO-0003DL-OD; Sat, 13 Jul 2013 15:21:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Uy5NO-0000Qs-DQ; Sat, 13 Jul 2013 15:21:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Sat, 13 Jul 2013 19:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 14593 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 14593-submit@debbugs.gnu.org id=B14593.13737432301574 (code B ref 14593); Sat, 13 Jul 2013 19:21:02 +0000 Original-Received: (at 14593) by debbugs.gnu.org; 13 Jul 2013 19:20:30 +0000 Original-Received: from localhost ([127.0.0.1]:53156 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Uy5Mr-0000PK-NO for submit@debbugs.gnu.org; Sat, 13 Jul 2013 15:20:30 -0400 Original-Received: from pd95189e0.dip0.t-ipconnect.de ([217.81.137.224]:45436 helo=acm.muc.de) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Uy5Mm-0000P2-7O for 14593@debbugs.gnu.org; Sat, 13 Jul 2013 15:20:26 -0400 Original-Received: (qmail 30261 invoked by uid 1000); 13 Jul 2013 19:19:36 -0000 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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: 140.186.70.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:76333 Archived-At: Hello, Patrick. On Wed, 12 Jun 2013 00:24:13, Patrick Brinich-Langlois wrote: > Java's try-with-resources statement (new in version 1.7) is indented > incorrectly in java-mode. Steps to reproduce: > * Create a new file. Enable java-mode and electric-indent-mode. > * Type the following: > public class Test { > public static void main(String[] args) { > Path dir = Paths.get(System.getProperty("user.home")); > try (DirectoryStream stream = Files.newDirectoryStream(dir)) { > System.out.println("test"); > } > } > } > The two lines after the try statement are indented an additional four > spaces. The final two closing braces are indented properly. This is indeed the case. The following patch should hopefully handle this case properly. After applying it, either recompile all the cc-*.el files, or just recompile cc-langs.el, cc-engine.el, cc-fonts.el, and cc-mode.el. Please confirm to me that the patch does indeed fix the bug, or report any further problems which aren't fixed. Thanks! diff -r a86a481f7a63 cc-engine.el --- a/cc-engine.el Mon May 27 12:17:11 2013 +0000 +++ b/cc-engine.el Sun Jul 07 14:15:36 2013 +0000 @@ -1140,9 +1140,13 @@ (not (memq sym '(boundary ignore nil)))) ;; Need to investigate closer whether we've crossed ;; between a substatement and its containing statement. - (if (setq saved (if (looking-at c-block-stmt-1-key) - ptok - pptok)) + (if (setq saved + (cond ((and (looking-at c-block-stmt-1-2-key) + (eq (char-after ptok) ?\()) + pptok) + ((looking-at c-block-stmt-1-key) + ptok) + (t pptok))) (cond ((> start saved) (setq pos saved)) ((= start saved) (setq ret 'up))))) @@ -8026,7 +8030,8 @@ (or (looking-at c-block-stmt-1-key) (and (eq (char-after) ?\() (zerop (c-backward-token-2 1 t lim)) - (looking-at c-block-stmt-2-key))) + (or (looking-at c-block-stmt-2-key) + (looking-at c-block-stmt-1-2-key)))) (point)))) (defun c-after-special-operator-id (&optional lim) diff -r a86a481f7a63 cc-fonts.el --- a/cc-fonts.el Mon May 27 12:17:11 2013 +0000 +++ b/cc-fonts.el Sun Jul 07 14:15:36 2013 +0000 @@ -1274,7 +1274,8 @@ (goto-char match-pos) (backward-char) (c-backward-token-2) - (looking-at c-block-stmt-2-key))) + (or (looking-at c-block-stmt-2-key) + (looking-at c-block-stmt-1-2-key)))) (setq context nil c-restricted-<>-arglists t)) ;; Near BOB. diff -r a86a481f7a63 cc-langs.el --- a/cc-langs.el Mon May 27 12:17:11 2013 +0000 +++ b/cc-langs.el Sun Jul 07 14:15:36 2013 +0000 @@ -2181,6 +2181,18 @@ t (c-make-keywords-re t (c-lang-const c-block-stmt-1-kwds))) (c-lang-defvar c-block-stmt-1-key (c-lang-const c-block-stmt-1-key)) +(c-lang-defconst c-block-stmt-1-2-kwds + "Statement keywords optionally followed by a paren sexp. +Keywords here should also be in `c-block-stmt-1-key'." + t nil + java '("try")) + +(c-lang-defconst c-block-stmt-1-2-key + ;; Regexp matching the start of a statement which may be followed by a + ;; paren sexp and will then be followed by a substatement. + t (c-make-keywords-re t (c-lang-const c-block-stmt-1-2-kwds))) +(c-lang-defvar c-block-stmt-1-2-key (c-lang-const c-block-stmt-1-2-key)) + (c-lang-defconst c-block-stmt-2-kwds "Statement keywords followed by a paren sexp and then by a substatement." t '("for" "if" "switch" "while") -- Alan Mackenzie (Nuremberg, Germany).