* How to implement comments that always start at the beginning of a line
@ 2006-10-24 9:40 Philipp
0 siblings, 0 replies; 3+ messages in thread
From: Philipp @ 2006-10-24 9:40 UTC (permalink / raw)
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?
Thanks,
Philipp
--
View this message in context: http://www.nabble.com/How-to-implement-comments-that-always-start-at-the-beginning-of-a-line-tf2500236.html#a6969840
Sent from the Emacs - Help mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <mailman.192.1161688642.27805.help-gnu-emacs@gnu.org>]
* Re: How to implement comments that always start at the beginning of a line
[not found] <mailman.192.1161688642.27805.help-gnu-emacs@gnu.org>
@ 2006-10-24 15:07 ` rgb
2006-10-24 16:01 ` Stefan Monnier
1 sibling, 0 replies; 3+ messages in thread
From: rgb @ 2006-10-24 15:07 UTC (permalink / raw)
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)))
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to implement comments that always start at the beginning of a line
[not found] <mailman.192.1161688642.27805.help-gnu-emacs@gnu.org>
2006-10-24 15:07 ` rgb
@ 2006-10-24 16:01 ` Stefan Monnier
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2006-10-24 16:01 UTC (permalink / raw)
> 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)
Firt, the syntax of the string passed as second argument treats the frst two
chars specially, so the "1" and "2" need to be placed further:
(modify-syntax-entry ?\n "> 1" form-mode-syntax-table)
(modify-syntax-entry ?* ". 2" form-mode-syntax-table)
but this likely won't work because this kind of mixing a close-comment with
a begin-comment in the same char-sequence was not expected by the (latest)
coder of the comment-handling code (i.e. myself). And even if I had
expected it, it's not clear how I'd have interpreted it: /*/ in c-mode
(and -- in snmp-mode) either closes or opens a comment, but not both.
> but that didn't work the way I expected. Does anybody have an idea how to
> solve this?
font-lock-syntactic-keywords is the onl thing that springs to my mind.
See fortran.el for an example.
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-10-24 16:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-24 9:40 How to implement comments that always start at the beginning of a line Philipp
[not found] <mailman.192.1161688642.27805.help-gnu-emacs@gnu.org>
2006-10-24 15:07 ` rgb
2006-10-24 16:01 ` Stefan Monnier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).