First study the doc-string of font-lock-keywords.
There you have MATCHER which can be a regexp but also can be a function that is called with one arg and should act like re-search-forward.
In the MATCHER function you have the chance to consider other conditions, as that one that your function that should return t.
You can use the form (MATCHER . (SUBEXP ...
You can call M-x sh-mode directly or, having added that shebang line, you could use M-x normal-mode which will at that point recognise the shell script content and set sh-mode.
Being familiar with M-x normal-mode means you generally don't need to care what the desired mode name is. I use this frequently enough that I have (defalias 'nm 'normal-mode) so ...
Yes it is possible to add the fontification of a minor mode to the existing fontification of the major mode.
You add font lock keywords with font-lock-add-keywords and remove them with font-lock-remove-keywords.
There are many possible structures for the keywords.
See the doc for the variable font-lock-keywords for the full list.
One such structure is:
When there is an error in the syntax highlighting code, it is silently ignored by the font-lock package. When this happens, the buffer can be left in an unhighlighted state.
You can use the package font-lock-studio to investigate what happens, and catch errors in the font-lock code. It is a debugger that lets you step each part of the font-lock rules and if ...
In trying to answer your problem, I ran into M-x regex-builder, which may help you as you try to build these regular expressions.
Anyways, you've only defined 4 characters to match:
something that's not a # or space
something that's an :alpha:
an equals sign
This regex will get you most of the way there: [[:alpha:]]* = as it will highlight zero or ...
If I understand correct, just add the other keywords to the list. Something like:
;; 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 ...
In my "my-mode-font-lock" function, this is what I ended up using:
; This regexp matches "function someName(", and sets a font face to "someName"
; This starts at the end of the previous regexp
; It matches everything up to "," or ")" - ...