[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to implement comments that always start at the beginning of a li
From: |
rgb |
Subject: |
Re: How to implement comments that always start at the beginning of a line |
Date: |
24 Oct 2006 08:07:07 -0700 |
User-agent: |
G2/1.0 |
Philipp wrote:
> Hi,
>
> I'm writing my own Emacs major mode for a language in with all comments
> start with an starisk at the beginning of a line. Unfortunately, I haven't
> found a way to implement this in the syntax table.
>
> I tried to do a two-character comment sequence, with the first character
> being a newline and the 2nd character an asterisk. This would neglect
> comments in the first line of a buffer, but it would be better than nothing.
> The lines I used were
>
> (modify-syntax-entry ?\n ">1" form-mode-syntax-table)
> (modify-syntax-entry ?* ".2" form-mode-syntax-table)
>
> but that didn't work the way I expected. Does anybody have an idea how to
> solve this?
You probably found that it only recognized every other comment line
or something basically similar. It's because the newline character
can't be both part of a comment starter and a comment ender at the
same time.
The only way to get exactly what you want is to use
font-lock-syntactic-keywords to assign comment starter syntax
specifically to to the characters you want.
Modified version of code ripped from ddl-mode...
(defvar ddl-font-lock-syntactic-keywords
`(("^\\*" (0 "<")))
"A list of regexp's or functions. Used to add syntax-table properties
to characters that can't be set by the syntax-table alone.")
... Later used in the "Further item elements" section of
font-lock-defaults.
;; I use font-lock-syntactic-keywords to set some properties
;; and I don't want them ignored.
(set (make-local-variable 'parse-sexp-lookup-properties) t)
(set (make-local-variable 'font-lock-defaults)
'(ddl-font-lock-keywords
;; keywords-only means no strings or comments get fontified
nil
;; case-fold (ignore case)
t
;; syntax-alist, nothing needs overriding
nil
;; syntax-begin - move outside syntactic block
nil
;; Further elements - set font-lock-syntactic-keywords
(font-lock-syntactic-keywords .
ddl-font-lock-syntactic-keywords)))
- Re: How to implement comments that always start at the beginning of a line,
rgb <=