Re: [Vim-latex-devel] Re: [Vim-latex-cvs] vimfiles/plugin imaps.vim,1.7,1.8
Brought to you by:
srinathava,
tmaas
From: Srinath A. <sr...@fa...> - 2002-12-12 01:27:48
|
I agree that the IMAP() with the variable number of arguments is the most elegant and sound. But consider the fact that changing imaps will also mean changing every place where Imap_PutTextWithMovement() and IMAP() are used... For example, consider the following code snippet from envmacros.vim: -----------------------------------%<----------------------------------- let s:figure =3D "\\begin{figure}[=ABhtpb=BB]\<cr>\\begin{center}\<cr>\\psf= ig{figure=3D=ABeps file=BB}\<cr>\\end{center}\<cr>\\caption{=ABcaption text= =BB}\<cr>\\label{fig:=ABlabel=BB}\<cr>\\end{figure}=AB=BB" " Tex_figure: {{{ function! Tex_figure(env) if g:Tex_UseMenuWizard =3D=3D 1 let flto =3D input('Float to (htbp)? ') let caption =3D input('Caption? ') let center =3D input('Center ([y]/n)? ') let label =3D input('Label (for use with \ref)? ') " additional to AUC Tex since my pics are usually external files let pic =3D input('Name of Pic-File? ') if flto !=3D '' let flto =3D '['.flto."]\<cr>" else let flto =3D "\<cr>" endif if pic !=3D '' let pic =3D '\input{'.pic."}\<cr>" else let pic =3D "=E4\<cr>" endif if caption !=3D '' let caption =3D '\caption{'.caption."}\<cr>" endif if label !=3D '' let label =3D '\label{fig:'.label."}\<cr>" endif if center =3D=3D 'y' let centr =3D '\begin{center}' . "\<cr>" let centr =3D centr . pic let centr =3D centr . caption let centr =3D centr . label let centr =3D centr . '\end{center}' . "\<cr>" else let centr =3D pic let centr =3D centr . caption let centr =3D centr . label endif let figure =3D '\begin{'.a:env.'}'.flto let figure =3D figure . centr let figure =3D figure . '\end{'.a:env.'}' return IMAP_PutTextWithMovement(figure) else return IMAP_PutTextWithMovement(s:figure) endif endfunction call IMAP('EDE', "\<C-r>=3DTex_description()\<CR>", 'tex') -----------------------------------%<----------------------------------- Ofcourse, this code is "extracted" from envmacros.vim rather than directly cut and pasted, but the general flow of information is as indicated... You will see that with the variable argument syntax, these kind of functions will take a significant amount of tweaking... I think almost of envmacros.vim and elementmacros.vim will have to be re-written. Also mathmacros.vim contains about 600 lines which look like this: -----------------------------------%<----------------------------------- let s:pA =3D 'amenu <silent> 85 '.s:MathMenuName exe s:pA2a.'mathbf{} <plug><C-r>=3DIMAP_PutTextWithMovement(= "\\mathbf{=E4}=AB=BB")<cr>' -----------------------------------%<----------------------------------- Changing these will also require a nontrivial amount of work. I hope I dont come across as discouraging or anything, but the fact remains that imaps.vim is heavily depended upon by many many things in latex-suite. (Ofcourse, thats all the more reason to make it better). So even if we do decide to go with the variable number of arguments method, we should make sure that latex-suite doesnt remain broken for too long in the change period. What about creating new functions called IMAP_new and Imap_PutTextWithMovement_new and begin to slowly port things across to use these. When we are satisfied that almost (or all) or latex-suite uses these functions, then rename them to IMAP and Imap_PutTextWithMovement and remove the originals... (the standard way to obsolete things in software, I suppose...) Let me know what you think. Also, in places like mathmacros.vim, I would think that the easiest way to affect the change is to first do a quick exec "% s/\e4/<++>/g" " for <a-umlaut> exec "% s/\xab/<+/g" " for "<<" exec "% s/\xbb/+>/g" " for ">>" % s/IMAP_PutTextWithMovement/Tex_PutTextWithMovement/g where Tex_PutTextWithMovement() will have to be the "hacky" function which knows both about the "\xab" characters and the [g:b]Imap_PlaceHolder* settings. This new function will split its arguments into variable arguments and then call Imap_PutTextWithMovement_new. In any case, I would think that some wrapper function like Tex_PutTextWithMovement would have been useful even if we had Imap_PutTextWithMovement_new from the beginning. Srinath On Wed, 11 Dec 2002, Benji Fisher wrote: > OK, I had a good, long look at imaps.vim. As currently written, > IMAP() and IMAP_PutTextWithMovement() are global functions, and their > input has to use the hard-coded special values. This could be a problem > if, for example, "<<" and ">>" are used a French quotation marks, and > the user wants them in the replacement text. I think the > [bg]:Imap_PlaceHolder* should be used internally as well as in the file. > > > Also, <C-j> only deletes the placeholders if they are things like > > "<++>". If there is some explanation like "<+something+>", then it wont > > get deleted by pressing <C-j>. It will be replaced when you type some > > printable char. > > Good. > > > Again, just to emphasize, we are not trying to decide on a single > > character to be used across all languages/locales etc. We are just > > trying to decide for latex-suite... imaps.vim is kinda independent of > > this. (At present, Imap_PutTextWithMovement tries to replace certain > > patterns in the lhs with the user's place holder settings. This should > > be moved over to something in latex-suite). > [snip] > > > >>IMAP(). I propose changing this to > >> > >> :call IMAP(ft, lhs, rhs1, ph1, rhs2, ph2, ...) > >> > > > > This is a beautiful solution. But consider that not all macros in > > latex-suite are triggered from IMAP(). Some of them do something like: > > > > inoremap <M-c> <C-r>=3DTex_MathCal()<CR> > > > > Then Tex_MathCal() does: > > > > return Imap_PutTextWithMovement("\\cite{=AB=BB)=AB=BB") > > > > So I suppose we will also have to change Imap_PutTextWithMovement() to > > accept variable arguments... Although the solution above does look lik= e > > it could be _the_ correct solution, I have a feeling that hardcoding > > placeholders is not such a big deal at all... > > > > Assumption: > > > > latex-suite will never need to use strings like "<+something+>" except > > for demarcating placeholer characters. > > This assumtion is ****important***** > > > > Execution: > > > > envmacros.vim does: > > > > call Tex_IMAP('`/', '\frac{<++>}{<++>}<++>', 'tex') > > > > texrc does: > > > > let g:Imap_PlaceHolderStart =3D "\xab" > > let g:Imap_PlaceHolderEnd =3D "\xbb" > > > > We define a new function Tex_IMAP which replaces "<+" with the user's > > choice of g:Imap_PlaceHolderSetting and then call IMAP() with this new > > thing. Similary Imap_PutTextWithMovement is replaced with > > Tex_PutTextWithMovement. > > > > Finally, when the user press `/, he expands to \frac{|}{=AB=BB}=AB=BB w= here | is > > the cursor position. If he wants he could set a different value of the > > place holder, if =AB=BB does not display nicely on his comp or if he us= es a > > language where =AB=BB are legitimate chars. > > > > NOTE: imaps.vim will no longer try to replace the "<+" chars with > > [gb]:Imap_PlaceHolderStart. It will only use this setting in the > > Imap_JumpFunc(). > > > > Therefore, we could presumably have a user with an ftplugin/xml.vim > > file where he sets: > > > > let b:Imap_PlaceHolderStart =3D '?' > > let b:Imap_PlaceHolderEnd =3D '?' > > > > call IMAP('li`', '<li>??</li>??', 'xml') > > > > The crazy mathematician does > > > > " I have proved that the following strings occur with a probability > > " less than 1/(2*pi)^5*10e-12 in my files. I hope this is safe > > " enough. > > let b:Imap_PlaceHolderStart =3D '%xdf@#$' > > let b:Imap_PlaceHolderEnd =3D '*&#$*&' > > > > When he presses `/, he will get \frac{|}{%xdf@#$*&#$*&}%xdf@#$*&#$*& > > with | ofcourse denoting cursor position. > > > > Does this make everyone happy? > > > > Please try to come up with cases where the above system might fail... > > > > Okay... this mail is getting out of hand... > > > > Srinath > > I think your proposal will work, but I think it will be hard to > maintain. First, I do not like the idea of an extra level of > indirection: Tex_Foo() as a wrapper for IMAP_Foo(). Second, it is > strange for Tex_Foo() to know about the "<+" character in LaTeX suite > and also the [bg]:Imap_PlaceHolder* variables. > > I propose changing the IMAP() and Imap_PutTextWithMovement() > functions with versions that take a variable number of arguments, as > discussed above. Internally and in the file, they will use the > [bg]:Imap_PlaceHolder* variables, with "<+" and "+>" as the defaults. > This scheme has the following advantages (some of which your proposal > shares): > > 1. no funky characters in script files > 2. Scripts that call IMAP() and Imap_PutTextWithMovement() do not need > to know what the special characters are. > 3. When the user decides to change [bg]:Imap_PlaceHolder*, nothing else > needs to be changed. > > There are also some other changes I would like to make. > > 4. Is there any reason not to use curly-brace variables? These are > available in all vim 6.x (i.e., not new in 6.1 and not, as far as I can > tell, a compilation option). > > 5. I would like to move the documentation from the comments to > doc/imaps.txt . > > 6. other clever simplifications > > If we can agree on the IMAP(ft, lhs, ...) approach, then I will do > the work. I should be able to get some of it done on Friday. > > --Benji > > > > ------------------------------------------------------- > This sf.net email is sponsored by: > With Great Power, Comes Great Responsibility > Learn to use your power at OSDN's High Performance Computing Channel > http://hpc.devchannel.org/ > _______________________________________________ > Vim-latex-devel mailing list > Vim...@li... > https://lists.sourceforge.net/lists/listinfo/vim-latex-devel > > --=20 Srinath Avadhanula Dec 11 4:58pm Excellent day for drinking heavily. Spike office water cooler. |