I'm trying to understand how syntax tables work, but my minimal major mode doesn't highlight anything.
I've written the following elisp, which is just supposed to highlight comments:
(defconst my-yaml-mode-syntax-table
(let ((table (make-syntax-table)))
(modify-syntax-entry ?# "<" table)
(modify-syntax-entry ?\n ">" table)
table)
"Syntax table for `my-yaml-mode'.")
(define-derived-mode my-yaml-mode fundamental-mode "My YAML"
"testing"
:syntax-table my-yaml-mode-syntax-table)
However, given a file:
# foo
# bar
baz
If I activate my major-mode with M-x my-yaml-mode
, I don't get any highlighting. C-u C-x =
shows that no faces have been applied.
M-;
correctly insert a#
? If yes, the syntax table is applied. You should look into font-lock specifications to get syntax highlighting. – T. Verron Sep 25 '14 at 12:35M-;
is bound tocomment-dwim
from newcomment.el, which usescomment-start
rather than the syntax table. AIUI. – Wilfred Hughes Sep 25 '14 at 12:37#
and pressC-u C-x =
, the output should contain the linesyntax: < which means: comment
. – T. Verron Sep 25 '14 at 12:41font-lock-mode
on in yourmy-yaml-mode
buffer.:)
– T. Verron Sep 25 '14 at 12:44