split into multiple files

This commit is contained in:
Pagwin 2025-09-25 01:09:18 -04:00
parent 1cd9fc15e8
commit a11caa4c50
No known key found for this signature in database
GPG key ID: 81137023740CA260
3 changed files with 29 additions and 10 deletions

View file

@ -1,11 +1,7 @@
local function split_sentences() -- get directory of this file
local view = vim.fn.winsaveview() -- keep cursor & view stable local config_dir = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":h")
vim.cmd([[%s/\([.?!]\)\s\+/\1\r/ge]])
vim.fn.winrestview(view)
end
-- run after leaving insert mode -- prepend it to Lua's search path
vim.api.nvim_create_autocmd({ "InsertLeave", "TextChanged" }, { package.path = config_dir .. "/?.lua;" .. config_dir .. "/?/init.lua;" .. package.path
pattern = { "*.md", "*.txt" },
callback = split_sentences require("sentence_lines")
})

View file

23
sentence_lines.lua Normal file
View file

@ -0,0 +1,23 @@
local function split_sentences_paragraph()
-- save cursor and window view
local view = vim.fn.winsaveview()
-- find the paragraph boundaries
local start_line = vim.fn.search('^\\s*$', 'bnW') + 1
if start_line == 1 then start_line = 1 end
local end_line = vim.fn.search('^\\s*$', 'nW') - 1
if end_line < start_line then end_line = vim.fn.line('$') end
-- build a range and run substitute with 'e' flag
local cmd = string.format("%d,%ds/\\([.?!]\\)\\s\\+/\\1\r/ge", start_line, end_line)
vim.cmd(cmd)
-- restore cursor
vim.fn.winrestview(view)
end
-- run after leaving insert mode
vim.api.nvim_create_autocmd({ "InsertLeave", "TextChanged" }, {
pattern = { "*.md", "*.txt" },
callback = split_sentences_paragraph
})