[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/d-mode 1ae5b7f 035/346: improve the auto/immutable and acc
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/d-mode 1ae5b7f 035/346: improve the auto/immutable and access level label workarounds |
Date: |
Sun, 29 Aug 2021 10:59:59 -0400 (EDT) |
branch: elpa/d-mode
commit 1ae5b7f2bc2a8ed64f17ab8a5adddad696c7308e
Author: finalpatch <fengli@gmail.com>
Commit: finalpatch <fengli@gmail.com>
improve the auto/immutable and access level label workarounds
---
d-mode.el | 48 ++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 40 insertions(+), 8 deletions(-)
diff --git a/d-mode.el b/d-mode.el
index f0f9675..0806797 100644
--- a/d-mode.el
+++ b/d-mode.el
@@ -394,7 +394,8 @@ operators."
(while (let ((type (match-string 1)))
(and type
(or (string= type "static")
- (string= type "return"))))
+ (string= type "return")
+ (string= type "new"))))
(setq pt (re-search-backward d-imenu-method-name-pattern nil t)))
pt)
;; Do not count invisible definitions.
@@ -442,15 +443,46 @@ Key bindings:
(c-update-modeline)
(setq imenu-generic-expression d-imenu-generic-expression))
+;; Hideous hacks!
+;;
+;; * auto/immutable: If we leve them in c-modifier-kwds (like
+;; c++-mode) then in the form "auto var;" var will be highlighted in
+;; type name face. Moving auto/immutable to font-lock-add-keywords
+;; lets cc-mode seeing them as a type name, so the next symbol can
+;; be fontified as a variable.
+;;
+;; * public/protected/private appear both in c-modifier-kwds and in
+;; c-protection-kwds. This causes cc-mode to fail parsing the first
+;; declaration after an access level label (because cc-mode trys to
+;; parse them as modifier but will fail due to the colon). But
+;; unfortunately we cannot remove them from either c-modifier-kwds
+;; or c-protection-kwds. Removing them from the former causes valid
+;; syntax like "private int foo() {}" to fail. Removing them from
+;; the latter cause indentation of the access level labels to
+;; fail. The solution used here is to use font-lock-add-keywords to
+;; add back the syntax highlight.
+
+(defconst d-var-decl-pattern "^[ \t]*\\(?:[_a-zA-Z0-9]+[
\t\n]+\\)*\\([_a-zA-Z0-9.!]+\\)\\(?:\\[[^]]*\\]\\|\\*\\)?[
\t\n]+\\([_a-zA-Z0-9]+\\)[ \t\n]*;")
+(defconst d-fun-decl-pattern "^[ \t]*\\(?:[_a-zA-Z0-9]+[
\t\n]+\\)*\\([_a-zA-Z0-9.!]+\\)\\(?:\\[[^]]*\\]\\|\\*\\)?[
\t\n]+\\([_a-zA-Z0-9]+\\)[ \t\n]*(")
+(defmacro d-try-match-decl (regex)
+ `(let ((pt))
+ (setq pt (re-search-forward ,regex limit t))
+ (while (let ((type (match-string 1)))
+ (and pt type
+ (save-match-data
+ (string-match (c-lang-const c-regular-keywords-regexp)
type))))
+ (setq pt (re-search-forward ,regex limit t)))
+ pt))
+(defun d-match-var-decl (limit)
+ (d-try-match-decl d-var-decl-pattern))
+(defun d-match-fun-decl (limit)
+ (d-try-match-decl d-fun-decl-pattern))
+
(font-lock-add-keywords
'd-mode
- '(("\\<\\(auto\\|immutable\\)\\>" 1 font-lock-keyword-face)
- ("^[ \t]*\\(?:[_a-zA-Z0-9]+[
\t\n]+\\)*\\([_a-zA-Z0-9.!]+\\)\\(?:\\[[^]]*\\]\\|\\*\\)?[
\t\n]+\\([_a-zA-Z0-9]+\\)[ \t\n]*;"
- (1 font-lock-type-face)
- (2 font-lock-variable-name-face))
- ("^[ \t]*\\(?:[_a-zA-Z0-9]+[
\t\n]+\\)*\\([_a-zA-Z0-9.!]+\\)\\(?:\\[[^]]*\\]\\|\\*\\)?[
\t\n]+\\([_a-zA-Z0-9]+\\)[ \t\n]*("
- (1 font-lock-type-face)
- (2 font-lock-function-name-face)))
+ '(("\\<\\(auto\\|immutable\\)\\>" 1 font-lock-keyword-face t)
+ (d-match-var-decl (1 font-lock-type-face) (2 font-lock-variable-name-face))
+ (d-match-fun-decl (1 font-lock-type-face) (2 font-lock-function-name-face)))
t)
- [nongnu] elpa/d-mode 9651a31 042/346: Remove warning regarding missing group., (continued)
- [nongnu] elpa/d-mode 9651a31 042/346: Remove warning regarding missing group., ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 3c9f78b 046/346: wording: `init file' rather than `.emacs', ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode fce658e 047/346: let minor-mode automatically set syntax table, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 2d6f15d 049/346: Update the date of the file to better represent reality., ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 9482533 008/346: Declare the 2.0.5 release., ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 1e3df1c 015/346: Added 'debug' to `c-paren-nontype-kwds', ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 46a9ad2 032/346: Merge pull request #12 from finalpatch/master, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode c2431c8 033/346: support fixed sized array, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 09b2aa8 034/346: support interface inheritance, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 5ef5f43 027/346: Re-add the removed __vector from the keyword lists. cf. 0268bde7ca6f188950486a8b55e380128223506d., ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 1ae5b7f 035/346: improve the auto/immutable and access level label workarounds,
ELPA Syncer <=
- [nongnu] elpa/d-mode 9ce0830 045/346: fix typo, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 7bf4dbf 048/346: Merge pull request #20 from roysc/master, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 3d0b55e 051/346: Debian Sid only has Emacs 24.3. Changed the version number and the fix for backslash in backticks works fine., ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode c810702 053/346: Add a Git ignore file and ignore all compiled files., ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode f1df773 055/346: Merge pull request #28 from dmakarov/master, ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 56517b5 057/346: Update the date of last amendment., ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode f4176c0 060/346: Correct the spelling error Sergei spotted and reported., ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode cca34f1 061/346: Add the mode hook definition. Fix a few spelling errors., ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 53efec4 063/346: Make the licence explicit in the README.md and add a copy of the licence text., ELPA Syncer, 2021/08/29
- [nongnu] elpa/d-mode 29589e6 064/346: Line after 'else' should not be a statment-cont, ELPA Syncer, 2021/08/29