mirror of
https://github.com/neovim/neovim.git
synced 2026-04-24 16:25:40 +00:00
refactor(lua): use vim.fs instead of fnamemodify
Although powerful -- especially with chained modifiers --, the readability (and therefore maintainability) of `fnamemodify()` and its modifiers is often worse than a function name, giving less context and having to rely on `:h filename-modifiers`. However, it is used plenty in the Lua stdlib: - 16x for the basename: `fnamemodify(path, ':t')` - 7x for the parents: `fnamemodify(path, ':h')` - 7x for the stem (filename w/o extension): `fnamemodify(path, ':r')` - 6x for the absolute path: `fnamemodify(path, ':p')` - 2x for the suffix: `fnamemodify(path, ':e')` - 2x relative to the home directory: `fnamemodify(path, ':~')` - 1x relative to the cwd: `fnamemodify(path, ':.')` The `fs` module in the stdlib provides a cleaner interface for most of these path operations: `vim.fs.basename` instead of `':t'`, `vim.fs.dirname` instead of `':h'`, `vim.fs.abspath` instead of `':p'`. This commit refactors the runtime to use these instead of fnamemodify. Not all fnamemodify calls are removed; some have intrinsic differences in behavior with the `vim.fs` replacement or do not yet have a replacement in the Lua module, i.e. `:~`, `:.`, `:e` and `:r`.
This commit is contained in:
committed by
Lewis Russell
parent
9988d7142d
commit
f7041625f1
@@ -262,7 +262,7 @@ local function get_path(name, sect)
|
||||
-- find any that match the specified name
|
||||
--- @param v string
|
||||
local namematches = vim.tbl_filter(function(v)
|
||||
local tail = fn.fnamemodify(v, ':t')
|
||||
local tail = vim.fs.basename(v)
|
||||
return tail:find(name, 1, true) ~= nil
|
||||
end, results) or {}
|
||||
local sectmatches = {}
|
||||
@@ -364,7 +364,7 @@ end
|
||||
--- @return string name
|
||||
--- @return string sect
|
||||
local function parse_path(path)
|
||||
local tail = fn.fnamemodify(path, ':t')
|
||||
local tail = vim.fs.basename(path)
|
||||
if
|
||||
path:match('%.[glx]z$')
|
||||
or path:match('%.bz2$')
|
||||
|
||||
Reference in New Issue
Block a user