Saturday, April 5, 2014

Capture error in omni completion, and switch to key completation

Hi, I'm writing a simple function to perform "smart" completions with LaTeX. I would like to use the <tab> key to perform omni completion by default, but if it produces no output, then it should try key completion (I use a dictionary with LaTeX keywords).

Is there a way to produce this flow? Currently, when completion can't find a match, I get the message "Pattern not found". Is there a way to say vim "when you find no pattern in omni completion, return <c-p>"?

Thanks a lot. 




For further details, I attach the current state of my function:


function! Smart_TabComplete_Tex()
  " if the pop-up window is shown, go down
  if(pumvisible())
    return "\<down>"
  endif

  " get the line to guess what the user wants
  let line = getline('.')

  " if the line is empty, return \ followed by omni completion
  if(match(line, '\S')==-1)
    noh
    return "\\\<c-x>\<c-o>"
  endif

  " find the last word in the line
  let lastword = matchstr(line, '\S*$')

  " if the last word contains some LaTeX-like character, omni completion
  if(match(lastword,'[\{}]') != -1) 
    noh
    return "\<c-x>\<c-o>"
  endif

  " if the last word seems like a folder, file completion
  if(match(lastword,'[/]') != -1)
    noh
    return "\<c-x>\<c-f>"
  endif

  " if nothing else works, key completion
  noh
  return "\<c-p>"
endfunction



--
Juan José Gómez-Navarro

University of Bern
Physics Institute
Sidlerstrasse 5
CH-3012 Bern
Switzerland

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: