So I've been trying to add custom syntax highlighting for digits using font-lock-add-keywords and regex.
I've been looking at all the Emacs resources to do this, and while I have been able to successfully define a face, font-lock-add-keywords has not been working for any apparent reason.
I have even copied the examples from different sources and directly tried to get them to work with no apparent success. I can't seem to figure out what's wrong with my code. I'm not receiving any errors, but when I try to eval the font-lock-add-keywords (with C-x C-e), it prints nil in the *Messages* buffer.
Update
I took Gilles advice and created a minor mode, set font-lock-add-keywords to that custom minor mode, and used a quote for the face. While I can see the minor mode in the mode line and know that it's working, font-lock-add-keywords still does not seem to work. Here is my updated code:
(defgroup gio-group nil "Group for customization" :prefix "gio-") (defface gio-highlight-numbers-face '((t :inherit (default) :foreground "#ffff00")) "Face for numbers" :group 'gio-group ) (define-minor-mode gio-minor-mode "Minor mode for customizaion" :init-value t :lighter " GioMode" :global t :group 'gio-group) (font-lock-add-keywords 'gio-minor-mode '(("[0-9]+" . 'gio-highlight-numbers-face))) I'm running GNU Emacs 26.3 (build 1, x86_64-w64-mingw32) on Windows 10. Any help is much appreciated! Thank you!
(font-lock-add-keywords nil '(("[0-9]+" . custom-faces-highlight-numbers-face)))in the buffer that you are trying to fontify? That's the same expression as in your code except thatnilis passed in for the MODE parameter. DoC-h v font-lock-add-keywordsfor more details. I believe that passingfont-lock-modefor the MODE parameter is wrong, but I'm no expert and YMMV.