From 5bab3a2258c4dd15d7bd15eb495baed75653f439 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Mon, 9 Sep 2024 00:35:04 +0300 Subject: [PATCH 1/7] feat(nvim): Add a rockspec for installation with rocks.nvim --- Makefile.am | 19 +++++++++++++++++++ decasify.nvim.rockspec.in | 34 ++++++++++++++++++++++++++++++++++ plugin/decasify.lua | 14 ++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 decasify.nvim.rockspec.in create mode 100644 plugin/decasify.lua diff --git a/Makefile.am b/Makefile.am index b5bd7ca..2004d2e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -41,9 +41,13 @@ TAG ?= v$(SEMVER) LUAROCKS_ARGS ?= --tree lua_modules DEV_SPEC = $(PACKAGE_NAME)-dev-$(ROCKREV).rockspec +DEV_SPEC_NVIM = $(PACKAGE_NAME).nvim-dev-$(ROCKREV).rockspec DEV_ROCK = $(PACKAGE_NAME)-dev-$(ROCKREV).src.rock +DEV_ROCK_NVIM = $(PACKAGE_NAME).nvim-dev-$(ROCKREV).src.rock REL_SPEC = rockspecs/$(PACKAGE_NAME)-$(SEMVER)-$(ROCKREV).rockspec +REL_SPEC_NVIM = rockspecs/$(PACKAGE_NAME).nvim-$(SEMVER)-$(ROCKREV).rockspec REL_ROCK = $(PACKAGE_NAME)-$(SEMVER)-$(ROCKREV).src.rock +REL_ROCK_NVIM = $(PACKAGE_NAME).nvim-$(SEMVER)-$(ROCKREV).src.rock EXTRA_decasify_SOURCES += $(REL_SPEC) $(DEV_SPEC) @@ -99,6 +103,15 @@ $(DEV_SPEC): $(PACKAGE_NAME).rockspec.in -e "1i -- DO NOT EDIT! Modify template $< and rebuild with \`make $@\`\n" \ $@ +$(DEV_SPEC_NVIM): SEMVER = dev +$(DEV_SPEC_NVIM): TAG = master +$(DEV_SPEC_NVIM): $(PACKAGE_NAME).nvim.rockspec.in + $(rockpec_template) + $(SED) -i \ + -e '/tag =/s/tag/branch/' \ + -e "1i -- DO NOT EDIT! Modify template $< and rebuild with \`make $@\`\n" \ + $@ + rockspecs/$(PACKAGE_NAME)-%-$(ROCKREV).rockspec: SEMVER = $* rockspecs/$(PACKAGE_NAME)-%-$(ROCKREV).rockspec: TAG = v$* rockspecs/$(PACKAGE_NAME)-%-$(ROCKREV).rockspec: $(PACKAGE_NAME).rockspec.in @@ -114,9 +127,15 @@ rockspecs/$(PACKAGE_NAME)-%-$(ROCKREV).rockspec: $(PACKAGE_NAME).rockspec.in $(PACKAGE_NAME)-dev-$(ROCKREV).src.rock: $(DEV_SPEC) $(LUAROCKS) $(LUAROCKS_ARGS) pack $< +$(PACKAGE_NAME).nvim-dev-$(ROCKREV).nvim.src.rock: $(DEV_SPEC) + $(LUAROCKS) $(LUAROCKS_ARGS) pack $< + $(PACKAGE_NAME)-%.src.rock: rockspecs/$(PACKAGE_NAME)-%.rockspec $(LUAROCKS) $(LUAROCKS_ARGS) pack $< +$(PACKAGE_NAME).nvim-%.src.rock: rockspecs/$(PACKAGE_NAME).nvim-%.rockspec + $(LUAROCKS) $(LUAROCKS_ARGS) pack $< + else !DEVELOPER_MODE $(PHONY_DEVELOPER_TARGETS): diff --git a/decasify.nvim.rockspec.in b/decasify.nvim.rockspec.in new file mode 100644 index 0000000..98896ca --- /dev/null +++ b/decasify.nvim.rockspec.in @@ -0,0 +1,34 @@ +rockspec_format = "3.0" +package = "@PACKAGE_NAME@.nvim" +version = "@SEMVER@-@ROCKREV@" + +source = { + url = "git+https://github.com/alerque/decasify.git", + tag = "@TAG@" +} + +description = { + summary = "NeoVIM plugin wrapping decasify crate to cast strings to title-case according to locale specific style guides including Turkish support", + detailed = [[ + A NeoVIM plugin for + Provides casing functions for long strings (not just individual words) + supporting the grammatical style guides of various locales including Turkish. + ]], + license = "LGPL-3.0-only", + homepage = "https://github.com/alerque/decasify", + issues_url = "https://github.com/alerque/decasify/issues", + maintainer = "Caleb Maclennan ", + labels = { "i18n" } +} + +dependencies = { + "lua >= 5.1", + "decasify" == version +} + +build = { + type = "builtin", + copy_directories = { + "plugin", + } +} diff --git a/plugin/decasify.lua b/plugin/decasify.lua new file mode 100644 index 0000000..9380716 --- /dev/null +++ b/plugin/decasify.lua @@ -0,0 +1,14 @@ +if vim.g.loaded_decasify then + return +end + +log.trace("Loading decasify") + +vim.api.nvim_create_user_command("Decasify", function () + print("Run decasify") +end) + + +print("Loaded decasify") + +vim.g.loaded_decasify = true From fd9ab2e84a80fe80cdd07f3ae622f8bd1abc1986 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 10 Sep 2024 00:31:32 +0300 Subject: [PATCH 2/7] feat(nvim): Add a new command that runs decasify titlecasing on input range --- plugin/decasify.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/plugin/decasify.lua b/plugin/decasify.lua index 9380716..f61dda2 100644 --- a/plugin/decasify.lua +++ b/plugin/decasify.lua @@ -2,13 +2,15 @@ if vim.g.loaded_decasify then return end -log.trace("Loading decasify") +local decasify = require("decasify") -vim.api.nvim_create_user_command("Decasify", function () - print("Run decasify") -end) - - -print("Loaded decasify") +vim.api.nvim_create_user_command("Decasify", function (args) + local first, last = args.line1, args.line2 + local lines = vim.api.nvim_buf_get_lines(0, first - 1, last, true) + for i, line in ipairs(lines) do + lines[i] = decasify.titlecase(line) + end + vim.api.nvim_buf_set_lines(0, first - 1, last, true, lines) +end, { range = true }) vim.g.loaded_decasify = true From 2fc751c45660b46fe696b597340a59b116deedc0 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 10 Sep 2024 02:21:28 +0300 Subject: [PATCH 3/7] feat(nvim): Add a subcommand to access all casing options --- plugin/decasify.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugin/decasify.lua b/plugin/decasify.lua index f61dda2..1045415 100644 --- a/plugin/decasify.lua +++ b/plugin/decasify.lua @@ -6,11 +6,16 @@ local decasify = require("decasify") vim.api.nvim_create_user_command("Decasify", function (args) local first, last = args.line1, args.line2 + local caser = args.fargs[1]:gsub("case$", "") .. "case" + if type(decasify[caser]) ~= "function" then + vim.notify(("Decasify doesn't know what case '%s' is."):format(caser)) + return false + end local lines = vim.api.nvim_buf_get_lines(0, first - 1, last, true) for i, line in ipairs(lines) do - lines[i] = decasify.titlecase(line) + lines[i] = decasify[caser](line) end vim.api.nvim_buf_set_lines(0, first - 1, last, true, lines) -end, { range = true }) +end, { desc = "Pass lines to decasify for recasing prose", nargs = "+", range = true }) vim.g.loaded_decasify = true From 08668d58fa243570577ad6b34927499f1c571fb2 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 10 Sep 2024 02:33:39 +0300 Subject: [PATCH 4/7] feat(nvim): Add global default case --- plugin/decasify.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin/decasify.lua b/plugin/decasify.lua index 1045415..cf46bd4 100644 --- a/plugin/decasify.lua +++ b/plugin/decasify.lua @@ -2,11 +2,15 @@ if vim.g.loaded_decasify then return end +if not vim.g.decasify_case then + vim.g.decasify_case = "title" +end + local decasify = require("decasify") vim.api.nvim_create_user_command("Decasify", function (args) local first, last = args.line1, args.line2 - local caser = args.fargs[1]:gsub("case$", "") .. "case" + local caser = (args.fargs[1] and args.fargs[1] or vim.g.decasify_case):gsub("case$", "") .. "case" if type(decasify[caser]) ~= "function" then vim.notify(("Decasify doesn't know what case '%s' is."):format(caser)) return false @@ -16,6 +20,6 @@ vim.api.nvim_create_user_command("Decasify", function (args) lines[i] = decasify[caser](line) end vim.api.nvim_buf_set_lines(0, first - 1, last, true, lines) -end, { desc = "Pass lines to decasify for recasing prose", nargs = "+", range = true }) +end, { desc = "Pass lines to decasify for recasing prose", nargs = "*", range = true }) vim.g.loaded_decasify = true From 56382eee44840dda0424056436ba444dbf88e719 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 10 Sep 2024 02:38:49 +0300 Subject: [PATCH 5/7] feat(nvim): Add global settings for locale and style guide --- plugin/decasify.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugin/decasify.lua b/plugin/decasify.lua index cf46bd4..0cc04ce 100644 --- a/plugin/decasify.lua +++ b/plugin/decasify.lua @@ -2,22 +2,22 @@ if vim.g.loaded_decasify then return end -if not vim.g.decasify_case then - vim.g.decasify_case = "title" -end +local case = vim.g.decasify_case or "title" +local locale = vim.g.decasify_locale or "en" +local style = vim.g.decasify_style or "gruber" local decasify = require("decasify") vim.api.nvim_create_user_command("Decasify", function (args) local first, last = args.line1, args.line2 - local caser = (args.fargs[1] and args.fargs[1] or vim.g.decasify_case):gsub("case$", "") .. "case" + local caser = case:gsub("case$", "") .. "case" if type(decasify[caser]) ~= "function" then vim.notify(("Decasify doesn't know what case '%s' is."):format(caser)) return false end local lines = vim.api.nvim_buf_get_lines(0, first - 1, last, true) for i, line in ipairs(lines) do - lines[i] = decasify[caser](line) + lines[i] = decasify[caser](line, locale, locale == "en" and style) end vim.api.nvim_buf_set_lines(0, first - 1, last, true, lines) end, { desc = "Pass lines to decasify for recasing prose", nargs = "*", range = true }) From ac75fbe885b5e92b7920194e8348491d5b1c66da Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 10 Sep 2024 02:39:46 +0300 Subject: [PATCH 6/7] feat(nvim): Allow and prioritize buffer local settings --- plugin/decasify.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/plugin/decasify.lua b/plugin/decasify.lua index 0cc04ce..5f5b78c 100644 --- a/plugin/decasify.lua +++ b/plugin/decasify.lua @@ -2,13 +2,12 @@ if vim.g.loaded_decasify then return end -local case = vim.g.decasify_case or "title" -local locale = vim.g.decasify_locale or "en" -local style = vim.g.decasify_style or "gruber" - local decasify = require("decasify") vim.api.nvim_create_user_command("Decasify", function (args) + local case = args.fargs[1] or vim.b.decasify_case or vim.g.decasify_case or "title" + local locale = vim.b.decasify_case or vim.g.decasify_locale or "en" + local style = vim.b.decasify_case or vim.g.decasify_style or "gruber" local first, last = args.line1, args.line2 local caser = case:gsub("case$", "") .. "case" if type(decasify[caser]) ~= "function" then From 7a83ed6b938336879350cb4f2d4001d4cc04ecd1 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 10 Sep 2024 03:24:54 +0300 Subject: [PATCH 7/7] chore(tooling): Help Luacheck to chill out about Neovim stuff --- .luacheckrc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.luacheckrc b/.luacheckrc index 357f7cd..48f65a8 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -14,4 +14,9 @@ exclude_files = { files["**/*_spec.lua"] = { std = "+busted", } +files["plugin/*.lua"] = { + globals = { + "vim", + } +} max_line_length = false