New answers tagged

2

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 ...


1

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 ...


1

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: (...


2

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 ...


0

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: a space an equals sign This regex will get you most of the way there: [[:alpha:]]* = as it will highlight zero or ...


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 ...


0

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" ("^[[:space:]]*?sub\\(?:[[:space:]]*\\)?\\([[:word:]]+\\)?\\(?:[^( \t\n]\\)?" (1 font-lock-function-name-face) ; This starts at the end of the previous regexp ; It matches everything up to "," or ")" - ...


Top 50 recent answers are included