Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • function! GotoCFile()
        :write!
        :redraw!
     
        let cfile_prefix     = '#\s*cfile:\s*'
        let cfile_expression = cfile_prefix . '\w\+'
        if match(getline('.'), cfile_expression) > -1
            let good_line = matchstr(getline('.'), cfile_expression)
            " probably need some more interesting way to make a relative path
            " also need to get rid of any stuff that might trail the filename
            execute ":edit ./" . substitute(good_line, cfile_prefix, "", "g")
        else
            echom "no cfile recognized with my wimpy regex"
        endif
    endfunction
    • Unfortunately matchstr() operates on a string, not the current buffer, so you've first of all had to read the current line into a string.

      This has the distinct disadvantage that it only works if you already happen to be on the line that you're looking for.

      Smylers

      • > only works if you already happen to be on the line

        I'm relying on some inside information to guess that he's expecting to be on the line when he uses this command. I could be wrong.

        We used to work at the same shop where we had a bunch of shortcuts that worked in that sort of fashion (go to test, implementation, module, base class, mason component).
    • Out of curiosity, how did you learn Vim scripting? Is there a decent tutorial out there or did you go through the docs?

      • > how did you learn Vim scripting?

        I'm not sure I'd say that I've learned it. When I started at Rentrak, they already had ,gi ,gt ,t and ,T. I just copy/paste/tweaked from there for the most part. Before I started at Rentrak, I'd primarily been a BBEdit user, with ten-year-rusty vi experience. Rentrak was the first place I used Vim.

        > Is there a decent tutorial out there or did you go through the docs

        There may well be a decent tutorial. If so, I never found it. Instead I spent way to much time banging m