all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Font-locking different "sections" in a file
@ 2006-06-27 18:45 wisnij
  2006-06-27 21:20 ` François Gannaz
  0 siblings, 1 reply; 2+ messages in thread
From: wisnij @ 2006-06-27 18:45 UTC (permalink / raw)


We have a file format at my company which is almost free-form ASCII
with some markup, but it can get hairy enough that I am obliged to
write an Emacs mode with font-locking to help with editing it.  The
problem is, files are broken into sections kind of like this:

    # some header information
    import(foo)
    import(bar)

    TEXT
    some paragraphs of &{marked-up text}
    etc etc

    DATA
    # tab-separated data

...and so forth.  Which is to say, the only delimiter between
different sections is the tokens "TEXT", "DATA", etc. on lines by
themselves.

Each section differs slightly some the others syntactically: certain
tokens are keywords in the header section but not elsewhere; one can
normally start a comment with #, except within the TEXT block where it
is just a normal character; and so forth.  There can still be
structure within that block, though, so it doesn't feel like calling
it all a string or comment is really the right way to go.

I've looked through the manual but I didn't really see anything
helpful, apart from the admonition not to use font-lock-keywords for
multi-line constructs.  Is there an accepted way to define syntactic
"block" within a file like this?

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Font-locking different "sections" in a file
  2006-06-27 18:45 Font-locking different "sections" in a file wisnij
@ 2006-06-27 21:20 ` François Gannaz
  0 siblings, 0 replies; 2+ messages in thread
From: François Gannaz @ 2006-06-27 21:20 UTC (permalink / raw)


Maybe you could try to set multiple modes for your file. I only know
mmm-mode, but similar extensions are available :
http://www.emacswiki.org/cgi-bin/wiki/MultipleModes

You could try something like :

(mmm-add-group
 'fancy-test
  '(
   (file-m
    :submode xhtml-mode         ; choose your own mode
    :face mmm-code-submode-face ; light grey background
    :front "^FILE$"
    :back "^DATA$")
   (data-m
    :submode text-mode
    :front "^DATA$"
    :back "^FILE$")
   ))
(add-to-list 'mmm-mode-ext-classes-alist '(text-mode nil fancy-test))

Hope that helps.
--
François

Le mar 27 jun 11:45, wisnij@gmail.com a écrit :
> We have a file format at my company which is almost free-form ASCII
> with some markup, but it can get hairy enough that I am obliged to
> write an Emacs mode with font-locking to help with editing it.  The
> problem is, files are broken into sections kind of like this:
> 
>     # some header information
>     import(foo)
>     import(bar)
> 
>     TEXT
>     some paragraphs of &{marked-up text}
>     etc etc
> 
>     DATA
>     # tab-separated data
> 
> ...and so forth.  Which is to say, the only delimiter between
> different sections is the tokens "TEXT", "DATA", etc. on lines by
> themselves.
> 
> Each section differs slightly some the others syntactically: certain
> tokens are keywords in the header section but not elsewhere; one can
> normally start a comment with #, except within the TEXT block where it
> is just a normal character; and so forth.  There can still be
> structure within that block, though, so it doesn't feel like calling
> it all a string or comment is really the right way to go.
> 
> I've looked through the manual but I didn't really see anything
> helpful, apart from the admonition not to use font-lock-keywords for
> multi-line constructs.  Is there an accepted way to define syntactic
> "block" within a file like this?
> 
> _______________________________________________
> help-gnu-emacs mailing list
> help-gnu-emacs@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-06-27 21:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-27 18:45 Font-locking different "sections" in a file wisnij
2006-06-27 21:20 ` François Gannaz

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.