bogado / file-line

Plugin for vim to enabling opening a file in a given line
http://www.vim.org/scripts/script.php?script_id=2184
299 stars 61 forks source link

Support for :e command #1

Closed zimbatm closed 12 years ago

zimbatm commented 12 years ago

Awesome, I wanted this for long. Is it possible to also support that for the :e command ? Just give me some pointers and I'll send you a pull request

bogado commented 12 years ago

The problem is that vim is not invoking the "BufNewFile" auto command in certain situations, ":e" and the "gf" (go file) key combo. This is either a problem with the documentation or a bug in vim it self.

zimbatm commented 12 years ago

Thanks, I just added the following line and it seems to work. Not sure if it will have side-effects though

autocmd! BufRead *:* nested call s:gotoline()
bogado commented 12 years ago

The side effect is that if you actually have a file 'xxxx:20' and also a file 'xxxx' it would become impossible to edit the file 'xxxx:20' because the plugin would be called by the BufRead and would change automatically read the 'xxxx' file and jump into line 20.

zimbatm commented 12 years ago

True. How many times did you had a file ending with a colon and a number ?-- Sent from my Palm PreOn 27 Oct 2011 17:58, Victor Bogado da Silva Lins reply@reply.github.com wrote: The side effect is that if you actually have a file 'xxxx:20' and also a file 'xxxx' it would become impossible to edit the file 'xxxx:20' because the plugin would be called by the BufRead and would change automatically read the 'xxxx' file and jump into line 20.

Reply to this email directly or view it on GitHub: https://github.com/bogado/file-line/issues/1#issuecomment-2546192

bogado commented 12 years ago

Well I know it is a corner case of a corner case, but one must fix it anyway. :-)

zimbatm commented 12 years ago

Ok then, how about checking if the file exists before doing the changes?

diff --git a/plugin/file:line.vim b/plugin/file:line.vim
index b5a0856..acfe606 100644
--- a/plugin/file:line.vim
+++ b/plugin/file:line.vim
@@ -9,7 +9,7 @@ function! s:gotoline()
        " Accept file:line:column: or file:line:column and file:line also
        let names =  matchlist( file, '\(.\{-1,}\):\(\d\+\)\(:\(\d*\):\?\)\?$')

-       if len(names) != 0 && filereadable(names[1])
+       if !filereadable(name) && len(names) != 0 && filereadable(names[1])
                let l:bufn = bufnr("%")
                exec "keepalt edit " . names[1]
                exec ":" . names[2]
@@ -26,3 +26,4 @@ function! s:gotoline()
 endfunction

 autocmd! BufNewFile *:* nested call s:gotoline()
+autocmd! BufRead *:* nested call s:gotoline()
bogado commented 12 years ago

I've done that, I already commited your change and a check to verifyu if the file exists. :-)

That's why I closed the issue. :-)

zimbatm commented 12 years ago

Alright :)