summaryrefslogtreecommitdiff
path: root/lua/vim/userregs/impl/dirname.lua
blob: 503601d30264fb87db8e5c0b8a0c1a18cd1aca70 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
--- Dirname Register: returns the direction for the filename.
---
--- This is similar to the "%" register (full filename), but returns only
--- the the directory.
---
--- This register is read-only and assigned to the character '<C-d>'.

local userregs = require("vim.userregs")
local api = vim.api

---@type table<string, fun(regname: string): any>
local handler = {}

--- Return the current buffer's basename without extension.
--- Equivalent to `expand('%:t:r')`
function handler.put(regname)
  return vim.fn.expand('%:p:h') .. '/'
end

-- Make this register read-only by omitting the yank handler.
handler.yank = nil

-- Register this handler under the user register '<C-d>'.
userregs.register_handler('\4', handler)


return {}