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

Jump to the next tag in the help files

Expand Messages
  • Balazs Kezes
    Hi! I m a newbie/wannabe in the software field so feel free to discourage me. I m sure that this was done before, but anyways, I was bored. ... So I just
    Message 1 of 2 , Dec 29, 2007
    • 0 Attachment
      Hi!
      I'm a newbie/wannabe in the software field so feel free to discourage me.
      I'm sure that this was done before, but anyways, I was bored.

      Quoting lines 1518, 1519 and 1529 from todo.txt:
      > 7 Add a help.vim plugin that maps <Tab> to jump to the next tag in || and
      > <C-Tab> (and <S-Tab>) to the previous tag.
      > - Default mapping for help files: <Tab> to position cursor on next |:tag|.

      So I just hacked together this vimscript to do something like that. I guess
      it's place would be ftplugin/help.vim, but not sure.
      (it works on my computer if I source the file when viewing help files)

      " Jumps to the next tag in ||.
      " If dir[ection] is nonzero it jumps forwards, if zero backwards.
      " It doesn't wrap at the end of the file.
      function! GetNextHelpTag(dir)
      if a:dir != 0
      let flags = "sW"
      else
      let flags = "bsW"
      endif

      " Save the original position for the case we didn't find a tag.
      let ori_pos = getpos('.')

      " For every possible match check if it is a tag for sure
      while 1
      let [lnum, col] = searchpos('|.\{-1,}|', flags)
      if lnum == 0
      break
      endif
      let tag = matchlist(getline('.'), '|\(.\{-1,}\)|', col-1)[1]
      if !empty(taglist(tag))
      return
      endif
      endwhile

      call setpos('.', ori_pos)
      echo "No more tags found."
      endfunction

      map <buffer> <Tab> :call GetNextHelpTag(1)<CR>
      map <buffer> <C-Tab> :call GetNextHelpTag(0)<CR>
      map <buffer> <S-Tab> :call GetNextHelpTag(0)<CR>

      Without hopes,
      Balazs

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • ap
      ... If this doesn t pass in the first run, the -mark will have no usefull position. ... Should be if !empty(taglist( ^ V .escape(tag, ). $ )) , because we
      Message 2 of 2 , Dec 30, 2007
      • 0 Attachment
        On Dec 30, 1:18 am, "Balazs Kezes" <rlblas...@...> wrote:
        > Hi!
        ...
        >
        > " Jumps to the next tag in ||.
        > " If dir[ection] is nonzero it jumps forwards, if zero backwards.
        > " It doesn't wrap at the end of the file.
        > function! GetNextHelpTag(dir)
        > if a:dir != 0
        > let flags = "sW"
        > else
        > let flags = "bsW"
        > endif
        >
        > " Save the original position for the case we didn't find a tag.
        > let ori_pos = getpos('.')
        >
        > " For every possible match check if it is a tag for sure
        > while 1
        > let [lnum, col] = searchpos('|.\{-1,}|', flags)
        If this doesn't pass in the first run, the '-mark will have no usefull
        position.
        > if lnum == 0
        > break
        > endif
        > let tag = matchlist(getline('.'), '|\(.\{-1,}\)|', col-1)[1]
        > if !empty(taglist(tag))
        Should be
        if !empty(taglist('^\V'.escape(tag,'\').'\$'))
        , because we are searching for a exact match of a string.
        Without escaping strings with backslash could produce an
        regex error.

        > return
        > endif
        > endwhile
        >
        > call setpos('.', ori_pos)
        > echo "No more tags found."
        > endfunction
        >
        > map <buffer> <Tab> :call GetNextHelpTag(1)<CR>
        > map <buffer> <C-Tab> :call GetNextHelpTag(0)<CR>
        > map <buffer> <S-Tab> :call GetNextHelpTag(0)<CR>
        >
        > Without hopes,
        > Balazs

        Confirming that the string between bars is indeed a valid tag
        takes considerably time and results in lag in case the <TAB>
        key is held down.
        I think we should simply search for the next tag with the regex
        from the syntax file. This should be correct in most cases and
        if not, it would be the fault of the helpfile author.

        Btw beeing able to comprehend a API and make use of it, shows
        that your hopelessness is unjustified.

        -ap


        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_dev" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      Your message has been successfully submitted and would be delivered to recipients shortly.