Hello Harry;

Harry Putnam <[email protected]> a écrit:
> Probably at risk of starting a vim/emacs tug of war. I hope not.

Do not be afraid. We have only compassion for our less fortunate
brothers and sisters.

> I have small bit of code using elisp that inserts a 'Keyword' entry
> around a selected region.  Now I want to replicate that ability using
> vim.

That is not very complicated except that...
[snip]

> It will look like this when done and I've removed the one comment
> to let the new rule work 
> 
>   # Keywords: Replace old rule with new experimental rule 
>   #        [Keydate:130922_214226 0 - Sun Sep 22, 2013
>   # This is the default setting because blah blah blah
>   # more blah blah blah blah blah
>   # current rule in rc file
>   New rule replacing line above
>   # &&

... how is the “current rule in rc file” identified as an old code
line to be commented? Here I’ll assume it is the last but one line,
following your example, but I suppose it’s quite unlikely that it will
always be so. The “:MarkChange” command should be called while the
region to be processed is selected; it could be modified so it is
called on the old code (to be commented) and then find the limits of
the entire region by itself (e.g. with blank lines).

Also, the command can take an optional argument, the “keywords” line
to be inserted; if not given, the function will prompt for it.

    " Put this in your .vimrc file.
    function! s:markchange (kw) range
      " Retrieve the one-line comment string, hoping it exists (could be
      " defined otherwise, too).
      let comment = matchstr(&comments, '[[:alnum:]]\@<!:\zs[^,]*\ze')

      " Ask for keywords if not given when calling MarkChange.
      if a:kw !~ '\S'
        let keywords = input("Keywords, please?\n")
      else
        let keywords = a:kw
      endif
      let keywords = comment . "Keywords: " . keywords

      " Comment the last-but-one line.
      call setline(a:lastline-1, comment . getline(a:lastline-1))

      " Append the end symbol; use :undojoin so ``u'' will undo
      " the entire operation.
      undojoin
      call append(a:lastline, comment . "&&")

      " Append the keywords and date lines.
      undojoin
      call append(a:firstline-1, [keywords, comment . "[Keydate:" . 
strftime("%c")])
    endfunction

    com! -range -nargs=* MarkChange <line1>,<line2>call s:markchange(<q-args>)
    " End of code.

I hope it helps.

Best,
Paul

-- 
-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to