summaryrefslogtreecommitdiff
path: root/plugin/basename.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2025-04-09 22:01:12 -0600
committerJosh Rahm <joshuarahm@gmail.com>2025-04-09 22:01:54 -0600
commitb3b09ff479510abc51ffb88743bb353bcc15e165 (patch)
treea2b7486a7146dfe4074faf9f1856fc25f461b466 /plugin/basename.lua
parent8495168e18c5d9f0dc1a7f5b8fcd23d2d0ab4652 (diff)
downloadrneovim-userregs-b3b09ff479510abc51ffb88743bb353bcc15e165.tar.gz
rneovim-userregs-b3b09ff479510abc51ffb88743bb353bcc15e165.tar.bz2
rneovim-userregs-b3b09ff479510abc51ffb88743bb353bcc15e165.zip
Update rneovim userregs to be compatible with userregs 2.0.
Diffstat (limited to 'plugin/basename.lua')
-rw-r--r--plugin/basename.lua34
1 files changed, 18 insertions, 16 deletions
diff --git a/plugin/basename.lua b/plugin/basename.lua
index 8b875d1..84d2991 100644
--- a/plugin/basename.lua
+++ b/plugin/basename.lua
@@ -1,24 +1,26 @@
--- 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 with one
--- extension removed.
---
--- Useful for Java when needing to reference the class.
---
--- This register is assigned to the character '$'
+--- Basename Register: returns the current filename without path and extension.
+---
+--- This is similar to the "%" register (full filename), but returns only
+--- the basename with one extension removed. Useful, for example, when referencing
+--- Java class names based on the file name.
+---
+--- This register is read-only and assigned to the character '$'.
-local userreg = require("vim.userreg")
+local userregs = require("vim.userregs")
local api = vim.api
+---@type table<string, fun(regname: string): any>
local handler = {}
-function handler.do_yank(self, content)
- return -1 -- Read-only register.
-end
-
-function handler.do_put()
+--- Return the current buffer's basename without extension.
+--- Equivalent to `expand('%:t:r')`
+function handler.put(regname)
return vim.fn.expand('%:t:r')
end
-userreg.register_handler('$', handler)
+-- Make this register read-only by omitting the yank handler.
+handler.yank = nil
+
+-- Register this handler under the user register '$'.
+userregs.register_handler('$', handler)
+