aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/file_io.lua15
-rw-r--r--core/lfs_ext.lua42
-rw-r--r--doc/manual.md13
-rw-r--r--modules/textadept/find.lua10
4 files changed, 36 insertions, 44 deletions
diff --git a/core/file_io.lua b/core/file_io.lua
index 8e252790..bd018e5a 100644
--- a/core/file_io.lua
+++ b/core/file_io.lua
@@ -370,7 +370,8 @@ io.quick_open_filters = {}
-- If *paths* is `nil`, uses the current project's root directory, which is
-- obtained from `io.get_project_root()`.
-- Files shown in the dialog do not match any pattern in either string or table
--- *filter* (or `lfs.FILTER` if *filter* is `nil`). A filter table contains:
+-- *filter* (or `lfs.default_filter` if *filter* is `nil`). A filter table
+-- contains:
--
-- + Lua patterns that match filenames to exclude.
-- + Optional `folders` sub-table that contains patterns matching directories
@@ -386,16 +387,16 @@ io.quick_open_filters = {}
-- not match the pattern that follows. The number of files in the list is capped
-- at `quick_open_max`.
-- If *filter* is `nil` and *paths* is ultimately a string, the filter from the
--- `io.quick_open_filters` table is used in place of `lfs.FILTER` if the former
--- exists.
+-- `io.quick_open_filters` table is used in place of `lfs.default_filter` if the
+-- former exists.
-- *opts* is an optional table of additional options for
-- `ui.dialogs.filteredlist()`.
-- @param paths Optional string directory path or table of directory paths to
-- search. The default value is the current project's root directory, if
-- available.
-- @param filter Optional filter for files and directories to exclude. The
--- default value is `lfs.FILTER` unless *paths* is a string and a filter for
--- it is defined in `io.quick_open_filters`.
+-- default value is `lfs.default_filter` unless *paths* is a string and a
+-- filter for it is defined in `io.quick_open_filters`.
-- @param opts Optional table of additional options for
-- `ui.dialogs.filteredlist()`.
-- @usage io.quick_open(buffer.filename:match('^.+/')) -- list all files in the
@@ -405,7 +406,7 @@ io.quick_open_filters = {}
-- @usage io.quick_open('/project', {folders = {'build'}}) -- list all non-built
-- files in a project directory
-- @see io.quick_open_filters
--- @see lfs.FILTER
+-- @see lfs.default_filter
-- @see quick_open_max
-- @see ui.dialogs.filteredlist
-- @name quick_open
@@ -422,7 +423,7 @@ function io.quick_open(paths, filter, opts)
if #utf8_list >= io.quick_open_max then return false end
filename = filename:gsub('^%.[/\\]', '')
utf8_list[#utf8_list + 1] = filename:iconv('UTF-8', _CHARSET)
- end, filter or lfs.FILTER)
+ end, filter or lfs.default_filter)
end
if #utf8_list >= io.quick_open_max then
local msg = string.format('%d %s %d', io.quick_open_max,
diff --git a/core/lfs_ext.lua b/core/lfs_ext.lua
index 4bf641e3..deaf0e89 100644
--- a/core/lfs_ext.lua
+++ b/core/lfs_ext.lua
@@ -9,14 +9,14 @@ module('lfs')]]
---
-- The filter table containing common binary file extensions and version control
-- directories to exclude when iterating over files and directories using
--- `dir_foreach` when its `exclude_FILTER` argument is `false`.
+-- `dir_foreach`.
-- @see dir_foreach
-- @class table
--- @name FILTER
-lfs.FILTER = {
+-- @name default_filter
+lfs.default_filter = {
extensions = {
'a', 'bmp', 'bz2', 'class', 'dll', 'exe', 'gif', 'gz', 'jar', 'jpeg', 'jpg',
- 'o', 'png', 'so', 'tar', 'tgz', 'tif', 'tiff', 'zip'
+ 'o', 'pdf', 'png', 'so', 'tar', 'tgz', 'tif', 'tiff', 'xz', 'zip'
},
folders = {'%.bzr$', '%.git$', '%.hg$', '%.svn$'}
}
@@ -44,9 +44,8 @@ end
---
-- Iterates over all files and sub-directories (up to *n* levels deep) in
-- directory *dir*, calling function *f* with each file found.
--- Files passed to *f* do not match any pattern in string or table *filter*,
--- and, unless *exclude_FILTER* is `true`, `lfs.FILTER` as well. A filter table
--- contains:
+-- Files passed to *f* do not match any pattern in string or table *filter*
+-- (or `lfs.default_filter` when *filter* is `nil`). A filter table contains:
--
-- + Lua patterns that match filenames to exclude.
-- + Optional `folders` sub-table that contains patterns matching directories
@@ -63,11 +62,8 @@ end
-- @param dir The directory path to iterate over.
-- @param f Function to call with each full file path found. If *f* returns
-- `false` explicitly, iteration ceases.
--- @param filter Optional filter for files and directories to exclude.
--- @param exclude_FILTER Optional flag indicating whether or not to exclude the
--- default filter `lfs.FILTER` in the search. If `false`, adds `lfs.FILTER` to
--- *filter*.
--- The default value is `false` to include the default filter.
+-- @param filter Optional filter for files and directories to exclude. The
+-- default value is `lfs.default_filter`.
-- @param n Optional maximum number of directory levels to descend into.
-- The default value is `nil`, which indicates no limit.
-- @param include_dirs Optional flag indicating whether or not to call *f* with
@@ -76,28 +72,14 @@ end
-- The default value is `false`.
-- @param level Utility value indicating the directory level this function is
-- at. This value is used and set internally, and should not be set otherwise.
--- @see FILTER
+-- @see filter
-- @name dir_foreach
-function lfs.dir_foreach(dir, f, filter, exclude_FILTER, n, include_dirs, level)
+function lfs.dir_foreach(dir, f, filter, n, include_dirs, level)
if not level then level = 0 end
if level == 0 then
-- Convert filter to a table from nil or string arguments.
- if not filter then filter = {} end
+ if not filter then filter = lfs.default_filter end
if type(filter) == 'string' then filter = {filter} end
- -- Add FILTER to filter unless specified otherwise.
- if not exclude_FILTER then
- for k, v in pairs(lfs.FILTER) do
- if type(v) == 'table' then
- if not filter[k] then filter[k] = {} end
- local filter_k = filter[k]
- for k2, v2 in pairs(v) do
- filter_k[tonumber(k2) and #filter_k + 1 or k2] = v2
- end
- else
- filter[tonumber(k) and #filter + 1 or k] = v
- end
- end
- end
-- Create file extension filter hash table for quick lookups.
local ext = filter.extensions
if ext then for i = 1, #ext do ext[ext[i]] = true end end
@@ -110,7 +92,7 @@ function lfs.dir_foreach(dir, f, filter, exclude_FILTER, n, include_dirs, level)
if mode == 'directory' and not exclude(filename, filter.folders) then
if include_dirs and f(filename..dir_sep) == false then return end
if not n or level < n then
- lfs.dir_foreach(filename, f, filter, nil, n, include_dirs, level + 1)
+ lfs.dir_foreach(filename, f, filter, n, include_dirs, level + 1)
end
elseif mode == 'file' and not exclude(filename, filter) then
if f(filename) == false then return end
diff --git a/doc/manual.md b/doc/manual.md
index 7d41a07f..0e0ddbfc 100644
--- a/doc/manual.md
+++ b/doc/manual.md
@@ -1853,10 +1853,19 @@ terminal's constraints:
Old API |Change |New API
----------------------------------|:------:|-------
+**lfs** | |
+FILTER |Renamed |[default\_filter][]
+dir\_foreach() |Changed |[dir\_foreach()][] _(Changed args)_
**textadept.editing** | |
-snapopen(...) |Changed |[quick\_open(paths, filter, opts)][]
-SNAPOPEN\_MAX |Renamed |[quick\_open\_max][]
+snapopen(...) |Changed |[quick\_open][](paths, filter, opts)
snapopen\_filters |Renamed |[quick\_open\_filters][]
+SNAPOPEN\_MAX |Renamed |[quick\_open\_max][]
+
+[default\_filter]: api.html#lfs.default_filter
+[dir\_foreach()]: api.html#lfs.dir_foreach
+[quick\_open]: api.html#io.quick_open
+[quick\_open\_filters]: api.html#io.quick_open_filters
+[quick\_open\_max]: api.html#io.quick_open_max
### Textadept 7 to 8
diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua
index 78b83d4f..9689b025 100644
--- a/modules/textadept/find.lua
+++ b/modules/textadept/find.lua
@@ -101,13 +101,13 @@ local preferred_view
--
-- Any patterns starting with '!' exclude files and directories that do not
-- match the pattern that follows.
--- The default value is `lfs.FILTER`, a filter for common binary file extensions
--- and version control directories.
+-- The default value is `lfs.default_filter`, a filter for common binary file
+-- extensions and version control directories.
-- @see find_in_files
--- @see lfs.FILTER
+-- @see lfs.default_filter
-- @class table
-- @name FILTER
-M.FILTER = lfs.FILTER
+M.FILTER = lfs.default_filter
-- Text escape sequences with their associated characters and vice-versa.
-- @class table
@@ -310,7 +310,7 @@ function M.find_in_files(dir)
line_num = line_num + 1
end
f:close()
- end, M.FILTER, true)
+ end, M.FILTER)
if not found then buffer:append_text(_L['No results found']) end
ui._print(_L['[Files Found Buffer]'], '') -- goto end, set save pos, etc.
end