From 5ab78d3d6a7efcb49d2a9be5b4bdb8eaf78f7a14 Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Sat, 27 Jul 2013 12:07:43 +0000 Subject: [PATCH] Make Java try-with-resources statement parse properly. progmodes/cc-langs.el (c-block-stmt-1-2-kwds, c-block-stmt-1-2-key): New language constants/variables. progmodes/cc-engine.el (c-beginning-of-statement-1, c-after-conditional): Adapt to deal with c-block-stmt-1-2-key. progmodes/cc-fonts.el (c-font-lock-declarations): Adapt to deal with c-block-stmt-1-2-key. --- lisp/ChangeLog | 10 ++++++++++ lisp/progmodes/cc-engine.el | 13 +++++++++---- lisp/progmodes/cc-fonts.el | 3 ++- lisp/progmodes/cc-langs.el | 12 ++++++++++++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 42ad403583b..e74c4ffe486 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,13 @@ +2013-07-27 Alan Mackenzie + + Make Java try-with-resources statement parse properly. + * progmodes/cc-langs.el (c-block-stmt-1-2-kwds) + (c-block-stmt-1-2-key): New language constants/variables. + * progmodes/cc-engine.el (c-beginning-of-statement-1) + (c-after-conditional): Adapt to deal with c-block-stmt-1-2-key. + * progmodes/cc-fonts.el (c-font-lock-declarations): Adapt to deal + with c-block-stmet-1-2-key. + 2013-07-27 Juanma Barranquero * desktop.el (desktop--make-frame): Apply most frame parameters after diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index a3bd000a4f3..c2ff5011a0e 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el @@ -1135,9 +1135,13 @@ comment at the start of cc-engine.el for more info." (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))))) @@ -7988,7 +7992,8 @@ comment at the start of cc-engine.el for more info." (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 --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index 6a4bfd9e875..4e8ce6bac28 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el @@ -1307,7 +1307,8 @@ casts and declarations are fontified. Used on level 2 and higher." (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 --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index af52ad53aad..4e488344e16 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el @@ -2187,6 +2187,18 @@ identifiers that follows the type in a normal declaration." 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-kwds'." + 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") -- 2.39.2