1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-25 04:24:48 +03:00

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
This commit is contained in:
Maxime Coste 2017-01-06 19:43:20 +00:00
parent d2199bc619
commit f9f11aa762
3 changed files with 8 additions and 2 deletions

View File

@ -776,6 +776,7 @@ Some of Kakoune state is available through environment variables:
* `kak_reg_<r>`: value of register <r> * `kak_reg_<r>`: value of register <r>
* `kak_session`: name of the current session * `kak_session`: name of the current session
* `kak_client`: name of current client * `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_line`: line of the end of the main selection
* `kak_cursor_column`: column of the end of the main selection (in byte) * `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) * `kak_cursor_char_column`: column of the end of the main selection (in character)

View File

@ -84,6 +84,9 @@ informations about Kakoune's state:
name of the current session name of the current session
*kak_client*:: *kak_client*::
name of current client name of current client
*kak_source*::
path of the file currently getting executed (through the source
command)
*kak_cursor_line*:: *kak_cursor_line*::
line of the end of the main selection line of the end of the main selection
*kak_cursor_column*:: *kak_cursor_column*::

View File

@ -1180,10 +1180,12 @@ const CommandDesc source_cmd = {
filename_completer, filename_completer,
[](const ParametersParser& parser, Context& context, const ShellContext&) [](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 try
{ {
CommandManager::instance().execute(file_content, context); CommandManager::instance().execute(file_content, context,
{{}, {{"source", path}}});
} }
catch (Kakoune::runtime_error& err) catch (Kakoune::runtime_error& err)
{ {