Skip to content

Commit

Permalink
Support for Lua 5.2 (updated to latest version of LuaInspect)
Browse files Browse the repository at this point in the history
Requested in issue #2 on GitHub:
  #2
  • Loading branch information
xolox committed Jul 18, 2013
1 parent 77f9da1 commit 0bf9775
Show file tree
Hide file tree
Showing 37 changed files with 3,277 additions and 1,938 deletions.
1 change: 1 addition & 0 deletions addon-info.json
@@ -0,0 +1 @@
{"vim_script_nr": 3169, "dependencies": {"vim-misc": {}}, "homepage": "http://peterodding.com/code/vim/lua-inspect", "name": "vim-lua-inspect"}
16 changes: 12 additions & 4 deletions autoload/xolox/luainspect.vim
@@ -1,9 +1,9 @@
" Vim script.
" Author: Peter Odding <peter@peterodding.com>
" Last Change: May 27, 2013
" Last Change: July 18, 2013
" URL: http://peterodding.com/code/vim/lua-inspect/

let g:xolox#luainspect#version = '0.4.27'
let g:xolox#luainspect#version = '0.5'

function! xolox#luainspect#toggle_cmd() " {{{1
if !(exists('b:luainspect_disabled') && b:luainspect_disabled)
Expand Down Expand Up @@ -126,8 +126,16 @@ endfunction
function! s:prepare_search_path() " {{{1
let code = ''
if !(has('lua') && g:lua_inspect_internal && exists('s:changed_path'))
let template = 'package.path = ''%s/?.lua;'' .. package.path'
let code = printf(template, escape(expand(g:lua_inspect_path), '"\'''))
let root = xolox#misc#path#absolute(g:lua_inspect_path)
let directories = [root]
call add(directories, xolox#misc#path#merge(root, 'metalualib'))
call add(directories, xolox#misc#path#merge(root, 'luainspect'))
let template = "package.path = package.path .. ';%s/?.lua'"
let lines = []
for directory in directories
call add(lines, printf(template, escape(directory, '"\''')))
endfor
let code = join(lines, '; ')
if has('lua') && g:lua_inspect_internal
execute 'lua' code
let s:changed_path = 1
Expand Down
174 changes: 82 additions & 92 deletions doc/luainspect.txt
@@ -1,23 +1,23 @@
*luainspect.txt* Semantic highlighting for Lua in Vim

===============================================================================
*luainspect-contents*
Contents ~

1. Introduction |luainspect-introduction|
2. Installation |luainspect-installation|
3. Usage |luainspect-usage|
1. Introduction |luainspect-introduction|
2. Installation |luainspect-installation|
3. Usage |luainspect-usage|
1. The |:LuaInspect| command
2. The |:LuaInspectToggle| command
3. The |g:loaded_luainspect| option
4. The |g:lua_inspect_warnings| option
5. The |g:lua_inspect_events| option
6. The |g:lua_inspect_internal| option
4. Contact |luainspect-contact|
5. License |luainspect-license|
4. Contact |luainspect-contact|
5. License |luainspect-license|
6. References |luainspect-references|

===============================================================================
*luainspect-introduction*
*luainspect-introduction*
Introduction ~

The Vim plug-in 'luainspect.vim' uses the LuaInspect [1] tool to
Expand All @@ -26,38 +26,39 @@ It was inspired by lua2-mode [2] (for Emacs [3]) and the SciTE [4] plug-in
included with LuaInspect. In addition to the semantic highlighting the
following features are currently supported:

- Press '<F2>' with the text cursor on a variable and the plug-in will prompt
you to rename the variable.
- Press '<F2>' with the text cursor on a variable and the plug-in will prompt
you to rename the variable.

- Press 'gd' (in normal mode) with the text cursor on a variable and you'll
jump to its declaration / first occurrence.
- Press 'gd' (in normal mode) with the text cursor on a variable and you'll
jump to its declaration / first occurrence.

- When you hover over a variable with the mouse cursor in graphical Vim,
information about the variable is displayed in a tooltip.
- When you hover over a variable with the mouse cursor in graphical Vim,
information about the variable is displayed in a tooltip.

- If the text cursor is on a variable while the highlighting is refreshed then
all occurrences of the variable will be marked in the style of Vim's
cursorline option (see |'cursorline'|).
- If the text cursor is on a variable while the highlighting is refreshed
then all occurrences of the variable will be marked in the style of Vim's
cursorline option (see |'cursorline'|).

- When luainspect reports a wrong argument count for a function call the text
will be highlighted with a green underline. When you hover over the
highlighted text a tooltip shows the associated warning message.
- When luainspect reports a wrong argument count for a function call the text
will be highlighted with a green underline. When you hover over the
highlighted text a tooltip shows the associated warning message.

- When LuaInspect reports warnings about unused variables, wrong argument
counts, etc. they are shown in a location list window (see |location-list|).
- When LuaInspect reports warnings about unused variables, wrong argument
counts, etc. they are shown in a location list window (see |location-
list|).

- When a syntax error is found (during highlighting or using the rename
functionality) the lines where the error is reported will be marked like a
spelling error.
- When a syntax error is found (during highlighting or using the rename
functionality) the lines where the error is reported will be marked like a
spelling error.

Screenshot of semantic highlighting, see reference [5]
Image: Screenshot of semantic highlighting (see reference [5])

===============================================================================
*luainspect-installation*
*luainspect-installation*
Installation ~

Please note that the vim-lua-inspect plug-in requires my vim-misc plug-in
which is separately distributed.
_Please note that the vim-lua-inspect plug-in requires my vim-misc plug-in
which is separately distributed._

Unzip the most recent ZIP archives of the vim-lua-inspect [6] and vim-misc [7]
plug-ins inside your Vim profile directory (usually this is '~/.vim' on UNIX
Expand All @@ -71,13 +72,13 @@ local clone of the git repository.
Now try it out: Edit a Lua file and within a few seconds semantic highlighting
should be enabled automatically!

Note that on Windows a command prompt window pops up whenever LuaInspect is
run as an external process. If this bothers you then you can install my
shell.vim [12] plug-in which includes a DLL [13] that works around this issue.
Once you've installed both plug-ins it should work out of the box!
Note that on Windows a command prompt window pops up whenever LuaInspect is run
as an external process. If this bothers you then you can install my shell.vim
[12] plug-in which includes a DLL [13] that works around this issue. Once
you've installed both plug-ins it should work out of the box!

===============================================================================
*luainspect-usage*
*luainspect-usage*
Usage ~

When you open any Lua file the semantic highlighting should be enabled
Expand All @@ -92,29 +93,18 @@ highlighting using |g:lua_inspect_events|. When you execute this command the
plug-in runs the LuaInspect tool 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

- luaInspectSelectedVariable

- luaInspectWrongArgCount

- luaInspectSyntaxError
- luaInspectGlobalDefined
- luaInspectGlobalUndefined
- luaInspectLocalUnused
- luaInspectLocalMutated
- luaInspectUpValue
- luaInspectParam
- luaInspectLocal
- luaInspectFieldDefined
- luaInspectFieldUndefined
- luaInspectSelectedVariable
- luaInspectWrongArgCount
- luaInspectSyntaxError

If you don't like one or more of the default styles the Vim documentation
describes how to change them (see |:hi-default|). If you want to disable the
Expand All @@ -127,52 +117,52 @@ The *:LuaInspectToggle* command

By default the semantic highlighting and the warning messages in the location
list window are automatically applied to Lua buffers and updated every once in
a while, but this can be disabled by setting |g:lua_inspect_events| to an
empty string in your |vimrc| script. If the plug-in is not automatically enabled
then it may be useful to enable/disable it using a key mapping. That's what
the |:LuaInspectToggle| command is for. You still have to define your key
mapping of choice in your |vimrc| script though. For example:
a while, but this can be disabled by setting |g:lua_inspect_events| to an empty
string in your |vimrc| script. If the plug-in is not automatically enabled then
it may be useful to enable/disable it using a key mapping. That's what the
|:LuaInspectToggle| command is for. You still have to define your key mapping
of choice in your |vimrc| script though. For example:
>
" Don't enable the lua-inspect plug-in automatically in Lua buffers.
let g:lua_inspect_events = ''
" Enable/disable the lua-inspect plug-in manually using <F6>.
imap <F6> <C-o>:LuaInspectToggle<CR>
nmap <F6> :LuaInspectToggle<CR>
" Don't enable the lua-inspect plug-in automatically in Lua buffers.
let g:lua_inspect_events = ''
" Enable/disable the lua-inspect plug-in manually using <F6>.
imap <F6> <C-o>:LuaInspectToggle<CR>
nmap <F6> :LuaInspectToggle<CR>
<
-------------------------------------------------------------------------------
The *g:loaded_luainspect* option

This variable isn't really an option but if you want to avoid loading the
'luainspect.vim' plug-in you can set this variable to any value in your |vimrc|
script:
>
:let g:loaded_luainspect = 1
:let g:loaded_luainspect = 1
<
-------------------------------------------------------------------------------
The *g:lua_inspect_warnings* option

When LuaInspect reports warnings about unused variables, wrong argument
counts, etc. they are automatically shown in a location list window (see
|location-list|). If you don't like this add the following to your |vimrc| script:
When LuaInspect reports warnings about unused variables, wrong argument counts,
etc. they are automatically shown in a location list window (see |location-
list|). If you don't like this add the following to your |vimrc| script:
>
:let g:lua_inspect_warnings = 0
:let g:lua_inspect_warnings = 0
<
-------------------------------------------------------------------------------
The *g:lua_inspect_events* option

By default semantic highlighting is automatically enabled after a short
timeout and when you save a buffer. If you want to disable automatic
highlighting altogether add the following to your |vimrc| script:
By default semantic highlighting is automatically enabled after a short timeout
and when you save a buffer. If you want to disable automatic highlighting
altogether add the following to your |vimrc| script:
>
:let g:lua_inspect_events = ''
:let g:lua_inspect_events = ''
<
You can also add events, for example if you also want to run |:LuaInspect| the
moment you edit a Lua file then try this:
>
:let g:lua_inspect_events = 'CursorHold,CursorHoldI,BufReadPost,BufWritePost'
Note that this only works when the plug-in is loaded (or reloaded) after
:let g:lua_inspect_events = 'CursorHold,CursorHoldI,BufReadPost,BufWritePost'
<
Note that this only works when the plug-in is loaded (or reloaded) _after_
setting the |g:lua_inspect_events| option.

-------------------------------------------------------------------------------
Expand All @@ -183,26 +173,26 @@ have to run LuaInspect as an external program (which can slow things down). If
you insist on running LuaInspect as an external program you can set this
variable to false (0) in your |vimrc| script:
>
:let g:lua_inspect_internal = 0
:let g:lua_inspect_internal = 0
<
===============================================================================
*luainspect-contact*
*luainspect-contact*
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 Vim Online [14].
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 Vim Online [14].

===============================================================================
*luainspect-license*
*luainspect-license*
License ~

This software is licensed under the MIT license [15]. Copyright 2013 Peter
Odding <peter@peterodding.com>.
This software is licensed under the MIT license [15]. © 2013 Peter Odding
<peter@peterodding.com>.

===============================================================================
*luainspect-references*
*luainspect-references*
References ~

[1] http://lua-users.org/wiki/LuaInspect
Expand Down

0 comments on commit 0bf9775

Please sign in to comment.