[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/d-mode b5fb492 204/346: Fix fontification of manifest (enu
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/d-mode b5fb492 204/346: Fix fontification of manifest (enum) constants |
Date: |
Sun, 29 Aug 2021 11:00:31 -0400 (EDT) |
branch: elpa/d-mode
commit b5fb492de31f55176d83a1571d10d6b09f84ac0e
Author: Vladimir Panteleev <git@thecybershadow.net>
Commit: Vladimir Panteleev <git@thecybershadow.net>
Fix fontification of manifest (enum) constants
---
d-mode-test.el | 3 ++-
d-mode.el | 55 +++++++++++++++++++++++++++++++++++++++++++++---
tests/fonts_enums.d | 22 +++++++++++++++++++
tests/fonts_enums.d.html | 22 +++++++++++++++++++
4 files changed, 98 insertions(+), 4 deletions(-)
diff --git a/d-mode-test.el b/d-mode-test.el
index 3c74f3f..3e99efb 100644
--- a/d-mode-test.el
+++ b/d-mode-test.el
@@ -304,7 +304,8 @@ is expected to succeed, and nil otherwise."
;; Run the tests
(d-test-deftest imenu "tests/imenu.d" t)
(d-test-deftest fonts "tests/fonts.d" t)
-(d-test-deftest i0019 "tests/I0019.d" (version< "25.1" emacs-version))
+(d-test-deftest fonts_enums "tests/fonts_enums.d" (version< "26.2"
emacs-version))
+(d-test-deftest i0019 "tests/I0019.d" (version< "26.2" emacs-version))
(d-test-deftest i0021 "tests/I0021.d" t)
(d-test-deftest i0026 "tests/I0026.d" t)
(d-test-deftest i0030 "tests/I0030.d" t)
diff --git a/d-mode.el b/d-mode.el
index c93e2cc..53b2894 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: 201909051403
+;; Version: 201909081425
;; Keywords: D programming language emacs cc-mode
;; Package-Requires: ((emacs "24.3"))
@@ -284,9 +284,16 @@ The expression is added to
`compilation-error-regexp-alist' and
;; ;; TODO: figure out how to make this work properly
;; d '("with" "version" "extern"))
+;; Remove "enum" from d-mode's value.
+;; By default this c-typedef-decl-kwds includes c-brace-list-decl-kwds,
+;; which is '("enum") by default.
+;; Instead, parse enums manually (see d-font-lock-enum-body) to avoid
+;; confusion with manifest constants.
(c-lang-defconst c-typedef-decl-kwds
- d (append (c-lang-const c-typedef-decl-kwds)
- '("typedef" "alias")))
+ ;; Keywords introducing declarations where the identifier(s) being
+ ;; declared are types.
+ d (append (c-lang-const c-class-decl-kwds)
+ '("typedef" "alias")))
(c-lang-defconst c-decl-hangon-kwds
d '("export"))
@@ -1093,6 +1100,48 @@ Key bindings:
(advice-add 'c-in-knr-argdecl :around #'d-around--c-in-knr-argdecl))
;;----------------------------------------------------------------------------
+;; We can't include "enum" in `c-typedef-decl-kwds', as that will not
+;; work well with D manifest constants (enum [TYPE] NAME = VALUE).
+;; Instead, omit it from `c-typedef-decl-kwds' (which allows manifest
+;; constants to be fontified properly), and handle actual enumerations
+;; manually by adding fontification of the enum name as a type name to
+;; our version of `c-font-lock-enum-body' below:
+
+(defun d-font-lock-enum-body (limit)
+ "Modified version of `c-font-lock-enum-body' for d-mode." ;;
checkdoc-params: limit
+ (while (search-forward-regexp c-enum-clause-introduction-re limit t)
+ (when (save-excursion
+ (backward-char)
+ (when (c-backward-over-enum-header)
+ ;; Fontify type name here
+ (c-forward-token-2) ; Over "enum"
+ (c-forward-syntactic-ws)
+ (c-fontify-types-and-refs ((id-start (point)))
+ (when (c-forward-type)
+ (c-backward-syntactic-ws)
+ (c-put-font-lock-face id-start
+ (point)
+ 'font-lock-type-face)))
+ t))
+ ;; As in the original `c-font-lock-enum-body', fontify the body
+ ;; (enum members).
+ (c-forward-syntactic-ws)
+ (c-font-lock-declarators limit t nil t)))
+ nil)
+
+(defun d-around--c-font-lock-enum-body (orig-fun &rest args)
+ ;; checkdoc-params: (orig-fun args)
+ "Advice function for fixing fontification for D enums."
+ (apply
+ (if (c-major-mode-is 'd-mode)
+ #'d-font-lock-enum-body
+ orig-fun)
+ args))
+
+(when (version<= "24.4" emacs-version)
+ (advice-add 'c-font-lock-enum-body :around
#'d-around--c-font-lock-enum-body))
+
+;;----------------------------------------------------------------------------
;;
;; Support for "Adjusting Alignment Rules for UCFS-Chains in D",
;; cf.
https://stackoverflow.com/questions/25797945/adjusting-alignment-rules-for-ucfs-chains-in-d
diff --git a/tests/fonts_enums.d b/tests/fonts_enums.d
new file mode 100644
index 0000000..547bffc
--- /dev/null
+++ b/tests/fonts_enums.d
@@ -0,0 +1,22 @@
+// #run: (d-test-fontification)
+
+auto var = true;
+enum var = true;
+enum int var = true;
+
+enum
+{
+ a = 1
+}
+enum : int
+{
+ a = 1
+}
+enum Foo
+{
+ a = 1
+}
+enum Foo : int
+{
+ a = 1
+}
diff --git a/tests/fonts_enums.d.html b/tests/fonts_enums.d.html
new file mode 100644
index 0000000..16bb4b9
--- /dev/null
+++ b/tests/fonts_enums.d.html
@@ -0,0 +1,22 @@
+<span class="comment-delimiter">// </span><span class="comment">#run:
(d-test-fontification)
+</span>
+<span class="keyword">auto</span> <span class="variable-name">var</span> =
<span class="constant">true</span>;
+<span class="keyword">enum</span> <span class="variable-name">var</span> =
<span class="constant">true</span>;
+<span class="keyword">enum</span> <span class="type">int</span> <span
class="variable-name">var</span> = <span class="constant">true</span>;
+
+<span class="keyword">enum</span>
+{
+ <span class="variable-name">a</span> = 1
+}
+<span class="keyword">enum</span> : <span class="type">int</span>
+{
+ <span class="variable-name">a</span> = 1
+}
+<span class="keyword">enum</span> <span class="type">Foo</span>
+{
+ <span class="variable-name">a</span> = 1
+}
+<span class="keyword">enum</span> <span class="type">Foo</span> : <span
class="type">int</span>
+{
+ <span class="variable-name">a</span> = 1
+}
- [nongnu] elpa/d-mode f384327 179/346: Fix imenu with typename ending with keyword, (continued)
- [nongnu] elpa/d-mode f384327 179/346: Fix imenu with typename ending with keyword, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode e809bd1 181/346: Fix imenu with conditional non-function declarations, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 5e08129 192/346: Fix indentation of function out contracts, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 06fb0ff 189/346: Fix indentation of enums with a base type, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 1afddc7 190/346: Fix a typo in a regex, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 382a677 195/346: Use c-major-mode-is, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 9edcfbd 197/346: Remove unused bits from d-in-knr-argdecl, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 175c6e5 193/346: Fix indentation of function constraints/contracts?, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 5fdba4e 202/346: Add pragma keyword, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 51b1af1 203/346: Fix K&R region detection and body-less function declarations, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode b5fb492 204/346: Fix fontification of manifest (enum) constants,
ELPA Syncer <=
- [nongnu] elpa/d-mode e52434e 218/346: d-mode-test.el: Save actual result to file in case of mismatch, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 609816b 219/346: tests: Move d-forward-type tests to new test file, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 4d9f9ce 211/346: Drop support for Emacs 24, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode f2b4aec 205/346: Fix fontification of "a in b" expressions, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode f69e94e 207/346: Change test suite enumeration and activation, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode b0a59de 214/346: Fix mis-parsing of concatenating two variables, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 445c696 210/346: Implement a more complete description for D type syntax, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode ed0de34 222/346: Refactor "this" (constructor) handling, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode aaa704a 216/346: Fix coverage issues in d-forward-type, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 572d707 221/346: Improve comprehension of constness and storage classes, ELPA Syncer, 2021/08/29