Compare commits

..

No commits in common. "experimental" and "main" have entirely different histories.

7 changed files with 10 additions and 243 deletions

4
README.md Normal file
View File

@ -0,0 +1,4 @@
# presser.nvim
A collection of word processing tools to press over your files easier with UIs.
For unstable and latest features, see the [experimental](https://git.closedless.xyz/TheOnePath/presser.nvim/src/branch/experimental) branch.

View File

@ -1,56 +0,0 @@
# presser.nvim
A collection of word processing tools to press over your files easier with UIs.
For unstable and latest features, see the [experimental](https://git.closedless.xyz/TheOnePath/presser.nvim/src/branch/experimental) branch.
## Architecture
The diagram below outlines the overall architecture of presser.nvim and how each component interacts with each other.
+++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++
+ + + + + +
+ + + + + +
+ + + + + +
+ Context Manager + + Steamers + + Actions +
+ + + + + +
+ + + + + +
+ + + + + +
+++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++
| | |
[5] +---------------------------------------------+-----+ [4] |
v |
+++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++ |
+ + + + |
+ + + + |
+ + [2] + + [3] |
+ Builtins + <--------------- + Pressers + <-----------------+
+ + + + |
+ + + + |
+ + + + |
+++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++ |
I |
| [1] | [6]
| I
+++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ + + +
+ User + + Window buffer +
+ + + +
+++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[1] - The User interacts with Builtins to use a Presser.
[2] - Builtins inherit Pressers and lazy loads them to be accessed by Users.
[3] - Pressers make use of Actions to do the work.
[4] - Pressers inherit Steamers, giving them the ability to generate UIs for the user.
[5] - Pressers make use of the Context Manager to organise and track Steamers.
[6] - Actions will directly modify the contents of the Window buffer.
### List of Components
* User + Window buffer - refers to Neovim, which has the User who does something within the Window buffer.
* Builtins - Lazy loaded interface responsible for acting as a proxy to Pressers.
* Pressers - Tools which allow the User to perform different word processing tasks. Comprised of Steamers, and perform
Actions to modify the Window buffer.
* Steamers - Class module which is responsible for constructing buffers, creating a UI for the User.
* Context Manager - A data structure which is used to store Steamers for a given context (the Presser). Also known as,
"GCM" due to being scoped to vim.g.
* Actions - Perform an action defined for a Presser, which will modify the Window buffer in some way.

View File

@ -1,5 +1,4 @@
local gcm = require'presser.context_manager'
--local actions = require'presser.actions'
local utils = require'presser.utils'
local a = vim.api
@ -60,34 +59,6 @@ actions.execute = function ()
a.nvim_exec( cmd, false )
end
actions.hyperlink_exec = function ()
local url = utils.clean_buf(read_buffer()[1])
actions.close()
if url == "" then return nil end
local _, cur_start, _, cur_end = utils.get_selection()
local line = a.nvim_get_current_line()
if line == "" then
return
end
local row, col = unpack(a.nvim_win_get_cursor(0))
if cur_start == -1 then
cur_start, cur_end = unpack(utils.subslice(line .. " ", col))
end
actions.suburl( line, row, url, cur_start, cur_end )
end
actions.suburl = function (line, row, url, cur_start, cur_end)
local prefix = string.sub(line, 1, cur_start) -- the first part up to selection
local suffix = string.sub(line, cur_end + 1, line:len()) -- the last part after selection
local infix = "[" .. utils.clean_buf(string.sub(line, cur_start, cur_end)) .. "]" .. "(" .. url .. ")"
a.nvim_buf_set_lines( 0, row-1, row, false, { prefix .. infix .. suffix } )
end
actions.buf_put_curser_at = function ( label )
for _, ctx_obj in pairs( vim.g.presser_buf_ctx ) do
for _, record in pairs( ctx_obj ) do

View File

@ -1,7 +1,6 @@
local gcm = require'presser.context_manager'
local steamers = require'presser.steamers'
local actions = require'presser.actions'
local utils = require 'presser.utils'
local a = vim.api
@ -81,130 +80,4 @@ modules.find_replace = function ()
a.nvim_feedkeys('A', 'n', false)
end
modules.hyperlink = function ()
local check_url = function ( text )
local text = string.lower( text )
-- string list of all possible URI schemes which have RFC specification and identified with permanent status
local patterns = "aaa|aaas|about|acap|acct|afs|cap|cid|coap|coap+tcp|coap+ws|coaps|coaps+tcp|coaps+ws|crid|data" ..
"|dav|dict|dns|dtn|example|fax|file|ftp|geo|go|gopher|h323|ham|http|https|iax|icap|im|imap|info|ipn|ipp|ipps" ..
"|iris|iris.beep|iris.lwz|iris.xpc|iris.xpcs|jms|ldap|leaptofrogans|mailserver|mailto|mid|modem|msrp|msrps" ..
"|mtqp|mupdate|news|nfs|ni|nih|nntp|opaquelocktoken|payto|pkcs11|pop|pres|prospero|reload|rsync|rtmfp|rtsp" ..
"|rtsps|rtspu|secret-token|service|session|sieve|sip|sips|sms|snews|snmp|soap.beep|soap.beeps|stun|stuns|tag" ..
"|tel|telnet|tftp|thismessage|tip|tn3270|turn|turns|tv|urn|vemmi|videotex|vnc|wais|ws|wss|xcon|xcon-userid" ..
"|xmlrpc.beep|xmlrpc.beeps|xmpp|z39.50|z39.50r|z39.50s|"
-- check if text is a type of URI
-- @Dev: TODO, consider option of logarithmic matching (patterns already in alphabetical order)
for proto in string.gmatch( patterns, "([^|]+)" ) do
-- if so, text can be converted directly to hyperlink (return true)
if string.find( text, proto ) then
return true
end
end
return false
end
local link_txt = nil
local row, col = unpack(a.nvim_win_get_cursor(0))
local h,j,_,l = utils.get_selection()
local line = a.nvim_get_current_line()
if vim.api.nvim_get_mode()["mode"] == "n" then
if (row-1) == h and (col == j or col == l) then
print("visual mode selection")
link_txt = string.sub(line, j, l)
else
link_txt = string.sub(line, unpack(utils.subslice(line, col)))
end
else
link_txt = vim.fn.expand "<cexpr>"
end
link_txt = utils.clean_buf(link_txt)
if link_txt == "" then
print("Presser.hyperlink: No text selected to convert.")
return
end
if check_url( link_txt ) then
print("Identified URI scheme under cursor, generating hyperlink for: " .. link_txt)
if not ( col == j or col == l ) then
j, l = unpack(utils.subslice( line .. " ", col ))
end
print(j,l)
actions.suburl( line, row, link_txt, j, l )
return nil
end
print("Cursor is not over an identified URI scheme: " .. link_txt .. ". Constructing UI...")
-- define the context which these windows will belong to in the context manager.
local ctx = "hyperlink"
gcm.create( ctx )
local keymap = {
n = {
["<esc>"] = "<cmd>lua require'presser.actions'.close()<CR>",
["<A-a>"] = "<cmd>lua require'presser.actions'.hyperlink_exec()<CR>",
},
i = {
["<A-a>"] = "<cmd>lua require'presser.actions'.hyperlink_exec()<CR>",
}
}
-- get the centre of the current buffer
local c_lines = math.floor( a.nvim_win_get_height(0) / 2 )
-- create a title buffer for the steamer
steamers
.new( ctx, {
label = "presser_title",
steamer = {
placeholder = "Hyperlink",
allowed = false,
window = {
line = c_lines - 2,
border = false,
minwidth = 82,
padding = { 0, 1, 1, 1 }
}
}
} )
steamers
.new( ctx, {
label = "selected_text",
steamer = {
placeholder = "Selected text: " .. link_txt,
allowed = false,
window = {
line = c_lines,
border = false,
minwidth = 82,
padding = { 0, 1, 1, 1 }
}
}
} )
-- create a new buffer for replace pattern
steamers
.new( ctx, {
label = "hyperlink_buf",
steamer = {
window = {
line = c_lines + 3,
title = "Hyperlink",
},
keybinds = keymap,
}
} )
local result = actions.buf_put_curser_at( "hyperlink_buf" )
a.nvim_feedkeys('A', 'n', false)
end
return modules

View File

@ -12,6 +12,5 @@ end
builtins.find_replace = require_on_exported_call("presser.builtins.__modules").find_replace
builtins.hyperlink = require_on_exported_call("presser.builtins.__modules").hyperlink
return builtins

View File

@ -23,7 +23,7 @@ presser.setup = function ( opts )
{
nargs = 1,
complete = function (ArgLead, CmdLine, CursorPos)
return { 'find_replace', 'hyperlink' }
return { 'find_replace' }
end,
}
)

View File

@ -31,32 +31,8 @@ M.clean_buf = function ( text )
return ""
end
return text:match( "^%s*(.-)%s*$" )
end
M.get_selection = function()
local _, csrow, cscol, _ = unpack(vim.fn.getpos("'<"))
local _, cerow, cecol, _ = unpack(vim.fn.getpos("'>"))
if csrow < cerow or (csrow == cerow and cscol <= cecol) then
return csrow - 1, cscol - 1, cerow - 1, cecol
else
return cerow - 1, cecol - 1, csrow - 1, cscol
end
end
M.subslice = function(line, col)
local i = 0
local j = 0
while true do
j = string.find(line, " ", j+1) -- find 'next' newline
if j == nil then break end
if j > col then break end
i = j
end
return { i, j }
return escape_chars( text )
:match( "^%s*(.-)%s*$" )
end