<--- On Feb 10, Aditya Mahajan wrote --->

> <--- On Feb 4, Mojca Miklavec wrote --->
>
>> if tex_preferred_dialect == context
>>    if the first few lines contain \documentclass or \documentstyle,
>>    declare it latex, otherwise ConTeXt
>> else
>>   [your script]:
>>   if the first line contains % tex= or any keywords that Hans sent
>>   or if the first six lines contain the keywords you suggested
>> (together with international alternatives)
>
> Actually, this may not be too hard to implement. Let me have a look at
> this, and I will get back to you when there is something working.

This is the else part of the script (modified from Hans ruby code to 
vimL). I tested it on the sources of the manuals, and the only thing 
that it could not detect correctly was metafun/mfun-ef.tex. Looking at 
that file, I do not think that it contains any context specific 
keyword.

Can others test on their context projects and see if this works 
correctly. I do not know the itnernational alternatives of all the 
commands. If your document uses any of those, let me know. Also check 
your latex documents to see that the script does not recognise it as 
context.

To run the script, save it as identify.vim . Inside vim,
:source identify.vim
:cd directory containing tex files
:argadd *.tex
:redir @a
:argdo call Identify_ConTeXt()
:redir END
:e temp_file
:put a

Now you have all the vim messages in temp_file

:g!/ConTeXt/d

Get rid of lines not containing context.

The message format from the script is
filename ConTeXt not detected/ detected at line ... format (en|nl|de|it)

Here is the script
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" A bit more detailed evaluation for english. \\set and \\use may be too
" ambiguous. Checking for setvariables and use encoding

let g:ConTeXt_en =
       \ 
'\\\(starttext\|startproject\|startproduct\|startcomponent\|startenvironment'.
       \ '\|enablemode\|enableregime\|setvariables\|useencoding\|setup' .
       \ '\|starttypescript' .
       \ '\|usemodule\|externalfigure\)'

let g:ConTeXt_nl =
       \ 
'\\\(starttekst\|startprodukt\|startprojekt\|startonderdeel\|startdocument\|startoverzicht'.
       \ '\|stel\|gebruik\|omgeving' .
       \ '\|externfiguur\)'

let g:ConTeXt_de =
       \ '\\\(stelle\|verwende\|umgebung\|benutze' .
       \ '\|externeabbildung\)'

let g:ConTeXt_it =
       \  '\\\(usa\|imposta\|ambiente' .
       \  '\|figuraesterna\)'

let g:ConTeXt_generic =
       \  '\\\(protect\|unprotect\|startmode\|mainlanguage\)'


function! Identify_ConTeXt()
   let g:ConTeXt_texformat = ""
   let l:last_line_num = line('$')
   let l:curr_line_num = 1
   while l:curr_line_num <= l:last_line_num
     let l:curr_line = getline(l:curr_line_num)
     if l:curr_line !~ '^%'
       if l:curr_line =~ g:ConTeXt_en
         let g:ConTeXt_texformat = 'en'
         break
       endif
       if l:curr_line =~ g:ConTeXt_generic
         let g:ConTeXt_texformat = 'generic'
       endif
       if l:curr_line =~ g:ConTeXt_nl
         let g:ConTeXt_texformat = 'nl'
         break
       endif
       if l:curr_line =~ g:ConTeXt_de
         let g:ConTeXt_texformat = 'de'
         break
       endif
       if l:curr_line =~ g:ConTeXt_it
         let g:ConTeXt_texformat = 'it'
         break
       endif
     endif
     let l:curr_line_num = l:curr_line_num + 1
   endwhile
   if g:ConTeXt_texformat == ""
     echo bufname("%") . ' ConTeXt not detected!'
   else
     echo bufname("%") . ' ConTeXt detected at line ' . l:curr_line_num .
    \  ' format: ' . g:ConTeXt_texformat
   endif
endf

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

  -- 
Aditya Mahajan, EECS Systems, University of Michigan
http://www.eecs.umich.edu/~adityam || Ph: 7342624008
_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

Reply via email to