Skip to content

Commit

Permalink
README improvements, miscellaneous other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Jul 27, 2010
1 parent 95ad683 commit ec4e1c3
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 23 deletions.
45 changes: 41 additions & 4 deletions README.md
Expand Up @@ -4,14 +4,51 @@ The Vim plug-in `luainspect.vim` uses the [LuaInspect](http://lua-users.org/wiki

## Installation

1. Download the latest [LuaInspect sources](http://github.com/davidm/lua-inspect/zipball/master) and unpack the contents of the `luainspectlib/` and `metalualib/` directories where Lua's `require()` function can find them.
1. Unzip the most recent [ZIP archive](http://peterodding.com/code/vim/downloads/lua-inspect) file inside your Vim profile directory (usually this is `~/.vim` on UNIX and `%USERPROFILE%\vimfiles` on Windows) and move or symlink the file `luainspect4vim.lua` somewhere where Lua's `require()` function can find it.

2. Save the Lua module [luainspect4vim.lua](http://github.com/xolox/vim-lua-inspect/raw/master/luainspect4vim.lua) somewhere where Lua's `require()` function can find it.
2. Download the latest [LuaInspect sources](http://github.com/davidm/lua-inspect/zipball/master) and unpack the contents of the `luainspectlib/` and `metalualib/` directories where Lua's `require()` function can find them.

3. Save the Vim plug-in [luainspect.vim](http://github.com/xolox/vim-lua-inspect/raw/master/luainspect.vim) in the directory `$HOME/.vim/plugin` (on UNIX) or `%USERPROFILE%\vimfiles\plugin` (on Windows).
3. Restart Vim and edit any Lua file. Within a few seconds semantic highlighting should be enabled automatically.

4. Restart Vim and edit any Lua file. Within a few seconds semantic highlighting should be enabled automatically.
## Usage

When you open any Lua file the semantic highlighting should be enabled automatically within a few seconds, so you don't have to configure anything if you're happy with the defaults.

### The `:LuaInspect` command

You shouldn't need to execute this command manually unless you've disabled automatic highlighting using the `g:lua_inspect_automatic` option. When you execute the `:LuaInspect` command the plug-in runs LuaInspect and then highlights all variables in the current buffer using one of the following highlighting groups:

* `luaInspectGlobalDefined`
* `luaInspectGlobalUndefined`
* `luaInspectLocalUnused`
* `luaInspectLocalMutated`
* `luaInspectUpValue`
* `luaInspectParam`
* `luaInspectLocal`
* `luaInspectFieldDefined`
* `luaInspectFieldUndefined`

### The `g:lua_inspect_automatic` option

By default semantic highlighting is automatically enabled after a short timeout. If you don't want this you can add the following to your [vimrc script](http://vimdoc.sourceforge.net/htmldoc/starting.html#vimrc):

:let g:lua_inspect_automatic = 0

### The `g:lua_inspect_internal` option

The plug-in can use the Lua interface for Vim so it doesn't have to run LuaInspect as an external program (which can slow things down). This feature isn't enabled by default though, because the Lua interface for Vim doesn't include most of `io.*` and `os.*` from Lua's standard library, and this causes LuaInspect to flag all references to those modules as undefined global variables! If you want to enable use of the Lua interface for Vim despite this, you can add the following to your [vimrc script](http://vimdoc.sourceforge.net/htmldoc/starting.html#vimrc):

:let g:lua_inspect_internal = 1

## Limitations

Right now the highlighting styles used by `luainspect.vim` are the same as those used by the SciTE plug-in and they don't work well on dark backgrounds. As soon as I get around to picking some alternate colors I'll include those in the plug-in.

## Contact

If you have questions, bug reports, suggestions, etc. the author can be contacted at <peter@peterodding.com>. The latest version is available at <http://peterodding.com/code/vim/lua-inspect/> and <http://github.com/xolox/vim-lua-inspect>. If you like this plug-in please vote for it on [www.vim.org](http://www.vim.org/scripts/script.php?script_id=3169).

## License

This software is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License).
© 2010 Peter Odding &lt;<peter@peterodding.com>&gt;.
26 changes: 13 additions & 13 deletions luainspect.vim
Expand Up @@ -2,7 +2,7 @@
" Author: Peter Odding <peter@peterodding.com>
" Last Change: July 27, 2010
" URL: http://peterodding.com/code/vim/lua-inspect/
" Version: 0.1
" Version: 0.1.2

" Configuration defaults. {{{1

Expand Down Expand Up @@ -64,25 +64,25 @@ endfunction

function! s:InitHighlighting()
" Clear existing highlighting.
if hlexists('luaInspectDefinedGlobal') | syntax clear luaInspectDefinedGlobal | endif
if hlexists('luaInspectUndefinedGlobal') | syntax clear luaInspectUndefinedGlobal | endif
if hlexists('luaInspectUnusedLocal') | syntax clear luaInspectUnusedLocal | endif
if hlexists('luaInspectMutatedLocal') | syntax clear luaInspectMutatedLocal | endif
if hlexists('luaInspectGlobalDefined') | syntax clear luaInspectGlobalDefined | endif
if hlexists('luaInspectGlobalUndefined') | syntax clear luaInspectGlobalUndefined | endif
if hlexists('luaInspectLocalUnused') | syntax clear luaInspectLocalUnused | endif
if hlexists('luaInspectLocalMutated') | syntax clear luaInspectLocalMutated | endif
if hlexists('luaInspectUpValue') | syntax clear luaInspectUpValue | endif
if hlexists('luaInspectParam') | syntax clear luaInspectParam | endif
if hlexists('luaInspectLocal') | syntax clear luaInspectLocal | endif
if hlexists('luaInspectDefinedField') | syntax clear luaInspectDefinedField | endif
if hlexists('luaInspectUndefinedField') | syntax clear luaInspectUndefinedField | endif
if hlexists('luaInspectFieldDefined') | syntax clear luaInspectFieldDefined | endif
if hlexists('luaInspectFieldUndefined') | syntax clear luaInspectFieldUndefined | endif
" Define default styles (copied from /luainspect/scite.lua for consistency).
hi luaInspectDefinedGlobal guifg=#600000
hi def link luaInspectUndefinedGlobal WarningMsg
hi luaInspectUnusedLocal guifg=#ffffff guibg=#0000ff
hi luaInspectMutatedLocal gui=italic guifg=#000080
hi luaInspectGlobalDefined guifg=#600000
hi def link luaInspectGlobalUndefined WarningMsg
hi luaInspectLocalUnused guifg=#ffffff guibg=#0000ff
hi luaInspectLocalMutated gui=italic guifg=#000080
hi luaInspectUpValue guifg=#0000ff
hi luaInspectParam guifg=#000040
hi luaInspectLocal guifg=#000080
hi luaInspectDefinedField guifg=#600000
hi luaInspectUndefinedField guifg=#c00000
hi luaInspectFieldDefined guifg=#600000
hi luaInspectFieldUndefined guifg=#c00000
" TODO Consider the &background?
endfunction

Expand Down
22 changes: 16 additions & 6 deletions luainspect4vim.lua
@@ -1,3 +1,13 @@
--[[
This module is part of the luainspect.vim plug-in for the Vim text editor.
Author: Peter Odding <peter@peterodding.com>
Last Change: July 27, 2010
URL: http://peterodding.com/code/vim/lua-inspect/
--]]
local function offset2lineinfo(text, offset)
-- TODO Cache intermediate results because they won't change within a single
-- call to the function returned from this module below.
Expand Down Expand Up @@ -37,15 +47,15 @@ return function(text)
for i, note in ipairs(LI.inspect(ast)) do
if note.type == 'global' then
if note.definedglobal then
dumpvar('luaInspectDefinedGlobal', note[1], note[2])
dumpvar('luaInspectGlobalDefined', note[1], note[2])
else
dumpvar('luaInspectUndefinedGlobal', note[1], note[2])
dumpvar('luaInspectGlobalUndefined', note[1], note[2])
end
elseif note.type == 'local' then
if not note.ast.localdefinition.isused then
dumpvar('luaInspectUnusedLocal', note[1], note[2])
dumpvar('luaInspectLocalUnused', note[1], note[2])
elseif note.ast.localdefinition.isset then
dumpvar('luaInspectMutatedLocal', note[1], note[2])
dumpvar('luaInspectLocalMutated', note[1], note[2])
elseif note.ast.localdefinition.functionlevel < note.ast.functionlevel then
dumpvar('luaInspectUpValue', note[1], note[2])
elseif note.ast.localdefinition.isparam then
Expand All @@ -55,9 +65,9 @@ return function(text)
end
elseif note.type == 'field' then
if note.definedglobal or note.ast.seevalue.value ~= nil then
dumpvar('luaInspectDefinedField', note[1], note[2])
dumpvar('luaInspectFieldDefined', note[1], note[2])
else
dumpvar('luaInspectUndefinedField', note[1], note[2])
dumpvar('luaInspectFieldUndefined', note[1], note[2])
end
end
end
Expand Down

0 comments on commit ec4e1c3

Please sign in to comment.