Skip to content

Commit

Permalink
Add all the files
Browse files Browse the repository at this point in the history
  • Loading branch information
dail8859 committed Nov 2, 2016
1 parent e5ac2a6 commit 4b5b885
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "love-api"]
path = love-api
url = https://github.com/love2d-community/love-api.git
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
# love-api-npp
LÖVE API autocomplete file for Notepad++

[![LOVE](https://img.shields.io/badge/L%C3%96VE-0.10.2-EA316E.svg)](http://love2d.org/)

[LÖVE](https://love2d.org/) API autocomplete file for Notepad++.

## Usage

1. Download the lua_love.xml from the [Release](https://github.com/dail8859/love-api-npp/releases) tab, and place it in Notepad++'s `plugins/APIs/` directory.
1. In Notepad++, go to `Settings > Preferences` in the menu.
1. Select the `Auto-Completion` tab.
1. Make sure `Enable auto-completion on each input` is checked.
1. Set it to `Function completion`.
1. And check `Function parameters hint on input`.
1 change: 1 addition & 0 deletions love-api
Submodule love-api added at 96ff32
154 changes: 154 additions & 0 deletions love-api-npp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
--[[
This file is part of love-api-npp.
Copyright (C)2016 Justin Dailey <[email protected]>
love-api-npp is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
--]]

local love = require("love-api.love_api")

local function reflow(str, limit)
local function wrap(str, limit)
local ws = string.match(str, "^(%s+)") or " "
local indent = ws .. " "
limit = limit or 100
local here = 1
return str:gsub("(%s+)()(%S+)()",
function(sp, st, word, fi)
if fi-here > limit then
here = st - #indent
return "\n" .. indent .. word
end
end)
end
return (str:gsub("[^\n]+",
function(line)
return wrap(line, limit)
end))
end

local function escape(s)
s = string.gsub(s, "&", "&amp;")
s = string.gsub(s, "<", "&lt;")
s = string.gsub(s, ">", "&gt;")
s = string.gsub(s, "'", "&apos;")
s = string.gsub(s, '"', "&quot;")
return s
end

local keywords = {}

local function add_keyword(kw)
keywords[#keywords + 1] = {name = kw, text = "\t\t<KeyWord name=\"" .. kw .. "\" />"}
end

local function format_table(t, name)
local indent = " "
local keys = {}
for _, key in ipairs(t) do
keys[#keys + 1] = indent .. indent .. "- " .. name .. "." .. key.name .. " " .. key.type .. ": " .. key.description
end
return table.concat(keys, "\n")
end

local function format_type(t)
local indent = " * "
local s

if t.description then
s = indent .. t.type .. " " .. t.name .. ": " .. t.description
else
s = indent .. t.type .. " " .. t.name
end

if t.type == "table" and t.table then
s = s .. "\n" .. format_table(t.table, t.name)
end
return s
end

function parse_function(func, prefix)
local xml = ""
xml = xml .. "\t\t<KeyWord name=\"" .. prefix .. func.name .. "\" func=\"yes\">\n"
for _, variant in ipairs(func.variants) do
local desc = variant.description or func.description

local args = {}
if variant.arguments then
for _, argument in ipairs(variant.arguments) do
args[#args + 1] = format_type(argument)
end
desc = desc .. "\n\nParameters:\n" .. table.concat(args, "\n")
end

args = {}
if variant.returns then
for _, ret in ipairs(variant.returns) do
args[#args + 1] = format_type(ret)
end
desc = desc .. "\n\nReturns:\n" .. table.concat(args, "\n")
end
xml = xml .. "\t\t\t<Overload retVal=\"\" descr=\"\n" .. reflow(escape(desc)) .. "\">\n"

args = {}
if variant.arguments then
for _, argument in ipairs(variant.arguments) do
local s = argument.type .. " " .. argument.name
if argument.default then
s = s .. " = " .. argument.default
end
xml = xml .. "\t\t\t\t<Param name=\"" .. escape(s) .. "\" />\n"
end
end
xml = xml .. "\t\t\t</Overload>\n"
end

xml = xml .. "\t\t</KeyWord>"

keywords[#keywords + 1] = {name = prefix .. func.name, text = xml}
end


add_keyword("love")
for _, func in ipairs(love.functions) do
parse_function(func, "love.")
end
for _, mod in ipairs(love.modules) do
add_keyword("love." .. mod.name)
for _, func in ipairs(mod.functions) do
parse_function(func, "love." .. mod.name .. ".")
end
end

for _, cb in ipairs(love.callbacks) do
parse_function(cb, "love.")
end


-- Now do it
print("<?xml version=\"1.0\" encoding=\"Windows-1252\" ?>")
print("<NotepadPlus>")
print("\t<!-- Love API v" .. love.version .. " -->")
print("\t<AutoComplete language=\"Lua\">")
print("\t\t<Environment ignoreCase=\"yes\" startFunc=\"(\" stopFunc=\")\" paramSeparator=\",\" terminal=\";\" additionalWordChar=\".\" />")

table.sort(keywords, function(a, b) return a.name < b.name end)
for _, keyword in ipairs(keywords) do
print(keyword.text)
end

print("\t</AutoComplete>")
print("</NotepadPlus>")

0 comments on commit 4b5b885

Please sign in to comment.