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

Add support for `file(line)`, and handle trash at the end #15

Closed blueyed closed 10 years ago

blueyed commented 10 years ago

This also improves the patterns anchoring. I could resist to use \v (very-magic).

Not much tested.

Fixes #14 (https://github.com/bogado/file-line/issues/14)

bogado commented 10 years ago

If we're adding more than one reg exp this has to be more generic. I've just added this support.

blueyed commented 10 years ago

@bogado Thanks!

I had a local patch to fall back to matching "... line X". Do you think it's useful and should get added to the list of regexps?

diff --git a/plugin/file_line.vim b/plugin/file_line.vim
index 31ea5b4..f3664ff 100644
--- a/plugin/file_line.vim
+++ b/plugin/file_line.vim
@@ -26,7 +26,12 @@ function! s:gotoline()
                let names =  matchlist( file, '\([^:]*\):\%(\(\d\+\)\%(:\(\d*\):\?\)\?\)\?[^: ]\{-}$')

                if empty(names)
-                       return
+                       " Handle 'file … line 42'
+                       let names =  matchlist(file, '\v^(.*) line (\d+)$')
+
+                       if empty(names)
+                               return
+                       endif
                end
        endif
bogado commented 10 years ago

I have made a more generic way to add different regular expressions to the filename parser. Check the latest version