Skip to content

Commit

Permalink
Version 0.5.1: Added symbol name completion based on the Hyperspec da…
Browse files Browse the repository at this point in the history
…tabase.
  • Loading branch information
kovisoft authored and vim-scripts committed Oct 18, 2010
1 parent 9c06691 commit 83693a8
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 45 deletions.
58 changes: 53 additions & 5 deletions doc/slimv.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
*slimv.txt* Slimv Last Change: 16 Apr 2009
*slimv.txt* Slimv Last Change: 23 Apr 2009

Slimv *slimv*
Version 0.5.0
Version 0.5.1

The Superior Lisp Interaction Mode for Vim.
This plugin is aimed to help Lisp development by interfacing between Vim and
Expand All @@ -13,6 +13,7 @@ the Lisp REPL, similarly to Emacs/SLIME.
|slimv-repl| Lisp REPL inside Vim
|slimv-clojure| Clojure support
|slimv-profiling| Profiling
|slimv-hyperspec| Hyperspec lookup and Completion
|slimv-external| External utilities
|slimv-faq| Frequently Asked Questions
|slimv-changelog| Change Log
Expand Down Expand Up @@ -62,6 +63,17 @@ To install the script:

You might already have an ftdetect/clojure.vim file if you already use
another Clojure filetype plugin. In this case just keep the original file.
If you intend to use the script only for Lisp programming, then most of
the files may be skipped, in this case it is enough to copy the following
files:

doc/slimv.txt
ftplugin/metering.lisp
ftplugin/slimv.py
ftplugin/slimv.vim
ftplugin/slimv-clhs.vim
ftplugin/lisp/slimv-lisp.vim

- Start Vim or goto an existing instance of Vim.
- Execute the following command:
>
Expand Down Expand Up @@ -695,6 +707,38 @@ templates (see |slimv_templates|):
|g:slimv_template_profile_reset|


===============================================================================
HYPERSPEC AND COMPLETION *slimv-hyperspec*

Slimv contains Common Lisp Hyperspec, Clojure API and JavaDoc symbol databases.
When you are looking for the definition of a symbol, just place the cursor on
the symbol and select the 'Hyperspec' function. If the symbol is found in the
symbol database then the corresponding web page is displayed in the default
browser. It is also possible to select this function having just the beginning
of the symbol name, then the first match is presented to the user, and he/she
is asked to confirm or edit the symbol name before the hyperspec lookup.

It is possible to use a local copy of the Hyperspec, for this you need to
define its base URL. See |g:slimv_clhs_root|, |g:slimv_cljapi_root| and
|g:slimv_javadoc_root| for details.

It is also possible to add user defined symbols to the Hyperspec database,
see |g:slimv_clhs_user_db| and |g:slimv_cljapi_user_db|.


Slimv uses the Hyperspec symbol database for symbol name completion, via
Vim's omni-completion feature (if it is enabled and 'omnifunc' is not
defined already to something else).
Start to enter the symbol in Insert mode, then at some point press the
<C-X> <C-O> (omni-complete) key combination or select the 'Complete Symbol'
function. The first match in the symbol database is inserted at the cursor
position and a list of matching symbols is displayed in a submenu.
Use <C-N> to select the next match, <C-P> to select the previous match.

See Vim help file |insert.txt| for details on the usage of the various
completion functions built in Vim.


===============================================================================
EXTERNAL UTILITIES *slimv-external*

Expand Down Expand Up @@ -771,7 +815,11 @@ topic for a Lisp programmer.
CTRL-P feature. You start typing a word, and when CTRL-P
or CTRL-N is pressed, then Vim looks up the keyword
starting with the same letters as typed in up or
down direction.
down direction in the current buffer.
This is not the same as the omni-completion
feature (see |slimv-hyperspec|). Omni-completion is
based on a symbol database and not on the contents
of the current buffer.

:set complete The |'complete'| option controls how keyword
completion works.
Expand Down Expand Up @@ -871,6 +919,8 @@ FAQ *slimv-faq*
===============================================================================
CHANGE LOG *slimv-changelog*

0.5.1 - Added symbol name completion based on the Hyperspec database.

0.5.0 - Major project reorganization:
Slimv is now a Lisp and Clojure filetype plugin.
- Added Common Lisp Hyperspec, Clojure API, and JavaDoc lookup.
Expand Down Expand Up @@ -954,8 +1004,6 @@ ISSUES, LIMITATIONS, KNOWN BUGS *slimv-issues*
===============================================================================
TODO *slimv-todo*

- Add JavaDoc to Clojure Hyperspec lookup.
- Autocomplete symbols based on the Hyperspec database.
- Add Compile System.
- Add Cross Reference functions.
- Add Debugger.
Expand Down
16 changes: 8 additions & 8 deletions ftplugin/clojure/slimv-clojure.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
" slimv-clojure.vim:
" Clojure filetype plugin for Slimv
" Version: 0.5.0
" Last Change: 18 Apr 2009
" Version: 0.5.1
" Last Change: 22 Apr 2009
" Maintainer: Tamas Kovacs <kovisoft at gmail dot com>
" License: This file is placed in the public domain.
" No warranty, express or implied.
Expand Down Expand Up @@ -51,7 +51,7 @@ function! b:SlimvREPLFile()
endfunction

" Lookup symbol in the list of Clojure Hyperspec symbol databases
function! b:SlimvHyperspecLookup( word, exact )
function! b:SlimvHyperspecLookup( word, exact, all )
if !exists( 'g:slimv_cljapi_loaded' )
runtime ftplugin/**/slimv-cljapi.vim
endif
Expand All @@ -60,21 +60,21 @@ function! b:SlimvHyperspecLookup( word, exact )
runtime ftplugin/**/slimv-javadoc.vim
endif

let symbol = ['', '']
let symbol = []
if exists( 'g:slimv_cljapi_db' )
let symbol = SlimvFindSymbol( a:word, a:exact, g:slimv_cljapi_db, g:slimv_cljapi_root, symbol )
let symbol = SlimvFindSymbol( a:word, a:exact, a:all, g:slimv_cljapi_db, g:slimv_cljapi_root, symbol )
endif
if exists( 'g:slimv_javadoc_db' )
let symbol = SlimvFindSymbol( a:word, a:exact, g:slimv_javadoc_db, g:slimv_javadoc_root, symbol )
let symbol = SlimvFindSymbol( a:word, a:exact, a:all, g:slimv_javadoc_db, g:slimv_javadoc_root, symbol )
endif
if exists( 'g:slimv_cljapi_user_db' )
" Give a choice for the user to extend the symbol database
" Give a choice for the user to extend the symbol database
if exists( 'g:slimv_cljapi_user_root' )
let user_root = g:slimv_cljapi_user_root
else
let user_root = ''
endif
let symbol = SlimvFindSymbol( a:word, a:exact, g:slimv_cljapi_user_db, user_root, symbol )
let symbol = SlimvFindSymbol( a:word, a:exact, a:all, g:slimv_cljapi_user_db, user_root, symbol )
endif
return symbol
endfunction
Expand Down
28 changes: 14 additions & 14 deletions ftplugin/lisp/slimv-lisp.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
" slimv-lisp.vim:
" Lisp filetype plugin for Slimv
" Version: 0.5.0
" Last Change: 18 Apr 2009
" Version: 0.5.1
" Last Change: 22 Apr 2009
" Maintainer: Tamas Kovacs <kovisoft at gmail dot com>
" License: This file is placed in the public domain.
" No warranty, express or implied.
Expand Down Expand Up @@ -104,30 +104,30 @@ function! b:SlimvREPLFile()
endfunction

" Lookup symbol in the list of Lisp Hyperspec symbol databases
function! b:SlimvHyperspecLookup( word, exact )
function! b:SlimvHyperspecLookup( word, exact, all )
if !exists( 'g:slimv_clhs_loaded' )
runtime ftplugin/**/slimv-clhs.vim
endif

let symbol = ['', '']
let symbol = []
if exists( 'g:slimv_clhs_loaded' )
let symbol = SlimvFindSymbol( a:word, a:exact, g:slimv_clhs_clhs, g:slimv_clhs_root, symbol )
let symbol = SlimvFindSymbol( a:word, a:exact, g:slimv_clhs_issues, g:slimv_clhs_root, symbol )
let symbol = SlimvFindSymbol( a:word, a:exact, g:slimv_clhs_chapters, g:slimv_clhs_root, symbol )
let symbol = SlimvFindSymbol( a:word, a:exact, g:slimv_clhs_control_chars, g:slimv_clhs_root, symbol )
let symbol = SlimvFindSymbol( a:word, a:exact, g:slimv_clhs_macro_chars, g:slimv_clhs_root, symbol )
let symbol = SlimvFindSymbol( a:word, a:exact, g:slimv_clhs_loop, g:slimv_clhs_root, symbol )
let symbol = SlimvFindSymbol( a:word, a:exact, g:slimv_clhs_arguments, g:slimv_clhs_root, symbol )
let symbol = SlimvFindSymbol( a:word, a:exact, g:slimv_clhs_glossary, g:slimv_clhs_root, symbol )
let symbol = SlimvFindSymbol( a:word, a:exact, a:all, g:slimv_clhs_clhs, g:slimv_clhs_root, symbol )
let symbol = SlimvFindSymbol( a:word, a:exact, a:all, g:slimv_clhs_issues, g:slimv_clhs_root, symbol )
let symbol = SlimvFindSymbol( a:word, a:exact, a:all, g:slimv_clhs_chapters, g:slimv_clhs_root, symbol )
let symbol = SlimvFindSymbol( a:word, a:exact, a:all, g:slimv_clhs_control_chars, g:slimv_clhs_root, symbol )
let symbol = SlimvFindSymbol( a:word, a:exact, a:all, g:slimv_clhs_macro_chars, g:slimv_clhs_root, symbol )
let symbol = SlimvFindSymbol( a:word, a:exact, a:all, g:slimv_clhs_loop, g:slimv_clhs_root, symbol )
let symbol = SlimvFindSymbol( a:word, a:exact, a:all, g:slimv_clhs_arguments, g:slimv_clhs_root, symbol )
let symbol = SlimvFindSymbol( a:word, a:exact, a:all, g:slimv_clhs_glossary, g:slimv_clhs_root, symbol )
endif
if exists( 'g:slimv_clhs_user_db' )
" Give a choice for the user to extend the symbol database
" Give a choice for the user to extend the symbol database
if exists( 'g:slimv_clhs_user_root' )
let user_root = g:slimv_clhs_user_root
else
let user_root = ''
endif
let symbol = SlimvFindSymbol( a:word, a:exact, g:slimv_clhs_user_db, user_root, symbol )
let symbol = SlimvFindSymbol( a:word, a:exact, a:all, g:slimv_clhs_user_db, user_root, symbol )
endif
return symbol
endfunction
Expand Down
79 changes: 61 additions & 18 deletions ftplugin/slimv.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
" slimv.vim: The Superior Lisp Interaction Mode for VIM
" Version: 0.5.0
" Last Change: 18 Apr 2009
" Version: 0.5.1
" Last Change: 24 Apr 2009
" Maintainer: Tamas Kovacs <kovisoft at gmail dot com>
" License: This file is placed in the public domain.
" No warranty, express or implied.
Expand Down Expand Up @@ -1349,18 +1349,25 @@ endfunction

" ---------------------------------------------------------------------

" Find word in the CLHS symbol database, with exact or partial match
function! SlimvFindSymbol( word, exact, db, root, prev )
if a:prev[0] != ''
" Find word in the CLHS symbol database, with exact or partial match.
" Return either the first symbol found with the associated URL,
" or the list of all symbols found without the associated URL.
function! SlimvFindSymbol( word, exact, all, db, root, init )
if a:word == ''
return []
endif
if !a:all && a:init != []
" Found something already at a previous db lookup, no need to search this db
return a:prev
return a:init
endif
let lst = a:init
let i = 0
let w = tolower( a:word )
if a:exact
while i < len( a:db )
" Try to find an exact match
if a:db[i][0] == w
" No reason to check a:all here
return [a:db[i][0], a:root . a:db[i][1]]
endif
let i = i + 1
Expand All @@ -1370,42 +1377,48 @@ function! SlimvFindSymbol( word, exact, db, root, prev )
" Try to find the symbol starting with the given word
let w2 = escape( w, '~' )
if match( a:db[i][0], w2 ) == 0
return [a:db[i][0], a:root . a:db[i][1]]
if a:all
call add( lst, a:db[i][0] )
else
return [a:db[i][0], a:root . a:db[i][1]]
endif
endif
let i = i + 1
endwhile
endif

" Nothing found
return ['', '']
" Return whatever found so far
return lst
endfunction

" Lookup word in Common Lisp Hyperspec
function! SlimvLookup( word )
" First try an exact match
let w = a:word
let symbol = ['', '']
while symbol[0] == ''
let symbol = b:SlimvHyperspecLookup( w, 1 )
if symbol[0] == ''
let symbol = []
while symbol == []
let symbol = b:SlimvHyperspecLookup( w, 1, 0 )
if symbol == []
" Symbol not found, try a match on beginning of symbol name
let symbol = b:SlimvHyperspecLookup( w, 0 )
if symbol[0] == ''
let symbol = b:SlimvHyperspecLookup( w, 0, 0 )
if symbol == []
" We are out of luck, can't find anything
let msg = 'Symbol ' . w . ' not found. Hyperspec lookup word: '
let val = ''
else
let msg = 'Hyperspec lookup word: '
let val = symbol[0]
endif
" Ask user if this is that he/she meant
let w = input( msg, symbol[0] )
let w = input( msg, val )
if w == ''
" OK, user does not want to continue
return
endif
let symbol = ['', '']
let symbol = []
endif
endwhile
if symbol[0] != ''
if symbol != []
" Symbol found, open HS page in browser
if match( symbol[1], ':' ) < 0
let page = g:slimv_hs_root . symbol[1]
Expand All @@ -1430,6 +1443,35 @@ function! SlimvHyperspec()
call SlimvLookup( SlimvGetSelection() )
endfunction

" Complete function that uses the Hyperspec database
function! SlimvComplete( findstart, base )
if a:findstart
" Locate the start of the symbol name
let line = getline( '.' )
let start = col( '.' ) - 1
while start > 0 && ( line[start - 1] =~ '\a' || match( '\*&', line[start - 1] ) >= 0 )
let start -= 1
endwhile
return start
else
" Find all symbols starting with "a:base"
let res = []
let symbol = b:SlimvHyperspecLookup( a:base, 0, 1 )
call sort( symbol )
for m in symbol
if m =~ '^' . a:base
call add( res, m )
endif
endfor
return res
endif
endfunction

" Define complete function only if none is defined yet
if &omnifunc == ''
set omnifunc=SlimvComplete
endif

" =====================================================================
" Slimv keybindings
" =====================================================================
Expand Down Expand Up @@ -1568,6 +1610,7 @@ if g:slimv_menu == 1
amenu &Slimv.&Documentation.Describe-&Symbol :call SlimvDescribeSymbol()<CR>
amenu &Slimv.&Documentation.&Apropos :call SlimvApropos()<CR>
amenu &Slimv.&Documentation.&Hyperspec :call SlimvHyperspec()<CR>
imenu &Slimv.&Documentation.&Complete-Symbol <C-X><C-O>
amenu &Slimv.&Documentation.Generate-&Tags :call SlimvGenerateTags()<CR>

amenu &Slimv.&Repl.&Connect-Server :call SlimvConnectServer()<CR>
Expand Down

0 comments on commit 83693a8

Please sign in to comment.