From f9f11aa7627761dd52bf12679190184cb807225e Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 6 Jan 2017 19:43:20 +0000 Subject: [PATCH] Make the currently sourced file path available through $kak_source The :source command sets an 'source' value to the real path of the file getting sourced while its commands are executed. Fixes #1112 --- README.asciidoc | 1 + doc/manpages/expansions.asciidoc | 3 +++ src/commands.cc | 6 ++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index 3d9d46b8..9136b593 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -776,6 +776,7 @@ Some of Kakoune state is available through environment variables: * `kak_reg_`: value of register * `kak_session`: name of the current session * `kak_client`: name of current client + * `kak_source`: path of the file currently getting executed (through the source command) * `kak_cursor_line`: line of the end of the main selection * `kak_cursor_column`: column of the end of the main selection (in byte) * `kak_cursor_char_column`: column of the end of the main selection (in character) diff --git a/doc/manpages/expansions.asciidoc b/doc/manpages/expansions.asciidoc index 4d3304b1..fcf9701a 100644 --- a/doc/manpages/expansions.asciidoc +++ b/doc/manpages/expansions.asciidoc @@ -84,6 +84,9 @@ informations about Kakoune's state: name of the current session *kak_client*:: name of current client +*kak_source*:: + path of the file currently getting executed (through the source + command) *kak_cursor_line*:: line of the end of the main selection *kak_cursor_column*:: diff --git a/src/commands.cc b/src/commands.cc index 5b5eefcd..62b35c9d 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1180,10 +1180,12 @@ const CommandDesc source_cmd = { filename_completer, [](const ParametersParser& parser, Context& context, const ShellContext&) { - String file_content = read_file(parse_filename(parser[0]), true); + String path = real_path(parse_filename(parser[0])); + String file_content = read_file(path, true); try { - CommandManager::instance().execute(file_content, context); + CommandManager::instance().execute(file_content, context, + {{}, {{"source", path}}}); } catch (Kakoune::runtime_error& err) {