Blame plugins/devhelp.vim

Packit 116408
" devhelp.vim: A Devhelp assistant and search plugin for VIM.
Packit 116408
"
Packit 116408
" Copyright (c) 2008 Jannis Pohlmann <jannis@xfce.org>
Packit 116408
"
Packit 116408
" To enable devhelp search:
Packit 116408
"   let g:devhelpSearch=1
Packit 116408
"
Packit 116408
" To enable devhelp assistant:
Packit 116408
"   let g:devhelpAssistant=1
Packit 116408
"
Packit 116408
" To change the update delay (e.g. to 150ms):
Packit 116408
"   set updatetime=150
Packit 116408
"
Packit 116408
" To change the search key (e.g. to F5):
Packit 116408
"   let g:devhelpSearchKey = '<F5>'
Packit 116408
"
Packit 116408
" To change the length (e.g. to 5 characters) before a word becomes
Packit 116408
" relevant:
Packit 116408
"   let g:devhelpWordLength = 5
Packit 116408
"
Packit 116408
" This program is free software; you can redistribute it and/or modify
Packit 116408
" it under the terms of the GNU General Public License as published by
Packit 116408
" the Free Software Foundation; either version 2 of the License, or
Packit 116408
" (at your option) any later version.
Packit 116408
"
Packit 116408
" This program is distributed in the hope that it will be useful,
Packit 116408
" but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 116408
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 116408
" General Public License for more details.
Packit 116408
"
Packit 116408
" You should have received a copy of the GNU General Public License
Packit 116408
" along with this program; if not, see <http://www.gnu.org/licenses/>.
Packit 116408
Packit 116408
" Devhelp plugin configuration. These variables may be set in .vimrc
Packit 116408
" to override the defaults
Packit 116408
if !exists ('g:devhelpSearchKey')
Packit 116408
  let g:devhelpSearchKey = '<F7>'
Packit 116408
endif
Packit 116408
if !exists ('g:devhelpWordLength')
Packit 116408
  let g:devhelpWordLength = 5
Packit 116408
endif
Packit 116408
Packit 116408
" Variable for remembering the last assistant word
Packit 116408
let s:lastWord = ''
Packit 116408
Packit 116408
function! GetCursorWord ()
Packit 116408
  " Try to get the word below the cursor
Packit 116408
  let s:word = expand ('<cword>')
Packit 116408
Packit 116408
  " If that's empty, try to use the word before the cursor
Packit 116408
  if empty (s:word)
Packit 116408
    let s:before = getline  ('.')[0 : getpos ('.')[2]-1]
Packit 116408
    let s:start  = match    (s:before, '\(\w*\)$')
Packit 116408
    let s:end    = matchend (s:before, '\(\w*\)$')
Packit 116408
    let s:word   = s:before[s:start : s:end]
Packit 116408
  end
Packit 116408
Packit 116408
  return s:word
Packit 116408
endfunction
Packit 116408
Packit 116408
function! DevhelpUpdate (flag)
Packit 116408
  try
Packit 116408
    " Get word below or before cursor
Packit 116408
    let s:word = GetCursorWord ()
Packit 116408
Packit 116408
    if a:flag == 'a'
Packit 116408
      " Update Devhelp assistant window
Packit 116408
      if s:lastWord != s:word && strlen (s:word) > g:devhelpWordLength
Packit 116408
        " Update Devhelp
Packit 116408
        call system ('devhelp -a '.s:word.' &')
Packit 116408
Packit 116408
        " Remember the word for next time
Packit 116408
        let s:lastWord = s:word
Packit 116408
      end
Packit 116408
    else
Packit 116408
      " Update devhelp search window. Since the user intentionally
Packit 116408
      " pressed the search key, the word is not checked for its
Packit 116408
      " length or whether it's new
Packit 116408
      call system ('devhelp -s '.s:word.' &')
Packit 116408
    end
Packit 116408
  catch
Packit 116408
  endtry
Packit 116408
endfunction
Packit 116408
Packit 116408
function! DevhelpUpdateI (flag)
Packit 116408
  " Use normal update function
Packit 116408
  call DevhelpUpdate (a:flag)
Packit 116408
Packit 116408
  if col ('.') == len (getline ('.'))
Packit 116408
    " Start appening if the cursor at the end of the line
Packit 116408
    startinsert!
Packit 116408
  else
Packit 116408
    " Otherwise move the cursor to the right and start inserting.
Packit 116408
    " This is required because <ESC> moves the cursor to the left
Packit 116408
    let s:pos = getpos ('.')
Packit 116408
    let s:pos[2] += 1
Packit 116408
    call setpos ('.', s:pos)
Packit 116408
    startinsert
Packit 116408
  endif
Packit 116408
endfunction
Packit 116408
Packit 116408
if exists ('g:devhelpSearch') && g:devhelpSearch
Packit 116408
  " Update the main Devhelp window when the search key is pressed
Packit 116408
  exec 'nmap '.g:devhelpSearchKey.' :call DevhelpUpdate("s")<CR>'
Packit 116408
  exec 'imap '.g:devhelpSearchKey.' <ESC>:call DevhelpUpdateI("s")<CR>'
Packit 116408
endif
Packit 116408
Packit 116408
if exists ('g:devhelpAssistant') && g:devhelpAssistant
Packit 116408
  " Update the assistant window if the user hasn't pressed a key for a
Packit 116408
  " while. See :help updatetime for how to change this delay
Packit 116408
  au! CursorHold  * nested call DevhelpUpdate('a')
Packit 116408
  au! CursorHoldI * nested call DevhelpUpdate('a')
Packit 116408
endif