0

I wrote a simple mode with the following font-lock definition, which defines just some keywords:

(defvar marpa-mode-font-lock
  `((,(regexp-opt '(":default" "action" "lexeme" "default" "latm" "separator") t)
     . 'font-lock-keyword-face)
    )
  "Highlighting for Marpa mode")

I use it in my mode function in this way:

(set (make-local-variable 'font-lock-defaults) '(marpa-mode-font-lock))

When I use the mode more than just the keywords are highlighted. Strings are also highlighted with some kind of C or Lisp default syntax.

How can I disable the default string syntax in order to replace it with my own definition?

In the language for which I wrote the mode, strings are not delimited by double quotes. Instead they are delimited by single quotes and may have a suffix attribute like this: 'create':i.

1

Strings and comments are highlighted based on the information in the syntax table.

Typically, this is much better than a keyword-based solution as it handles multi-line constructs better.

However, if you really want to disable this, you can set font-lock-keywords-only:

font-lock-keywords-only is a variable defined in `font-lock.el'. Its value is nil

Documentation: Non-nil means Font Lock should not fontify comments or strings. This is normally set via `font-lock-defaults'.

  • I see. I have stolen the syntax-table modification from sql-mode: (modify-syntax-entry ?' "\"" table) and (modify-syntax-entry ?\" "." table). There seems to be no way to make the suffix also part of the string? – ceving Nov 18 '15 at 9:36
  • @ceving, can you give me some concrete examples on what is a correct string and something that incorrectly is highlighted as one. (I don't know sql). – Lindydancer Nov 18 '15 at 10:01
  • I think i got it; btw nice piece of software your el2markdown. – ceving Nov 18 '15 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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