aboutsummaryrefslogtreecommitdiff
path: root/core/ext
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2008-02-10 21:32:34 -0500
committermitchell <70453897+667e-11@users.noreply.github.com>2008-02-10 21:32:34 -0500
commitc153f47a09d83f5b28e3954a0e2ce3b293ebb3ba (patch)
treedef7388c53a37136bdcd6581e89f0ef296892362 /core/ext
parent2a8b91209627608fe61c21ec96de31b7fffcea94 (diff)
downloadtextadept-c153f47a09d83f5b28e3954a0e2ce3b293ebb3ba.tar.gz
textadept-c153f47a09d83f5b28e3954a0e2ce3b293ebb3ba.zip
Added new find in files project manager browser.
Diffstat (limited to 'core/ext')
-rw-r--r--core/ext/pm.lua3
-rw-r--r--core/ext/pm/find_browser.lua101
2 files changed, 103 insertions, 1 deletions
diff --git a/core/ext/pm.lua b/core/ext/pm.lua
index 8e84b969..c1f0f5ae 100644
--- a/core/ext/pm.lua
+++ b/core/ext/pm.lua
@@ -50,7 +50,8 @@
-- @name browsers
-- @usage Add additional browsers to this list.
local browsers = {
- 'buffer_browser', 'file_browser', 'ctags_browser', 'macro_browser'
+ 'buffer_browser', 'file_browser', 'ctags_browser', 'macro_browser',
+ 'find_browser'
}
for _, b in ipairs(browsers) do require('ext/pm.'..b) end
diff --git a/core/ext/pm/find_browser.lua b/core/ext/pm/find_browser.lua
new file mode 100644
index 00000000..496df1f1
--- /dev/null
+++ b/core/ext/pm/find_browser.lua
@@ -0,0 +1,101 @@
+-- Copyright 2007 Mitchell mitchell<att>caladbolg.net. See LICENSE.
+
+---
+-- Find in files browser for the Textadept project manager.
+-- It is enabled with the prefix 'find' in the project manager entry field.
+module('textadept.pm.browsers.find', package.seeall)
+
+---
+-- The directory recursively searched. If pm.search_directory is not specified,
+-- defaults to the current working directory.
+local search_directory
+
+---
+-- The table of file matches.
+-- Each key is a filename and the value is a table containing the usual as well
+-- as a children key that contains entries for line number matches.
+-- @class table
+-- @name find_matches
+local find_matches
+
+--- Matches 'file:search text' (search text can contain spaces)
+function matches(entry_text)
+ return entry_text:sub(1, 4) == 'find'
+end
+
+---
+-- If not expanding, creates the entire tree; otherwise returns the child table
+-- of the parent being expanded.
+function get_contents_for(full_path, expanding)
+ local search_string, recursive
+ if full_path[1]:sub(1, 5) == 'findr' then
+ search_string = full_path[1]:sub(7) -- ignore 'findr:'
+ recursive = true
+ else
+ search_string = full_path[1]:sub(6) -- ignore 'find:'
+ recursive = false
+ end
+ if #search_string == 0 then return {} end
+ if expanding then
+ local parent = find_matches
+ for i = 2, #full_path do
+ local filename = full_path[i]
+ if not parent[filename] then return {} end
+ parent = parent[filename].children
+ end
+ return parent
+ else
+ find_matches = {}
+ local p
+ search_directory = _G.textadept.pm.search_directory
+ if not search_directory then
+ p = io.popen('pwd')
+ search_directory = p:read('*all'):match('^[^\n]+')
+ p:close()
+ end
+ search_string = search_string:gsub('"', '\\"')
+ search_directory = search_directory:gsub('"', '\\"')
+ local opts = 'nH'..(recursive and 'r' or '')
+ p = io.popen('grep -'..opts..' "'..search_string..'" "'..
+ search_directory..'"')
+ for line in p:lines() do
+ local filename, line_num, line_text = line:match('^([^:]+):(%d+):%s-(.+)$')
+ if filename and line_num and line_text then
+ if not find_matches[filename] then
+ find_matches[filename] = {
+ parent = true,
+ children = {},
+ display_text = filename
+ }
+ end
+ local entry = {}
+ entry.display_text = line_num..':'..line_text
+ entry.line_num = line_num
+ entry.filepath = filename
+ find_matches[filename].children[line_num] = entry
+ end
+ end
+ p:close()
+ return find_matches
+ end
+end
+
+function perform_action(selected_item)
+ local item = find_matches
+ for i = 2, #selected_item do
+ local match = selected_item[i]
+ item = item[match]
+ if item.children then item = item.children end
+ end
+ textadept.io.open(item.filepath)
+ buffer:goto_line(item.line_num - 1)
+ view:focus()
+end
+
+function get_context_menu(selected_item)
+
+end
+
+function perform_menu_action(menu_item, selected_item)
+
+end