Skip to content

Commit

Permalink
Support extra face properties on identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Hi-Angel committed Sep 22, 2024
1 parent 83f68aa commit 7097b12
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ If you like it, enable it for all supported files by adding the following to you
## Configuration

* Recoloring delay: the time before recoloring newly appeared identifiers is `2` seconds by default. To change it e.g. to `1` second add to your config `(setq color-identifiers:recoloring-delay 1)`
* Additional face-properties *(such as italic or bold)* can be added to the identifiers by modifying `color-identifiers:extra-face-attributes`. E.g. to make identifiers look bold use `(setq color-identifiers:extra-face-attributes '(:weight bold))`. But make sure not to change `:foreground` because it is the color of identifiers.
* To make the variables stand out, you can turn off highlighting for all other keywords in supported modes using a code like:
```lisp
(defun myfunc-color-identifiers-mode-hook ()
Expand Down
14 changes: 11 additions & 3 deletions color-identifiers-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ color should be avoided when generating colors, this can be warning colors,
error colors etc."
:type '(repeat face))

(defcustom color-identifiers:extra-face-attributes nil
"Extra face attributes to apply to identifiers. Can be used to make
identifiers bold or italic, but avoid changing `:foreground'
because it is the color determined by the mode."
:type 'plist
:group 'color-identifiers)

(defvar color-identifiers:modes-alist nil
"Alist of major modes and the ways to distinguish identifiers in those modes.
The value of each cons cell provides four constraints for finding
Expand Down Expand Up @@ -803,9 +810,10 @@ evaluates to true."
(let* ((identifier (buffer-substring-no-properties start end))
(hex (color-identifiers:color-identifier identifier)))
(when hex
(put-text-property start end 'face `(:foreground ,hex))
(put-text-property start end 'color-identifiers:fontified t))))
limit))
(let ((face-spec (append `(:foreground ,hex) color-identifiers:extra-face-attributes)))
(put-text-property start end 'face face-spec)
(put-text-property start end 'color-identifiers:fontified t)))))
limit))

(defun color-identifiers-mode-maybe ()
"Enable `color-identifiers-mode' in the current buffer if desired.
Expand Down

0 comments on commit 7097b12

Please sign in to comment.