Remove runtime command, use shell expansion to source files in rc dir.
With the help of a new kak_runtime env var.
This commit is contained in:
parent
f9e31856cf
commit
82a2bb37e7
|
@ -609,35 +609,6 @@ void exec_commands_in_file(const CommandParameters& params,
|
|||
CommandManager::instance().execute(file_content, context);
|
||||
}
|
||||
|
||||
void exec_commands_in_runtime_file(const CommandParameters& params,
|
||||
Context& context)
|
||||
{
|
||||
if (params.size() != 1)
|
||||
throw wrong_argument_count();
|
||||
|
||||
const String& filename = params[0];
|
||||
char buffer[2048];
|
||||
#if defined(__linux__)
|
||||
ssize_t res = readlink("/proc/self/exe", buffer, 2048 - (int)filename.length());
|
||||
assert(res != -1);
|
||||
buffer[res] = '\0';
|
||||
#elif defined(__APPLE__)
|
||||
uint32_t bufsize = 2048 - (int)filename.length();
|
||||
_NSGetExecutablePath(buffer, &bufsize);
|
||||
char* canonical_path = realpath(buffer, NULL);
|
||||
strncpy(buffer, canonical_path, 2048 - (int)filename.length());
|
||||
free(canonical_path);
|
||||
#else
|
||||
# error "finding executable path is not implemented on this platform"
|
||||
#endif
|
||||
char* ptr = strrchr(buffer, '/');
|
||||
if (ptr)
|
||||
{
|
||||
strcpy(ptr+1, filename.c_str());
|
||||
exec_commands_in_file(CommandParameters(buffer), context);
|
||||
}
|
||||
}
|
||||
|
||||
void set_option(OptionManager& option_manager, const CommandParameters& params,
|
||||
Context& context)
|
||||
{
|
||||
|
@ -849,7 +820,6 @@ void register_commands()
|
|||
cm.register_command("hook", add_hook);
|
||||
|
||||
cm.register_command("source", exec_commands_in_file, filename_completer);
|
||||
cm.register_command("runtime", exec_commands_in_runtime_file);
|
||||
|
||||
cm.register_command("exec", exec_string);
|
||||
cm.register_command("menu", menu);
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
hook global WinCreate .* %{ addhl regex \h+(?=\n) 0:default,red }
|
||||
hook global WinCreate .* %{ addhl number_lines }
|
||||
|
||||
runtime rc/cpp.kak
|
||||
runtime rc/kakrc.kak
|
||||
runtime rc/asciidoc.kak
|
||||
runtime rc/git.kak
|
||||
runtime rc/global.kak
|
||||
runtime rc/diff.kak
|
||||
runtime rc/make.kak
|
||||
runtime rc/grep.kak
|
||||
%sh{ for rcfile in ${kak_runtime}/rc/*; do echo "try %{ source '${rcfile}' } catch %{ }"; done }
|
||||
|
|
28
src/main.cc
28
src/main.cc
|
@ -302,6 +302,28 @@ void select_to_next_char(Context& context)
|
|||
});
|
||||
}
|
||||
|
||||
String runtime_directory()
|
||||
{
|
||||
char buffer[2048];
|
||||
#if defined(__linux__)
|
||||
ssize_t res = readlink("/proc/self/exe", buffer, 2048);
|
||||
assert(res != -1);
|
||||
buffer[res] = '\0';
|
||||
#elif defined(__APPLE__)
|
||||
uint32_t bufsize = 2048;
|
||||
_NSGetExecutablePath(buffer, &bufsize);
|
||||
char* canonical_path = realpath(buffer, NULL);
|
||||
strncpy(buffer, canonical_path, 2048);
|
||||
free(canonical_path);
|
||||
#else
|
||||
# error "finding executable path is not implemented on this platform"
|
||||
#endif
|
||||
char* ptr = strrchr(buffer, '/');
|
||||
if (not ptr)
|
||||
throw runtime_error("unable do determine runtime directory");
|
||||
return String(buffer, ptr);
|
||||
}
|
||||
|
||||
std::unordered_map<Key, std::function<void (Context& context)>> keymap =
|
||||
{
|
||||
{ { Key::Modifiers::None, 'h' }, [](Context& context) { context.editor().move_selections({ 0, -std::max(context.numeric_param(),1) }); } },
|
||||
|
@ -424,6 +446,9 @@ int main(int argc, char* argv[])
|
|||
shell_manager.register_env_var("selection",
|
||||
[](const String& name, const Context& context)
|
||||
{ return context.window().selections_content().back(); });
|
||||
shell_manager.register_env_var("runtime",
|
||||
[](const String& name, const Context& context)
|
||||
{ return runtime_directory(); });
|
||||
shell_manager.register_env_var("opt_.+",
|
||||
[](const String& name, const Context& context)
|
||||
{ return context.option_manager()[name.substr(4)].as_string(); });
|
||||
|
@ -446,7 +471,8 @@ int main(int argc, char* argv[])
|
|||
try
|
||||
{
|
||||
Context initialisation_context;
|
||||
command_manager.execute("runtime kakrc", initialisation_context);
|
||||
command_manager.execute("source " + runtime_directory() + "/kakrc",
|
||||
initialisation_context);
|
||||
}
|
||||
catch (Kakoune::runtime_error& error)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user