Allow opening non existing files from arguments
This commit is contained in:
parent
9763701cbf
commit
000caf2e43
|
@ -593,6 +593,25 @@ local function add_config_files_hooks()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- The function below works like system.absolute_path except it
|
||||||
|
-- doesn't fail if the file does not exist. We consider that the
|
||||||
|
-- current dir is core.project_dir so relative filename are considered
|
||||||
|
-- to be in core.project_dir.
|
||||||
|
-- Please note that .. or . in the filename are not taken into account.
|
||||||
|
-- This function should get only filenames normalized using
|
||||||
|
-- common.normalize_path function.
|
||||||
|
function core.project_absolute_path(filename)
|
||||||
|
if filename:match('^%a:\\') or filename:find('/', 1, true) == 1 then
|
||||||
|
return common.normalize_path(filename)
|
||||||
|
elseif not core.project_dir then
|
||||||
|
local cwd = system.absolute_path(".")
|
||||||
|
return cwd .. PATHSEP .. common.normalize_path(filename)
|
||||||
|
else
|
||||||
|
return core.project_dir .. PATHSEP .. filename
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function core.init()
|
function core.init()
|
||||||
command = require "core.command"
|
command = require "core.command"
|
||||||
keymap = require "core.keymap"
|
keymap = require "core.keymap"
|
||||||
|
@ -626,23 +645,20 @@ function core.init()
|
||||||
local project_dir = core.recent_projects[1] or "."
|
local project_dir = core.recent_projects[1] or "."
|
||||||
local project_dir_explicit = false
|
local project_dir_explicit = false
|
||||||
local files = {}
|
local files = {}
|
||||||
local delayed_error
|
|
||||||
for i = 2, #ARGS do
|
for i = 2, #ARGS do
|
||||||
local arg_filename = strip_trailing_slash(ARGS[i])
|
local arg_filename = strip_trailing_slash(ARGS[i])
|
||||||
local info = system.get_file_info(arg_filename) or {}
|
local info = system.get_file_info(arg_filename) or {}
|
||||||
if info.type == "file" then
|
if info.type == "dir" then
|
||||||
local file_abs = system.absolute_path(arg_filename)
|
|
||||||
if file_abs then
|
|
||||||
table.insert(files, file_abs)
|
|
||||||
project_dir = file_abs:match("^(.+)[/\\].+$")
|
|
||||||
end
|
|
||||||
elseif info.type == "dir" then
|
|
||||||
project_dir = arg_filename
|
project_dir = arg_filename
|
||||||
project_dir_explicit = true
|
project_dir_explicit = true
|
||||||
else
|
else
|
||||||
-- on macOS we can get an argument like "-psn_0_52353" that we just ignore.
|
-- on macOS we can get an argument like "-psn_0_52353" that we just ignore.
|
||||||
if not ARGS[i]:match("^-psn") then
|
if not ARGS[i]:match("^-psn") then
|
||||||
delayed_error = string.format("error: invalid file or directory %q", ARGS[i])
|
local file_abs = core.project_absolute_path(arg_filename)
|
||||||
|
if file_abs then
|
||||||
|
table.insert(files, file_abs)
|
||||||
|
project_dir = file_abs:match("^(.+)[/\\].+$")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -728,10 +744,6 @@ function core.init()
|
||||||
core.root_view:open_doc(core.open_doc(filename))
|
core.root_view:open_doc(core.open_doc(filename))
|
||||||
end
|
end
|
||||||
|
|
||||||
if delayed_error then
|
|
||||||
core.error(delayed_error)
|
|
||||||
end
|
|
||||||
|
|
||||||
if not plugins_success or got_user_error or got_project_error then
|
if not plugins_success or got_user_error or got_project_error then
|
||||||
command.perform("core:open-log")
|
command.perform("core:open-log")
|
||||||
end
|
end
|
||||||
|
@ -1002,22 +1014,6 @@ function core.normalize_to_project_dir(filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- The function below works like system.absolute_path except it
|
|
||||||
-- doesn't fail if the file does not exist. We consider that the
|
|
||||||
-- current dir is core.project_dir so relative filename are considered
|
|
||||||
-- to be in core.project_dir.
|
|
||||||
-- Please note that .. or . in the filename are not taken into account.
|
|
||||||
-- This function should get only filenames normalized using
|
|
||||||
-- common.normalize_path function.
|
|
||||||
function core.project_absolute_path(filename)
|
|
||||||
if filename:match('^%a:\\') or filename:find('/', 1, true) == 1 then
|
|
||||||
return filename
|
|
||||||
else
|
|
||||||
return core.project_dir .. PATHSEP .. filename
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function core.open_doc(filename)
|
function core.open_doc(filename)
|
||||||
local new_file = not filename or not system.get_file_info(filename)
|
local new_file = not filename or not system.get_file_info(filename)
|
||||||
local abs_filename
|
local abs_filename
|
||||||
|
|
Loading…
Reference in New Issue