diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2022-08-19 00:08:58 -0600 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2022-08-19 00:08:58 -0600 |
commit | 57171e2191fa769d15d2a33db13703d239cb4acf (patch) | |
tree | ee6f1b42c0f153c270b522a1755996f64e860a82 | |
parent | 852bd19b8148023db10aad2d9d1e0c44bf38cac6 (diff) | |
download | rneovim-userregs-57171e2191fa769d15d2a33db13703d239cb4acf.tar.gz rneovim-userregs-57171e2191fa769d15d2a33db13703d239cb4acf.tar.bz2 rneovim-userregs-57171e2191fa769d15d2a33db13703d239cb4acf.zip |
add basename register
-rw-r--r-- | plugin/basename.lua | 21 | ||||
-rw-r--r-- | plugin/fileregister.lua | 3 |
2 files changed, 23 insertions, 1 deletions
diff --git a/plugin/basename.lua b/plugin/basename.lua new file mode 100644 index 0000000..81cc971 --- /dev/null +++ b/plugin/basename.lua @@ -0,0 +1,21 @@ +-- Implementation of the basename register. +-- +-- The basename register is like the filename register ("%), but instead of +-- returning the whole filename, it will return just the basename. +-- +-- This register is assigned to the character '$' + +local userreg = require("vim.userreg") +local api = vim.api + +local handler = {} + +function handler.do_yank(self, content) + return +end + +function handler.do_put() + return vim.fn.expand('%:t') +end + +userreg.register_handler('$', handler) diff --git a/plugin/fileregister.lua b/plugin/fileregister.lua index a2b5621..856149a 100644 --- a/plugin/fileregister.lua +++ b/plugin/fileregister.lua @@ -9,7 +9,6 @@ -- requires 'json-lua' local userreg = require("vim.userreg") -local json = require('JSON') local api = vim.api local handler = {} @@ -23,6 +22,7 @@ end -- Stores the yanked text into the fileregister as JSON. function handler.do_yank(self, content) + local json = require('JSON') local file = self.get_file_name(); string = json:encode(content) @@ -34,6 +34,7 @@ end -- Reads the text from the file register and returns it. function handler.do_put(self) local file = self.get_file_name(); + local json = require('JSON') file = io.open(file, "r") |