Reputation: 8042
I am trying to create an emacs syntax highlighting for a language in which the comments are written as
; A single line comment
;; This comment has
multipline lines ;;
To do this I need to modify the entries in the syntax table. I have found that the following works perfectly for comments on multiple lines:
(modify-syntax-entry ?\; ". 1234" sbgl-mode-syntax-table)
And the following works perfectly for single line comments:
(modify-syntax-entry ?\; "< b" sbgl-mode-syntax-table)
(modify-syntax-entry ?\n "> b" sbgl-mode-syntax-table)
Does anybody know of a way to combine these?
Upvotes: 3
Views: 965
Reputation: 1273
If you can survive adding a space after each semicolon starting a single-line comment, you can treat it as an second character for one of the comment-start sequences and then here's a snippet that works for me:
(define-derived-mode sbgl-mode prog-mode "sbgl"
(set (make-local-variable 'font-lock-defaults)
'(nil ;; keywords
nil ;; keywords-only
nil ;; case-fold
((?\; . ". 1234b")
(?\n . ">")
(?\ . "- 2")))))
If not, then you always have an option to do the syntactic analysis prior to fontification via syntax-propertize-function
variable (or font-lock-syntactic-keywords
variable for pre-Emacs24).
Upvotes: 2
Reputation: 28531
You can try something like:
(modify-syntax-entry ?\; "< 1234b" sbgl-mode-syntax-table)
(modify-syntax-entry ?\n ">" sbgl-mode-syntax-table)
Upvotes: 0