1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-08-17 00:30:26 +03:00

Compare commits

...

6 Commits

Author SHA1 Message Date
Philipp Jungkamp
a4fb92eb5c
Merge 0a10612786 into 374a7a8c99 2024-06-24 14:16:47 +00:00
Philipp Jungkamp
0a10612786 Add EnterDirectory hook
This hook runs on `change-directory` and is also emitted just before
KakBegin after kakrc has been sourced.
2024-06-24 16:16:33 +02:00
Philipp Jungkamp
07000adb9b Philipp Jungkamp Copyright Waiver
I dedicate any and all copyright interest in this software to the
public domain.  I make this dedication for the benefit of the public at
large and to the detriment of my heirs and successors.  I intend this
dedication to be an overt act of relinquishment in perpetuity of all
present and future rights to this software under copyright law.
2024-06-24 16:16:33 +02:00
Maxime Coste
374a7a8c99 Remove some selection copies in pipe and throw early if read only
Throwing early avoids losing selections in this case.
2024-06-24 21:18:17 +10:00
Maxime Coste
6674fe7587 Merge remote-tracking branch 'stacyharper/elixir-heex' 2024-06-23 11:14:34 +10:00
Willow Barraco
0bb355557e
elixir: detect heex additionaly to leex 2024-06-19 12:45:20 +02:00
6 changed files with 26 additions and 8 deletions

View File

@ -147,6 +147,11 @@ name. Hooks with no description will always use an empty string.
*SessionRenamed* `<old name>:<new name>`::
executed when a session is renamed using the `rename-session` command
*EnterDirectory* `path`::
executed on startup and when the current working directory is changed
using the `change-directory` command. The hook param is an absolute path
to the new working directory.
*RuntimeError* `error message`::
an error was encountered while executing a user command

View File

@ -8,7 +8,7 @@ hook global BufCreate .*[.](ex|exs) %{
set-option buffer filetype elixir
}
hook global BufCreate .*[.]html[.]l?eex %{
hook global BufCreate .*[.]html[.][lh]?eex %{
set-option buffer filetype eex
}
@ -64,6 +64,7 @@ add-highlighter shared/elixir/single_string region "'" "(?<!\\)(?:\\\\)*'" fill
add-highlighter shared/elixir/comment region '#' '$' fill comment
add-highlighter shared/elixir/leex region -match-capture '~L("""|")' '(?<!\\)(?:\\\\)*("""|")' ref eex
add-highlighter shared/elixir/heex region -match-capture '~H("""|")' '(?<!\\)(?:\\\\)*("""|")' ref eex
add-highlighter shared/elixir/double_string/base default-region fill string
add-highlighter shared/elixir/double_string/interpolation region -recurse \{ \Q#{ \} fill builtin

View File

@ -2600,13 +2600,15 @@ const CommandDesc change_directory_cmd = {
cursor_pos, FilenameFlags::OnlyDirectories),
Completions::Flags::Menu };
}),
[](const ParametersParser& parser, Context&, const ShellContext&)
[](const ParametersParser& parser, Context& ctx, const ShellContext&)
{
StringView target = parser.positional_count() == 1 ? StringView{parser[0]} : "~";
if (chdir(parse_filename(target).c_str()) != 0)
auto path = real_path(parse_filename(target));
if (chdir(path.c_str()) != 0)
throw runtime_error(format("unable to change to directory: '{}'", target));
for (auto& buffer : BufferManager::instance())
buffer->update_display_name();
ctx.hooks().run_hook(Hook::EnterDirectory, path, ctx);
}
};

View File

@ -50,6 +50,7 @@ enum class Hook
NextKeyIdle,
NormalKey,
ModeChange,
EnterDirectory,
RawKey,
RegisterModified,
WinClose,
@ -97,6 +98,7 @@ constexpr auto enum_desc(Meta::Type<Hook>)
{Hook::NextKeyIdle, "NextKeyIdle"},
{Hook::NormalKey, "NormalKey"},
{Hook::ModeChange, "ModeChange"},
{Hook::EnterDirectory, "EnterDirectory"},
{Hook::RawKey, "RawKey"},
{Hook::RegisterModified, "RegisterModified"},
{Hook::WinClose, "WinClose"},

View File

@ -842,6 +842,7 @@ int run_server(StringView session, StringView server_init,
{
Context empty_context{Context::EmptyContextFlag{}};
global_scope.hooks().run_hook(Hook::EnterDirectory, real_path("."), empty_context);
global_scope.hooks().run_hook(Hook::KakBegin, session, empty_context);
}

View File

@ -589,13 +589,13 @@ void pipe(Context& context, NormalParams params)
return;
Buffer& buffer = context.buffer();
SelectionList selections = context.selections();
if (replace)
{
buffer.throw_if_read_only();
ScopedEdition edition(context);
ForwardChangesTracker changes_tracker;
size_t timestamp = buffer.timestamp();
Vector<Selection> new_sels;
SelectionList selections = context.selections();
for (auto& sel : selections)
{
const auto beg = changes_tracker.get_new_coord_tolerant(sel.min());
@ -614,20 +614,27 @@ void pipe(Context& context, NormalParams params)
auto new_end = apply_diff(buffer, beg, in, out);
if (new_end != beg)
new_sels.push_back(keep_direction({beg, buffer.char_prev(new_end), std::move(sel.captures())}, sel));
{
auto& min = sel.min();
auto& max = sel.max();
min = beg;
max = buffer.char_prev(new_end);
}
else
{
if (new_end != BufferCoord{})
new_end = buffer.char_prev(new_end);
new_sels.push_back({new_end, new_end, std::move(sel.captures())});
sel.set(new_end);
}
changes_tracker.update(buffer, timestamp);
}
context.selections_write_only().set(std::move(new_sels), selections.main_index());
selections.force_timestamp(timestamp);
context.selections_write_only() = std::move(selections);
}
else
{
SelectionList& selections = context.selections();
const auto old_main = selections.main_index();
for (int i = 0; i < selections.size(); ++i)
{