Re: escape() and '

2006-10-23 Thread A.J.Mechelynck

Mikolaj Machowski wrote:

Hello,

I understand that escape() was primarily designed to escape strings when
passing to system functions, but personally I never used that and in
didn't noticed such use in various scripts but very often it is used to
escape various charaters in Vim's own regexp matching or passing one
string to some other Vim command.

Hence is the problem: when escaping ' with escape(), character is
prepended with \ which doesn't make sense when passing it to other Vim
command because proper way to escape it in Vim is doubling it with
another '. Example::

:echo escape('as''df', )

m.





escape() is for a double-quoted string, or for the unquoted strings accepted 
by some commands. For a single-quoted string you need something else, such as


substitute(substitute(string,','',g),'^.*$','''\0''')


Best regards,
Tony.


Re: escape() and '

2006-10-23 Thread Nikolai Weibull

On 10/23/06, A.J.Mechelynck [EMAIL PROTECTED] wrote:

Mikolaj Machowski wrote:
 Hello,

 I understand that escape() was primarily designed to escape strings when
 passing to system functions, but personally I never used that and in
 didn't noticed such use in various scripts but very often it is used to
 escape various charaters in Vim's own regexp matching or passing one
 string to some other Vim command.

 Hence is the problem: when escaping ' with escape(), character is
 prepended with \ which doesn't make sense when passing it to other Vim
 command because proper way to escape it in Vim is doubling it with
 another '. Example::

 :echo escape('as''df', )



escape() is for a double-quoted string, or for the unquoted strings accepted
by some commands. For a single-quoted string you need something else, such as

substitute(substitute(string,','',g),'^.*$','''\0''')


I realize that you want to provide a solution to a problem and that's
fine, but you don't seem to have understood Mikolaj's
statement/question.  He begins with I understand that escape() was
primarily designed to escape strings when passing to system
functions, so I think he can figure out the solution well enough, and
he's instead asking why escape() hasn't been adopted to other areas of
use, such as escaping for regexes, which is a very common operation,
or passing a string to another Vim command.

Also, why would you ever write substitute(x, '^.*$', '''\0''') instead
of ' . x . '?

 nikolai


Re: escape() and '

2006-10-23 Thread Yakov Lerner

On 10/23/06, Nikolai Weibull [EMAIL PROTECTED] wrote:

On 10/23/06, Mikolaj Machowski [EMAIL PROTECTED] wrote:
 Hello,

 I understand that escape() was primarily designed to escape strings when
 passing to system functions, but personally I never used that and in
 didn't noticed such use in various scripts but very often it is used to
 escape various charaters in Vim's own regexp matching or passing one
 string to some other Vim command.

 Hence is the problem: when escaping ' with escape(), character is
 prepended with \ which doesn't make sense when passing it to other Vim
 command because proper way to escape it in Vim is doubling it with
 another '. Example::

 :echo escape('as''df', )

There should really be a third, optional, parameter to escape() where
you can specify what character to use for escaping.


I'd suggest that 3rd arg for escape(), if it's neeed (well you
always can brute-force escape things using substitute()), it would
be code of the context (1-5) for which escaping is destined. Because
Vim has at least 4-5 different escaping rules in different contexts:

1) escaping rules for double-quoted strings
2) escaping rules for single-quoted strings
3) escaping rules for :-command-line
4) escaping rules for regexes
5) escaping rules rules for rhs of the mapping.

Escaping would be different for each of those contexts.

Yakov


[PATCH] zip plugin: support any filename

2006-10-23 Thread tobutaz

Hello,
I've made a small fix to vim's zip plugin.
Before the patch, the plugin could only edit filenames with the zip extension.
When using an autoloadcmd to open jars, the files would be edited
correctly, but they would be saved at the wrong place, and would be
ignored when opening the archive they were saved to.
The plugin basically stripped the zip suffix in some places, and added
it back at some point, causing these problems. Now the plugin always
uses the full path.

I'm using this to edit firefox extensions directly inside their jar
files. I'm also attaching a patch that adds the required associations
(jar and xpi, I'm sure there are more).

Cheers,
--
Gabriel de Perthuis
--- /usr/share/vim/vim70/autoload/zip.vim	2006-10-20 11:48:47.0 +0200
+++ autoload/zip.vim	2006-10-23 21:04:06.0 +0200
@@ -131,7 +131,7 @@
   call Decho(fname.fname.)
 
get zipfile to the new-window
-  let zipfile= substitute(w:zipfile,'.zip$','','e')
+  let zipfile= w:zipfile
   let curfile= expand(%)
   call Decho(zipfile.zipfile.)
   call Decho(curfile.curfile.)
@@ -255,8 +255,8 @@
let zipfile = substitute(system(cygpath .zipfile),'\n','','e')
   endif
 
-  call Decho(zip -u '.zipfile..zip' '.fname.')
-  call system(zip -u '.zipfile..zip' '.fname.')
+  call Decho(zip -u '.zipfile.' '.fname.')
+  call system(zip -u '.zipfile.' '.fname.')
   if v:shell_error != 0
echohl Error | echo ***error*** (zip#Write) sorry, unable to update .zipfile. with .fname | echohl None
call inputsave()|call input(Press cr to continue)|call inputrestore()
@@ -264,12 +264,12 @@
   elseif s:zipfile_{winnr()} =~ '^\a\+://'
 support writing zipfiles across a network
let netzipfile= s:zipfile_{winnr()}
-   call Decho(handle writing .zipfile..zip across network as .netzipfile.)
+   call Decho(handle writing .zipfile. across network as .netzipfile.)
1split|enew
let binkeep= binary
let eikeep = ei
set binary ei=all
-   exe e! .zipfile..zip
+   exe e! .zipfile
call netrw#NetWrite(netzipfile)
let ei = eikeep
let binary = binkeep
--- /usr/share/vim/vim70/plugin/zipPlugin.vim	2006-10-20 11:48:47.0 +0200
+++ plugin/zipPlugin.vim	2006-10-23 21:59:30.0 +0200
@@ -35,6 +35,8 @@
  endif
 
  au BufReadCmd   *.zip		call zip#Browse(expand(amatch))
+ au BufReadCmd   *.jar		call zip#Browse(expand(amatch))
+ au BufReadCmd   *.xpi		call zip#Browse(expand(amatch))
 augroup END
 
  


Re: missing setbufline()?

2006-10-23 Thread Yegappan Lakshmanan

Hi Bram,

On 10/23/06, Bram Moolenaar [EMAIL PROTECTED] wrote:


Yegappan Lakshmanan wrote:

 On 10/22/06, Hari Krishna Dara [EMAIL PROTECTED] wrote:
   On 10/22/06, Hari Krishna Dara [EMAIL PROTECTED] wrote:
   
I see functions for creating new unlisted buffers (bufnr() with {create}
option), and for reading the lines from the buffer using getbufline(),
all without having to change the current buffer, but I don't see a
setbufline() so there is no way to set the lines without having to
switch to it. Is there a reason to leave this circle incomplete?
   
  
   Yes. I had a patch for the setbufline() function last year. There were
   several problems with it. So it was not included in Vim7 and only
   the getbufline() function was included.
  
   The setbufline() function worked only for loaded buffers. The undo
   history was not updated correctly.
  
   But I agree that it will be good to have the setbufline() function.
  
   - Yegappan
 
  Nice, so it will be included at some point after resolving these issues.
 

 You can try the attached patch against the latest Vim7 sources.
 The syntax of the new function is:

 setbufline({expr}, {lnum}, {line})

 where, {expr} specifies the loaded buffer name/number, {lnum} specifies
 a valid line number in that buffer and {line} is either a single line
 or a List of lines.

 Note. The patch also includes the new gettabvar() and settabvar()
 functions.

It looks like after this patch, if you change lines in another buffer
some marks in the current window will be moved.  Especially the
jumplist, perhaps setting cmdmod.lockmarks would help.  The ' and '
marks are probably moved.  Manual folds might be moved.  There may also
be redrawing problems.



The setbufline() implementation is similar to the one used in
if_perl.xs (Set) , if_python.c (SetBufferLine), if_ruby.c (set_buffer_line)
if_mzsch.c (set_buffer_line_list) and if_tcl.c (BUF_SET) interface
files. These problems should also be seen with those
interfaces also.



This needs a test in src/testdir.  And documentation, of course.



Will add the doc updates.



I'm very careful with including something like this.  Currently there is
no code that changes another buffer.  It could break more than you
expect.



You can't change the buffer contents with the Perl/Python/Tcl/Ruby
interfaces?

- Yegappan


Re: [PATCH] zip plugin: support any filename

2006-10-23 Thread Martin Stubenschrott
On Mon, Oct 23, 2006 at 10:02:48PM +0200, [EMAIL PROTECTED] wrote:
 I'm using this to edit firefox extensions directly inside their jar
 files. I'm also attaching a patch that adds the required associations
 (jar and xpi, I'm sure there are more).

I exactly wanted to do the same, but it didn't work. Hopefully your
patch gets accepted (didn't test it myself yet though).

--
Martin


Re: missing setbufline()?

2006-10-23 Thread Bram Moolenaar

Yegappan Lakshmanan wrote:

   On 10/22/06, Hari Krishna Dara [EMAIL PROTECTED] wrote:
 On 10/22/06, Hari Krishna Dara [EMAIL PROTECTED] wrote:
 
  I see functions for creating new unlisted buffers (bufnr() with 
  {create}
  option), and for reading the lines from the buffer using 
  getbufline(),
  all without having to change the current buffer, but I don't see a
  setbufline() so there is no way to set the lines without having to
  switch to it. Is there a reason to leave this circle incomplete?
 

 Yes. I had a patch for the setbufline() function last year. There were
 several problems with it. So it was not included in Vim7 and only
 the getbufline() function was included.

 The setbufline() function worked only for loaded buffers. The undo
 history was not updated correctly.

 But I agree that it will be good to have the setbufline() function.

 - Yegappan
   
Nice, so it will be included at some point after resolving these issues.
   
  
   You can try the attached patch against the latest Vim7 sources.
   The syntax of the new function is:
  
   setbufline({expr}, {lnum}, {line})
  
   where, {expr} specifies the loaded buffer name/number, {lnum} specifies
   a valid line number in that buffer and {line} is either a single line
   or a List of lines.
  
   Note. The patch also includes the new gettabvar() and settabvar()
   functions.
 
  It looks like after this patch, if you change lines in another buffer
  some marks in the current window will be moved.  Especially the
  jumplist, perhaps setting cmdmod.lockmarks would help.  The ' and '
  marks are probably moved.  Manual folds might be moved.  There may also
  be redrawing problems.
 
 
 The setbufline() implementation is similar to the one used in
 if_perl.xs (Set) , if_python.c (SetBufferLine), if_ruby.c (set_buffer_line)
 if_mzsch.c (set_buffer_line_list) and if_tcl.c (BUF_SET) interface
 files. These problems should also be seen with those
 interfaces also.

There also have been bugs in this implementation.  I don't know if there
are any others, it does not appear to be used much.

  This needs a test in src/testdir.  And documentation, of course.
 
 Will add the doc updates.
 
  I'm very careful with including something like this.  Currently there is
  no code that changes another buffer.  It could break more than you
  expect.
 
 You can't change the buffer contents with the Perl/Python/Tcl/Ruby
 interfaces?

OK, so you can.  But this doesn't mean it actually works properly,
without any undesired side effects.  This code is only included
optionally.  For the main Vim code I'm more careful.

-- 
From know your smileys:
 C=};*{)) Drunk, devilish chef with a toupee in an updraft,
   a mustache, and a double chin

 /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\download, build and distribute -- http://www.A-A-P.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///


Calling a non-existing dictionary function doesn't result in an error

2006-10-23 Thread Yegappan Lakshmanan

Hi all,

When a non-existing dictionary function is invoked using the :call
command, there is no error. But when it is used in an expression,
an error message is displayed. Is this the expected behavior?

  let a = {}
  call a.xyz()

The :call command silently returns without any errors. But
the following commands result in error:

:let x = a.xyz()
E716: Key not present in Dictionary: xyz()
E15: Invalid expression: a.xyz()

:echo a.xyz()
E716: Key not present in Dictionary: xyz()
E15: Invalid expression: a.xyz()

- Yegappan


Re: [PATCH] zip plugin: support any filename

2006-10-23 Thread Benji Fisher
On Mon, Oct 23, 2006 at 10:42:41PM +0200, Martin Stubenschrott wrote:
 On Mon, Oct 23, 2006 at 10:02:48PM +0200, [EMAIL PROTECTED] wrote:
  I'm using this to edit firefox extensions directly inside their jar
  files. I'm also attaching a patch that adds the required associations
  (jar and xpi, I'm sure there are more).
 
 I exactly wanted to do the same, but it didn't work. Hopefully your
 patch gets accepted (didn't test it myself yet though).

 The patch applies to runtime files, so you should be able to apply
it without having to re-compile.

HTH --Benji Fisher