[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)
+ {
+ }
+}
- [nongnu] elpa/d-mode 438cf53 109/346: fixed missing keyword "idouble", (continued)
- [nongnu] elpa/d-mode 438cf53 109/346: fixed missing keyword "idouble", ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode f6bf2b7 141/346: tests: Split test into individual ert tests, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 23d7a1a 148/346: tests: Fix testing compilation-mode buffers with Emacs 26, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode a731ae6 157/346: Fix imenu for functions with parameter types containing parens, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode ab1057f 159/346: Fix imenu for functions with tail qualifiers on their own line, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode f61e72c 173/346: Drop support for Emacs < 24.3, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 09745ba 175/346: Merge pull request #87 from CyberShadow/emacs-24-plus, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode cfd1d08 180/346: Use rx-to-string instead of rx-form to support Emacs master (#97), ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode af6dbfa 183/346: Generalize StorageClass/VisibilityAttribute parsing in imenu, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 2964263 184/346: Fix imenu with alias templates, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 71e8bda 196/346: Improve constructor handling and fix constructor contract indentation,
ELPA Syncer <=
- [nongnu] elpa/d-mode 28810ef 194/346: Add test for function contracts, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 1bce6c4 191/346: Somewhat improve fontification of module names, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode b413942 198/346: Tighten K&R region detection, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 07cb4d0 199/346: Add d-lineup-arglists, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode d3ceb14 200/346: Make d--imenu-rx-def-start a compile-time constant, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 0b6a089 217/346: .travis.yml: Try using a emacs-travis.mk which does not use FTP, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 653661e 220/346: Fix parsing qualified types, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode f07f365 201/346: Fix fontification of constructor parameters, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode fd8e70a 209/346: Partially implement D type modifiers (const/immutable/etc.), ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 8647147 208/346: Fix tests' minimum Emacs versions, ELPA Syncer, 2021/08/29