Skip to content

Commit

Permalink
Use highlight-numbers-number instead of writing my own number parser
Browse files Browse the repository at this point in the history
This is cleaner, more maintainable, and it has a couple of added benefits:

1. It will no longer be troublesome for people switching between themes, since
   the hook that we automatically injected would still be there.
2. Lexical binding is not discarded, with all its benefits.

As suggested by @riscy in melpa/melpa#6808.

Signed-off-by: Miquel Sabaté Solà <msabate@suse.com>
  • Loading branch information
mssola committed Apr 5, 2020
1 parent eb0d662 commit 57709c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ PKG = soria

ELS_ALL = $(wildcard *.el)
ELS = $(filter-out $(PKG)-autoloads.el,$(ELS_ALL))
OBJECTS = $(ELS:.el=.elc)

EMACS ?= emacs
BATCH = $(EMACS) --quick --batch $(LOAD_PATH)
Expand All @@ -20,7 +21,7 @@ version:

.PHONY: clean
clean:
@rm -rf $(TOP)vendor/* $(PKG)-autoloads.el*
@rm -rf $(TOP)vendor/* $(PKG)-autoloads.el* $(OBJECTS)

##
# Test
Expand Down
33 changes: 5 additions & 28 deletions soria-theme.el
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,6 @@ The theme has to be reloaded after changing anything in this group."
:type 'boolean
:group 'soria)

;; First of all, let's create our own font-lock for numbers.

(make-face 'font-lock-number-face)
(set-face-attribute 'font-lock-number-face nil :inherit font-lock-constant-face)
(setq font-lock-number-face 'font-lock-number-face)

(defun soria-theme-add-font-lock-numbers ()
"Add to the list of keywords numeric formats.
It adds to `font-lock-number-face' decimal, octal, hex and bin formats."

(defvar soria-theme-font-lock-number "[0-9]+\\([eE][+-]?[0-9]*\\)?")
(defvar soria-theme-font-lock-hexnumber "0[xX][0-9a-fA-F]+")
(defvar soria-theme-font-lock-binnumber "0[bB][01]+")

(font-lock-add-keywords
nil
(list
(list (concat "\\<\\(" soria-theme-font-lock-number "\\)\\>" )
0 font-lock-number-face)
(list (concat "\\<\\(" soria-theme-font-lock-hexnumber "\\)\\>" )
0 font-lock-number-face)
(list (concat "\\<\\(" soria-theme-font-lock-binnumber "\\)\\>" )
0 font-lock-number-face))))

;; The color theme itself.

(let*
Expand Down Expand Up @@ -228,6 +204,11 @@ It adds to `font-lock-number-face' decimal, octal, hex and bin formats."
`(font-lock-warning-face
((,class (:foreground ,soria-green))))

;; highlight-numbers

`(highlight-numbers-number
((,class (:foreground ,soria-orange))))

;; Search

`(isearch
Expand Down Expand Up @@ -1366,10 +1347,6 @@ It adds to `font-lock-number-face' decimal, octal, hex and bin formats."
`(org-date
((,class (:foreground ,soria-gray, :weight normal :underline nil))))))

;; And finally hook the defined font locks and call provide-theme.

(add-hook 'prog-mode-hook 'soria-theme-add-font-lock-numbers)

(defun soria-theme-purple-identifiers ()
"Make function identifiers purple.
This function might be used as a hook for modes that prefer having purple
Expand Down

0 comments on commit 57709c3

Please sign in to comment.