|
13 | 13 | (defvar convention-comments-decoration-colors |
14 | 14 | '("#1f77b4" "#ff7f0e" "#2ca02c" "#d62728" "#9467bd" "#17becf" |
15 | 15 | "#bcbd22" "#7f7f7f" "#e377c2" "#ff6f61" "#30cfcf" "#b5bd00" |
16 | | - "#a01920" "#4db6ac" "#9c89b8" "#8c564b" "#8dd35f""#6a5acd") |
| 16 | + "#a01920" "#4db6ac" "#9c89b8" "#8c564b" "#8dd35f" "#6a5acd") |
17 | 17 | "List of decoration colors to alternate through.") |
18 | 18 |
|
19 | | -(defsubst convention-comments-syntax-elisp-keywords () |
20 | | - "Create conventional comments keywords for ELisp." |
21 | | - `((,(rx (literal ";") (*? whitespace) |
22 | | - (group (or "praise" "nitpick" "suggestion" |
23 | | - "issue" "todo" "question" |
24 | | - "thought" "chore" "note")) |
| 19 | +(defvar convention-comments-keywords |
| 20 | + '("praise" "nitpick" "suggestion" |
| 21 | + "issue" "todo" "question" |
| 22 | + "thought" "chore" "note") |
| 23 | + "Default used keywords.") |
| 24 | + |
| 25 | +(defsubst convention-comments-syntax-keywords (comment-string) |
| 26 | + "Create conventional comments keywords for ELisp. |
| 27 | +Argument COMMENT-STRING represents one or more characters beginning a comment." |
| 28 | + (let ((plain |
| 29 | + (rx-to-string `(and |
| 30 | + (literal ,comment-string) (*? whitespace) |
| 31 | + (group (or ,@convention-comments-keywords)) |
25 | 32 | (*? not-newline) |
26 | 33 | (group (literal ":")) |
27 | 34 | (group (*? not-newline)) |
28 | | - line-end) |
29 | | - (1 'font-lock-keyword-face t) |
30 | | - (2 'bold t) |
31 | | - (3 'italic append)) |
32 | | - (,(rx (literal ";") (*? whitespace) |
33 | | - (or "praise" "nitpick" "suggestion" |
34 | | - "issue" "todo" "question" |
35 | | - "thought" "chore" "note") |
| 35 | + line-end))) |
| 36 | + (decorated |
| 37 | + (rx-to-string `(and |
| 38 | + (literal ,comment-string) (*? whitespace) |
| 39 | + (or ,@convention-comments-keywords) |
36 | 40 | (*? not-newline) |
37 | 41 | (group (literal "(")) |
38 | 42 | (*? not-newline) |
39 | 43 | (group (literal ")")) |
40 | 44 | (group (literal ":")) |
41 | 45 | (group (*? not-newline)) |
42 | | - line-end) |
43 | | - (1 'bold t) |
44 | | - (2 'bold t) |
45 | | - (3 'bold t) |
46 | | - (4 'italic append)) |
47 | | - (,(rx (literal ";") (*? whitespace) |
48 | | - (or "praise" "nitpick" "suggestion" |
49 | | - "issue" "todo" "question" |
50 | | - "thought" "chore" "note") |
| 46 | + line-end))) |
| 47 | + (decoration-anchor |
| 48 | + (rx-to-string `(and |
| 49 | + (literal ,comment-string) (*? whitespace) |
| 50 | + (or ,@convention-comments-keywords) |
51 | 51 | (*? whitespace) |
52 | 52 | (literal "(") |
53 | 53 | (group (*? anychar)) |
54 | 54 | (literal ")") |
55 | | - (literal ":")) |
56 | | - (,(rx (+? (group (+ not-newline)) (*? (literal ",")))) |
| 55 | + (literal ":")))) |
| 56 | + (decoration (rx (+? (group (+ not-newline)) (*? (literal ",")))))) |
| 57 | + `((,plain |
| 58 | + (1 'font-lock-keyword-face t) |
| 59 | + (2 'bold t) |
| 60 | + (3 'italic append)) |
| 61 | + (,decorated |
| 62 | + (1 'bold t) |
| 63 | + (2 'bold t) |
| 64 | + (3 'bold t) |
| 65 | + (4 'italic append)) |
| 66 | + (,decoration-anchor |
| 67 | + (,decoration |
57 | 68 | ;; pre-match form |
58 | 69 | (progn |
59 | 70 | ;; start matching in the parenthesis |
|
80 | 91 | ;; post-match form |
81 | 92 | nil |
82 | 93 | ;; no group-matching props needed |
83 | | - )))) |
| 94 | + ))))) |
84 | 95 |
|
85 | | -(defsubst convention-comments-set-syntax-elisp () |
86 | | - "Add conventional comments syntax in ELisp." |
| 96 | +(defsubst convention-comments-set-syntax (comment-string) |
| 97 | + "Add conventional comments syntax in ELisp. |
| 98 | +Argument COMMENT-STRING represents one or more characters beginning a comment." |
87 | 99 | (convention-comments-syntax-defaults) |
88 | | - (font-lock-add-keywords nil (convention-comments-syntax-elisp-keywords)) |
| 100 | + (font-lock-add-keywords nil (convention-comments-syntax-keywords |
| 101 | + comment-string)) |
89 | 102 | (font-lock-update)) |
90 | 103 |
|
91 | | -(defsubst convention-comments-unset-syntax-elisp () |
92 | | - "Remove conventional comments syntax in ELisp." |
| 104 | +(defsubst convention-comments-unset-syntax (comment-string) |
| 105 | + "Remove conventional comments syntax in ELisp. |
| 106 | +Argument COMMENT-STRING represents one or more characters beginning a comment." |
93 | 107 | (convention-comments-syntax-defaults) |
94 | | - (font-lock-remove-keywords nil (convention-comments-syntax-elisp-keywords)) |
| 108 | + (font-lock-remove-keywords nil (convention-comments-syntax-keywords |
| 109 | + comment-string)) |
95 | 110 | (font-lock-update)) |
96 | 111 |
|
97 | 112 | (defun convention-comments-syntax--activate () |
98 | 113 | "Add conventional comments syntax." |
99 | | - (cond ((derived-mode-p 'emacs-lisp-mode) |
100 | | - (convention-comments-set-syntax-elisp)))) |
| 114 | + (if (and (boundp 'comment-start) |
| 115 | + comment-start |
| 116 | + (not (string= "" comment-start))) |
| 117 | + (convention-comments-set-syntax comment-start) |
| 118 | + (warn "convention: missing comment-start, fallback") |
| 119 | + (cond ((derived-mode-p 'emacs-lisp-mode) |
| 120 | + (convention-comments-set-syntax ";"))))) |
101 | 121 |
|
102 | 122 | (defun convention-comments-syntax--deactivate () |
103 | 123 | "Remove conventional comments syntax." |
104 | | - (cond ((derived-mode-p 'emacs-lisp-mode) |
105 | | - (convention-comments-unset-syntax-elisp)))) |
| 124 | + (if (and (boundp 'comment-start) |
| 125 | + comment-start |
| 126 | + (not (string= "" comment-start))) |
| 127 | + (convention-comments-unset-syntax comment-start) |
| 128 | + (warn "convention: missing comment-start, fallback") |
| 129 | + (cond ((derived-mode-p 'emacs-lisp-mode) |
| 130 | + (convention-comments-unset-syntax ";"))))) |
106 | 131 |
|
107 | 132 |
|
108 | 133 | (provide 'convention-comments) |
|
0 commit comments