Wednesday, May 31, 2017

Re: Insert lines at begin of file with writefile

Hi,

2017/5/31 Wed 18:11:29 UTC+9 Ni Va wrote:
> Le mardi 30 mai 2017 13:29:10 UTC+2, ZyX a écrit :
> > 2017-05-30 14:21 GMT+03:00 Ni Va <nivaemail@gmail.com>:
> > > Le mardi 30 mai 2017 13:03:38 UTC+2, ZyX a écrit :
> > >> 2017-05-30 11:21 GMT+03:00 Ni Va <nivaemail@gmail.com>:
> > >> > Hi,
> > >> >
> > >> >
> > >> > Is that a way to tell writefile() func to append lines at the beginning of file?
> > >>
> > >> Just read the whole file, prepend and then write the whole file. In
> > >> any case I do not know a way to actually prepend bytes to the file: if
> > >> you seek to the end of file (or open it in append mode) and start
> > >> writing to it you get appending. If you seek to the start and start
> > >> writing you will just overwrite first bytes. So programming languages
> > >> do not have "prepending" abstraction because it is not supported by
> > >> the OS and thus is going to either cost very much or have problems
> > >> like loosing data on crashes.
> > >>
> > >> >
> > >> > Thank you
> > >> > Niva
> > >> >
> > >> > --
> > >> > --
> > >> > You received this message from the "vim_use" maillist.
> > >> > Do not top-post! Type your reply below the text you are replying to.
> > >> > For more information, visit http://www.vim.org/maillist.php
> > >> >
> > >> > ---
> > >> > You received this message because you are subscribed to the Google Groups "vim_use" group.
> > >> > To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
> > >> > For more options, visit https://groups.google.com/d/optout.
> > >
> > > Do you think readfile writefile would be faster than that :
> > >
> > > let begin = [$vimruntime."/gvim.exe", "-c", "edit ".makefile, "-c",
> > > \"call append(0, ".string(lines2Append).")", "-c", "wq"]
> > > call x.add_cmd(begin) " ==>>>> Launch cmd as job
> >
> > With readfile+writefile you load a file into memory and write there.
> > With gvim you are forking, loading gvim.exe and a big bunch of
> > libraries needed for GUI, loading a file into memory (though buffer
> > structure should be a bit more efficient then a list from `readfile()`
> > AFAIK), loading a big bunch of plugins (do not do such things without
> > `-u NONE -i NONE`), loading GUI (use `--cmd` for such things, not
> > `-c`). Which is faster? Actually may be your variant if you do not
> > need to wait for gvim to finish prepending because time would be
> > limited to only forking. readfile()+writefile() if you do need to
> > wait.
> >
> > >
> > > --
> > > --
> > > You received this message from the "vim_use" maillist.
> > > Do not top-post! Type your reply below the text you are replying to.
> > > For more information, visit http://www.vim.org/maillist.php
> > >
> > > ---
> > > You received this message because you are subscribed to the Google Groups "vim_use" group.
> > > To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
> > > For more options, visit https://groups.google.com/d/optout.
>
> Ok applying your advise it is sure the radfile writefile method is amazing faster in binary mode.
>
> Then this method 2 below can be done by job_start( ?
>
> Thank you
>
>
>
> " add append lines
> let lines2Append = [
> \ expand("SDK_INCLUDE_DIR=$ProgramFiles (x86)/Windows Kits/8.1/Include")
> \, expand("VS_DIR=$ProgramFiles (x86)/Microsoft Visual Studio 14.0/VC")
> \, 'CPU=AMD64'
> \, 'FEATURES=HUGE'
> \, 'OLE=yes'
> \, 'GUI=yes'
> \, 'XPM=no'
> \, 'NETBEANS=no'
> \, 'CSCOPE=no'
> \, 'MBYTE=yes'
> \, 'DYNAMIC_LUA=yes'
> \, 'LUA=.\\lua53'
> \, 'LUA_VER=53'
> \, 'DYNAMIC_PYTHON=yes'
> \, 'PYTHON=C:\Python27'
> \, 'PYTHON_VER=27'
> \, 'DYNAMIC_PYTHON3=no'
> \, 'PYTHON3='
> \, 'PYTHON3_VER='
> \, 'EVENT_LOOP=yes'
> \, '
> '
> \]
> " method 1 : slow to add lines but job able
> let cmd = [$vimruntime."/gvim.exe", "-c", "edit ".makefile, "-c",
> \"call append(0, ".string(lines2Append).")", "-c", "wq"]
> " call x.add_cmd(cmd) "started as job by job_start( and handlers
>
>
> " method 2 : faster but no job able ??!?
> let originalFile = readfile(makefile,'b')
> call writefile( lines2Append, makefile, 'b')
> call writefile( originalFile, makefile, 'a')

Just curious.
Why you edit Make_mvc.mak?

Normally you just need to specify the option in the command line. E.g.:

nmake -f Make_mvc.mak "SDK_INCLUDE_DIR=..." CPU=AMD64 FEATURES=... ...

Another option is creating a batch file which sets the options to environment
variables, then run nmake. E.g.:

@echo off
set SDK_INCLUDE_DIR=...
set CPU=AMD64
set FEATURES=...
...
nmake -f Make_mvc.mak


Regards,
Ken Takata

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: