Reputation: 1229
Simple question, I am using generic-mode in Emacs for color coding. The following works great except that in this language "
and '
can be used to denote strings as in 'this is a string'
or "this is a string"
. By default in generic-mode, "hightlighted" but 'is not'.
(require 'generic-x)
(define-generic-mode
'foo-mode ;; name of the mode to create
'("#") ;; comments start with '!!'
'("for" "if" "else" ) ;; some keywords
'(("=" . 'font-lock-operator) ;; '=' is an operator
("+" . 'font-lock-operator) ;; '=' is an operator
("-" . 'font-lock-operator) ;; '=' is an operator
("'" . 'font-lock-builtin) ;; '=' is an operator
("<-" . 'font-lock-operator) ;; '=' is an operator
("*" . 'font-lock-operator) ;; '=' is an operator
("/" . 'font-lock-operator) ;; '=' is an operator
("," . 'font-lock-builtin) ;; ';' is a built-in
(";" . 'font-lock-builtin)) ;; ';' is a built-in
'("\\.myext$") ;; files for which to activate this mode
nil ;; other functions to call
"A generic mode for myext files" ;; doc string for this mode
)
Is there a simple way to make the above treat 's as "s?
Upvotes: 3
Views: 359
Reputation:
You probably better follow Stefans advice and use define-derived-mode
, but as this question was the first time I heard of generic.el
, I got curious and had to find a way.
In my tests, removing the font-lock-keyword
entry for '
and modifying the syntax-table entry for '
in a function ('(lambda () (modify-syntax-entry ?' "\""))
) in the functions list seems to work.
The complete code I tested:
(define-generic-mode
'foo-mode ;; name of the mode to create
'("#") ;; comments start with '!!'
'("for" "if" "else" ) ;; some keywords
'(("=" . 'font-lock-operator) ;; '=' is an operator
("+" . 'font-lock-operator) ;; '=' is an operator
("-" . 'font-lock-operator) ;; '=' is an operator
("<-" . 'font-lock-operator) ;; '=' is an operator
("*" . 'font-lock-operator) ;; '=' is an operator
("/" . 'font-lock-operator) ;; '=' is an operator
("," . 'font-lock-builtin) ;; ';' is a built-in
(";" . 'font-lock-builtin)) ;; ';' is a built-in
'("\\.myext$") ;; files for which to activate this mode
'((lambda () (modify-syntax-entry ?' "\""))) ;; other functions to call
"A generic mode for myext files" ;; doc string for this mode
)
Upvotes: 1