From 4b5b8858248f86093c4dbcac01dc516c1f536965 Mon Sep 17 00:00:00 2001 From: dail8859 Date: Wed, 2 Nov 2016 16:05:15 -0400 Subject: [PATCH] Add all the files --- .gitmodules | 3 + README.md | 14 ++++- love-api | 1 + love-api-npp.lua | 154 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 .gitmodules create mode 160000 love-api create mode 100644 love-api-npp.lua diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..fe06dfc --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "love-api"] + path = love-api + url = https://github.com/love2d-community/love-api.git diff --git a/README.md b/README.md index 7becd4d..92dbb3f 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/love-api b/love-api new file mode 160000 index 0000000..96ff322 --- /dev/null +++ b/love-api @@ -0,0 +1 @@ +Subproject commit 96ff322f65ce2a1a29304ca9d94ae79a4dabe65f diff --git a/love-api-npp.lua b/love-api-npp.lua new file mode 100644 index 0000000..60d7c00 --- /dev/null +++ b/love-api-npp.lua @@ -0,0 +1,154 @@ +--[[ + This file is part of love-api-npp. + + Copyright (C)2016 Justin Dailey + + 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, "&", "&") + s = string.gsub(s, "<", "<") + s = string.gsub(s, ">", ">") + s = string.gsub(s, "'", "'") + s = string.gsub(s, '"', """) + return s +end + +local keywords = {} + +local function add_keyword(kw) + keywords[#keywords + 1] = {name = kw, text = "\t\t"} +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\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\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\n" + end + end + xml = xml .. "\t\t\t\n" + end + + xml = xml .. "\t\t" + + 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("") +print("") +print("\t") +print("\t") +print("\t\t") + +table.sort(keywords, function(a, b) return a.name < b.name end) +for _, keyword in ipairs(keywords) do + print(keyword.text) +end + +print("\t") +print("")