Loading ...
Sorry, an error occurred while loading the content.
 

Fixing the year in a copyright line

Expand Messages
  • Scott LaBounty
    I m trying to write a small function that when I write a file will a) find the copyright message and b) check if the year listed is the current year and c)
    Message 1 of 13 , Dec 7, 2001
      I'm trying to write a small function that when I write a file will a) find
      the copyright message and b) check if the year listed is the current year
      and c) change if it is not. Here's what I have so far:

      autocmd BufWrite *.java call FixCopyright()

      function! FixCopyright ()
      if filewritable (expand ("%"))
      let l:year = strftime ("%Y")
      execute search("Copyright.*-[0-9]\\{4}", "w")
      execute "s/-[0-9]\\{4}/-" . l:year . "/"
      endif
      endfunction

      This works fine but, it doesn't actually check the year it just replaces the
      year with the current year. How do I save the piece of the search that
      contains the year ( [0-9]\\{4} , check it against l:year, and replace it?
      Here's the Copyright line I'm trying to use:

      * Copyright(c) 1999-2000 My Company INC. All Rights Reserved.

      I'd like to replace 2000 with 2001 (or the current year) in this line any
      time I write the file.

      TIA

      Scott LaBounty
      Netaphor Software, Inc.
    • Benji Fisher
      ... First of all, the search() command positions the cursor on the match, so there is no need to :execute the return value (although it does no harm). I would
      Message 2 of 13 , Dec 7, 2001
        On Friday, December 7, 2001, at 02:42 PM, Scott LaBounty wrote:

        > I'm trying to write a small function that when I write a file will a)
        > find
        > the copyright message and b) check if the year listed is the current
        > year
        > and c) change if it is not. Here's what I have so far:
        >
        > autocmd BufWrite *.java call FixCopyright()
        >
        > function! FixCopyright ()
        > if filewritable (expand ("%"))
        > let l:year = strftime ("%Y")
        > execute search("Copyright.*-[0-9]\\{4}", "w")
        > execute "s/-[0-9]\\{4}/-" . l:year . "/"
        > endif
        > endfunction
        >
        > This works fine but, it doesn't actually check the year it just
        > replaces the
        > year with the current year. How do I save the piece of the search that
        > contains the year ( [0-9]\\{4} , check it against l:year, and replace
        > it?
        > Here's the Copyright line I'm trying to use:
        >
        > * Copyright(c) 1999-2000 My Company INC. All Rights Reserved.
        >
        > I'd like to replace 2000 with 2001 (or the current year) in this line
        > any
        > time I write the file.

        First of all, the search() command positions the cursor on the
        match, so there is no need to :execute the return value (although it
        does no harm). I would use :call search(...) .

        What is the harm in replacing the current year with the current
        year? If you only call this when writing a file, it will already be
        modified, right? Oh, well:

        let l:year = strftime ("%Y")
        let yrpat = '/[0-9]\{4}'
        " Note that \ does not need to be doubled in 'literal quotes'.
        execute search("Copyright.*-" . yrpat , "w")
        let docyear = matchstr(line("."), yrpat)
        if docyear < l:year
        execute "s/-" . docyear . "/-" . l:year . "/"
        endif

        :help matchstr()
        :help getline()

        I generally do not use "l:" but it does not make any difference.

        Are you sure that the copyright notice is not repeated? If it is,
        you might be updating some, but not all, of the copyright notices.

        HTH --Benji Fisher
      • Scott LaBounty
        Benji, Thanks for the quick response. Yeah, I d figured out that it didn t make any difference if I did do the modification but, it was bugging me that I
        Message 3 of 13 , Dec 7, 2001
          Benji,

          Thanks for the quick response. Yeah, I'd figured out that it didn't make any
          difference if I did do the modification but, it was bugging me that I
          couldn't make it work the way I wanted it to. As to the copyright notice
          only getting changed in one place that *should* (famous last words) also be
          OK.

          Thanks again!

          Scott LaBounty
          Netaphor Software, Inc.

          -----Original Message-----
          From: Benji Fisher [mailto:fisherbb@...]
          Sent: Friday, December 07, 2001 12:34 PM
          To: Scott LaBounty
          Cc: Vim (E-mail)
          Subject: Re: Fixing the year in a copyright line


          On Friday, December 7, 2001, at 02:42 PM, Scott LaBounty wrote:

          > I'm trying to write a small function that when I write a file will a)
          > find
          > the copyright message and b) check if the year listed is the current
          > year
          > and c) change if it is not. Here's what I have so far:
          >
          > autocmd BufWrite *.java call FixCopyright()
          >
          > function! FixCopyright ()
          > if filewritable (expand ("%"))
          > let l:year = strftime ("%Y")
          > execute search("Copyright.*-[0-9]\\{4}", "w")
          > execute "s/-[0-9]\\{4}/-" . l:year . "/"
          > endif
          > endfunction
          >
          > This works fine but, it doesn't actually check the year it just
          > replaces the
          > year with the current year. How do I save the piece of the search that
          > contains the year ( [0-9]\\{4} , check it against l:year, and replace
          > it?
          > Here's the Copyright line I'm trying to use:
          >
          > * Copyright(c) 1999-2000 My Company INC. All Rights Reserved.
          >
          > I'd like to replace 2000 with 2001 (or the current year) in this line
          > any
          > time I write the file.

          First of all, the search() command positions the cursor on the
          match, so there is no need to :execute the return value (although it
          does no harm). I would use :call search(...) .

          What is the harm in replacing the current year with the current
          year? If you only call this when writing a file, it will already be
          modified, right? Oh, well:

          let l:year = strftime ("%Y")
          let yrpat = '/[0-9]\{4}'
          " Note that \ does not need to be doubled in 'literal quotes'.
          execute search("Copyright.*-" . yrpat , "w")
          let docyear = matchstr(line("."), yrpat)
          if docyear < l:year
          execute "s/-" . docyear . "/-" . l:year . "/"
          endif

          :help matchstr()
          :help getline()

          I generally do not use "l:" but it does not make any difference.

          Are you sure that the copyright notice is not repeated? If it is,
          you might be updating some, but not all, of the copyright notices.

          HTH --Benji Fisher
        • Gary Holloway
          / FROM: Benji Fisher , Dec 7 15:33 2001 ... ^^^^^^^^^ You mean getline( . ) right? -g ... END: Benji Fisher
          Message 4 of 13 , Dec 7, 2001
            / FROM: Benji Fisher <fisherbb@...>, Dec 7 15:33 2001
            | ABOUT: Re: Fixing the year in a copyright line
            |
            | On Friday, December 7, 2001, at 02:42 PM, Scott LaBounty wrote:
            |
            | > I'm trying to write a small function that when I write a file will a)
            | > find
            | > the copyright message and b) check if the year listed is the current
            | > year
            | > and c) change if it is not. Here's what I have so far:
            | >
            | > autocmd BufWrite *.java call FixCopyright()
            | >
            | > function! FixCopyright ()
            | > if filewritable (expand ("%"))
            | > let l:year = strftime ("%Y")
            | > execute search("Copyright.*-[0-9]\\{4}", "w")
            | > execute "s/-[0-9]\\{4}/-" . l:year . "/"
            | > endif
            | > endfunction
            | >
            | > This works fine but, it doesn't actually check the year it just
            | > replaces the
            | > year with the current year. How do I save the piece of the search that
            | > contains the year ( [0-9]\\{4} , check it against l:year, and replace
            | > it?
            | > Here's the Copyright line I'm trying to use:
            | >
            | > * Copyright(c) 1999-2000 My Company INC. All Rights Reserved.
            | >
            | > I'd like to replace 2000 with 2001 (or the current year) in this line
            | > any
            | > time I write the file.
            |
            | First of all, the search() command positions the cursor on the
            | match, so there is no need to :execute the return value (although it
            | does no harm). I would use :call search(...) .
            |
            | What is the harm in replacing the current year with the current
            | year? If you only call this when writing a file, it will already be
            | modified, right? Oh, well:
            |
            | let l:year = strftime ("%Y")
            | let yrpat = '/[0-9]\{4}'
            | " Note that \ does not need to be doubled in 'literal quotes'.
            | execute search("Copyright.*-" . yrpat , "w")
            | let docyear = matchstr(line("."), yrpat)
            ^^^^^^^^^
            You mean getline(".")
            right?

            -g

            | if docyear < l:year
            | execute "s/-" . docyear . "/-" . l:year . "/"
            | endif
            |
            | :help matchstr()
            | :help getline()
            |
            | I generally do not use "l:" but it does not make any difference.
            |
            | Are you sure that the copyright notice is not repeated? If it is,
            | you might be updating some, but not all, of the copyright notices.
            |
            | HTH --Benji Fisher
            |
            \ END: Benji Fisher
          • Benji Fisher
            ... Oops, right. ... At least, I got it right that time. ;) --Benji Fisher
            Message 5 of 13 , Dec 7, 2001
              On Friday, December 7, 2001, at 05:09 PM, Gary Holloway wrote:

              > [snip]

              > | let l:year = strftime ("%Y")
              > | let yrpat = '/[0-9]\{4}'
              > | " Note that \ does not need to be doubled in 'literal quotes'.
              > | execute search("Copyright.*-" . yrpat , "w")
              > | let docyear = matchstr(line("."), yrpat)
              > ^^^^^^^^^
              > You mean getline(".")
              > right?

              Oops, right.

              > | if docyear < l:year
              > | execute "s/-" . docyear . "/-" . l:year . "/"
              > | endif
              > |
              > | :help matchstr()
              > | :help getline()

              At least, I got it right that time. ;)

              --Benji Fisher
            • Gary Holloway
              I liked the concept of this, so I took Benji s answer as a start and modified it a bit (see below). It ll handle a copyright message with a single year
              Message 6 of 13 , Dec 7, 2001
                I liked the concept of this, so I took Benji's answer as a start and modified
                it a bit (see below).

                It'll handle a copyright message with a single year (changing yyyy to
                yyyy-YYYY), or year range (changing yyyy-yyyy to yyyy-YYYY), where YYYY is the
                current year.

                I've also tweaked the originating search patter to look specifically for our
                particular form of copyright line.

                Cheers.

                -gary


                " Update copyright message (if any) with current year, if not present.

                function! UpdateCopyright()
                if filewritable (expand ("%"))
                let current_year = strftime("%Y")

                if search('Copyright *(c) Cast & Crew.*\<\d\{4}\(-\d\{4}\)\=\>', "w") > 0
                let copyright_line = getline(".")
                let docyear = matchstr(copyright_line, '\<\d\{4}-\d\{4}\>')

                if docyear == ""
                let docyear = matchstr(getline("."), '\<\d\{4}\>')
                if docyear != "" && docyear < current_year
                " Only one year listed; and it's old; append current year.
                execute 's/\<\(\d\{4}\)\>/\1-' . current_year
                endif
                else
                " Two years listed; extract second one.
                let docyear = matchstr(docyear, '\d\{4}$')
                if docyear < current_year
                " Second year is old; make it the current year.
                execute 's/\<\(\d\{4}\)-\d\{4}\>/\1-' . current_year
                endif
                endif

                if getline(".") != copyright_line
                se cmdheight+=5
                echohl Warningmsg
                echo 'OLD:'
                echohl Comment
                echo copyright_line
                echohl Warningmsg
                echo 'NEW:'
                echohl Comment
                echo getline(".")
                echohl Question
                let foo = input("Updated copyright (press RETURN)")
                echohl NONE
                se cmdheight-=5
                endif
                endif
                endif

                endfunction
              • Martin Metz
                Hello, I m also very glad of the below given code and use it with an autocommand when writing a buffer. But one detail is ugly: Because of the search() the
                Message 7 of 13 , Jan 3, 2002
                  Hello,

                  I'm also very glad of the below given code and use it with an
                  autocommand when writing a buffer. But one detail is ugly:

                  Because of the "search()" the cursor position changes. That's not
                  important if I close the VIM. But if I just save the current buffer e.
                  g. with ":w" I loose the current position and stay at the copyright
                  message. :-(

                  Does any one have a good idea to jump back to the old position? Maybe
                  with marks? I'm currently to stupid to find a solution.

                  Gary Holloway wrote:
                  >
                  > I liked the concept of this, so I took Benji's answer as a start and modified
                  > it a bit (see below).
                  >
                  [...]
                  >
                  > " Update copyright message (if any) with current year, if not present.
                  >
                  > function! UpdateCopyright()
                  > if filewritable (expand ("%"))
                  > let current_year = strftime("%Y")
                  >
                  > if search('Copyright *(c) Cast & Crew.*\<\d\{4}\(-\d\{4}\)\=\>', "w") > 0
                  > let copyright_line = getline(".")
                  > let docyear = matchstr(copyright_line, '\<\d\{4}-\d\{4}\>')
                  >
                  > if docyear == ""
                  > let docyear = matchstr(getline("."), '\<\d\{4}\>')
                  > if docyear != "" && docyear < current_year
                  > " Only one year listed; and it's old; append current year.
                  > execute 's/\<\(\d\{4}\)\>/\1-' . current_year
                  > endif
                  > else
                  > " Two years listed; extract second one.
                  > let docyear = matchstr(docyear, '\d\{4}$')
                  > if docyear < current_year
                  > " Second year is old; make it the current year.
                  > execute 's/\<\(\d\{4}\)-\d\{4}\>/\1-' . current_year
                  > endif
                  > endif
                  >
                  > if getline(".") != copyright_line
                  > se cmdheight+=5
                  > echohl Warningmsg
                  > echo 'OLD:'
                  > echohl Comment
                  > echo copyright_line
                  > echohl Warningmsg
                  > echo 'NEW:'
                  > echohl Comment
                  > echo getline(".")
                  > echohl Question
                  > let foo = input("Updated copyright (press RETURN)")
                  > echohl NONE
                  > se cmdheight-=5
                  > endif
                  > endif
                  > endif
                  >
                  > endfunction

                  --
                  Gruesse,

                  Martin Metz

                  /***************************************************************
                  * Dipl. Inform. (FH) Martin Metz - Software engineering
                  *
                  * OneVision Software AG | Phone: +49-941-780040
                  * Dr.-Leo-Ritter-Str. 9 | FAX: +49-941-7800449
                  * 93049 Regensburg | mailto:Martin.Metz@...
                  * Germany | WWW: http://www.OneVision.de
                  **************************************************************/
                • Benji Fisher
                  ... [snip] To do it with marks, see ... If you are doing it from inside a script, and want to avoid using marks (which are global) then look at the Mark()
                  Message 8 of 13 , Jan 3, 2002
                    Martin Metz wrote:
                    >
                    > Hello,
                    >
                    > I'm also very glad of the below given code and use it with an
                    > autocommand when writing a buffer. But one detail is ugly:
                    >
                    > Because of the "search()" the cursor position changes. That's not
                    > important if I close the VIM. But if I just save the current buffer e.
                    > g. with ":w" I loose the current position and stay at the copyright
                    > message. :-(
                    >
                    > Does any one have a good idea to jump back to the old position? Maybe
                    > with marks? I'm currently to stupid to find a solution.
                    [snip]

                    To do it with marks, see

                    :help restore-position

                    If you are doing it from inside a script, and want to avoid using marks (which
                    are global) then look at the Mark() function in foo.vim:

                    http://vim.sourceforge.net/scripts/script.php?script_id=72

                    HTH --Benji Fisher
                  • Gary Holloway
                    Here s a more recent version... it utilizes the preview window to avoid that, and leaves the copyright line visible in the preview window if it was changed;
                    Message 9 of 13 , Jan 3, 2002
                      Here's a more recent version... it utilizes the preview window to avoid that,
                      and leaves the copyright line visible in the preview window if it was changed;
                      and fixed several "oddities" (ok, bugs :).

                      I edited out some company-specifics; I don't think I created any bug doing
                      that... :)

                      -gary

                      -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

                      " Update copyright message (if any) with current year, if not present.
                      "
                      " EXAMPLE USAGE:
                      " au BufWrite * call UpdateCopyright()

                      " $Header: /usr/home/common/vim/autoload/RCS/UpdateCopyright.vim,v 1.5 2002/01/03 02:17:25 gary Exp $

                      function! UpdateCopyright()
                      if !&modified || !filewritable(expand("%"))
                      return
                      endif

                      if version >= 600
                      " Using the preview window, we don't mess up the current
                      " session's jump stack with the search, and it's nice to leave
                      " the window open showing the change, if any.
                      "
                      silent! pedit %
                      wincmd p
                      if !&previewwindow
                      " Should never happen; oh well, just do it in the normal
                      " window.
                      wincmd p
                      pclose
                      endif
                      endif

                      if !&previewwindow
                      " Save the current cursor position. This could be done with marks,
                      " but we don't like to do that because we might overwrite a user's
                      " mark.
                      "
                      " NOTE: We only do it this way if we don't have a preview window.
                      " That way, we will normally avoid moving with 'H' so we don't mess
                      " up the jump history.
                      "
                      let current_line = line(".")
                      let current_col = virtcol(".")
                      normal H
                      let top_line = line(".")
                      endif

                      let found_copyright = 0

                      if search('Copyright *(c).*\<\d\{4}\(\s*-\s*\d\{4}\)\=\>', "w") > 0 "{
                      " Found a Copyright line.
                      let found_copyright = 1

                      let current_year = strftime("%Y")
                      let copyright_line = getline(".")
                      let docyear = matchstr(copyright_line, '\<\d\{4}\s*-\s*\d\{4}\>')

                      if docyear == ""
                      let docyear = matchstr(getline("."), '\<\d\{4}\>')
                      if docyear != "" && docyear < current_year
                      " Only one year listed; and it's old; append current year.
                      execute 's/\<\(\d\{4}\)\>/\1-' . current_year
                      endif
                      else
                      " Two years listed; extract second one.
                      let docyear = matchstr(docyear, '\d\{4}$')
                      if docyear < current_year
                      " Second year is old; make it the current year.
                      execute 's/\<\(\d\{4}\)\s*-\s*\d\{4}\>/\1-' . current_year
                      endif
                      endif

                      " Center the copyright line (on an 80-character line).
                      "
                      " We do this in a buffer, and then see if what we came up with
                      " differs from what's already there. That way we don't modify this
                      " line unneccessarily (putting it into the 'undo' chain, etc.)
                      "
                      " NOTE: This is expecting vim's auto formatting turned on (e.g.,
                      " formatoptions=cloqr)
                      "
                      " Look for various language's comment leader...
                      "
                      let leader = matchstr(getline("."), '^\([/ ]\=[*]\|#\{1,2}\|//\)\s')
                      if leader != ''
                      let cline = getline(".")
                      let cline = substitute(cline, '^.\{' . strlen(leader) . '}', '', '')
                      let cline = substitute(cline, '^\s\+', '', '')
                      let cline = substitute(cline, '\s\+$', '', '')
                      let length = (80 - strlen(cline) - strlen(leader)) / 2
                      " Don't know a way to mimic repeat(c, n), so...
                      if (length > 0)
                      let padding = matchstr(" ", ' \{' . length . '}')
                      else
                      let padding = ''
                      endif
                      let leader = substitute(leader, '\s$', '', '')
                      let cline = leader . padding . cline

                      if cline != getline(".")
                      exe "normal 0Da" . cline
                      endif
                      endif

                      if getline(".") != copyright_line
                      se cmdheight+=6
                      echohl Question
                      echo "Updated copyright..."
                      echohl Warningmsg
                      echo 'OLD:'
                      echohl Comment
                      echo copyright_line
                      echohl Warningmsg
                      echo 'NEW:'
                      echohl Comment
                      echo getline(".")
                      echohl Question
                      let foo = input("Press RETURN")
                      echohl NONE
                      se cmdheight-=6
                      endif
                      endif "}

                      if found_copyright && getline(".") != copyright_line
                      " We found, and changed a Copyright line; if we're in the preview
                      " window, return to the normal window, otherwise stay on the
                      " copyright line.
                      "
                      if &previewwindow
                      3 wincmd _
                      normal zz
                      silent wincmd p
                      endif
                      else
                      " We did not find a Copyright line; if we're in the preview window,
                      " close it, otherwise put the cursor back where it was.
                      "
                      if &previewwindow
                      pclose
                      else
                      " Put the cursor back in the original location the hard way.
                      exe top_line
                      normal zt
                      exe current_line
                      exe "normal 0" . current_col . "|"
                      endif
                      endif

                      endfunction

                      -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

                      / FROM: Martin Metz <martin.metz@...>, Jan 3 13:18 2002
                      | ABOUT: Re: Fixing the year in a copyright line
                      |
                      | Hello,
                      |
                      | I'm also very glad of the below given code and use it with an
                      | autocommand when writing a buffer. But one detail is ugly:
                      |
                      | Because of the "search()" the cursor position changes. That's not
                      | important if I close the VIM. But if I just save the current buffer e.
                      | g. with ":w" I loose the current position and stay at the copyright
                      | message. :-(
                      |
                      | Does any one have a good idea to jump back to the old position? Maybe
                      | with marks? I'm currently to stupid to find a solution.
                      |
                      | Gary Holloway wrote:
                      | >
                      | > I liked the concept of this, so I took Benji's answer as a start and modified
                      | > it a bit (see below).
                      | >
                      | [...]
                      | >
                      | > " Update copyright message (if any) with current year, if not present.
                      | >
                      | > function! UpdateCopyright()
                      | > if filewritable (expand ("%"))
                      | > let current_year = strftime("%Y")
                      | >
                      | > if search('Copyright *(c) Cast & Crew.*\<\d\{4}\(-\d\{4}\)\=\>', "w") > 0
                      | > let copyright_line = getline(".")
                      | > let docyear = matchstr(copyright_line, '\<\d\{4}-\d\{4}\>')
                      | >
                      | > if docyear == ""
                      | > let docyear = matchstr(getline("."), '\<\d\{4}\>')
                      | > if docyear != "" && docyear < current_year
                      | > " Only one year listed; and it's old; append current year.
                      | > execute 's/\<\(\d\{4}\)\>/\1-' . current_year
                      | > endif
                      | > else
                      | > " Two years listed; extract second one.
                      | > let docyear = matchstr(docyear, '\d\{4}$')
                      | > if docyear < current_year
                      | > " Second year is old; make it the current year.
                      | > execute 's/\<\(\d\{4}\)-\d\{4}\>/\1-' . current_year
                      | > endif
                      | > endif
                      | >
                      | > if getline(".") != copyright_line
                      | > se cmdheight+=5
                      | > echohl Warningmsg
                      | > echo 'OLD:'
                      | > echohl Comment
                      | > echo copyright_line
                      | > echohl Warningmsg
                      | > echo 'NEW:'
                      | > echohl Comment
                      | > echo getline(".")
                      | > echohl Question
                      | > let foo = input("Updated copyright (press RETURN)")
                      | > echohl NONE
                      | > se cmdheight-=5
                      | > endif
                      | > endif
                      | > endif
                      | >
                      | > endfunction
                      |
                      | --
                      | Gruesse,
                      |
                      | Martin Metz
                      |
                      | /***************************************************************
                      | * Dipl. Inform. (FH) Martin Metz - Software engineering
                      | *
                      | * OneVision Software AG | Phone: +49-941-780040
                      | * Dr.-Leo-Ritter-Str. 9 | FAX: +49-941-7800449
                      | * 93049 Regensburg | mailto:Martin.Metz@...
                      | * Germany | WWW: http://www.OneVision.de
                      | **************************************************************/
                      |
                      \ END: Martin Metz
                    • Douglas L . Potts
                      ... [--- snip ---] ... Or using the VirMark.vim plugin on: http://vim.sourceforge.net/scripts/script.php?script_id=140 Which expands on Benji s Mark() idea.
                      Message 10 of 13 , Jan 3, 2002
                        On Thu, Jan 03, 2002 at 09:08:46AM -0500 Benji Fisher wrote:
                        > Martin Metz wrote:
                        [--- snip ---]
                        > If you are doing it from inside a script, and want to avoid using marks (which
                        > are global) then look at the Mark() function in foo.vim:
                        >
                        > http://vim.sourceforge.net/scripts/script.php?script_id=72

                        Or using the VirMark.vim plugin on:
                        http://vim.sourceforge.net/scripts/script.php?script_id=140

                        Which expands on Benji's Mark() idea.

                        -Doug

                        --
                        *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
                        Douglas L. Potts
                        "Where do you want to crash, toady?" -Rich Paul (or at least his .sig)
                        GPG Fingerprint: 768A EEF8 197A 4C9A 5EF7 DA5B 464C 97DF DCD5 68C2
                        *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
                      • Gary Johnson
                        ... I ve been using your UpdateCopyright() since you first posted it, but with the following change to the search() function call to make the copyright string
                        Message 11 of 13 , Jan 3, 2002
                          On Thu, Jan 03, 2002 at 09:02:59AM -0800, Gary Holloway wrote:
                          > Here's a more recent version... it utilizes the preview window to avoid that,
                          > and leaves the copyright line visible in the preview window if it was changed;
                          > and fixed several "oddities" (ok, bugs :).
                          >
                          > I edited out some company-specifics; I don't think I created any bug doing
                          > that... :)

                          I've been using your UpdateCopyright() since you first posted it, but
                          with the following change to the search() function call to make the
                          copyright string customizable without having to further modify your
                          function:

                          if search(g:copyright_pre.'\<\d\{4}\(-\d\{4}\)\=\>'.g:copyright_post, "w") > 0

                          I have copyright_pre and copyright_post defined in my .vimrc as follows
                          to agree with our company standards:

                          let g:copyright_pre = "(c) Copyright *"
                          let g:copyright_post = " *Agilent Technologies"

                          One could also use autocommands to change among different strings for
                          company files and personal files.

                          With the little bit of testing I did last year, it worked great. Now
                          that a new year is here, I'll have a chance to use it for real when I
                          get back to work next week.

                          If one could choose whether or not to center the copyright notice, e.g.,
                          using a g:copyright_centered flag, this would make a great plugin to
                          contribute to vim online.

                          Gary

                          --
                          Gary Johnson | Agilent Technologies
                          garyjohn@... | Spokane, Washington, USA
                        • HALIM,SALMAN (HP-NewJersey,ex2)
                          once you have the line in question (copyright_line), you could just try something like: if (g:copyright_centered == 1) execute copyright_line . center endif
                          Message 12 of 13 , Jan 3, 2002
                            once you have the line in question (copyright_line), you could just try
                            something like:

                            if (g:copyright_centered == 1)
                            execute copyright_line . "center"
                            endif

                            this will center it in the current textwidth -- you could force a specific
                            textwidth by doing this:

                            if (g:copyright_centered == 1)
                            let savetw=&tw
                            set tw=80
                            execute copyright_line . "center"
                            let &tw=savetw
                            endif

                            hope this helps,

                            salman.

                            -----Original Message-----
                            From: Gary Johnson [mailto:garyjohn@...]
                            Sent: Thursday, January 03, 2002 4:25 PM
                            To: Vim (E-mail)
                            Subject: Re: Fixing the year in a copyright line


                            On Thu, Jan 03, 2002 at 09:02:59AM -0800, Gary Holloway wrote:
                            > Here's a more recent version... it utilizes the preview window to avoid
                            that,
                            > and leaves the copyright line visible in the preview window if it was
                            changed;
                            > and fixed several "oddities" (ok, bugs :).
                            >
                            > I edited out some company-specifics; I don't think I created any bug doing
                            > that... :)

                            I've been using your UpdateCopyright() since you first posted it, but
                            with the following change to the search() function call to make the
                            copyright string customizable without having to further modify your
                            function:

                            if search(g:copyright_pre.'\<\d\{4}\(-\d\{4}\)\=\>'.g:copyright_post,
                            "w") > 0

                            I have copyright_pre and copyright_post defined in my .vimrc as follows
                            to agree with our company standards:

                            let g:copyright_pre = "(c) Copyright *"
                            let g:copyright_post = " *Agilent Technologies"

                            One could also use autocommands to change among different strings for
                            company files and personal files.

                            With the little bit of testing I did last year, it worked great. Now
                            that a new year is here, I'll have a chance to use it for real when I
                            get back to work next week.

                            If one could choose whether or not to center the copyright notice, e.g.,
                            using a g:copyright_centered flag, this would make a great plugin to
                            contribute to vim online.

                            Gary

                            --
                            Gary Johnson | Agilent Technologies
                            garyjohn@... | Spokane, Washington, USA
                          • Gary Holloway
                            / FROM: HALIM,SALMAN (HP-NewJersey,ex2) , Jan 3 14:02 2002 ... [snip] Actually, centered is a little bit of a misnomer... It ll change
                            Message 13 of 13 , Jan 3, 2002
                              / FROM: "HALIM,SALMAN (HP-NewJersey,ex2)" <salman@...>, Jan 3 14:02 2002
                              | ABOUT: RE: Fixing the year in a copyright line
                              |
                              | once you have the line in question (copyright_line), you could just try
                              | something like:
                              |
                              | if (g:copyright_centered == 1)
                              | execute copyright_line . "center"
                              | endif
                              |
                              | this will center it in the current textwidth -- you could force a specific
                              | textwidth by doing this:
                              |
                              [snip]

                              Actually, "centered" is a little bit of a misnomer...
                              It'll change something like:

                              * Copyright (c) Cast & Crew Entertainment Services, Inc. 1998-2002

                              to:

                              * Copyright (c) Cast & Crew Entertainment Services, Inc. 1998-2002

                              (Note the leading '*')
                              So, the 'center' command (alone) wouldn't quite do the job.

                              In context, we've got file-header comments like:

                              /******************************************************************************
                              *
                              [snip]
                              *
                              * Copyright (c) Cast & Crew Entertainment Services, Inc. 1998-2002
                              *
                              [snip]
                              *
                              * Description:
                              * This makes a foobar
                              *
                              ******************************************************************************/

                              And the function is trying to maintain the "centeredness" of the line after it
                              [potentially] appends a year to it.

                              -gary
                            Your message has been successfully submitted and would be delivered to recipients shortly.