branch: elpa/d-mode
commit 6a19457dba7e8fd7a4da6ac8ee646703ca656ae3
Author: Vladimir Panteleev <[email protected]>
Commit: Vladimir Panteleev <[email protected]>
Fix function calls being mis-parsed as declarations after static else
---
d-mode.el | 21 ++++++++++++++++++---
tests/fonts.d | 3 +++
tests/fonts.d.html | 3 +++
3 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/d-mode.el b/d-mode.el
index c8419a8..d6756df 100644
--- a/d-mode.el
+++ b/d-mode.el
@@ -7,7 +7,7 @@
;; Maintainer: Russel Winder <[email protected]>
;; Vladimir Panteleev <[email protected]>
;; Created: March 2007
-;; Version: 201909092149
+;; Version: 201909092218
;; Keywords: D programming language emacs cc-mode
;; Package-Requires: ((emacs "25.1"))
@@ -428,8 +428,10 @@ The expression is added to
`compilation-error-regexp-alist' and
d nil)
(c-lang-defconst c-other-decl-kwds
- d (append (list "else")
- (c-lang-const d-storage-class-kwds)))
+ d (c-lang-const d-storage-class-kwds))
+
+(c-lang-defconst c-decl-start-kwds
+ d '("else"))
(c-lang-defconst c-other-kwds
;; Keywords not accounted for by any other `*-kwds' language constant.
@@ -688,6 +690,19 @@ Each list item should be a regexp matching a single
identifier."
(looking-at (c-make-keywords-re t '("in"))))))
nil)
+ ;; D: The "else" following a "version" or "static if" can start a
+ ;; declaration even without a { } block. For this reason, "else" is
+ ;; in `c-decl-start-kwds'.
+ ;; However, cc-mode invokes `c-forward-decl-or-cast-1' with point
+ ;; at the "else" keyword, which, when followed by a function call,
+ ;; is mis-parsed as a function declaration.
+ ;; Fix this by moving point forward, past the "else" keyword, to
+ ;; put cc-mode on the right track.
+ ((looking-at (c-make-keywords-re t '("else")))
+ (goto-char (match-end 1))
+ (c-forward-syntactic-ws)
+ (apply orig-fun args))
+
(t
(add-function :around (symbol-function 'c-forward-name)
#'d-special-case-c-forward-name)
diff --git a/tests/fonts.d b/tests/fonts.d
index faaecff..7cb6789 100644
--- a/tests/fonts.d
+++ b/tests/fonts.d
@@ -13,3 +13,6 @@ void main()
}
version(none) string readLink();
+
+static if (true) {} else fun();
+static if (true) {} else void fun();
diff --git a/tests/fonts.d.html b/tests/fonts.d.html
index 214d0e3..ff8b85d 100644
--- a/tests/fonts.d.html
+++ b/tests/fonts.d.html
@@ -13,3 +13,6 @@
}
<span class="keyword">version</span>(none) <span class="type">string</span>
<span class="function-name">readLink</span>();
+
+<span class="keyword">static if</span> (<span class="constant">true</span>) {}
<span class="keyword">else</span> fun();
+<span class="keyword">static if</span> (<span class="constant">true</span>) {}
<span class="keyword">else</span> <span class="type">void</span> <span
class="function-name">fun</span>();