git: a4aac455499f - main - editors/lite: text editor written mostly in Lua (new port added)

From: Alexey Dokuchaev <danfe_at_FreeBSD.org>
Date: Wed, 06 Jul 2022 17:36:38 UTC
The branch main has been updated by danfe:

URL: https://cgit.FreeBSD.org/ports/commit/?id=a4aac455499f337ffbc145f7abe2a58fce71cb4c

commit a4aac455499f337ffbc145f7abe2a58fce71cb4c
Author:     Alexey Dokuchaev <danfe@FreeBSD.org>
AuthorDate: 2022-07-06 17:35:14 +0000
Commit:     Alexey Dokuchaev <danfe@FreeBSD.org>
CommitDate: 2022-07-06 17:35:14 +0000

    editors/lite: text editor written mostly in Lua (new port added)
    
    It aims to provide something practical, pretty, small, and fast,
    implemented as simply as possible; easy to modify and extend via
    plugins, or to use without doing either.
    
    WWW: https://github.com/rxi/lite
---
 editors/Makefile                                   |  1 +
 editors/lite/Makefile                              | 46 ++++++++++++++++++++
 editors/lite/distinfo                              |  3 ++
 editors/lite/files/makefile                        | 25 +++++++++++
 .../lite/files/patch-data_core_commands_core.lua   | 11 +++++
 editors/lite/files/patch-data_core_init.lua        | 49 ++++++++++++++++++++++
 editors/lite/files/patch-data_core_style.lua       | 17 ++++++++
 editors/lite/files/patch-src_main.c                | 34 +++++++++++++++
 editors/lite/pkg-descr                             |  6 +++
 editors/lite/pkg-plist                             | 48 +++++++++++++++++++++
 10 files changed, 240 insertions(+)

diff --git a/editors/Makefile b/editors/Makefile
index 283e9163216c..7d6e629ecb85 100644
--- a/editors/Makefile
+++ b/editors/Makefile
@@ -193,6 +193,7 @@
     SUBDIR += linux-sublime-text4
     SUBDIR += linux-sublime3
     SUBDIR += linux-wps-office
+    SUBDIR += lite
     SUBDIR += madedit
     SUBDIR += marker
     SUBDIR += mg
diff --git a/editors/lite/Makefile b/editors/lite/Makefile
new file mode 100644
index 000000000000..b5fe9d81aa3d
--- /dev/null
+++ b/editors/lite/Makefile
@@ -0,0 +1,46 @@
+# Created by: Alexey Dokuchaev <danfe@FreeBSD.org>
+
+PORTNAME=	lite
+PORTVERSION=	1.11
+CATEGORIES=	editors
+PKGNAMESUFFIX=	-editor		# PORTNAME alone is too vague
+
+MAINTAINER=	danfe@FreeBSD.org
+COMMENT=	Lightweight text editor written mostly in Lua
+
+LICENSE=	MIT
+
+USES=		gmake lua pkgconfig sdl
+USE_SDL=	sdl2
+
+USE_GITHUB=	yes
+GH_ACCOUNT=	rxi
+GH_TAGNAME=	38bd9b3
+
+BUILD_WRKSRC=	${WRKSRC}/src
+MAKEFILE=	${FILESDIR}/makefile
+
+PORTDOCS=	usage.md
+
+OPTIONS_DEFINE=	DOCS
+
+post-extract:
+# Prevent accidental build/use of bundled code/headers
+	@${RM} -r ${BUILD_WRKSRC}/lib/lua52 ${WRKSRC}/winlib
+
+post-patch:
+	@${REINPLACE_CMD} -e '/^#include/s,lib/lua52/,,' \
+		${BUILD_WRKSRC}/api/api.h
+	@${REINPLACE_CMD} -e 's,%%DATADIR%%,${DATADIR},' \
+		${BUILD_WRKSRC}/main.c
+
+do-install:
+	${INSTALL_PROGRAM} ${BUILD_WRKSRC}/${PORTNAME} \
+		${STAGEDIR}${PREFIX}/bin
+	${CP} -a ${WRKSRC}/data ${STAGEDIR}${DATADIR}
+
+do-install-DOCS-on:
+	@${MKDIR} ${STAGEDIR}${DOCSDIR}
+	${INSTALL_DATA} ${WRKSRC}/doc/* ${STAGEDIR}${DOCSDIR}
+
+.include <bsd.port.mk>
diff --git a/editors/lite/distinfo b/editors/lite/distinfo
new file mode 100644
index 000000000000..f7e67df7767a
--- /dev/null
+++ b/editors/lite/distinfo
@@ -0,0 +1,3 @@
+TIMESTAMP = 1610208177
+SHA256 (rxi-lite-1.11-38bd9b3_GH0.tar.gz) = 63b0f22eb90f38564736f56d4d0f51f7219fcb7fe6398018e3435a62badd10d9
+SIZE (rxi-lite-1.11-38bd9b3_GH0.tar.gz) = 10707650
diff --git a/editors/lite/files/makefile b/editors/lite/files/makefile
new file mode 100644
index 000000000000..5274d363e360
--- /dev/null
+++ b/editors/lite/files/makefile
@@ -0,0 +1,25 @@
+CFLAGS+=	-Wall -Wextra
+CPPFLAGS+=	-DLUA_USE_POSIX -I. \
+		$(shell pkg-config --cflags lua-$(LUA_VER) sdl2)
+LIBS=		$(shell pkg-config --libs lua-$(LUA_VER) sdl2)
+
+lite_OBJS=	api/api.o \
+		api/renderer.o \
+		api/renderer_font.o \
+		api/system.o \
+		lib/stb/stb_truetype.o \
+		main.o \
+		rencache.o \
+		renderer.o
+
+CCACHE?=	$(shell command -v ccache)
+
+%.o: %.c
+	$(CCACHE) $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<
+
+lite: $(lite_OBJS)
+	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
+
+all: lite
+
+.PHONY: all install
diff --git a/editors/lite/files/patch-data_core_commands_core.lua b/editors/lite/files/patch-data_core_commands_core.lua
new file mode 100644
index 000000000000..5be8d1f4ead5
--- /dev/null
+++ b/editors/lite/files/patch-data_core_commands_core.lua
@@ -0,0 +1,11 @@
+--- data/core/commands/core.lua.orig	2021-01-09 16:02:57 UTC
++++ data/core/commands/core.lua
+@@ -85,7 +85,7 @@ command.add(nil, {
+   end,
+ 
+   ["core:open-user-module"] = function()
+-    core.root_view:open_doc(core.open_doc(EXEDIR .. "/data/user/init.lua"))
++    core.root_view:open_doc(core.open_doc(DATADIR .. "/user/init.lua"))
+   end,
+ 
+   ["core:open-project-module"] = function()
diff --git a/editors/lite/files/patch-data_core_init.lua b/editors/lite/files/patch-data_core_init.lua
new file mode 100644
index 000000000000..7d13910080af
--- /dev/null
+++ b/editors/lite/files/patch-data_core_init.lua
@@ -0,0 +1,49 @@
+--- data/core/init.lua.orig	2021-01-09 16:02:57 UTC
++++ data/core/init.lua
+@@ -82,7 +82,7 @@ function core.init()
+   CommandView = require "core.commandview"
+   Doc = require "core.doc"
+ 
+-  local project_dir = EXEDIR
++  local project_dir = os.getenv("HOME") or EXEDIR
+   local files = {}
+   for i = 2, #ARGS do
+     local info = system.get_file_info(ARGS[i]) or {}
+@@ -131,16 +131,16 @@ local function delete_temp_files()
+ local temp_file_counter = 0
+ 
+ local function delete_temp_files()
+-  for _, filename in ipairs(system.list_dir(EXEDIR)) do
++  for _, filename in ipairs(system.list_dir("/tmp")) do
+     if filename:find(temp_file_prefix, 1, true) == 1 then
+-      os.remove(EXEDIR .. PATHSEP .. filename)
++      os.remove("/tmp" .. PATHSEP .. filename)
+     end
+   end
+ end
+ 
+ function core.temp_filename(ext)
+   temp_file_counter = temp_file_counter + 1
+-  return EXEDIR .. PATHSEP .. temp_file_prefix
++  return "/tmp" .. PATHSEP .. temp_file_prefix
+       .. string.format("%06x", temp_file_counter) .. (ext or "")
+ end
+ 
+@@ -174,7 +174,7 @@ function core.load_plugins()
+ 
+ function core.load_plugins()
+   local no_errors = true
+-  local files = system.list_dir(EXEDIR .. "/data/plugins")
++  local files = system.list_dir(DATADIR .. "/plugins")
+   for _, filename in ipairs(files) do
+     local modname = "plugins." .. filename:gsub(".lua$", "")
+     local ok = core.try(require, modname)
+@@ -464,7 +464,7 @@ function core.on_error(err)
+ 
+ function core.on_error(err)
+   -- write error to file
+-  local fp = io.open(EXEDIR .. "/error.txt", "wb")
++  local fp = io.open("/tmp/lite-error.txt", "wb")
+   fp:write("Error: " .. tostring(err) .. "\n")
+   fp:write(debug.traceback(nil, 4))
+   fp:close()
diff --git a/editors/lite/files/patch-data_core_style.lua b/editors/lite/files/patch-data_core_style.lua
new file mode 100644
index 000000000000..5107bf8479ef
--- /dev/null
+++ b/editors/lite/files/patch-data_core_style.lua
@@ -0,0 +1,17 @@
+--- data/core/style.lua.orig	2021-01-09 16:02:57 UTC
++++ data/core/style.lua
+@@ -7,10 +7,10 @@ style.tab_width = common.round(170 * SCALE)
+ style.caret_width = common.round(2 * SCALE)
+ style.tab_width = common.round(170 * SCALE)
+ 
+-style.font = renderer.font.load(EXEDIR .. "/data/fonts/font.ttf", 14 * SCALE)
+-style.big_font = renderer.font.load(EXEDIR .. "/data/fonts/font.ttf", 34 * SCALE)
+-style.icon_font = renderer.font.load(EXEDIR .. "/data/fonts/icons.ttf", 14 * SCALE)
+-style.code_font = renderer.font.load(EXEDIR .. "/data/fonts/monospace.ttf", 13.5 * SCALE)
++style.font = renderer.font.load(DATADIR .. "/fonts/font.ttf", 14 * SCALE)
++style.big_font = renderer.font.load(DATADIR .. "/fonts/font.ttf", 34 * SCALE)
++style.icon_font = renderer.font.load(DATADIR .. "/fonts/icons.ttf", 14 * SCALE)
++style.code_font = renderer.font.load(DATADIR .. "/fonts/monospace.ttf", 13.5 * SCALE)
+ 
+ style.background = { common.color "#2e2e32" }
+ style.background2 = { common.color "#252529" }
diff --git a/editors/lite/files/patch-src_main.c b/editors/lite/files/patch-src_main.c
new file mode 100644
index 000000000000..1041196a88a6
--- /dev/null
+++ b/editors/lite/files/patch-src_main.c
@@ -0,0 +1,34 @@
+--- src/main.c.orig	2021-01-09 16:02:57 UTC
++++ src/main.c
+@@ -9,6 +9,8 @@
+   #include <unistd.h>
+ #elif __APPLE__
+   #include <mach-o/dyld.h>
++#elif __FreeBSD__
++  #include <sys/sysctl.h>
+ #endif
+ 
+ 
+@@ -38,6 +40,10 @@ static void get_exe_filename(char *buf, int sz) {
+ #elif __APPLE__
+   unsigned size = sz;
+   _NSGetExecutablePath(buf, &size);
++#elif __FreeBSD__
++  size_t len = sz;
++  const int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
++  sysctl(mib, 4, buf, &len, NULL, 0);
+ #else
+   strcpy(buf, "./lite");
+ #endif
+@@ -123,8 +129,9 @@ int main(int argc, char **argv) {
+     "  SCALE = tonumber(os.getenv(\"LITE_SCALE\")) or SCALE\n"
+     "  PATHSEP = package.config:sub(1, 1)\n"
+     "  EXEDIR = EXEFILE:match(\"^(.+)[/\\\\].*$\")\n"
+-    "  package.path = EXEDIR .. '/data/?.lua;' .. package.path\n"
+-    "  package.path = EXEDIR .. '/data/?/init.lua;' .. package.path\n"
++    "  DATADIR = '%%DATADIR%%'\n"
++    "  package.path = DATADIR .. '/?.lua;' .. package.path\n"
++    "  package.path = DATADIR .. '/?/init.lua;' .. package.path\n"
+     "  core = require('core')\n"
+     "  core.init()\n"
+     "  core.run()\n"
diff --git a/editors/lite/pkg-descr b/editors/lite/pkg-descr
new file mode 100644
index 000000000000..7f5c781f0471
--- /dev/null
+++ b/editors/lite/pkg-descr
@@ -0,0 +1,6 @@
+lite is a lightweight text editor written mostly in Lua.  It aims to
+provide something practical, pretty, small, and fast, implemented as
+simply as possible; easy to modify and extend via plugins, or to use
+without doing either.
+
+WWW: https://github.com/rxi/lite
diff --git a/editors/lite/pkg-plist b/editors/lite/pkg-plist
new file mode 100644
index 000000000000..e3028f0a1938
--- /dev/null
+++ b/editors/lite/pkg-plist
@@ -0,0 +1,48 @@
+bin/lite
+%%DATADIR%%/core/command.lua
+%%DATADIR%%/core/commands/command.lua
+%%DATADIR%%/core/commands/core.lua
+%%DATADIR%%/core/commands/doc.lua
+%%DATADIR%%/core/commands/findreplace.lua
+%%DATADIR%%/core/commands/root.lua
+%%DATADIR%%/core/commandview.lua
+%%DATADIR%%/core/common.lua
+%%DATADIR%%/core/config.lua
+%%DATADIR%%/core/doc/highlighter.lua
+%%DATADIR%%/core/doc/init.lua
+%%DATADIR%%/core/doc/search.lua
+%%DATADIR%%/core/doc/translate.lua
+%%DATADIR%%/core/docview.lua
+%%DATADIR%%/core/init.lua
+%%DATADIR%%/core/keymap.lua
+%%DATADIR%%/core/logview.lua
+%%DATADIR%%/core/object.lua
+%%DATADIR%%/core/rootview.lua
+%%DATADIR%%/core/statusview.lua
+%%DATADIR%%/core/strict.lua
+%%DATADIR%%/core/style.lua
+%%DATADIR%%/core/syntax.lua
+%%DATADIR%%/core/tokenizer.lua
+%%DATADIR%%/core/view.lua
+%%DATADIR%%/fonts/font.ttf
+%%DATADIR%%/fonts/icons.ttf
+%%DATADIR%%/fonts/monospace.ttf
+%%DATADIR%%/plugins/autocomplete.lua
+%%DATADIR%%/plugins/autoreload.lua
+%%DATADIR%%/plugins/language_c.lua
+%%DATADIR%%/plugins/language_css.lua
+%%DATADIR%%/plugins/language_js.lua
+%%DATADIR%%/plugins/language_lua.lua
+%%DATADIR%%/plugins/language_md.lua
+%%DATADIR%%/plugins/language_python.lua
+%%DATADIR%%/plugins/language_xml.lua
+%%DATADIR%%/plugins/macro.lua
+%%DATADIR%%/plugins/projectsearch.lua
+%%DATADIR%%/plugins/quote.lua
+%%DATADIR%%/plugins/reflow.lua
+%%DATADIR%%/plugins/tabularize.lua
+%%DATADIR%%/plugins/treeview.lua
+%%DATADIR%%/plugins/trimwhitespace.lua
+%%DATADIR%%/user/colors/fall.lua
+%%DATADIR%%/user/colors/summer.lua
+%%DATADIR%%/user/init.lua