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

VIM 7.0 scripts, ctags and taglist.vim

Expand Messages
  • Mikhail Shvarts
    VIM 7.0 is known have been extended with rather advanced scripting capabilities such as complex data structures and object-oriented programming in embryo. So,
    Message 1 of 3 , Jul 10, 2006
    • 0 Attachment
      VIM 7.0 is known have been extended with rather advanced scripting capabilities such as complex data structures and object-oriented programming in embryo. So, now we can define methods for some object type in such a way:

      let MyObjectType = {}
      function! MyObjectType.method1()
      echo 'Hello world from method1!'
      endf
      function! MyObjectType.method2()
      echo 'Hello world from method2!'
      endf

      However, if one tries to open taglist for such a code one will see:
      |- variable
      || MyObjectType
      |
      |- function
      || MyObjectType
      || MyObjectType

      Such a behavior most likely is far from one's expectations. Though, there is no any riddle here, just the latest version of exuberant ctags cannot parse new extensions to VIM script.

      I've found an easy way to extend the latest version of ctags to make it more suitable for using with new VIM scripts. With this extension taglist for code above will look so:

      |- class
      || MyObjectType
      |
      |- function
      || MyObjectType.method1
      || MyObjectType.method2

      Here (http://community.livejournal.com/screenshot_vim/4893.html) once more example.

      Note that you will not be able to jump to method definitions using <C-]> neither with original ctags nor with patched. Though, with patched version you will be able to jump to method definition through taglist.

      To obtain such a behavior you need to patch latest version of exuberant ctags, namely file vim.c

      1. Download the latest version of ctags (5.6) here: http://sourceforge.net/project/showfiles.php?group_id=6556
      2. Unpack it and go to directory created: tar zxvf ctags-5.6.tar.gz; cd ctags-5.6
      3. Patch file vim.c with this patch:

      32c32,34
      < K_VARIABLE
      ---
      > K_VARIABLE,
      > K_CLASS
      >
      38a41
      > { TRUE, 'c', "class", "class definitions" },
      105c108
      < } while (isalnum ((int) *cp) || *cp == '_');
      ---
      > } while (isalnum ((int) *cp) || *cp == '_' || *cp == '.' || *cp == '\'' || *cp == '"' || *cp == '[' || *cp == ']');
      157c160
      < } while (isalnum ((int) *cp) || *cp == '_');
      ---
      > } while (isalnum ((int) *cp) || *cp == '_'|| *cp == '.' || *cp == '\'' || *cp == '"' || *cp == '[' || *cp == ']');
      159c162,176
      < makeSimpleTag (name, VimKinds, K_VARIABLE);
      ---
      > while(isspace((int) *cp))
      > ++cp;
      > if(*cp == '=')
      > {
      > ++cp;
      > while(isspace((int) *cp))
      > ++cp;
      > if(*cp == '{' || strncmp ((const char*) cp, "extend", (size_t) 6) == 0 ||
      > strncmp ((const char*) cp, "copy", (size_t) 4) == 0 ||
      > strncmp ((const char*) cp, "deepcopy", (size_t) 8) == 0 ||
      > strncmp ((const char*) cp, "filter", (size_t) 6) == 0 ||
      > strncmp ((const char*) cp, "map", (size_t) 3) == 0)
      > makeSimpleTag(name, VimKinds, K_CLASS);
      > else makeSimpleTag (name, VimKinds, K_VARIABLE);
      > }

      4) Build ctags and install:
      ./configure
      make; make install

      --
      No virus found in this outgoing message.
      Checked by AVG Free Edition.
      Version: 7.1.394 / Virus Database: 268.9.10/383 - Release Date: 7/7/2006
    • Marc Weber
      ... It can t parse function autoload#blah#foo#method, either. So if you want to include this into your patch, too? It s only a hack there might be better
      Message 2 of 3 , Jul 11, 2006
      • 0 Attachment
        > Such a behavior most likely is far from one's expectations. Though, there is no any riddle here, just the latest version of exuberant ctags cannot parse new extensions to VIM script.

        It can't parse function autoload#blah#foo#method, either.

        So if you want to include this into your patch, too?
        It's only a hack there might be better solutions but it should work fine


        99c99,102
        < if (isupper ((int) *cp) || scope == 's' || scope == '<')
        ---
        > if (isupper ((int) *cp) ||
        > islower ((int) *cp) || // this is because of the new autoload style fun ab#Upper() (folders may start with lower case letters)
        > // I think its useful if the location is included into the tag
        > scope == 's' || scope == '<')
        105c108,109
        < } while (isalnum ((int) *cp) || *cp == '_');
        ---
        > } while (isalnum ((int) *cp) || *cp == '_' || *cp == '#' );
        > // '#' is sed in the new autoload mechanism. see :h autoload in vim help

        Marc
      • Aaron Griffin
        Commet nitpick/correction: // # is sed in the new autoload mechanism. see :h autoload in vim help Is missing a u : // # is used in the new autoload
        Message 3 of 3 , Jul 12, 2006
        • 0 Attachment
          Commet nitpick/correction:

          // '#' is sed in the new autoload mechanism. see :h autoload in vim help
          Is missing a 'u':
          // '#' is used in the new autoload mechanism. see :h autoload in vim help
        Your message has been successfully submitted and would be delivered to recipients shortly.