Re: filename completion and filereadable

2006-08-15 Thread Alexander 'boesi' Bösecke
Hi

Am 09.08.2006 13:49:15 schrieb Alexander 'boesi' Bösecke:

Well all the discussion about single and double quoted didn't solve my
problem - the completion of a filename adds a \ before a space.

Try the following:

:let s = g:\\CS\ Simple\\
:echo s
g:\CS Simple

As you can see the additional \ is removed. I think the same happens in
the following, because it just works:

:e g:\CS\ Simple\run.pyw   Here I've used file completion

But when using input(...), the \ isn't removed. And the problem is now,
that filereadable doesn't accept that.

So the question is, where is the bug? 


cu boesi
-- 
seasons82 was ist rl?
seasons82 und muss man das wissen?
...der moment wo einem klar wird,
  dass man zuviel chattet...


Re: filename completion and filereadable

2006-08-15 Thread Yakov Lerner

On 8/15/06, Alexander 'boesi' Bösecke [EMAIL PROTECTED] wrote:

Hi

Am 09.08.2006 13:49:15 schrieb Alexander 'boesi' Bösecke:

Well all the discussion about single and double quoted didn't solve my
problem - the completion of a filename adds a \ before a space.

Try the following:

:let s = g:\\CS\ Simple\\
:echo s
g:\CS Simple

As you can see the additional \ is removed. I think the same happens in
the following, because it just works:

:e g:\CS\ Simple\run.pyw   Here I've used file completion

But when using input(...), the \ isn't removed. And the problem is now,
that filereadable doesn't accept that.

So the question is, where is the bug?


The bug is in completion in the input() function.
Since filename is unlikely to begin with whitespace, you have a workaround:

  let fn = input('Mainfile: ', expand('%:p'), 'file')
  fn = substitute(fn, '\\ ', ' ', 'g')

Yakov


Re: filename completion and filereadable

2006-08-10 Thread Alexander 'boesi' Bösecke
Hi

Am 10.08.2006 16:02:54 schrieb Alan G Isaac:

 On Thu, 10 Aug 2006, Matthew Winn apparently wrote: 
  But ... versus '...' is just as explicit.
 
 Ah, that explains why the question keeps coming up on this 
 list and never in a Python forum ... Or not?
 
  In fact, apart from Python and XML I can't think of any 
  languages that don't make a distinction between double and 
  single quotes, as it's an extremely useful difference and 
  it's a waste of a limited character set to ignore it. 
 
 Hmm, I guess you 'never need' nested quotes?

As an additional note not especially related to ViM - with '...' and
... you have 2 kind of strings. But how do you express unicode-strings?
Use `...` or something like that? And what happens, when in the future
there will be a 4. string-type? With the syntax of python that's no
problem. 


cu boesi
-- 
A Achkatz'l ofm Baam
des hot a schins Laam
braucht keen Pfenng Gald
un freit sich of dr Walt


Re: filename completion and filereadable

2006-08-10 Thread A.J.Mechelynck

Alan G Isaac wrote:
On Thu, 10 Aug 2006, Matthew Winn apparently wrote: 

But ... versus '...' is just as explicit.


Ah, that explains why the question keeps coming up on this 
list and never in a Python forum ... Or not?


In fact, apart from Python and XML I can't think of any 
languages that don't make a distinction between double and 
single quotes, as it's an extremely useful difference and 
it's a waste of a limited character set to ignore it. 


Hmm, I guess you 'never need' nested quotes?

In any case, I did not suggest changing the current quote
behavior, just adding an additional syntax.

Cheers,
Alan Isaac






No, in Vim v7, 'I don''t need nested quotes.' because a pair of single 
quotes within a single-quoted string means a single single-quote at that 
point in the resulting string. In pre-v7 Vim, I could have used string 
concatenation, which is less elegant, but works too.



Best regards,
Tony.


Re: filename completion and filereadable

2006-08-10 Thread A.J.Mechelynck

Alexander 'boesi' Bösecke wrote:

Hi

Am 10.08.2006 16:02:54 schrieb Alan G Isaac:

On Thu, 10 Aug 2006, Matthew Winn apparently wrote: 

But ... versus '...' is just as explicit.
Ah, that explains why the question keeps coming up on this 
list and never in a Python forum ... Or not?


In fact, apart from Python and XML I can't think of any 
languages that don't make a distinction between double and 
single quotes, as it's an extremely useful difference and 
it's a waste of a limited character set to ignore it. 

Hmm, I guess you 'never need' nested quotes?


As an additional note not especially related to ViM - with '...' and
... you have 2 kind of strings. But how do you express unicode-strings?
Use `...` or something like that? And what happens, when in the future
there will be a 4. string-type? With the syntax of python that's no
problem. 



cu boesi


What happens in the future when there's a 4th string type? The whole 
point of this argument is to show you that there's even no need for a 
3rd one.


If the script is in Unicode, I can enter any character into a 'raw' or 
cooked string, using digraphs, a keymap, or the method described under 
:help i_CTRL-V_digit. No problem. To describe, in a non-Unicode 
script, strings containing Unicode codepoints not available in the 
script's encoding, I would have to use a cooked string with \u or 
maybe \Char-0x in it, where every h is a nybble, or else (for 
one or a few particular codepoints) move them to a data item at the 
start of the script, using for instance 'let s:bom = \uFEFF' then use 
string concatenation elsewhere in the script. This only shows that when 
describing strings containing non-Latin characters, Latin1 is not the 
best encoding for the script (and BTW, the :scriptencoding command may 
come in handy if the script is neither in Latin1 nor in UTF-8 with BOM.)



Best regards,
Tony.


Re: filename completion and filereadable

2006-08-09 Thread Yakov Lerner

On 8/9/06, Alexander 'boesi' Bösecke [EMAIL PROTECTED] wrote:

Hi

I'm using
let fn = input('Mainfile: ', expand('%:p'), 'file')
to ask for a filename. When I press Tab to complete the filename, a
spacewill be replaced by a \space. So G:\Projekte\CS
Simple\run.pyw becomes G:\Projekte\CS\ Simple\run.pyw. When I check
this filename with filereadable, it returns False. But when the filename
is G:\Projekte\CS Simple\run.pyw (ie. not using completion),
filereadable returns True.

Well I could modify the filename with
let fn = substitute(fn,  ,  , g)
before calling filereadable. But I think this can not be the right way.

So where is the error - is it me, is it input or is it filereadable?


Looks like an input() bug to me. Confirmed in Linux for filenames
containing spaces:
 :cd /tmp
 :!touch a b
 :let x=input(file-,,file)
Enter: 'a', space, 'b' , press Tab. Input turns into 'a\ b' and after
Enter, variable contains 4 chars 'a\ b'

Yakov


Re: filename completion and filereadable

2006-08-09 Thread Alexander 'boesi' Bösecke
Hi

Am 09.08.2006 14:08:04 schrieb Yakov Lerner:

 Looks like an input() bug to me.

To me it looks even more strange. I've tested a bit more.

:echo filereadable(G:\Projekte\CS Simple\run.pyw)
:echo filereadable(G:\Projekte\CS\ Simple\run.pyw)
returns 0

:echo filereadable(G:\\Projekte\\CS Simple\\run.pyw)
:echo filereadable(G:\\Projekte\\CS\ Simple\\run.pyw)
:echo filereadable(G:/Projekte/CS Simple/run.pyw)
returns 1

In my script versions 1, 3 and 5 work. So there filereadable has a
problem with the quoted space. And in command mode the unqouted
backslash is the problem.


Here is the function from my script:
---snip---
function! s:SetMainScript()
  if s:mainfile == 
let fnInput = expand('%:p')
  else
let fnInput = s:mainfile
  endif
  call inputsave()
  let fn = input('Mainfile: ', fnInput, 'file')
  call inputrestore()
   input precedes space with \, but filereadable does not like that
   let fn = substitute(fn,  ,  , g)
  if filereadable(fn) == 1
let s:mainfile = fn
let s:ExeDir = fnamemodify(fn, ':p:h')
echo s:mainfile . ' set as the starting program.'
  else
echoerr fn . ' is not readable'
  endif
endfunction
---snap---


cu boesi
-- 

...schlafen ist sowieso ungesund...
   .-==Police Academy I==-.


Re: filename completion and filereadable

2006-08-09 Thread Yakov Lerner

On 8/9/06, Alexander 'boesi' Bösecke [EMAIL PROTECTED] wrote:

Hi

Am 09.08.2006 14:08:04 schrieb Yakov Lerner:

 Looks like an input() bug to me.

To me it looks even more strange. I've tested a bit more.

:echo filereadable(G:\Projekte\CS Simple\run.pyw)


Use single quotes, where backslash is not treated specially.
Otherwize ..\r... will be treated as CR char, ...\t... as
tab char etc, which is not what you want.

Yakov


Re: filename completion and filereadable

2006-08-09 Thread Alexander 'boesi' Bösecke
Hi

Am 09.08.2006 15:16:08 schrieb Yakov Lerner:

 Use single quotes, where backslash is not treated specially.
 Otherwize ..\r... will be treated as CR char, ...\t... as
 tab char etc, which is not what you want.

Umm sorry I always forgot the difference between single and double
quoted. Python does not have this... *G*

But
:e G:\Projekte\CS\ Simple\run.pyw
This works! So the behaviour of ViM is a bit inconsistent, isn't it?
Either file-completion should not add the \ or filereadable (and other
functions) should accept it.


cu boesi
-- 
seasons82 was ist rl?
seasons82 und muss man das wissen?
...der moment wo einem klar wird,
  dass man zuviel chattet...


Re: filename completion and filereadable

2006-08-09 Thread A.J.Mechelynck

Alan G Isaac wrote:
Am 09.08.2006 14:08:04 schrieb Yakov Lerner: 
Looks like an input() bug to me. 


On 8/9/06, Alexander 'boesi' Bösecke [EMAIL PROTECTED] wrote: 
To me it looks even more strange. I've tested a bit more.  
:echo filereadable(G:\Projekte\CS Simple\run.pyw) 


On Wed, 9 Aug 2006, Yakov Lerner apparently wrote: 
Use single quotes, where backslash is not treated specially. 
Otherwize ..\r... will be treated as CR char, ...\t... as 
tab char etc, which is not what you want. 


Since this is stumbled over so often,
I have an enhancement request:
allow raw strings to be created
with the raw string notation from Python.
This would be backwards compatible, I believe.

Cheers,
Alan Isaac








What is the raw string notation from Python ?

IMHO it would only create one additional type of string. We already have 
single-quoted 'raw' strings in Vim, yet many people constantly forget 
that double-quoted strings in Vim are cooked.



Best regards,
Tony.