Skip to content

Commit

Permalink
Merge pull request #20 from alerque/nvim-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque authored Sep 10, 2024
2 parents 6f9a3b2 + 7a83ed6 commit 9b7f9c8
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ exclude_files = {
files["**/*_spec.lua"] = {
std = "+busted",
}
files["plugin/*.lua"] = {
globals = {
"vim",
}
}
max_line_length = false
19 changes: 19 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down
34 changes: 34 additions & 0 deletions decasify.nvim.rockspec.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
rockspec_format = "3.0"
package = "@[email protected]"
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 <[email protected]>",
labels = { "i18n" }
}

dependencies = {
"lua >= 5.1",
"decasify" == version
}

build = {
type = "builtin",
copy_directories = {
"plugin",
}
}
24 changes: 24 additions & 0 deletions plugin/decasify.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
if vim.g.loaded_decasify then
return
end

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
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, 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 })

vim.g.loaded_decasify = true

0 comments on commit 9b7f9c8

Please sign in to comment.