lisp - How do I ensure the correct precedence in Emacs highlighting keywords? -


i'm trying write simple major mode lisp dialect. here's mode:

(defconst example-font-lock-keywords   (list    `(";.*" . font-lock-comment-face)    `(,(regexp-opt '("function" "macro") 'symbols) . font-lock-builtin-face)    `("\"[^\"]+?\"" . font-lock-string-face))   "highlighting example mode.")  (defvar example-mode-syntax-table   (make-syntax-table))  (define-derived-mode example-mode lisp-mode "example"   "major mode editing example lisp code."   :syntax-table example-mode-syntax-table   (set (make-local-variable 'font-lock-defaults) '(example-font-lock-keywords))) 

here's sample program:

; highlighting tests. ; comment despite "quotes"  (function foo () "bar") 

here's result i'm seeing:

emacs screenshot

what doing wrong? why string regexp 'win' against comment regexp?

emacs highlights buffer in 2 phases. first syntactic phase, based on information found in syntax table, typically highlights strings , comments. second keyword phase.

in case, default syntax table sets double quotes mean string. effect before keywords executed, strings highlighted. default, keyword applied when there no highlighting in matched content, reason why comment keyword works on lines without strings. (see override flag in text of font-lock-keywords details on overriding.)

the best solution update syntax table ; means "comment start", , drop comment , string rules set of keywords.


Comments

Popular posts from this blog

.htaccess - htaccess convert request to clean url and add slash at the end of the url -

php - facebook and github login HWIOAuthBundle and FOSUserBundle in Symfony2.1 -

hadoop - Sqoop installation export and import from postgresql -