aboutsummaryrefslogtreecommitdiff
path: root/core/lfs_ext.lua
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2020-03-10 11:19:00 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2020-03-10 11:19:00 -0400
commitff6fbbc3227b49fc5407ddbcc7a3f7dac6993482 (patch)
treecd83d4e5b9919c4987272397a70146e182148a87 /core/lfs_ext.lua
parent610bfcc47679ec6b9abb15b6a1cf6087be904369 (diff)
downloadtextadept-ff6fbbc3227b49fc5407ddbcc7a3f7dac6993482.tar.gz
textadept-ff6fbbc3227b49fc5407ddbcc7a3f7dac6993482.zip
Core code cleanup, reformat, refactoring, and bugfixes.
`events.FILE_CHANGED` was not emitting a filename. Added tests for key commands, keychains, and key modes.
Diffstat (limited to 'core/lfs_ext.lua')
-rw-r--r--core/lfs_ext.lua21
1 files changed, 11 insertions, 10 deletions
diff --git a/core/lfs_ext.lua b/core/lfs_ext.lua
index 6d9fe2af..ada0431e 100644
--- a/core/lfs_ext.lua
+++ b/core/lfs_ext.lua
@@ -81,7 +81,8 @@ function lfs.dir_foreach(dir, f, filter, n, include_dirs, level)
end
for basename in lfs.dir(dir) do
if basename:find('^%.%.?$') then goto continue end -- ignore . and ..
- local filename = dir..(dir ~= '/' and '/' or '')..basename
+ local filename = string.format(
+ '%s%s%s', dir, dir ~= '/' and '/' or '', basename)
local mode = lfs.attributes(filename, 'mode')
if mode ~= 'directory' and mode ~= 'file' then goto continue end
local include
@@ -98,15 +99,14 @@ function lfs.dir_foreach(dir, f, filter, n, include_dirs, level)
-- Treat inclusive patterns as logical OR.
include = include or (not patt:find('^!') and filename:find(patt))
end
- local dir_sep = not WIN32 and '/' or '\\'
- local os_filename = not WIN32 and filename or filename:gsub('/', dir_sep)
+ local sep = not WIN32 and '/' or '\\'
+ local os_filename = not WIN32 and filename or filename:gsub('/', sep)
if include and mode == 'directory' then
- if include_dirs and f(os_filename..dir_sep) == false then return end
- if not n or (level or 0) < n then
- local halt = lfs.dir_foreach(filename, f, filter, n, include_dirs,
- (level or 0) + 1) == false
- if halt then return false end
- end
+ if include_dirs and f(os_filename .. sep) == false then return false end
+ if n and (level or 0) >= n then goto continue end
+ local halt = lfs.dir_foreach(
+ filename, f, filter, n, include_dirs, (level or 0) + 1) == false
+ if halt then return false end
elseif include and mode == 'file' then
if f(os_filename) == false then return false end
end
@@ -129,7 +129,8 @@ function lfs.abspath(filename, prefix)
if not filename:find(not WIN32 and '^/' or '^%a:[/\\]') and
not (WIN32 and filename:find('^\\\\')) then
if not prefix then prefix = lfs.currentdir() end
- filename = prefix..(not WIN32 and '/' or '\\')..filename
+ filename = string.format(
+ '%s%s%s', prefix, not WIN32 and '/' or '\\', filename)
end
filename = filename:gsub('%f[^/\\]%.[/\\]', '') -- clean up './'
while filename:find('[^/\\]+[/\\]%.%.[/\\]') do