Skip to content

Commit bd43656

Browse files
authored
Merge pull request #459 from jsmestad/numbers-with-underscore
Customizable face for numbers
2 parents c548a84 + 80562fa commit bd43656

File tree

2 files changed

+44
-14
lines changed

2 files changed

+44
-14
lines changed

elixir-format.el

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
(defcustom elixir-format-arguments nil
2929
"Additional arguments to 'mix format'"
3030
:type '(repeat string)
31+
:group 'elixir
3132
:group 'elixir-format)
3233

3334
(defcustom elixir-format-hook nil
3435
"Hook called by `elixir-format'."
3536
:type 'hook
37+
:group 'elixir
3638
:group 'elixir-format)
3739

3840

elixir-mode.el

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;;; elixir-mode.el --- Major mode for editing Elixir files
1+
;;; elixir-mode.el --- Major mode for editing Elixir files -*- lexical-binding: t -*-
22

33
;; Copyright 2011-2015 secondplanet
44
;; 2013-2015 Samuel Tonini, Matt DeBoard, Andreas Fuchs
@@ -10,7 +10,7 @@
1010
;; URL: https://github.com/elixir-editors/emacs-elixir
1111
;; Created: Mon Nov 7 2011
1212
;; Keywords: languages elixir
13-
;; Version: 2.3.1
13+
;; Version: 2.4.0
1414
;; Package-Requires: ((emacs "24") (pkg-info "0.4"))
1515

1616
;; This file is not a part of GNU Emacs.
@@ -48,13 +48,17 @@
4848
:link '(url-link :tag "Github" "https://github.com/elixir-editors/emacs-elixir")
4949
:link '(emacs-commentary-link :tag "Commentary" "elixir-mode"))
5050

51-
(defvar elixir-mode-website-url "http://elixir-lang.org"
52-
"Official url of Elixir programming website.")
51+
(defcustom elixir-mode-website-url "http://elixir-lang.org"
52+
"Official url of Elixir programming website."
53+
:type 'string)
5354

54-
(defvar elixir-mode-doc-url "https://hexdocs.pm/elixir"
55-
"Official documentation for the Elixir programming language.")
55+
(defcustom elixir-mode-doc-url "https://hexdocs.pm/elixir"
56+
"Official documentation for the Elixir programming language."
57+
:type 'string)
5658

57-
(defvar elixir-mode-hook nil)
59+
(defcustom elixir-mode-hook nil
60+
"Hook that runs when switching to major mode"
61+
:type 'hook)
5862

5963
(defvar elixir-mode-map
6064
(let ((map (make-sparse-keymap)))
@@ -72,21 +76,36 @@
7276
("Tests" "^\\s-*test[ \t\n]+\"?\\(:?[a-z0-9_@+() \t-]+\\)\"?[ \t\n]+.*" 1))
7377
"Imenu pattern for `elixir-mode'.")
7478

75-
(defvar elixir-basic-offset 2)
76-
(defvar elixir-key-label-offset 0)
77-
(defvar elixir-match-label-offset 2)
79+
(defcustom elixir-basic-offset 2
80+
"Basic offset."
81+
:type 'integer)
82+
(defcustom elixir-key-label-offset 0
83+
"Offset used for key label."
84+
:type 'integer)
85+
(defcustom elixir-match-label-offset 2
86+
"Offset for a match label."
87+
:type 'integer)
88+
89+
(defgroup elixir-faces nil
90+
"Font-lock faces for `elixir'."
91+
:group 'elixir
92+
:group 'faces)
7893

7994
(defvar elixir-attribute-face 'elixir-attribute-face)
8095
(defface elixir-attribute-face
8196
'((t (:inherit font-lock-preprocessor-face)))
82-
"For use with module attribute tokens."
83-
:group 'font-lock-faces)
97+
"For use with module attribute tokens.")
8498

8599
(defvar elixir-atom-face 'elixir-atom-face)
86100
(defface elixir-atom-face
87101
'((t (:inherit font-lock-builtin-face)))
88-
"For use with atoms & map keys."
89-
:group 'font-lock-faces)
102+
"For use with atoms & map keys.")
103+
104+
(defvar elixir-number-face 'elixir-number-face)
105+
(defface elixir-number-face
106+
'((t (:inherit default)))
107+
"For use with numbers.")
108+
90109

91110
(eval-when-compile
92111
(defconst elixir-rx-constituents
@@ -107,6 +126,11 @@
107126
(zero-or-more (any "a-z" "A-Z" "0-9" "_" "\"" "'" "!" "@" "?")))
108127
(and "\"" (one-or-more (not (any "\""))) "\"")
109128
(and "'" (one-or-more (not (any "'"))) "'"))))
129+
(numbers . ,(rx (and symbol-start
130+
(? "-")
131+
(+ digit)
132+
(0+ (and "_" (= 3 digit)))
133+
symbol-end)))
110134
(builtin . ,(rx symbol-start
111135
(or "case" "cond" "for" "if" "quote" "raise" "receive" "send"
112136
"super" "throw" "try" "unless" "unquote" "unquote_splicing"
@@ -382,6 +406,10 @@ is used to limit the scan."
382406
(optional "="))
383407
1 elixir-atom-face)
384408

409+
;; Numbers
410+
(,(elixir-rx (group numbers))
411+
1 elixir-number-face)
412+
385413
;; Gray out variables starting with "_"
386414
(,(elixir-rx symbol-start
387415
(group (and "_"

0 commit comments

Comments
 (0)