0

I want to change the color which in package import go defer in go-mode ,need a regex..these code only change the pacakge word color

    (defface my-font-lock-gokeyword-face
    `((t (:foreground "#ab4642"))) ;; change to desired color
    "Face for go keyword.")

    (font-lock-add-keywords 'go-mode
    ;; change to desired operator regex
    '(("package"  0 'my-font-lock-gokeyword-face)))

enter image description here

3
  • 1
    Do you want all keywords to be fontified differently, or only a subset?
    – Basil
    Apr 4, 2021 at 16:40
  • The question remains unclear, so I've voted to close it.
    – phils
    Jul 24 at 5:27
  • My best guess is that you simply want to M-x customize-face RET font-lock-keyword-face and change the colour of that pre-existing face to something you prefer.
    – phils
    Jul 24 at 5:27

2 Answers 2

0

If you change "package" to "^package.*" I think it will match every line that starts with package to the end of the line. I don't know enough about go to know if that is always the right thing to do here.

2
  • thanks for your reply ,i update the comment. you can see this pic ,i think its better. Oct 11, 2019 at 13:19
  • I don't get what you want. You just want the package word in another color than it already is? Oct 11, 2019 at 18:19
0

If I understand correct, just add the other keywords to the list. Something like:

(font-lock-add-keywords 'go-mode
;; change to desired operator regex
'(("package"  0 'my-font-lock-gokeyword-face)
  ("go"  0 'my-font-lock-gokeyword-face)
  ("defer"  0 'my-font-lock-gokeyword-face)
  ("package"  0 'my-font-lock-gokeyword-face)))

I understood you want the same color for all four keywords, then this is fine. Otherwise you can change the faces to whatever color you want for the keywords.

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.