branch: elpa/d-mode
commit f07f365906340c4b1eeeade04ce48d095989c8c2
Author: Vladimir Panteleev <[email protected]>
Commit: Vladimir Panteleev <[email protected]>
Fix fontification of constructor parameters
Fixes issue #82.
---
d-mode-test.el | 1 +
d-mode.el | 31 ++++++++++++++++++++++++++++++-
tests/I0082.d | 8 ++++++++
tests/I0082.d.html | 8 ++++++++
4 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/d-mode-test.el b/d-mode-test.el
index 50f206c..3c74f3f 100644
--- a/d-mode-test.el
+++ b/d-mode-test.el
@@ -318,6 +318,7 @@ is expected to succeed, and nil otherwise."
(d-test-deftest i0069 "tests/I0069.txt" t)
(d-test-deftest i0070 "tests/I0070.d" (version< "24.4" emacs-version))
(d-test-deftest i0072 "tests/I0072.txt" t)
+(d-test-deftest i0082 "tests/I0082.d" (version< "24.4" emacs-version))
(d-test-deftest i0090 "tests/I0090.d" t)
;;----------------------------------------------------------------------------
diff --git a/d-mode.el b/d-mode.el
index affa862..e8baef1 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: 201908300712
+;; Version: 201909051329
;; Keywords: D programming language emacs cc-mode
;; Package-Requires: ((emacs "24.3"))
@@ -833,6 +833,35 @@ Each list item should be a regexp matching a single
identifier."
(advice-add 'c-forward-decl-or-cast-1 :around
#'d-around--c-forward-decl-or-cast-1))
;;----------------------------------------------------------------------------
+;;; Fixes fontification of constructor parameter lists in D code.
+
+(defun d-special-case-looking-at-2 (orig-fun regexp)
+ ;; checkdoc-params: (orig-fun regexp)
+ "Advice function for fixing cc-mode handling of D constructors."
+ (if (and
+ (eq regexp c-not-decl-init-keywords)
+ (apply orig-fun (c-make-keywords-re t '("this")) nil)) ; looking-at
"this"
+ nil
+ (apply orig-fun regexp nil)))
+
+(defun d-around--c-font-lock-declarations (orig-fun &rest args)
+ ;; checkdoc-params: (orig-fun args)
+ "Advice function for fixing cc-mode handling of D constructors."
+ (if (not (c-major-mode-is 'd-mode))
+ (apply orig-fun args)
+ (progn
+ (add-function :around (symbol-function 'looking-at)
+ #'d-special-case-looking-at-2)
+ (unwind-protect
+ (apply orig-fun args)
+ (remove-function (symbol-function 'looking-at)
+ #'d-special-case-looking-at-2)
+ ))))
+
+(when (version<= "24.4" emacs-version)
+ (advice-add 'c-font-lock-declarations :around
#'d-around--c-font-lock-declarations))
+
+;;----------------------------------------------------------------------------
;; Borrowed from
https://github.com/josteink/csharp-mode/blob/master/csharp-mode.el
(defun d--syntax-propertize-function (beg end)
"Apply syntax table properties to special constructs in region BEG to END.
diff --git a/tests/I0082.d b/tests/I0082.d
new file mode 100644
index 0000000..820a1d6
--- /dev/null
+++ b/tests/I0082.d
@@ -0,0 +1,8 @@
+// #run: (d-test-fontification)
+
+struct S
+{
+ this(Object o) {}
+ this(Object* o) {}
+ this(Object * o) {}
+}
diff --git a/tests/I0082.d.html b/tests/I0082.d.html
new file mode 100644
index 0000000..eb75859
--- /dev/null
+++ b/tests/I0082.d.html
@@ -0,0 +1,8 @@
+<span class="comment-delimiter">// </span><span class="comment">#run:
(d-test-fontification)
+</span>
+<span class="keyword">struct</span> <span class="type">S</span>
+{
+ <span class="keyword">this</span>(<span class="type">Object</span>
<span class="variable-name">o</span>) {}
+ <span class="keyword">this</span>(<span class="type">Object</span>*
<span class="variable-name">o</span>) {}
+ <span class="keyword">this</span>(<span class="type">Object</span> *
<span class="variable-name">o</span>) {}
+}