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

feature request: v:register

Expand Messages
  • Benji Fisher
    I would like a v:register variable, analogous to the v:count ... Then mappings could effectively accept registers as well as counts. --Benji Fisher
    Message 1 of 13 , Dec 4, 2002
    • 0 Attachment
      I would like a v:register variable, analogous to the v:count
      variable. Sample usage:

      :command! -register Foo echo "The register is <reg>"
      :nmap \F :execute "Foo" v:register<CR>

      Then mappings could effectively accept registers as well as counts.

      --Benji Fisher
    • Giuseppe Bilotta
      ... Ditto for functions: a:register -- Giuseppe Oblomov Bilotta
      Message 2 of 13 , Dec 4, 2002
      • 0 Attachment
        On Wednesday, December 4, 2002 Benji Fisher wrote:
        > I would like a v:register variable, analogous to the v:count
        > variable. Sample usage:

        > :command! -register Foo echo "The register is <reg>"
        > :nmap \F :execute "Foo" v:register<CR>

        > Then mappings could effectively accept registers as well as counts.

        Ditto for functions: a:register

        --
        Giuseppe "Oblomov" Bilotta
      • Benji Fisher
        ... Functions would also be able to access the internal variable. I think that v:register would be enough. Besides, if a:register is reserved, you cannot use
        Message 3 of 13 , Dec 4, 2002
        • 0 Attachment
          Giuseppe Bilotta wrote:
          > On Wednesday, December 4, 2002 Benji Fisher wrote:
          >
          >> I would like a v:register variable, analogous to the v:count
          >>variable. Sample usage:
          >[snip]
          >
          > Ditto for functions: a:register

          Functions would also be able to access the internal variable. I
          think that v:register would be enough. Besides, if a:register is
          reserved, you cannot use "register" as a formal parameter to a function.
          (I recently made the mistake of defining a function Foo(lastline) ...")

          --Benji Fisher
        • Bram Moolenaar
          ... Good idea. I ll add it to the todo list. Won t be implemented soon though (unless someone can send me a good patch for it). -- hundred-and-one symptoms
          Message 4 of 13 , Dec 30, 2002
          • 0 Attachment
            Benji Fisher wrote:

            > I would like a v:register variable, analogous to the v:count
            > variable. Sample usage:
            >
            > :command! -register Foo echo "The register is <reg>"
            > :nmap \F :execute "Foo" v:register<CR>
            >
            > Then mappings could effectively accept registers as well as counts.

            Good idea. I'll add it to the todo list. Won't be implemented soon
            though (unless someone can send me a good patch for it).

            --
            hundred-and-one symptoms of being an internet addict:
            225. You sign up for free subscriptions for all the computer magazines

            /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
            /// Creator of Vim - Vi IMproved -- http://www.vim.org \\\
            \\\ Project leader for A-A-P -- http://www.a-a-p.org ///
            \\\ Lord Of The Rings helps Uganda - http://iccf-holland.org/lotr.html ///
          • Bram Moolenaar
            ... Thanks for making this. I don t see the advantage of using setreg() over :let @a = string and getreg() over @a . -- GOD: That is your purpose Arthur ...
            Message 5 of 13 , Jan 2, 2003
            • 0 Attachment
              Michael Geddes wrote:

              > Try this out:
              >
              > I've even done the doco.
              >
              > I've implemented v:register as well as getreg(regname) and
              > setreg(regname,value [,append] )
              > The bonus with getreg() is that it will get the last evaluated '=3D'
              > register, as well as being able
              > to simply pass v:register to it.
              > The bonus with setreg() is that I've added an optional 'append' flag,
              > that will force an append. This seems to work with the '*' register as
              > well... and as it was trivial to add, I thought it may as well be there.
              >
              > Any thoughts?

              Thanks for making this.

              I don't see the advantage of using setreg() over ":let @a = string" and
              getreg() over "@a".

              --
              GOD: That is your purpose Arthur ... the Quest for the Holy Grail ...
              "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

              /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
              /// Creator of Vim - Vi IMproved -- http://www.vim.org \\\
              \\\ Project leader for A-A-P -- http://www.a-a-p.org ///
              \\\ Lord Of The Rings helps Uganda - http://iccf-holland.org/lotr.html ///
            • Michael Geddes
              You re right about the advantage of getreg( a ) over @a.. you d never do it the first way. But if you don t know what the register name is - being passed in,
              Message 6 of 13 , Jan 2, 2003
              • 0 Attachment
                You're right about the advantage of getreg('a') over @a.. you'd never do
                it the first way. But if you don't know what the register name is -
                being passed in, or used from v:register, then it is very useful.. you
                can use getreg(regname) instead of having to wrap it in an 'exe'.

                The main advantage is not having to do this:

                map \P :exe "echo @".v:register<CR>

                'cause you can do this:

                map \P :echo getreg(v:register)<CR>


                Also, getreg() allows you to get the last expression register evaluated.
                'cause You can't use @=... though I've made it so we could add this
                functionality easily (there's an extra argument to one of the functions,
                that would change to TRUE).

                Adding setreg() also means you can make mappings like this:

                map \yf :setreg(v:register,expand('%:p'))<CR>

                Or like this (and here, it's really useful)

                map \yy :setreg(v:register, getline('.'), 1)<CR>

                I suppose you COULD get around this one, but this makes it SOO much
                easier.

                In the end, it's up to you.. The nice thing about both of these are
                they are very low-footprint implementations as they use existing
                internal functions to do their stuff... just exposing it as a function.

                //.ichael G.


                -----Original Message-----
                From: Bram Moolenaar [mailto:Bram@...]
                Sent: Thursday, 2 January 2003 8:47 PM
                To: Michael Geddes
                Cc: Benji Fisher; Vim Dev
                Subject: RE: feature request: v:register



                Michael Geddes wrote:

                > Try this out:
                >
                > I've even done the doco.
                >
                > I've implemented v:register as well as getreg(regname) and
                > setreg(regname,value [,append] ) The bonus with getreg() is that it
                > will get the last evaluated '=3D' register, as well as being able
                > to simply pass v:register to it.
                > The bonus with setreg() is that I've added an optional 'append' flag,
                > that will force an append. This seems to work with the '*' register
                as
                > well... and as it was trivial to add, I thought it may as well be
                there.
                >
                > Any thoughts?

                Thanks for making this.

                I don't see the advantage of using setreg() over ":let @a = string" and
                getreg() over "@a".

                --
                GOD: That is your purpose Arthur ... the Quest for the Holy Grail ...
                "Monty Python and the Holy Grail" PYTHON (MONTY)
                PICTURES LTD

                /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net
                \\\
                /// Creator of Vim - Vi IMproved -- http://www.vim.org
                \\\
                \\\ Project leader for A-A-P -- http://www.a-a-p.org
                ///
                \\\ Lord Of The Rings helps Uganda - http://iccf-holland.org/lotr.html
                ///
              • Bram Moolenaar
                ... OK, avoiding :exe is a good point. When adding these functions, there is one extra issue considering registers that we might want to take care of:
                Message 7 of 13 , Jan 3, 2003
                • 0 Attachment
                  Michael Geddes wrote:

                  > You're right about the advantage of getreg('a') over @a.. you'd never do
                  > it the first way. But if you don't know what the register name is -
                  > being passed in, or used from v:register, then it is very useful.. you
                  > can use getreg(regname) instead of having to wrap it in an 'exe'.

                  OK, avoiding ":exe" is a good point.

                  When adding these functions, there is one extra issue considering
                  registers that we might want to take care of: Whether the text is used
                  linewise, characterwise or blockwise. Since a function can't return two
                  values at the same time, perhaps we should think of adding setregtype()
                  and getregtype()? Although setreg() could set the type at the same time
                  the contents is set, using an optional third argument.

                  --
                  DINGO: Wicked wicked Zoot ... she is a bad person and she must pay the
                  penalty. And here in Castle Anthrax, we have but one punishment
                  ... you must tie her down on a bed ... and spank her. Come!
                  GIRLS: A spanking! A spanking!
                  "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

                  /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
                  /// Creator of Vim - Vi IMproved -- http://www.vim.org \\\
                  \\\ Project leader for A-A-P -- http://www.a-a-p.org ///
                  \\\ Lord Of The Rings helps Uganda - http://iccf-holland.org/lotr.html ///
                • Michael Geddes
                  Hmm, yes, very good idea. Unfortunately there is already an optional third argument.. (whether to append). I think the orthognal setregtype/getregtype might
                  Message 8 of 13 , Jan 5, 2003
                  • 0 Attachment
                    Hmm, yes, very good idea. Unfortunately there is already an optional
                    third argument.. (whether to append). I think the orthognal
                    setregtype/getregtype might be the way to go... I'll have a think (any
                    ideas?)
                    //.

                    -----Original Message-----
                    From: Bram Moolenaar [mailto:Bram@...]
                    Sent: Saturday, 4 January 2003 6:54 AM
                    To: Michael Geddes
                    Cc: Benji Fisher; Vim Dev
                    Subject: RE: feature request: v:register



                    Michael Geddes wrote:

                    > You're right about the advantage of getreg('a') over @a.. you'd never
                    > do it the first way. But if you don't know what the register name is -

                    > being passed in, or used from v:register, then it is very useful.. you

                    > can use getreg(regname) instead of having to wrap it in an 'exe'.

                    OK, avoiding ":exe" is a good point.

                    When adding these functions, there is one extra issue considering
                    registers that we might want to take care of: Whether the text is used
                    linewise, characterwise or blockwise. Since a function can't return two
                    values at the same time, perhaps we should think of adding setregtype()
                    and getregtype()? Although setreg() could set the type at the same time
                    the contents is set, using an optional third argument.
                  • Michael Geddes
                    How about the optional third argument on setreg() being an options argument... so if you want to append, you include a , linewise selection l (or V ),
                    Message 9 of 13 , Jan 6, 2003
                    • 0 Attachment
                      How about the optional third argument on 'setreg()' being an 'options'
                      argument...

                      so if you want to append, you include 'a', linewise selection 'l' (or
                      'V'), block selection 'b', character selection 'c' or 'v'.

                      (I'll have to check out the rules for what happens with mixing types and
                      appending).

                      //.ichael G.

                      -----Original Message-----
                      From: Michael Geddes
                      Sent: Monday, 6 January 2003 9:20 AM
                      To: Bram Moolenaar
                      Cc: Vim-dev@...
                      Subject: RE: feature request: v:register


                      Hmm, yes, very good idea. Unfortunately there is already an optional
                      third argument.. (whether to append). I think the orthognal
                      setregtype/getregtype might be the way to go... I'll have a think (any
                      ideas?)
                      //.

                      -----Original Message-----
                      From: Bram Moolenaar [mailto:Bram@...]
                      Sent: Saturday, 4 January 2003 6:54 AM
                      To: Michael Geddes
                      Cc: Benji Fisher; Vim Dev
                      Subject: RE: feature request: v:register



                      Michael Geddes wrote:

                      > You're right about the advantage of getreg('a') over @a.. you'd never
                      > do it the first way. But if you don't know what the register name is -

                      > being passed in, or used from v:register, then it is very useful.. you

                      > can use getreg(regname) instead of having to wrap it in an 'exe'.

                      OK, avoiding ":exe" is a good point.

                      When adding these functions, there is one extra issue considering
                      registers that we might want to take care of: Whether the text is used
                      linewise, characterwise or blockwise. Since a function can't return two
                      values at the same time, perhaps we should think of adding setregtype()
                      and getregtype()? Although setreg() could set the type at the same time
                      the contents is set, using an optional third argument.
                    • Michael Geddes
                      Here are the help sections I ve added explaining the new functionality. I ll forward the patch to Bram. Benji, is this what you wanted? Any comments?
                      Message 10 of 13 , Jan 6, 2003
                      • 0 Attachment
                        Here are the help sections I've added explaining the new functionality.
                        I'll forward the patch to Bram. Benji, is this what you wanted? Any
                        comments?

                        //.ichael G.


                        v:register *v:register* *register-variable*
                        The register supplied to the last normal mode command.
                        Empty
                        if none were supplied. |getreg()| |setreg()|


                        *getreg()*
                        getreg( {regname}) The Result is a String, which is the value of the
                        specified
                        register. Example: >
                        getreg(v:register)
                        < NOTE: getreg('=') returns the last evaluated value of
                        the
                        expression register. (For use in maps).
                        *getregtype()*
                        getregtype( {regname})The Result is a String, which is yank type of the
                        specified register. The value will be one of:
                        'c' - character mode buffer
                        'l' - line mode buffer
                        'b' - block mode buffer, followed by its width.


                        *setreg()*
                        setreg( {regname}, {value}[,{options}, [{width}] ]) set value to
                        specified register
                        Set the register {regname} to {value}.
                        If {options} contains 'a' (or the register is
                        capitalised), then the
                        value is appended.
                        If {options} contains 'c', 'l' or 'b' then the register
                        is set
                        to character, line, or block mode respectively.
                        If block mode is specified, then the width of the block
                        is set
                        to {width}, or set to the number of characters in the
                        longest
                        line.
                        If {options} contains no register settings, then the
                        default
                        is to use line mode unless {value} ends in a <CR>.
                        Examples: >
                        :call setreg( v:register, @*)
                        :call setreg( '*', @%, 'ac')
                        :call setreg( 'a', "1\n2\n3", 'b', 5)
                        <

                        -----Original Message-----
                        From: Michael Geddes
                        Sent: Tuesday, 7 January 2003 9:38 AM
                        To: Bram Moolenaar
                        Cc: Vim-dev@...
                        Subject: RE: feature request: v:register


                        How about the optional third argument on 'setreg()' being an 'options'
                        argument...

                        so if you want to append, you include 'a', linewise selection 'l' (or
                        'V'), block selection 'b', character selection 'c' or 'v'.

                        (I'll have to check out the rules for what happens with mixing types and
                        appending).

                        //.ichael G.

                        -----Original Message-----
                        From: Michael Geddes
                        Sent: Monday, 6 January 2003 9:20 AM
                        To: Bram Moolenaar
                        Cc: Vim-dev@...
                        Subject: RE: feature request: v:register


                        Hmm, yes, very good idea. Unfortunately there is already an optional
                        third argument.. (whether to append). I think the orthognal
                        setregtype/getregtype might be the way to go... I'll have a think (any
                        ideas?)
                        //.

                        -----Original Message-----
                        From: Bram Moolenaar [mailto:Bram@...]
                        Sent: Saturday, 4 January 2003 6:54 AM
                        To: Michael Geddes
                        Cc: Benji Fisher; Vim Dev
                        Subject: RE: feature request: v:register



                        Michael Geddes wrote:

                        > You're right about the advantage of getreg('a') over @a.. you'd never
                        > do it the first way. But if you don't know what the register name is -

                        > being passed in, or used from v:register, then it is very useful.. you

                        > can use getreg(regname) instead of having to wrap it in an 'exe'.

                        OK, avoiding ":exe" is a good point.

                        When adding these functions, there is one extra issue considering
                        registers that we might want to take care of: Whether the text is used
                        linewise, characterwise or blockwise. Since a function can't return two
                        values at the same time, perhaps we should think of adding setregtype()
                        and getregtype()? Although setreg() could set the type at the same time
                        the contents is set, using an optional third argument.
                      • Bram Moolenaar
                        ... Looks very good. Just a few suggestions. ... How about making the argument optional? In that case v:register would be used. reg_a = getreg( a ) reg =
                        Message 11 of 13 , Jan 7, 2003
                        • 0 Attachment
                          Michael Geddes wrote:

                          > Here are the help sections I've added explaining the new
                          > functionality. I'll forward the patch to Bram. Benji, is this what
                          > you wanted? Any comments?

                          Looks very good. Just a few suggestions.

                          > v:register *v:register* *register-variable*
                          > The register supplied to the last normal mode command. Empty
                          > if none were supplied. |getreg()| |setreg()|
                          >
                          >
                          > *getreg()*
                          > getreg( {regname}) The Result is a String, which is the value of the
                          > specified
                          > register. Example: >
                          > getreg(v:register)
                          > < NOTE: getreg('=3D') returns the last evaluated value of the
                          > expression register. (For use in maps).

                          How about making the argument optional? In that case v:register would
                          be used.
                          reg_a = getreg("a")
                          reg = getreg()

                          > *getregtype()*
                          > getregtype( {regname})The Result is a String, which is yank type of the
                          > specified register. The value will be one of:
                          > 'c' - character mode buffer
                          > 'l' - line mode buffer
                          > 'b' - block mode buffer, followed by its width.

                          Same idea for optional argument here.

                          I suppose "b20" would mean block mode with a width of 20. Can't we use
                          the same for setreg()? That makes it easy to copy a register and
                          restore it later. No need for a fourth argument in setreg().

                          --
                          ARTHUR: Well, I can't just call you `Man'.
                          DENNIS: Well, you could say `Dennis'.
                          ARTHUR: Well, I didn't know you were called `Dennis.'
                          DENNIS: Well, you didn't bother to find out, did you?
                          The Quest for the Holy Grail (Monty Python)

                          /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
                          /// Creator of Vim - Vi IMproved -- http://www.vim.org \\\
                          \\\ Project leader for A-A-P -- http://www.a-a-p.org ///
                          \\\ Lord Of The Rings helps Uganda - http://iccf-holland.org/lotr.html ///
                        • Michael Geddes
                          ... Ta & Ta ... the ... be used. Yes, very good idea. ... the ... Yup, can do. ... use the same for setreg()? That makes it easy to copy a register and
                          Message 12 of 13 , Jan 7, 2003
                          • 0 Attachment
                            > -----Original Message-----
                            > From: Bram Moolenaar [mailto:Bram@...]
                            >
                            > Michael Geddes wrote:
                            >
                            > > Here are the help sections I've added explaining the new
                            > > functionality. I'll forward the patch to Bram. Benji, is this what

                            > > you wanted? Any comments?
                            >
                            > Looks very good. Just a few suggestions.
                            Ta & Ta

                            >
                            > > *getreg()*
                            > > getreg( {regname}) The Result is a String, which is the value of the
                            > > specified
                            > > register. Example: >
                            > > getreg(v:register)
                            > > < NOTE: getreg('=') returns the last evaluated value of
                            the
                            > > expression register. (For use in maps).
                            >
                            > How about making the argument optional? In that case v:register would
                            be used.
                            Yes, very good idea.

                            > reg_a = getreg("a")
                            > reg = getreg()
                            >
                            > > *getregtype()*
                            > > getregtype( {regname})The Result is a String, which is yank type of
                            the
                            > > specified register. The value will be one of:
                            > > 'c' - character mode buffer
                            > > 'l' - line mode buffer
                            > > 'b' - block mode buffer, followed by its width.
                            >
                            > Same idea for optional argument here.
                            Yup, can do.

                            >
                            > I suppose "b20" would mean block mode with a width of 20. Can't we
                            use the same for setreg()? That makes it easy to copy a register and
                            restore it later. No need for a fourth argument in setreg().
                            >
                            Indeed, I sent a second patch with this functionality to you and Benji.
                            The only
                            thing was that I allowed either 'b20' or 'b', 20, but I guess it's not
                            really
                            that necessary, as you can always do 'b'.20 instead of 'b',20

                            I'll remove that 4th argument if you want... actually I'll do it anyway,
                            there's no huge gain.

                            hows this then ?

                            //.ichael G.

                            ---------8<------------------------


                            *setreg()*
                            setreg( {regname}, {value}[,{options}]) set value to specified register
                            Set the register {regname} to {value}.
                            If {options} contains 'a' (or the register is
                            capitalised), then the
                            value is appended.
                            If {options} contains 'c', 'l' or 'b' then the register
                            is set
                            to character, line, or block mode respectively.
                            If a number immediately follows 'b', this is used as the
                            width of the selection - if it is not specified then the
                            width
                            of the block is set to the number of characters in the
                            longest
                            line. (NB <TAB> only counts as 1 character).

                            If {options} contains no register settings, then the
                            default
                            is to use line mode unless {value} ends in a <CR>.
                            Examples: >
                            :call setreg( v:register, @*)
                            :call setreg( '*', @%, 'ac')
                            :call setreg( 'a', "1\n2\n3", 'b5' )

                            < This examples shows using the functions to save and
                            restore a
                            register. >
                            :let var_a=getreg('a')
                            :let var_amode=getregtype('a')
                            ....
                            :call setreg( 'a',var_a, var_amode)
                            <
                          • Bram Moolenaar
                            ... [ your quoting was messed up. Don t you use Vim to edit messages? ] ... Looks good. Now, before I include this new feature, you also need to fix at least
                            Message 13 of 13 , Jan 8, 2003
                            • 0 Attachment
                              Michael Geddes wrote:

                              > > I suppose "b20" would mean block mode with a width of 20. Can't we
                              > > use the same for setreg()? That makes it easy to copy a register and
                              > > restore it later. No need for a fourth argument in setreg().

                              [ your quoting was messed up. Don't you use Vim to edit messages? ]

                              > Indeed, I sent a second patch with this functionality to you and Benji.
                              > The only thing was that I allowed either 'b20' or 'b', 20, but I guess
                              > it's not really that necessary, as you can always do 'b'.20 instead of
                              > 'b',20
                              >
                              > I'll remove that 4th argument if you want... actually I'll do it anyway,
                              > there's no huge gain.
                              >
                              > hows this then ?

                              Looks good.

                              Now, before I include this new feature, you also need to fix at least
                              one bug. :-)

                              --
                              A poem: read aloud:

                              <> !*''# Waka waka bang splat tick tick hash,
                              ^"`$$- Caret quote back-tick dollar dollar dash,
                              !*=@$_ Bang splat equal at dollar under-score,
                              %*<> ~#4 Percent splat waka waka tilde number four,
                              &[]../ Ampersand bracket bracket dot dot slash,
                              |{,,SYSTEM HALTED Vertical-bar curly-bracket comma comma CRASH.

                              Fred Bremmer and Steve Kroese (Calvin College & Seminary of Grand Rapids, MI.)

                              /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
                              /// Creator of Vim - Vi IMproved -- http://www.vim.org \\\
                              \\\ Project leader for A-A-P -- http://www.a-a-p.org ///
                              \\\ Lord Of The Rings helps Uganda - http://iccf-holland.org/lotr.html ///
                            Your message has been successfully submitted and would be delivered to recipients shortly.