0

I am using web-mode for my php files: http://web-mode.org/

And I call often a php function which looks like this:

__lg('Some text here', 'Global', NULL, FALSE);

This function can be call with only one argument like:

__lg('Hello world');

Is it possible to automaticly highlight the text between the 2 single quotes of the first argument of my function __lg() ?

I would like it to be colored in #ff007c for exemple.

I think I would have to modify the library web-mode.el that I use ?

1 Answer 1

2

You do not need to modify web-mode.el. You just add a new font-lock keyword in web-mode-hook. The code below demonstrates that. You can store it in your init file.

(defface my-web-mode-hl__lg '((t (:foreground "#ff007c")))
  "Face for the first arg of __lg.")

(defun my-web-mode-hl__lg ()
  "Configure web mode such that the first arg of __lg(...) is high-lighted.
Function for `web-mode-hook'."
  (font-lock-add-keywords
   nil
   '(("\\_<__lg(\\('[^']*'\\)" ;; The regexp
      1 ;; decorate the first regexp group, i.e., the quoted string
      'my-web-mode-hl__lg ;; the face as we defined it
      t ;; this keyword should override any previous fontification
      ))
   t ;; append this to `font-lock-keywords`
   ))


(add-hook 'web-mode-hook #'my-web-mode-hl__lg)
1
  • Waouh, amazing! Working like a charm just after calling web-mode. Mar 22, 2019 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.