Commits

Tamas Kovacs committed 83693a8

Version 0.5.1: Added symbol name completion based on the Hyperspec database.

Comments (0)

Files changed (4)

-*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
 |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
 
     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:
 >
 
 
 ===============================================================================
+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*
 
 This section is about utilities, settings, etc., not related strongly to Slimv,
     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.
 ===============================================================================
 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.
 ===============================================================================
 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.

ftplugin/clojure/slimv-clojure.vim

 " 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.
 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
         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

ftplugin/lisp/slimv-lisp.vim

 " 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.
 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
 " 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.
 
 " ---------------------------------------------------------------------
 
-" 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
             " 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]
     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
 " =====================================================================
     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>