help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: syntax coloring - own syntax - my solution


From: Dieter Demerre
Subject: Re: syntax coloring - own syntax - my solution
Date: Thu, 19 Oct 2000 09:26:49 +0200 (CEST)

Thanks to Nancy Mazur for guiding my first steps that at least lead to a
works-for-me-sollution.

On Tue, 26 Sep 2000, Dieter Demerre wrote:

> I've defined two small syntax' for specific files.
> one of them has to color @-following text on a line as comment (different
> of other text).  quoted text (strings) should NOT be colored.
> the other has the same specs except that comment is /* - */ delimited and
> can be multi-lined.
> 
> Now I can disable the quote-coloring for the @-syntax, but this does not
> work for the /* - */ syntax.  syntax coloring doesn't work there anymore.
> 
> Does anymody has any suggestion on this part ?
> 
> - --mode_croll.el---" works fine !! " -------------------------
> (if ebp-croll-mode-syntax-table
>     ()
>   (let ((table (make-syntax-table)))
>     (modify-syntax-entry ?@ "< a" table)
>     (modify-syntax-entry ?\n "> a" table)
>     (modify-syntax-entry ?\" " " table)
>     (setq ebp-croll-mode-syntax-table table)
>   )
> )
> - --------------------------------------------------------------
> 
> above extract works fine, but now in the following, modifying ?\" to " "
> will cause syntax-coloring to be disabled, not mentioning it will cause
> strings to be colored as strings again, which I don't want
> 
> - --mode_start.el---" won't work like I want it to "----------
> (if ebp-star-mode-syntax-table
>     ()
>   (let ((table (make-syntax-table)))
>     (modify-syntax-entry ?/ "  14" table)
>     (modify-syntax-entry ?* "  23" table)
>     (modify-syntax-entry ?\" " " table)
>     (setq ebp-star-mode-syntax-table table)
>   )
> )
> - --------------------------------------------------------------

For other users that might encounter similar problems, here my findings:

1. to enable syntax highlighting, use 
(setq font-lock-mode 1)

2. to automatically load a certain syntax for certain files, use
(setq auto-mode-alist 
  (cons '("files" . mysyntax-mode) auto-mode-alist)
)
where "files" is a emacs regexp matching the files to open in
mysyntax-mode like ".+\.\\(c\\|C\\)" matches all .c and .C files (at least
one character in front of the .c or .C

3. to define a mode, use
(defvar mymode-map nil)

if mymode-syntax-table
    (
     )
  (let ((table (make-syntax-table)))
    ; /* - */ comment
    (modify-syntax-entry ?/ "  14" table)
    (modify-syntax-entry ?* "  23" table)
    ; ? - ? strings
    (modify-syntax-entry ?\? "\"" table) 
    ; NO " - " strings.  " are like space
    (modify-syntax-entry ?\" " " table) 
    (setq mymode-syntax-table table)
  )
)

(defun mysyntax-mode ()
  (kill-all-local-variables)
  (use-local-map mymode-map)
  (setq major-mode 'mysyntax-mode)
  (setq mode-name "MYSYN")
  (set-syntax-table mymode-syntax-table)
  (mymode-variables)
  (run-hooks 'mymode-hook)
)

Trying to cancel quoted-text colouring within double-character indicated
comment-syntax apparently is not that easy (see cry for help in the
included message above).  There seems to be a need for at least one
character that indicates string-borders.  If that character is NOT
defined, defining \" as a space or punctuation character will disable
syntax-coloring.  defining another character to take that role (like I did
with \? in the above example-code), will enable the coloring, disable the
""-in-between-coloring.  But of course now you have
??-in-between-coloring.  My sollution now works since my syntax does not
accept '?'.

Hope this code helps people with similar problems.

It's quite possible there are mistakes, incorrect assumptions,
too-much-code.  I'm all open for fixes or comment, but above all: It works
for me...

greets

******* Groetjes vanwege ***** Greetings From *******
Dieter Demerre - http://www.angelfire.com/de/ddemerre
  ddemerre@acm.org - ext.dieter.demerre@siemens.be

Although this private and confidential e-mail has been sent 
to you through a personal Siemens account, it does NOT 
represent any official opinion of Siemens.

If you are not the intended recipient of this e-mail and 
have received it in error, please notify the sender by 
replying with 'received in error' as the subject and then 
delete it from your mailbox.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]