I want to modify the highlighting of my JS files, so that every line starting with LOG
gets shown in a different color.1
I wrote the following
(require 'font-core)
(font-lock-mode 1)
(defface mg-js-pseudo-face '((t (:background "White"))) "..." :group 'faces)
(defvar mg-js-pseudo-regex "^[ \t]*\\(LOG .*\\)")
(defun mg-js-pseudo-hook ()
(font-lock-add-keywords
nil
`(
(,mg-js-pseudo-regex 1 'mg-js-pseudo-face t)) ;;; <----- here
))
(add-hook 'js-mode-hook 'mg-js-pseudo-hook)
It works well when highlighting the whole line (using 0
instead of 1
in the marked line). It does nothing at all, when used as is. Why?
1It's invalid JS, I know. It gets preprocessed by the server to console.log
with some added information.
C-u C-x =
(what-cursor-position) to find out what faces are there. That often helps me find which other font-lock rule is setting the face. When I tried it with your regexp, it was telling mems-js-pseudo-face
,js2-external-variable
, andjs2-warning
were all fighting to be there. (Do you have a :background for one of those other faces?) – amitp Aug 26 '16 at 15:59