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

[Patch] Refine listed tags with regex

Expand Messages
  • Cody Cutler
    Hello list. The attached patch allows optional regexs to be passed to ... tags before they are printed. This patch is useful when you have many tags for a
    Message 1 of 5 , Mar 28, 2013
    • 0 Attachment
      Hello list. The attached patch allows optional regexs to be passed to
      :tj and friends. these regexs is then used to further refine available
      tags before they are printed.

      This patch is useful when you have many tags for a single identifier.
      For example, suppose a large C++ project has initialize() methods for
      100s of classes. Going through the list of tags printed by :tj is
      tedious. Most of the time I know additional information about the
      identifier I am looking for like the containing object type or source
      filename. The text after the '/' in the argument is used as a regex
      (unless a '/' is the first character of the tag identifier, then the
      text after the second '/' is used) to match against the "other" tag
      fields (which often contains the containing type name). If a '!' is
      present, text after it is used to match against filenames. With this
      patch you can type:

      :tj initialize/SomeClass

      to list all tags that also contain "SomeClass" in their "other" fields
      or

      :ts initialize/!arch/amd64

      to list all tags matching initialize that contain "arch/amd64" in the
      containing file's pathname. Or a mix:

      :ts initialize/SomeClass!arch/amd64

      The '/' and '!' characters were chosen somewhat arbitrarily--I'm not
      sure if they are a safe choice.

      Any comments are appreciated.

      --
      --
      You received this message from the "vim_dev" 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_dev" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Lech Lorens
      ... I haven t tested your patch but it reminds me of a patch I prepared some 2 years ago. You could search the list archives for a feature called tagfunc
      Message 2 of 5 , Mar 29, 2013
      • 0 Attachment
        On 29-Mar-2013 Cody Cutler <ccutler@...> wrote:
        > Hello list. The attached patch allows optional regexs to be passed to
        > :tj and friends. these regexs is then used to further refine available
        > tags before they are printed.
        >
        > This patch is useful when you have many tags for a single identifier.
        > For example, suppose a large C++ project has initialize() methods for
        > 100s of classes. Going through the list of tags printed by :tj is
        > tedious. Most of the time I know additional information about the
        > identifier I am looking for like the containing object type or source
        > filename. The text after the '/' in the argument is used as a regex
        > (unless a '/' is the first character of the tag identifier, then the
        > text after the second '/' is used) to match against the "other" tag
        > fields (which often contains the containing type name). If a '!' is
        > present, text after it is used to match against filenames. With this
        > patch you can type:
        >
        > :tj initialize/SomeClass
        >
        > to list all tags that also contain "SomeClass" in their "other" fields
        > or
        >
        > :ts initialize/!arch/amd64
        >
        > to list all tags matching initialize that contain "arch/amd64" in the
        > containing file's pathname. Or a mix:
        >
        > :ts initialize/SomeClass!arch/amd64
        >
        > The '/' and '!' characters were chosen somewhat arbitrarily--I'm not
        > sure if they are a safe choice.
        >
        > Any comments are appreciated.

        I haven't tested your patch but it reminds me of a patch I prepared some
        2 years ago. You could search the list archives for a feature called
        'tagfunc' which with the awesome SmartTag vim script by Robert Webb I've
        been happily using ever since.

        Cheers,
        Lech

        --
        --
        You received this message from the "vim_dev" 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_dev" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • Cody Cutler
        lech.lorens@gmail.com (Lech Lorens) - Fri, Mar 29, 2013 at 10:35:41AM +0100 ... Hello Lech. Thank you, I missed that thread in my search for different
        Message 3 of 5 , Mar 29, 2013
        • 0 Attachment
          lech.lorens@... (Lech Lorens) - Fri, Mar 29, 2013 at 10:35:41AM +0100
          > On 29-Mar-2013 Cody Cutler <ccutler@...> wrote:
          > > [ snip ]
          >
          > I haven't tested your patch but it reminds me of a patch I prepared some
          > 2 years ago. You could search the list archives for a feature called
          > 'tagfunc' which with the awesome SmartTag vim script by Robert Webb I've
          > been happily using ever since.

          Hello Lech. Thank you, I missed that thread in my search for different
          solutions.

          I think this patch is different in two important aspects though: 1) it
          requires no configuration or additional work (besides typing a regex,
          something all vim power users are quite comfortably with!) and 2) it is
          more general in that it is language agnostic (but depends on the tags).

          For years, my solution to the 100s-of-tags-for-one-identifier problem
          was grep. This patch makes finding the right tag take one or two
          seconds instead of 10s of seconds or longer.

          --
          --
          You received this message from the "vim_dev" 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_dev" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • Lech Lorens
          ... I ve been thinking about your proposed patch and I would have one problem with it: it doesn t seem intuitive and although I do work with software projects
          Message 4 of 5 , Apr 14 2:04 PM
          • 0 Attachment
            On 29-Mar-2013 Cody Cutler <ccutler@...> wrote:
            > Hello list. The attached patch allows optional regexs to be passed to
            > :tj and friends. these regexs is then used to further refine available
            > tags before they are printed.
            >
            > This patch is useful when you have many tags for a single identifier.
            > For example, suppose a large C++ project has initialize() methods for
            > 100s of classes. Going through the list of tags printed by :tj is
            > tedious. Most of the time I know additional information about the
            > identifier I am looking for like the containing object type or source
            > filename. The text after the '/' in the argument is used as a regex
            > (unless a '/' is the first character of the tag identifier, then the
            > text after the second '/' is used) to match against the "other" tag
            > fields (which often contains the containing type name). If a '!' is
            > present, text after it is used to match against filenames. With this
            > patch you can type:
            >
            > :tj initialize/SomeClass
            >
            > to list all tags that also contain "SomeClass" in their "other" fields
            > or
            >
            > :ts initialize/!arch/amd64
            >
            > to list all tags matching initialize that contain "arch/amd64" in the
            > containing file's pathname. Or a mix:
            >
            > :ts initialize/SomeClass!arch/amd64
            >
            > The '/' and '!' characters were chosen somewhat arbitrarily--I'm not
            > sure if they are a safe choice.
            >
            > Any comments are appreciated.

            I've been thinking about your proposed patch and I would have one
            problem with it: it doesn't seem intuitive and although I do work with
            software projects with quite large amounts of source code, I don't think
            I would use it much (because I wouldn't be able to remember all the
            quirks of the command).

            However, I think that there is a very simple solution to your problem
            which does not require changing the behaviour of Vim itself: create
            a command in VimL which will do everything you need. For this command
            I would use the following:
            - input() – for getting the name of the tag to jump to,
            - taglist() – to get a list of tags matching what the user chose to
            view,
            - input() – to get the name of the class,
            - input() – to get the file name pattern,
            - match() – to filter the tag list returned by taglist() with the
            criteria based on the values input by the user,
            - setqflist(), setloclist() – to create a list displayed in the quickfix
            window (:copen, :lopen),
            - inputlist() – perhaps instead of using setqflist() to make the
            experience akin to using :tselect.

            I believe that using such a command should be much more pleasant than
            poring through hundreds of lines of output generated by grep. And it has
            the potential of being more user-friendly – whenever you use input(),
            you can help the user by providing a hint in the prompt.

            What do you think? I'll be happy to hear from you.

            --
            Cheers,
            Lech

            --
            --
            You received this message from the "vim_dev" 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_dev" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
          • Cody Cutler
            lech.lorens@gmail.com (Lech Lorens) - Sun, Apr 14, 2013 at 11:04:33PM +0200 ... I agree that appending a / followed by a regex is not a very intuitive way to
            Message 5 of 5 , Apr 14 3:34 PM
            • 0 Attachment
              lech.lorens@... (Lech Lorens) - Sun, Apr 14, 2013 at 11:04:33PM +0200
              > On 29-Mar-2013 Cody Cutler <ccutler@...> wrote:
              > > Hello list. The attached patch allows optional regexs to be passed to
              > > :tj and friends. these regexs is then used to further refine available
              > > tags before they are printed.
              > >
              > > This patch is useful when you have many tags for a single identifier.
              > > For example, suppose a large C++ project has initialize() methods for
              > > 100s of classes. Going through the list of tags printed by :tj is
              > > tedious. Most of the time I know additional information about the
              > > identifier I am looking for like the containing object type or source
              > > filename. The text after the '/' in the argument is used as a regex
              > > (unless a '/' is the first character of the tag identifier, then the
              > > text after the second '/' is used) to match against the "other" tag
              > > fields (which often contains the containing type name). If a '!' is
              > > present, text after it is used to match against filenames. With this
              > > patch you can type:
              > >
              > > :tj initialize/SomeClass
              > >
              > > to list all tags that also contain "SomeClass" in their "other" fields
              > > or
              > >
              > > :ts initialize/!arch/amd64
              > >
              > > to list all tags matching initialize that contain "arch/amd64" in the
              > > containing file's pathname. Or a mix:
              > >
              > > :ts initialize/SomeClass!arch/amd64
              > >
              > > The '/' and '!' characters were chosen somewhat arbitrarily--I'm not
              > > sure if they are a safe choice.
              > >
              > > Any comments are appreciated.
              >
              > I've been thinking about your proposed patch and I would have one
              > problem with it: it doesn't seem intuitive and although I do work with
              > software projects with quite large amounts of source code, I don't think
              > I would use it much (because I wouldn't be able to remember all the
              > quirks of the command).

              I agree that appending a '/' followed by a regex is not a very intuitive
              way to specify the info for the search but I don't think it is less
              intuitive than the current state since :tj and company already treat '/'
              specially if it is the first character of search string (which is why
              the paragraph explaining my patch's usage is so long -- I wanted to be
              clear that the original functionality was preserved).

              There's really not much to remember! If :tj generates a huge list of
              tags, just append a / with a search pattern. If you haven't tried the
              patch yet, you should give it a whirl!

              > However, I think that there is a very simple solution to your problem
              > which does not require changing the behaviour of Vim itself: create
              > a command in VimL which will do everything you need. For this command
              > I would use the following:
              > - input() ??? for getting the name of the tag to jump to,
              > - taglist() ??? to get a list of tags matching what the user chose to
              > view,
              > - input() ??? to get the name of the class,
              > - input() ??? to get the file name pattern,
              > - match() ??? to filter the tag list returned by taglist() with the
              > criteria based on the values input by the user,
              > - setqflist(), setloclist() ??? to create a list displayed in the quickfix
              > window (:copen, :lopen),
              > - inputlist() ??? perhaps instead of using setqflist() to make the
              > experience akin to using :tselect.

              Cool, thanks for this. One reason I submitted the patch was to see what
              other ways people deal with this situation -- I've had a hard time
              finding other solutions. I would love a solution in base though.

              Thanks Lech.

              --
              --
              You received this message from the "vim_dev" 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_dev" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
              For more options, visit https://groups.google.com/groups/opt_out.
            Your message has been successfully submitted and would be delivered to recipients shortly.