emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/d-mode 71e8bda 196/346: Improve constructor handling and f


From: ELPA Syncer
Subject: [nongnu] elpa/d-mode 71e8bda 196/346: Improve constructor handling and fix constructor contract indentation
Date: Sun, 29 Aug 2021 11:00:30 -0400 (EDT)

branch: elpa/d-mode
commit 71e8bda9d9e50fcc79a50e45e8ac6b1e97759d5c
Author: Vladimir Panteleev <git@thecybershadow.net>
Commit: Vladimir Panteleev <git@thecybershadow.net>

    Improve constructor handling and fix constructor contract indentation
---
 d-mode-test.el |  4 ++--
 d-mode.el      | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
 tests/I0067.d  | 13 ++++++++++
 3 files changed, 81 insertions(+), 11 deletions(-)

diff --git a/d-mode-test.el b/d-mode-test.el
index f90cf40..dd1f7f8 100644
--- a/d-mode-test.el
+++ b/d-mode-test.el
@@ -84,7 +84,7 @@
         (inline-close          . 0)
         (func-decl-cont        . +)
         (topmost-intro         . 0)
-        (topmost-intro-cont    . c-lineup-topmost-intro-cont)
+        (topmost-intro-cont    . 1)
         (member-init-intro     . +)
         (member-init-cont      . c-lineup-multi-inher)
         (inher-intro           . +)
@@ -314,7 +314,7 @@ is expected to succeed, and nil otherwise."
 (d-test-deftest i0054 "tests/I0054.d" t)
 (d-test-deftest i0058 "tests/I0058.d" (version< "24.4" emacs-version))
 (d-test-deftest i0064 "tests/I0064.d" t)
-(d-test-deftest i0067 "tests/I0067.d" t)
+(d-test-deftest i0067 "tests/I0067.d" (version< "24.4" emacs-version))
 (d-test-deftest i0069 "tests/I0069.txt" t)
 (d-test-deftest i0072 "tests/I0072.txt" t)
 (d-test-deftest i0090 "tests/I0090.d" t)
diff --git a/d-mode.el b/d-mode.el
index 2f4e044..862e3dc 100644
--- a/d-mode.el
+++ b/d-mode.el
@@ -7,7 +7,7 @@
 ;; Maintainer:  Russel Winder <russel@winder.org.uk>
 ;;              Vladimir Panteleev <vladimir@thecybershadow.net>
 ;; Created:  March 2007
-;; Version:  201908290531
+;; Version:  201908290919
 ;; Keywords:  D programming language emacs cc-mode
 ;; Package-Requires: ((emacs "24.3"))
 
@@ -297,12 +297,11 @@ The expression is added to 
`compilation-error-regexp-alist' and
       "abstract" "scope"
       "private" "package" "protected" "public" "export"))
 
-;;(c-lang-defconst c-postfix-decl-spec-kwds
-;;  ;Keywords introducing extra declaration specifiers in the region
-;;  ;between the header and the body (i.e. the "K&R-region") in
-;;  ;declarations.
-;;; This doesn't seem to have any effect.  They aren't exactly "K&R-regions".
-;;  d '("in" "out" "body"))
+(c-lang-defconst c-postfix-spec-kwds
+ ;Keywords introducing extra declaration specifiers in the region
+ ;between the header and the body (i.e. the "K&R-region") in
+ ;declarations.
+ d '("if" "in" "out" "body"))
 
 (c-lang-defconst c-recognize-knr-p
   d t)
@@ -789,6 +788,50 @@ Each list item should be a regexp matching a single 
identifier."
 (when (version<= "24.4" emacs-version)
   (advice-add 'c-add-stmt-syntax :around #'d-around--c-add-stmt-syntax))
 
+;;----------------------------------------------------------------------------
+;;; Implements handling of D constructors
+;;; Fixes e.g. indentation of contracts on constructors.
+
+;; Make it so that inside c-forward-decl-or-cast-1,
+;; "this" looks like a function identifier but not a type identifier.
+
+(defun d-special-case-c-forward-name (orig-fun &rest args)
+  ;; checkdoc-params: (orig-fun args)
+  "Advice function for fixing cc-mode handling of D constructors."
+  (if (not (looking-at (c-make-keywords-re t '("this"))))
+      (apply orig-fun args)
+    (forward-char 4)
+    t))
+
+(defun d-special-case-c-forward-type (orig-fun &rest args)
+  ;; checkdoc-params: (orig-fun args)
+  "Advice function for fixing cc-mode handling of D constructors."
+  (if (not (looking-at (c-make-keywords-re t '("this"))))
+      (apply orig-fun args)
+    nil))
+
+(defun d-around--c-forward-decl-or-cast-1 (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 'c-forward-name)
+                   #'d-special-case-c-forward-name)
+      (add-function :around (symbol-function 'c-forward-type)
+                   #'d-special-case-c-forward-type)
+      (unwind-protect
+         (apply orig-fun args)
+       (remove-function (symbol-function 'c-forward-name)
+                        #'d-special-case-c-forward-name)
+       (remove-function (symbol-function 'c-forward-type)
+                        #'d-special-case-c-forward-type)
+       ))))
+
+(when (version<= "24.4" emacs-version)
+  (advice-add 'c-forward-decl-or-cast-1 :around 
#'d-around--c-forward-decl-or-cast-1))
+
+;;----------------------------------------------------------------------------
 ;; 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.
@@ -921,6 +964,20 @@ Key bindings:
 
 ;;----------------------------------------------------------------------------
 
+(defun d--on-func-identifier ()
+  "Version of `c-on-identifier', but also match D constructors."
+
+  (save-excursion
+    (skip-syntax-backward "w_")
+
+    (or
+     ;; Check for a normal (non-keyword) identifier.
+     (and (looking-at c-symbol-start)
+         (or
+          (looking-at (c-make-keywords-re t '("this")))
+          (not (looking-at c-keywords-regexp)))
+         (point)))))
+
 (defun d-in-knr-argdecl (&optional lim)
   "Modified version of `c-in-knr-argdecl' for d-mode." ;; checkdoc-params: lim
   (save-excursion
@@ -971,11 +1028,11 @@ Key bindings:
                     (progn
                       (goto-char before-lparen)
                       (eq (c-backward-token-2) 0)
-                      (or (eq (c-on-identifier) (point))
+                      (or (eq (d--on-func-identifier) (point))
                           (and (eq (char-after) ?\))
                                (c-go-up-list-backward)
                                (eq (c-backward-token-2) 0)
-                               (eq (c-on-identifier) (point)))))
+                               (eq (d--on-func-identifier) (point)))))
 
                     ;; (... original c-in-knr-argdecl logic omitted here ...)
                     t)
diff --git a/tests/I0067.d b/tests/I0067.d
index 2cd3c54..ad12f15 100644
--- a/tests/I0067.d
+++ b/tests/I0067.d
@@ -3,3 +3,16 @@
 void foo(T)(T stuff)
 if (isInputRange!T) {
 }
+
+struct S
+{
+  void foo()()
+  if (true)
+    {
+    }
+
+  this()()
+  if (true)
+    {
+    }
+}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]