Merge branch 'master' into hierarchical-highlighters
This commit is contained in:
commit
1c69764774
|
@ -784,10 +784,14 @@ existing hooks are:
|
||||||
* +BufOpen+: A buffer for an existing file has been created, filename is
|
* +BufOpen+: A buffer for an existing file has been created, filename is
|
||||||
used for filtering
|
used for filtering
|
||||||
* +BufCreate+: A buffer has been created, filename is used for filtering
|
* +BufCreate+: A buffer has been created, filename is used for filtering
|
||||||
* +BufWritePre+: Executre just before a buffer is written, filename is
|
* +BufWritePre+: Executed just before a buffer is written, filename is
|
||||||
used for filtering.
|
used for filtering.
|
||||||
* +BufWritePost+: Executre just after a buffer is written, filename is
|
* +BufWritePost+: Executed just after a buffer is written, filename is
|
||||||
used for filtering.
|
used for filtering.
|
||||||
|
* +BufClose+: Executed when a buffer is deleted, while it is still valid.
|
||||||
|
* +BufCloseFifo+: Executed when a fifo buffer closes its fifo file descriptor
|
||||||
|
either because the buffer is being deleted, or because the writing
|
||||||
|
end has been closed.
|
||||||
* +RuntimeError+: an error was encountered while executing an user command
|
* +RuntimeError+: an error was encountered while executing an user command
|
||||||
the error message is used for filtering
|
the error message is used for filtering
|
||||||
* +KakBegin+: Kakoune started, this is called just after reading the user
|
* +KakBegin+: Kakoune started, this is called just after reading the user
|
||||||
|
|
|
@ -39,7 +39,7 @@ def -shell-params \
|
||||||
echo "eval -try-client '$kak_opt_docsclient' %{
|
echo "eval -try-client '$kak_opt_docsclient' %{
|
||||||
edit! -fifo ${output} *git*
|
edit! -fifo ${output} *git*
|
||||||
set buffer filetype '${filetype}'
|
set buffer filetype '${filetype}'
|
||||||
hook buffer BufClose .* %{ nop %sh{ rm -r $(dirname ${output}) } }
|
hook buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } }
|
||||||
}"
|
}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ def -shell-params -file-completion \
|
||||||
echo "eval -try-client '$kak_opt_toolsclient' %{
|
echo "eval -try-client '$kak_opt_toolsclient' %{
|
||||||
edit! -fifo ${output} -scroll *grep*
|
edit! -fifo ${output} -scroll *grep*
|
||||||
set buffer filetype grep
|
set buffer filetype grep
|
||||||
hook buffer BufClose .* %{ nop %sh{ rm -r $(dirname ${output}) } }
|
hook buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } }
|
||||||
}"
|
}"
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
|
30
rc/make.kak
30
rc/make.kak
|
@ -1,5 +1,6 @@
|
||||||
decl str makecmd make
|
decl str makecmd make
|
||||||
decl str toolsclient
|
decl str toolsclient
|
||||||
|
decl -hidden int _make_current_error_line
|
||||||
|
|
||||||
def -shell-params make %{ %sh{
|
def -shell-params make %{ %sh{
|
||||||
output=$(mktemp -d -t kak-make.XXXXXXXX)/fifo
|
output=$(mktemp -d -t kak-make.XXXXXXXX)/fifo
|
||||||
|
@ -9,7 +10,8 @@ def -shell-params make %{ %sh{
|
||||||
echo "eval -try-client '$kak_opt_toolsclient' %{
|
echo "eval -try-client '$kak_opt_toolsclient' %{
|
||||||
edit! -fifo ${output} -scroll *make*
|
edit! -fifo ${output} -scroll *make*
|
||||||
set buffer filetype make
|
set buffer filetype make
|
||||||
hook buffer BufClose .* %{ nop %sh{ rm -r $(dirname ${output}) } }
|
set buffer _make_current_error_line 0
|
||||||
|
hook buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } }
|
||||||
}"
|
}"
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
@ -28,12 +30,30 @@ decl str jumpclient
|
||||||
def errjump -docstring 'Jump to error location' %{
|
def errjump -docstring 'Jump to error location' %{
|
||||||
try %{
|
try %{
|
||||||
exec gll<a-?> "Entering directory" <ret>
|
exec gll<a-?> "Entering directory" <ret>
|
||||||
exec s "Entering directory '([^']+)'.*\n([^:]+):(\d+):(\d+):[^\n]+\'" <ret>l
|
exec s "Entering directory '([^']+)'.*\n([^:]+):(\d+):(\d+):([^\n]+)\'" <ret>l
|
||||||
eval -try-client %opt{jumpclient} edit %rec{%reg{1}/%reg{2}} %reg{3} %reg{4}
|
set buffer _make_current_error_line %val{cursor_line}
|
||||||
|
eval -try-client %opt{jumpclient} %rec{edit %reg{1}/%reg{2} %reg{3} %reg{4}; echo -color Information '%reg{5}'}
|
||||||
try %{ focus %opt{jumpclient} }
|
try %{ focus %opt{jumpclient} }
|
||||||
} catch %{
|
} catch %{
|
||||||
exec ghgl s "([^:]+):(\d+):(\d+):[^\n]+\'" <ret>l
|
exec ghgl s "([^:]+):(\d+):(\d+):([^\n]+)\'" <ret>l
|
||||||
eval -try-client %opt{jumpclient} edit %reg{1} %reg{2} %reg{3}
|
set buffer _make_current_error_line %val{cursor_line}
|
||||||
|
eval -try-client %opt{jumpclient} %rec{edit %reg{1} %reg{2} %reg{3}; echo -color Information '%reg{4}'}
|
||||||
try %{ focus %opt{jumpclient} }
|
try %{ focus %opt{jumpclient} }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def errnext -docstring 'Jump to next error' %{
|
||||||
|
eval -try-client %opt{jumpclient} %{
|
||||||
|
buffer '*make*'
|
||||||
|
exec %rec{%opt{_make_current_error_line}ggl/[0-9]+: error:<ret>}
|
||||||
|
errjump
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def errprev -docstring 'Jump to previous error' %{
|
||||||
|
eval -try-client %opt{jumpclient} %{
|
||||||
|
buffer '*make*'
|
||||||
|
exec %rec{%opt{_make_current_error_line}ggh<a-/>[0-9]+: error:<ret>}
|
||||||
|
errjump
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -64,6 +64,7 @@ Buffer* create_fifo_buffer(String name, int fd, bool scroll)
|
||||||
buffer->flags() &= ~Buffer::Flags::Fifo;
|
buffer->flags() &= ~Buffer::Flags::Fifo;
|
||||||
buffer->flags() &= ~Buffer::Flags::NoUndo;
|
buffer->flags() &= ~Buffer::Flags::NoUndo;
|
||||||
close(fifo);
|
close(fifo);
|
||||||
|
buffer->run_hook_in_own_context("BufCloseFifo", "");
|
||||||
delete &watcher;
|
delete &watcher;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -74,6 +75,7 @@ Buffer* create_fifo_buffer(String name, int fd, bool scroll)
|
||||||
if (buffer->flags() & Buffer::Flags::Fifo)
|
if (buffer->flags() & Buffer::Flags::Fifo)
|
||||||
{
|
{
|
||||||
close(watcher->fd());
|
close(watcher->fd());
|
||||||
|
buffer->run_hook_in_own_context("BufCloseFifo", "");
|
||||||
delete watcher;
|
delete watcher;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -55,6 +55,7 @@ struct Token
|
||||||
ShellExpand,
|
ShellExpand,
|
||||||
RegisterExpand,
|
RegisterExpand,
|
||||||
OptionExpand,
|
OptionExpand,
|
||||||
|
ValExpand,
|
||||||
CommandSeparator
|
CommandSeparator
|
||||||
};
|
};
|
||||||
Token() : m_type(Type::Raw) {}
|
Token() : m_type(Type::Raw) {}
|
||||||
|
@ -150,6 +151,8 @@ Token::Type token_type(StringView type_name)
|
||||||
return Token::Type::RegisterExpand;
|
return Token::Type::RegisterExpand;
|
||||||
else if (type_name == "opt")
|
else if (type_name == "opt")
|
||||||
return Token::Type::OptionExpand;
|
return Token::Type::OptionExpand;
|
||||||
|
else if (type_name == "val")
|
||||||
|
return Token::Type::ValExpand;
|
||||||
else if (type_name == "rec")
|
else if (type_name == "rec")
|
||||||
return Token::Type::RawEval;
|
return Token::Type::RawEval;
|
||||||
else if (throw_on_invalid)
|
else if (throw_on_invalid)
|
||||||
|
@ -316,6 +319,8 @@ String eval_token(const Token& token, Context& context,
|
||||||
return RegisterManager::instance()[content].values(context)[0];
|
return RegisterManager::instance()[content].values(context)[0];
|
||||||
case Token::Type::OptionExpand:
|
case Token::Type::OptionExpand:
|
||||||
return context.options()[content].get_as_string();
|
return context.options()[content].get_as_string();
|
||||||
|
case Token::Type::ValExpand:
|
||||||
|
return ShellManager::instance().get_val(content, context);
|
||||||
case Token::Type::RawEval:
|
case Token::Type::RawEval:
|
||||||
return eval(content, context, shell_params, env_vars);
|
return eval(content, context, shell_params, env_vars);
|
||||||
case Token::Type::Raw:
|
case Token::Type::Raw:
|
||||||
|
|
|
@ -108,21 +108,12 @@ String ShellManager::pipe(StringView input,
|
||||||
setenv(("kak_" + name).c_str(), local_var->second.c_str(), 1);
|
setenv(("kak_" + name).c_str(), local_var->second.c_str(), 1);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto env_var = std::find_if(
|
try
|
||||||
m_env_vars.begin(), m_env_vars.end(),
|
|
||||||
[&](const std::pair<Regex, EnvVarRetriever>& pair)
|
|
||||||
{ return boost::regex_match(name.begin(), name.end(),
|
|
||||||
pair.first); });
|
|
||||||
|
|
||||||
if (env_var != m_env_vars.end())
|
|
||||||
{
|
{
|
||||||
try
|
String value = get_val(name, context);
|
||||||
{
|
setenv(("kak_"_str + name).c_str(), value.c_str(), 1);
|
||||||
String value = env_var->second(name, context);
|
|
||||||
setenv(("kak_"_str + name).c_str(), value.c_str(), 1);
|
|
||||||
}
|
|
||||||
catch (runtime_error&) {}
|
|
||||||
}
|
}
|
||||||
|
catch (runtime_error&) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
++it;
|
++it;
|
||||||
|
@ -149,4 +140,17 @@ void ShellManager::register_env_var(StringView regex,
|
||||||
m_env_vars.push_back({ Regex(regex.begin(), regex.end()), std::move(retriever) });
|
m_env_vars.push_back({ Regex(regex.begin(), regex.end()), std::move(retriever) });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String ShellManager::get_val(StringView name, const Context& context) const
|
||||||
|
{
|
||||||
|
auto env_var = std::find_if(
|
||||||
|
m_env_vars.begin(), m_env_vars.end(),
|
||||||
|
[&](const std::pair<Regex, EnvVarRetriever>& pair)
|
||||||
|
{ return boost::regex_match(name.begin(), name.end(),
|
||||||
|
pair.first); });
|
||||||
|
|
||||||
|
if (env_var == m_env_vars.end())
|
||||||
|
throw runtime_error("no such env var: " + name);
|
||||||
|
return env_var->second(name, context);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ public:
|
||||||
int* exit_status = nullptr);
|
int* exit_status = nullptr);
|
||||||
|
|
||||||
void register_env_var(StringView regex, EnvVarRetriever retriever);
|
void register_env_var(StringView regex, EnvVarRetriever retriever);
|
||||||
|
String get_val(StringView name, const Context& context) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::pair<Regex, EnvVarRetriever>> m_env_vars;
|
std::vector<std::pair<Regex, EnvVarRetriever>> m_env_vars;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user