ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Aditya Mahajan <adityam@umich.edu>
Subject: Re: Identifying context files
Date: Sat, 11 Feb 2006 02:05:23 -0500 (EST)	[thread overview]
Message-ID: <Pine.WNT.4.63.0602110148560.1048@nqvgln> (raw)
In-Reply-To: <Pine.WNT.4.63.0602102353270.1048@nqvgln>

<--- 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

      reply	other threads:[~2006-02-11  7:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-03  2:17 Aditya Mahajan
2006-02-03  7:10 ` Thomas A. Schmitz
2006-02-03  8:15   ` Hans Hagen
2006-02-03  8:22     ` Taco Hoekwater
2006-02-03  9:24       ` Hans Hagen
2006-02-03 17:22     ` Aditya Mahajan
2006-02-03 20:47       ` Hans Hagen
2006-02-04 23:41 ` Mojca Miklavec
2006-02-11  4:59   ` Aditya Mahajan
2006-02-11  7:05     ` Aditya Mahajan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.WNT.4.63.0602110148560.1048@nqvgln \
    --to=adityam@umich.edu \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).