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.
  • Note that you're duplicating the filetype detection there, twice. The standard $VIMRUNTIME/filetype.vim defines an autocommand such that starting to edit a file matching svn-commit*.tmp will trigger a FileType event for svn. As you've got it set up, making a commit causes these steps to run:

    1. .vim/ftplugin/svn.vim is run (because you have filetype plug-ins enabled), which in your case defines a function.
    2. Your autocommand for that filetype runs, which runs the function that svn.vim has just defined.
    3. Your function checks that the filename is svn-commit.tmp.

    If in step 1 you just run the commands immediately in svn.vim rather than defining a function then you can get rid of step 2 entirely. And the check in step 3 is unnecessary, since svn.vim only runs at all if the filename matches.

    So this can be refactored quite a bit. Also:

    • fnamemodify() can do the filename manipulation.
    • You can do the insert a single go with a substitution.
    • The substitution conveniently leaves the cursor on the right line, and using the above-recommended startinsert! but with the exclamation mark conveniently puts the cursor at the end of the line, which is more robust than having to track how many lines and characters you've inserted.

    Putting all that together, I think you can just have the following in .vim/ftplugin/svn.vim:

    let parent_dir = fnamemodify(getcwd(), ':t')
    if parent_dir != 'trunk'
      execute '1s//Branch: ' . parent_dir . '\r\r -  '
    endif
    startinsert!

    However, neither your nor my version actually seems to do the right thing! It seems that svn commit changes to the directory of the file being committed, which messes up getcwd() for commits in subdirectories. So it looks like parsing svn info will be needed, unfortunately.