I'm using SampleMode
and the ModeTutorial
to create my own mode. I have a problem with the syntax table. As I understand, // and # start one-line comments like this:
(defvar my-mode-syntax-table
(let ((st (make-syntax-table)))
(modify-syntax-entry ?_ "w" st)
(modify-syntax-entry ?# "<" st)
(modify-syntax-entry ?\n ">" st)
(modify-syntax-entry ?/ ". 124b" st)
(modify-syntax-entry ?\n "> b" st)
st)
"Syntax table for `my-mode'.")
;;;###autoload
(define-derived-mode my-mode fundamental-mode "My"
"A major mode for editing My files."
:syntax-table my-mode-syntax-table
(setq-local comment-start "// ")
(setq-local comment-end "")
(setq-local comment-start-skip "\\s<+\\s-*")
(setq-local font-lock-defaults
'(my-font-lock-keywords nil t)
)
(setq-local indent-line-function 'my-indent-line)
;; (setq-local imenu-generic-expression
;; my-imenu-generic-expression)
;; (setq-local outline-regexp my-outline-regexp)
;; ...
)
I have a test file that contains these lines:
#pragma Index = 0
//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
Even without my-mode-syntax-table, the #pragma is font-locked as
comment.
The lines starting with // appear as normal text.
what-cursor-position gives me this information for the //:
position: 89 of 47986 (0%), column: 0
character: / (displayed as /) (codepoint 47, #o57, #x2f)
preferred charset: iso-8859-1 (Latin-1 (ISO/IEC 8859-1))
code point in charset: 0x2F
script: latin
syntax: _ which means: symbol
category: .:Base, a:ASCII, l:Latin, r:Roman
to input: type "C-x 8 RET 2f" or "C-x 8 RET SOLIDUS"
buffer code: #x2F
file code: #x2F (encoded by coding system iso-latin-1-dos)
display: by this font (glyph code)
uniscribe:-outline-DejaVu Sans Mono-normal-normal-normal-mono-17-*-*-*-c-*-iso8859-1 (#x12)
Character code properties: customize what to show
name: SOLIDUS
old-name: SLASH
general-category: Po (Punctuation, Other)
decomposition: (47) ('/')
There are text properties here:
charset iso-8859-1
fontified t
As I understand it, this means that the syntax is not detected
correctly. For reference, if I run what-cursor-position in a .cpp file
on a /, the output contains:
syntax: . 124b which means: punctuation,
is the first character of a comment-start sequence,
is the second character of a comment-start sequence,
is the second character of a comment-end sequence (comment style b)
This is right what I would like to have in my-mode, but I don't see what I do wrong...
(Just fyi: font-locking and other stuff is fine, and the mode appears on the mode-line, so I'm convinced that my-mode works ok in general...)
Many thanks for your help!
C-u what-cursor-positionI getsyntax: . 124b which means: punctuation