0

I am proficient in developing basic syntax highlighting modes based on font-lock-defaults and regex (even with font-lock-multiline and font-lock-extend-region-functions).

Today I faced with format of natural language translation dictionary which look like:

__

begin
  [bɪˈgɪn]
  v1
began
  [bɪˈgæn]
  v2
begun
  [bɪˈgʌn]
  v3

v
ru: начать
ua: починати
__

smile
  [smaɪl]

v
ru: улыбаться

n
ru: улыбка
__

e.g.

abbr
en: for example
la: exempli gratia
__

x-rays

topic: sci
en: a kind of radiation that can pass through
  most solid materials, often used in medicine
__

woman
  [ˈwʊmən]
  s
women
  [wɪmɪn]
  pl

n
ru: женщина
ua: жінка
__

colour
  gb
  ['kʌlə]
color
  us
  ['kʌlər]

n
ru: цвет
ua: колір
__

white
  [waɪt]

adj
ant: black
ru: чорный
ua: чорний

As easy to see indenting and new lines with special prefixes define syntax.

Indenting in first part of entry used to separate word variances. Blank lines in second part of article separate different word meaning, lines should begin with defined prefixes and indenting is not allowed.

regex is not context aware and can't be used to properly highlight such file format.

File format have property that is can be validated from any point of file with small lookup around for ^__$ regex.

So I am interested in writing mode that properly highlighted and "localy" validated file (no need to validate far from screen several screens).

Is it possible to develop code or mark text in buffer after parsing so in a few cases when intending necessary function for indenting (by TAB) would be easy to code?

What API should I use to develop such mode myself?

Are there any good reference of existing code to follow?

  • I'm not sure if you can use Semantic for this, (I never actually managed to, but I also didn't try very hard), but it seems like it would be the tool for it. – wvxvw Mar 14 '16 at 6:49
2

You need to use a function for finding the match data. I think this example could help https://stackoverflow.com/questions/14668225/context-sensitive-font-locking-in-emacs

It is a little tricky but basically you can search forward and then search back and forward for context. Set the match data and leave the point at the end I think.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.