From 37952bf7b442cac794c4663f2e0123e7d72bc443 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 6 Aug 2024 21:19:12 +0800 Subject: vim-patch:8.2.4838: checking for absolute path is not trivial (#29990) Problem: Checking for absolute path is not trivial. Solution: Add isabsolutepath(). (closes vim/vim#10303) https://github.com/vim/vim/commit/dca1d40cd0f2af0755519e7028378bd3c8fefd31 vim-patch:8a3b805c6c9c Co-authored-by: LemonBoy --- runtime/doc/builtin.txt | 15 +++++++++++++++ runtime/doc/usr_41.txt | 1 + runtime/lua/vim/_meta/vimfn.lua | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+) (limited to 'runtime') diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt index 97baed6cc9..4bd8975583 100644 --- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -3868,6 +3868,21 @@ invert({expr}) *invert()* let bits = invert(bits) < +isabsolutepath({path}) *isabsolutepath()* + The result is a Number, which is |TRUE| when {path} is an + absolute path. + On Unix, a path is considered absolute when it starts with '/'. + On MS-Windows, it is considered absolute when it starts with an + optional drive prefix and is followed by a '\' or '/'. UNC paths + are always absolute. + Example: >vim + echo isabsolutepath('/usr/share/') " 1 + echo isabsolutepath('./foobar') " 0 + echo isabsolutepath('C:\Windows') " 1 + echo isabsolutepath('foobar') " 0 + echo isabsolutepath('\\remote\file') " 1 +< + isdirectory({directory}) *isdirectory()* The result is a Number, which is |TRUE| when a directory with the name {directory} exists. If {directory} doesn't diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt index b3911dfd09..08ef9ac886 100644 --- a/runtime/doc/usr_41.txt +++ b/runtime/doc/usr_41.txt @@ -836,6 +836,7 @@ System functions and manipulation of files: getfperm() get the permissions of a file setfperm() set the permissions of a file getftype() get the kind of a file + isabsolutepath() check if a path is absolute isdirectory() check if a directory exists getfsize() get the size of a file getcwd() get the current working directory diff --git a/runtime/lua/vim/_meta/vimfn.lua b/runtime/lua/vim/_meta/vimfn.lua index 4f9cc881c1..9cddf0e81f 100644 --- a/runtime/lua/vim/_meta/vimfn.lua +++ b/runtime/lua/vim/_meta/vimfn.lua @@ -4659,6 +4659,24 @@ function vim.fn.interrupt() end --- @return any function vim.fn.invert(expr) end +--- The result is a Number, which is |TRUE| when {path} is an +--- absolute path. +--- On Unix, a path is considered absolute when it starts with '/'. +--- On MS-Windows, it is considered absolute when it starts with an +--- optional drive prefix and is followed by a '\' or '/'. UNC paths +--- are always absolute. +--- Example: >vim +--- echo isabsolutepath('/usr/share/') " 1 +--- echo isabsolutepath('./foobar') " 0 +--- echo isabsolutepath('C:\Windows') " 1 +--- echo isabsolutepath('foobar') " 0 +--- echo isabsolutepath('\\remote\file') " 1 +--- < +--- +--- @param path any +--- @return 0|1 +function vim.fn.isabsolutepath(path) end + --- The result is a Number, which is |TRUE| when a directory --- with the name {directory} exists. If {directory} doesn't --- exist, or isn't a directory, the result is |FALSE|. {directory} -- cgit