* Identifying context files @ 2006-02-03 2:17 Aditya Mahajan 2006-02-03 7:10 ` Thomas A. Schmitz 2006-02-04 23:41 ` Mojca Miklavec 0 siblings, 2 replies; 10+ messages in thread From: Aditya Mahajan @ 2006-02-03 2:17 UTC (permalink / raw) I use (g)vim to edit both context and latex files. Unfortunately, both of them usually have *.tex extension. This mean that detecting filetype from extension is not possible, so one should look into the contents of the file to see if it a context file or not. I am planning to submit a ftdetect for context to vim. Right now, I check if the first six lines of the file contain any of '\\start\|\\enablemode\|\\unprotect\|\\setvariables\|\\module\|\\usemodule' and if so, set the filetype to context, otherwise it is set to tex (that loads latex plugins). This works for my context writing style. I would like to know about other people's preference. 1. Do you write some keyword unique to context in the first few lines of the file. Should I also check the last few line lines. 2. Are there any other keywords that you will like to include. 3. Is it enough to check the first 6 line or should I check more. I do not want to check more lines as this will make the detection slower (by a few mili secs). Thanks, Aditya -- Aditya Mahajan, EECS Systems, University of Michigan http://www.eecs.umich.edu/~adityam || Ph: 7342624008 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Identifying context files 2006-02-03 2:17 Identifying context files Aditya Mahajan @ 2006-02-03 7:10 ` Thomas A. Schmitz 2006-02-03 8:15 ` Hans Hagen 2006-02-04 23:41 ` Mojca Miklavec 1 sibling, 1 reply; 10+ messages in thread From: Thomas A. Schmitz @ 2006-02-03 7:10 UTC (permalink / raw) That sounds like an excellent idea, and I'd be very grateful to have such a detector. As to keywords: most of my ConTeXt files start with \enableregime; you may want to add this to your list. Best Thomas On Feb 3, 2006, at 3:17 AM, Aditya Mahajan wrote: > I use (g)vim to edit both context and latex files. Unfortunately, both > of them usually have *.tex extension. This mean that detecting > filetype from extension is not possible, so one should look into the > contents of the file to see if it a context file or not. > > I am planning to submit a ftdetect for context to vim. Right now, I > check if the first six lines of the file contain any of > '\\start\|\\enablemode\|\\unprotect\|\\setvariables\|\\module\|\ > \usemodule' > and if so, set the filetype to context, otherwise it is set to tex > (that loads latex plugins). > > This works for my context writing style. I would like to know about > other people's preference. > > 1. Do you write some keyword unique to context in the first few lines > of the file. Should I also check the last few line lines. > > 2. Are there any other keywords that you will like to include. > > 3. Is it enough to check the first 6 line or should I check more. I do > not want to check more lines as this will make the detection slower > (by a few mili secs). > > Thanks, > Aditya > > -- > 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Identifying context files 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 17:22 ` Aditya Mahajan 0 siblings, 2 replies; 10+ messages in thread From: Hans Hagen @ 2006-02-03 8:15 UTC (permalink / raw) Thomas A. Schmitz wrote: > That sounds like an excellent idea, and I'd be very grateful to have > such a detector. As to keywords: most of my ConTeXt files start with > \enableregime; you may want to add this to your list. > > Best > > Thomas > > > On Feb 3, 2006, at 3:17 AM, Aditya Mahajan wrote: > > >> I use (g)vim to edit both context and latex files. Unfortunately, both >> of them usually have *.tex extension. This mean that detecting >> filetype from extension is not possible, so one should look into the >> contents of the file to see if it a context file or not. >> >> I am planning to submit a ftdetect for context to vim. Right now, I >> check if the first six lines of the file contain any of >> '\\start\|\\enablemode\|\\unprotect\|\\setvariables\|\\module\|\ >> \usemodule' >> and if so, set the filetype to context, otherwise it is set to tex >> (that loads latex plugins). >> >> This works for my context writing style. I would like to know about >> other people's preference. >> >> 1. Do you write some keyword unique to context in the first few lines >> of the file. Should I also check the last few line lines. >> convention: % interface=en language=nl program=pdfetex etc, the following are understood by texexec ['tex','texengine'], ['program','texengine'], ['translate','tcxfilter'], ['tcx','tcxfilter'], ['output','backend'], ['mode','mode'], ['ctx','ctxfile'], ['version','contextversion'], ['format','texformats'], ['interface','texformats'] >> 2. Are there any other keywords that you will like to include. >> >> 3. Is it enough to check the first 6 line or should I check more. I do >> not want to check more lines as this will make the detection slower >> (by a few mili secs). >> >> checking does not take much time, for instance in scite, i check till i know; also (probably goes unnoticed), texexec does soem checking: it needs to figure out the interface: Hans ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Identifying context files 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 1 sibling, 1 reply; 10+ messages in thread From: Taco Hoekwater @ 2006-02-03 8:22 UTC (permalink / raw) Hans Hagen wrote: > > checking does not take much time, for instance in scite, i check till i > know; also (probably goes unnoticed), texexec does soem checking: it > needs to figure out the interface: While on that subject, can we make texexec honour % format={latex,pdflatex,plain,pdfetex} etc.? No need to do smart things, just run the command that results from engine+format, once. Taco ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Identifying context files 2006-02-03 8:22 ` Taco Hoekwater @ 2006-02-03 9:24 ` Hans Hagen 0 siblings, 0 replies; 10+ messages in thread From: Hans Hagen @ 2006-02-03 9:24 UTC (permalink / raw) Taco Hoekwater wrote: > Hans Hagen wrote: > >> checking does not take much time, for instance in scite, i check till i >> know; also (probably goes unnoticed), texexec does soem checking: it >> needs to figure out the interface: >> > > While on that subject, can we make texexec honour > > % format={latex,pdflatex,plain,pdfetex} > > etc.? No need to do smart things, just run the command > that results from engine+format, once. > the ruby version of texexec can handle that (if i did it right); Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl ----------------------------------------------------------------- ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Identifying context files 2006-02-03 8:15 ` Hans Hagen 2006-02-03 8:22 ` Taco Hoekwater @ 2006-02-03 17:22 ` Aditya Mahajan 2006-02-03 20:47 ` Hans Hagen 1 sibling, 1 reply; 10+ messages in thread From: Aditya Mahajan @ 2006-02-03 17:22 UTC (permalink / raw) >> On Feb 3, 2006, at 3:17 AM, Aditya Mahajan wrote: >> >>> 3. Is it enough to check the first 6 line or should I check more. I do >>> not want to check more lines as this will make the detection slower >>> (by a few mili secs). On Fri, 3 Feb 2006, Hans Hagen wrote: > > checking does not take much time, for instance in scite, i check till i > know; also (probably goes unnoticed), texexec does soem checking: it > needs to figure out the interface: > Can you send me the scite code which does the checking. I do not know lua, but it should not be too hard to covnert it to VimL. I do not want to reinvent the wheel. Aditya ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Identifying context files 2006-02-03 17:22 ` Aditya Mahajan @ 2006-02-03 20:47 ` Hans Hagen 0 siblings, 0 replies; 10+ messages in thread From: Hans Hagen @ 2006-02-03 20:47 UTC (permalink / raw) Aditya Mahajan wrote: >>> On Feb 3, 2006, at 3:17 AM, Aditya Mahajan wrote: >>> >>> >>>> 3. Is it enough to check the first 6 line or should I check more. I do >>>> not want to check more lines as this will make the detection slower >>>> (by a few mili secs). >>>> > > On Fri, 3 Feb 2006, Hans Hagen wrote: > >> checking does not take much time, for instance in scite, i check till i >> know; also (probably goes unnoticed), texexec does soem checking: it >> needs to figure out the interface: >> >> > > Can you send me the scite code which does the checking. I do not know lua, > but it should not be too hard to covnert it to VimL. I do not want to > reinvent the wheel. > her eis the ruby method used in newtexexec: def scantexcontent(filename) if FileTest.file?(filename) and tex = File.open(filename) then while str = tex.gets do case str.chomp when /^\%/o then # next when /\\(starttekst|stoptekst|startonderdeel|startdocument|startoverzicht)/o then setvariable('texformats','nl') ; break when /\\(stelle|verwende|umgebung|benutze)/o then setvariable('texformats','de') ; break when /\\(stel|gebruik|omgeving)/o then setvariable('texformats','nl') ; break when /\\(use|setup|environment)/o then setvariable('texformats','en') ; break when /\\(usa|imposta|ambiente)/o then setvariable('texformats','it') ; break when /(height|width|style)=/o then setvariable('texformats','en') ; break when /(hoehe|breite|schrift)=/o then setvariable('texformats','de') ; break when /(hoogte|breedte|letter)=/o then setvariable('texformats','nl') ; break when /(altezza|ampiezza|stile)=/o then setvariable('texformats','it') ; break when /externfiguur/o then setvariable('texformats','nl') ; break when /externalfigure/o then setvariable('texformats','en') ; break when /externeabbildung/o then setvariable('texformats','de') ; break when /figuraesterna/o then setvariable('texformats','it') ; break end end tex.close end end ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl ----------------------------------------------------------------- ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Identifying context files 2006-02-03 2:17 Identifying context files Aditya Mahajan 2006-02-03 7:10 ` Thomas A. Schmitz @ 2006-02-04 23:41 ` Mojca Miklavec 2006-02-11 4:59 ` Aditya Mahajan 1 sibling, 1 reply; 10+ messages in thread From: Mojca Miklavec @ 2006-02-04 23:41 UTC (permalink / raw) On 2/2/06, Aditya Mahajan wrote: > I use (g)vim to edit both context and latex files. Unfortunately, both > of them usually have *.tex extension. This mean that detecting > filetype from extension is not possible, so one should look into the > contents of the file to see if it a context file or not. > > I am planning to submit a ftdetect for context to vim. Right now, I > check if the first six lines of the file contain any of > '\\start\|\\enablemode\|\\unprotect\|\\setvariables\|\\module\|\\usemodule' > and if so, set the filetype to context, otherwise it is set to tex > (that loads latex plugins). > > This works for my context writing style. I would like to know about > other people's preference. > > 1. Do you write some keyword unique to context in the first few lines > of the file. Should I also check the last few line lines. \enableregime, \setupoutput Is \setup too general (will it recognize any LaTeX document)? I don't know how slow/fast the detection is since I only use short files, but if you check the last few lines, \stoptext (together with its international alternatives) isn't a bad idea. Also, if you check the last few lines: emacs users usually put some lines of code at the end to mark the document as being written in ConTeXt. > 2. Are there any other keywords that you will like to include. A keyword like set tex_preferred_dialect=latex/context :) and then 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) (don't take that suggestion too seriously) Mojca ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Identifying context files 2006-02-04 23:41 ` Mojca Miklavec @ 2006-02-11 4:59 ` Aditya Mahajan 2006-02-11 7:05 ` Aditya Mahajan 0 siblings, 1 reply; 10+ messages in thread From: Aditya Mahajan @ 2006-02-11 4:59 UTC (permalink / raw) <--- On Feb 4, Mojca Miklavec wrote ---> > On 2/2/06, Aditya Mahajan wrote: >> I use (g)vim to edit both context and latex files. Unfortunately, both >> of them usually have *.tex extension. This mean that detecting >> filetype from extension is not possible, so one should look into the >> contents of the file to see if it a context file or not. >> >> I am planning to submit a ftdetect for context to vim. Right now, I >> check if the first six lines of the file contain any of >> '\\start\|\\enablemode\|\\unprotect\|\\setvariables\|\\module\|\\usemodule' >> and if so, set the filetype to context, otherwise it is set to tex >> (that loads latex plugins). >> >> This works for my context writing style. I would like to know about >> other people's preference. >> >> 1. Do you write some keyword unique to context in the first few lines >> of the file. Should I also check the last few line lines. > > \enableregime, \setupoutput > > Is \setup too general (will it recognize any LaTeX document)? That is the main trouble. In principle, you can have latex document with \starttext as the first line. But most usual tex files do not have it. I have not seen a latex macro with \setup. So, I will include that also. > I don't know how slow/fast the detection is since I only use short > files, but if you check the last few lines, \stoptext (together with > its international alternatives) isn't a bad idea. The file may not necessarily end with \stoptext. It can be \stopcomponent, \stopproduct, \stopproject, \stopenvironment. Anything else? > Also, if you check the last few lines: emacs users usually put some > lines of code at the end to mark the document as being written in > ConTeXt. Ah, compatibility with Emacs. I will look at that later ;) >> 2. Are there any other keywords that you will like to include. > > A keyword like > set tex_preferred_dialect=latex/context :) I looked it up and it seems that g:Tex_Flavor is meant for this kind of thing. > and then > > 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. Aditya -- Aditya Mahajan, EECS Systems, University of Michigan http://www.eecs.umich.edu/~adityam || Ph: 7342624008 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Identifying context files 2006-02-11 4:59 ` Aditya Mahajan @ 2006-02-11 7:05 ` Aditya Mahajan 0 siblings, 0 replies; 10+ messages in thread From: Aditya Mahajan @ 2006-02-11 7:05 UTC (permalink / raw) <--- 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2006-02-11 7:05 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2006-02-03 2:17 Identifying context files 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 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).