Merge branch 'master-2.0' into master-luajit-2.0
This commit is contained in:
commit
f18c6ac790
|
@ -6,6 +6,7 @@ local LogView = require "core.logview"
|
||||||
|
|
||||||
|
|
||||||
local fullscreen = false
|
local fullscreen = false
|
||||||
|
local restore_title_view = false
|
||||||
|
|
||||||
local function suggest_directory(text)
|
local function suggest_directory(text)
|
||||||
text = common.home_expand(text)
|
text = common.home_expand(text)
|
||||||
|
@ -28,9 +29,12 @@ command.add(nil, {
|
||||||
|
|
||||||
["core:toggle-fullscreen"] = function()
|
["core:toggle-fullscreen"] = function()
|
||||||
fullscreen = not fullscreen
|
fullscreen = not fullscreen
|
||||||
|
if fullscreen then
|
||||||
|
restore_title_view = core.title_view.visible
|
||||||
|
end
|
||||||
system.set_window_mode(fullscreen and "fullscreen" or "normal")
|
system.set_window_mode(fullscreen and "fullscreen" or "normal")
|
||||||
core.show_title_bar(not fullscreen)
|
core.show_title_bar(not fullscreen and restore_title_view)
|
||||||
core.title_view:configure_hit_test(not fullscreen)
|
core.title_view:configure_hit_test(not fullscreen and restore_title_view)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["core:reload-module"] = function()
|
["core:reload-module"] = function()
|
||||||
|
@ -160,7 +164,10 @@ command.add(nil, {
|
||||||
core.error("Cannot open folder %q", text)
|
core.error("Cannot open folder %q", text)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
core.confirm_close_docs(core.docs, core.open_folder_project, text)
|
core.confirm_close_docs(core.docs, function(dirpath)
|
||||||
|
core.close_current_project()
|
||||||
|
core.open_folder_project(dirpath)
|
||||||
|
end, text)
|
||||||
end, suggest_directory)
|
end, suggest_directory)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
local core = require "core"
|
local core = require "core"
|
||||||
|
local common = require "core.common"
|
||||||
local config = require "core.config"
|
local config = require "core.config"
|
||||||
local tokenizer = require "core.tokenizer"
|
local tokenizer = require "core.tokenizer"
|
||||||
local Object = require "core.object"
|
local Object = require "core.object"
|
||||||
|
@ -40,6 +41,13 @@ end
|
||||||
|
|
||||||
function Highlighter:reset()
|
function Highlighter:reset()
|
||||||
self.lines = {}
|
self.lines = {}
|
||||||
|
self:soft_reset()
|
||||||
|
end
|
||||||
|
|
||||||
|
function Highlighter:soft_reset()
|
||||||
|
for i=1,#self.lines do
|
||||||
|
self.lines[i] = false
|
||||||
|
end
|
||||||
self.first_invalid_line = 1
|
self.first_invalid_line = 1
|
||||||
self.max_wanted_line = 0
|
self.max_wanted_line = 0
|
||||||
end
|
end
|
||||||
|
@ -51,16 +59,16 @@ end
|
||||||
|
|
||||||
function Highlighter:insert_notify(line, n)
|
function Highlighter:insert_notify(line, n)
|
||||||
self:invalidate(line)
|
self:invalidate(line)
|
||||||
|
local blanks = { }
|
||||||
for i = 1, n do
|
for i = 1, n do
|
||||||
table.insert(self.lines, line, false)
|
blanks[i] = false
|
||||||
end
|
end
|
||||||
|
common.splice(self.lines, line, 0, blanks)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Highlighter:remove_notify(line, n)
|
function Highlighter:remove_notify(line, n)
|
||||||
self:invalidate(line)
|
self:invalidate(line)
|
||||||
for i = 1, n do
|
common.splice(self.lines, line, n)
|
||||||
table.remove(self.lines, line)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ function Doc:reset_syntax()
|
||||||
local syn = syntax.get(self.filename or "", header)
|
local syn = syntax.get(self.filename or "", header)
|
||||||
if self.syntax ~= syn then
|
if self.syntax ~= syn then
|
||||||
self.syntax = syn
|
self.syntax = syn
|
||||||
self.highlighter:reset()
|
self.highlighter:soft_reset()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -62,12 +62,15 @@ function Doc:load(filename)
|
||||||
local fp = assert( io.open(filename, "rb") )
|
local fp = assert( io.open(filename, "rb") )
|
||||||
self:reset()
|
self:reset()
|
||||||
self.lines = {}
|
self.lines = {}
|
||||||
|
local i = 1
|
||||||
for line in fp:lines() do
|
for line in fp:lines() do
|
||||||
if line:byte(-1) == 13 then
|
if line:byte(-1) == 13 then
|
||||||
line = line:sub(1, -2)
|
line = line:sub(1, -2)
|
||||||
self.crlf = true
|
self.crlf = true
|
||||||
end
|
end
|
||||||
table.insert(self.lines, line .. "\n")
|
table.insert(self.lines, line .. "\n")
|
||||||
|
self.highlighter.lines[i] = false
|
||||||
|
i = i + 1
|
||||||
end
|
end
|
||||||
if #self.lines == 0 then
|
if #self.lines == 0 then
|
||||||
table.insert(self.lines, "\n")
|
table.insert(self.lines, "\n")
|
||||||
|
|
|
@ -65,6 +65,22 @@ function core.set_project_dir(new_dir, change_project_fn)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function core.close_current_project()
|
||||||
|
-- When using system.unwatch_dir we need to pass the watch_id provided by dmon.
|
||||||
|
-- In reality when unwatching a directory the dmon library shifts the other watch_id
|
||||||
|
-- values so the actual watch_id changes. To workaround this problem we assume the
|
||||||
|
-- first watch_id is always 1 and the watch_id are continguous and we unwatch the
|
||||||
|
-- first watch_id repeateadly up to the number of watch_ids.
|
||||||
|
local watch_id_max = 0
|
||||||
|
for _, project_dir in ipairs(core.project_directories) do
|
||||||
|
if project_dir.watch_id and project_dir.watch_id > watch_id_max then
|
||||||
|
watch_id_max = project_dir.watch_id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for i = 1, watch_id_max do
|
||||||
|
system.unwatch_dir(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function core.open_folder_project(dir_path_abs)
|
function core.open_folder_project(dir_path_abs)
|
||||||
if core.set_project_dir(dir_path_abs, core.on_quit_project) then
|
if core.set_project_dir(dir_path_abs, core.on_quit_project) then
|
||||||
|
@ -200,12 +216,12 @@ local function file_search(files, info)
|
||||||
inf = curr
|
inf = curr
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
repeat
|
while inf <= sup and not system.path_compare(filename, type, files[inf].filename, files[inf].type) do
|
||||||
if files[inf].filename == filename then
|
if files[inf].filename == filename then
|
||||||
return inf, true
|
return inf, true
|
||||||
end
|
end
|
||||||
inf = inf + 1
|
inf = inf + 1
|
||||||
until inf > sup or system.path_compare(filename, type, files[inf].filename, files[inf].type)
|
end
|
||||||
return inf, false
|
return inf, false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1165,8 +1181,8 @@ end
|
||||||
|
|
||||||
|
|
||||||
-- no-op but can be overrided by plugins
|
-- no-op but can be overrided by plugins
|
||||||
function core.on_dirmonitor_modify()
|
function core.on_dirmonitor_modify() end
|
||||||
end
|
function core.on_dirmonitor_delete() end
|
||||||
|
|
||||||
|
|
||||||
function core.on_dir_change(watch_id, action, filepath)
|
function core.on_dir_change(watch_id, action, filepath)
|
||||||
|
@ -1175,6 +1191,7 @@ function core.on_dir_change(watch_id, action, filepath)
|
||||||
core.dir_rescan_add_job(dir, filepath)
|
core.dir_rescan_add_job(dir, filepath)
|
||||||
if action == "delete" then
|
if action == "delete" then
|
||||||
project_scan_remove_file(dir, filepath)
|
project_scan_remove_file(dir, filepath)
|
||||||
|
core.on_dirmonitor_delete(dir, filepath)
|
||||||
elseif action == "create" then
|
elseif action == "create" then
|
||||||
project_scan_add_file(dir, filepath)
|
project_scan_add_file(dir, filepath)
|
||||||
core.on_dirmonitor_modify(dir, filepath);
|
core.on_dirmonitor_modify(dir, filepath);
|
||||||
|
|
|
@ -237,8 +237,13 @@ function tokenizer.tokenize(incoming_syntax, text, state)
|
||||||
|
|
||||||
-- consume character if we didn't match
|
-- consume character if we didn't match
|
||||||
if not matched then
|
if not matched then
|
||||||
push_token(res, "normal", text:sub(i, i))
|
local n = 0
|
||||||
i = i + 1
|
-- reach the next character
|
||||||
|
while text:byte(i + n + 1) and common.is_utf8_cont(text, i + n + 1) do
|
||||||
|
n = n + 1
|
||||||
|
end
|
||||||
|
push_token(res, "normal", text:sub(i, i + n))
|
||||||
|
i = i + n + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
local syntax = require "core.syntax"
|
local syntax = require "core.syntax"
|
||||||
|
|
||||||
syntax.add {
|
syntax.add {
|
||||||
|
name = "C",
|
||||||
files = { "%.c$", "%.h$", "%.inl$" },
|
files = { "%.c$", "%.h$", "%.inl$" },
|
||||||
comment = "//",
|
comment = "//",
|
||||||
patterns = {
|
patterns = {
|
||||||
|
|
|
@ -4,6 +4,7 @@ pcall(require, "plugins.language_c")
|
||||||
local syntax = require "core.syntax"
|
local syntax = require "core.syntax"
|
||||||
|
|
||||||
syntax.add {
|
syntax.add {
|
||||||
|
name = "C++",
|
||||||
files = {
|
files = {
|
||||||
"%.h$", "%.inl$", "%.cpp$", "%.cc$", "%.C$", "%.cxx$",
|
"%.h$", "%.inl$", "%.cpp$", "%.cc$", "%.C$", "%.cxx$",
|
||||||
"%.c++$", "%.hh$", "%.H$", "%.hxx$", "%.hpp$", "%.h++$"
|
"%.c++$", "%.hh$", "%.H$", "%.hxx$", "%.hpp$", "%.h++$"
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
local syntax = require "core.syntax"
|
local syntax = require "core.syntax"
|
||||||
|
|
||||||
syntax.add {
|
syntax.add {
|
||||||
|
name = "CSS",
|
||||||
files = { "%.css$" },
|
files = { "%.css$" },
|
||||||
patterns = {
|
patterns = {
|
||||||
{ pattern = "\\.", type = "normal" },
|
{ pattern = "\\.", type = "normal" },
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
local syntax = require "core.syntax"
|
local syntax = require "core.syntax"
|
||||||
|
|
||||||
syntax.add {
|
syntax.add {
|
||||||
|
name = "HTML",
|
||||||
files = { "%.html?$" },
|
files = { "%.html?$" },
|
||||||
patterns = {
|
patterns = {
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
local syntax = require "core.syntax"
|
local syntax = require "core.syntax"
|
||||||
|
|
||||||
syntax.add {
|
syntax.add {
|
||||||
|
name = "JavaScript",
|
||||||
files = { "%.js$", "%.json$", "%.cson$" },
|
files = { "%.js$", "%.json$", "%.cson$" },
|
||||||
comment = "//",
|
comment = "//",
|
||||||
patterns = {
|
patterns = {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
local syntax = require "core.syntax"
|
local syntax = require "core.syntax"
|
||||||
|
|
||||||
syntax.add {
|
syntax.add {
|
||||||
|
name = "Lua",
|
||||||
files = "%.lua$",
|
files = "%.lua$",
|
||||||
headers = "^#!.*[ /]lua",
|
headers = "^#!.*[ /]lua",
|
||||||
comment = "--",
|
comment = "--",
|
||||||
|
|
|
@ -4,6 +4,7 @@ local syntax = require "core.syntax"
|
||||||
|
|
||||||
|
|
||||||
syntax.add {
|
syntax.add {
|
||||||
|
name = "Markdown",
|
||||||
files = { "%.md$", "%.markdown$" },
|
files = { "%.md$", "%.markdown$" },
|
||||||
patterns = {
|
patterns = {
|
||||||
{ pattern = "\\.", type = "normal" },
|
{ pattern = "\\.", type = "normal" },
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
local syntax = require "core.syntax"
|
local syntax = require "core.syntax"
|
||||||
|
|
||||||
syntax.add {
|
syntax.add {
|
||||||
|
name = "Python",
|
||||||
files = { "%.py$", "%.pyw$" },
|
files = { "%.py$", "%.pyw$" },
|
||||||
headers = "^#!.*[ /]python",
|
headers = "^#!.*[ /]python",
|
||||||
comment = "#",
|
comment = "#",
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
local syntax = require "core.syntax"
|
local syntax = require "core.syntax"
|
||||||
|
|
||||||
syntax.add {
|
syntax.add {
|
||||||
|
name = "XML",
|
||||||
files = { "%.xml$" },
|
files = { "%.xml$" },
|
||||||
headers = "<%?xml",
|
headers = "<%?xml",
|
||||||
patterns = {
|
patterns = {
|
||||||
|
|
|
@ -2,10 +2,12 @@
|
||||||
local config = require "core.config"
|
local config = require "core.config"
|
||||||
local style = require "core.style"
|
local style = require "core.style"
|
||||||
local DocView = require "core.docview"
|
local DocView = require "core.docview"
|
||||||
|
local CommandView = require "core.commandview"
|
||||||
|
|
||||||
local draw_overlay = DocView.draw_overlay
|
local draw_overlay = DocView.draw_overlay
|
||||||
|
|
||||||
function DocView:draw_overlay(...)
|
function DocView:draw_overlay(...)
|
||||||
|
if not self:is(CommandView) then
|
||||||
local ns = ("n"):rep(config.line_limit)
|
local ns = ("n"):rep(config.line_limit)
|
||||||
local ss = self:get_font():subpixel_scale()
|
local ss = self:get_font():subpixel_scale()
|
||||||
local offset = self:get_font():get_width_subpixel(ns) / ss
|
local offset = self:get_font():get_width_subpixel(ns) / ss
|
||||||
|
@ -16,6 +18,6 @@ function DocView:draw_overlay(...)
|
||||||
|
|
||||||
local color = style.guide or style.selection
|
local color = style.guide or style.selection
|
||||||
renderer.draw_rect(x, y, w, h, color)
|
renderer.draw_rect(x, y, w, h, color)
|
||||||
|
end
|
||||||
draw_overlay(self, ...)
|
draw_overlay(self, ...)
|
||||||
end
|
end
|
||||||
|
|
|
@ -42,6 +42,19 @@ function TreeView:new()
|
||||||
self.target_size = default_treeview_size
|
self.target_size = default_treeview_size
|
||||||
self.cache = {}
|
self.cache = {}
|
||||||
self.tooltip = { x = 0, y = 0, begin = 0, alpha = 0 }
|
self.tooltip = { x = 0, y = 0, begin = 0, alpha = 0 }
|
||||||
|
self:add_core_hooks()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function TreeView:add_core_hooks()
|
||||||
|
-- When a file or directory is deleted we delete the corresponding cache entry
|
||||||
|
-- because if the entry is recreated we may use wrong information from cache.
|
||||||
|
local on_delete = core.on_dirmonitor_delete
|
||||||
|
core.on_dirmonitor_delete = function(dir, filepath)
|
||||||
|
local cache = self.cache[dir.name]
|
||||||
|
if cache then cache[filepath] = nil end
|
||||||
|
on_delete(dir, filepath)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -723,6 +723,13 @@ static int f_watch_dir(lua_State *L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int f_unwatch_dir(lua_State *L) {
|
||||||
|
dmon_watch_id watch_id;
|
||||||
|
watch_id.id = luaL_checkinteger(L, 1);
|
||||||
|
dmon_unwatch(watch_id);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#if __linux__
|
#if __linux__
|
||||||
static int f_watch_dir_add(lua_State *L) {
|
static int f_watch_dir_add(lua_State *L) {
|
||||||
dmon_watch_id watch_id;
|
dmon_watch_id watch_id;
|
||||||
|
@ -826,6 +833,7 @@ static const luaL_Reg lib[] = {
|
||||||
{ "fuzzy_match", f_fuzzy_match },
|
{ "fuzzy_match", f_fuzzy_match },
|
||||||
{ "set_window_opacity", f_set_window_opacity },
|
{ "set_window_opacity", f_set_window_opacity },
|
||||||
{ "watch_dir", f_watch_dir },
|
{ "watch_dir", f_watch_dir },
|
||||||
|
{ "unwatch_dir", f_unwatch_dir },
|
||||||
{ "path_compare", f_path_compare },
|
{ "path_compare", f_path_compare },
|
||||||
#if __linux__
|
#if __linux__
|
||||||
{ "watch_dir_add", f_watch_dir_add },
|
{ "watch_dir_add", f_watch_dir_add },
|
||||||
|
|
Loading…
Reference in New Issue