Skip to content

Commit de1516a

Browse files
committed
Replace on_scope_end with CTAD with OnScopeEnd directly
1 parent ce1d512 commit de1516a

File tree

13 files changed

+28
-34
lines changed

13 files changed

+28
-34
lines changed

src/buffer_utils.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ void write_buffer_to_file(Buffer& buffer, StringView filename,
221221
}
222222

223223
{
224-
auto close_fd = on_scope_end([fd]{ close(fd); });
224+
auto close_fd = OnScopeEnd([fd]{ close(fd); });
225225
write_buffer_to_fd(buffer, fd);
226226
if (flags & WriteFlags::Sync)
227227
::fsync(fd);
@@ -310,7 +310,7 @@ Buffer* create_fifo_buffer(String name, int fd, Buffer::Flags flags, AutoScroll
310310
const int fifo = fd();
311311

312312
{
313-
auto restore_flags = on_scope_end([this, flags=m_buffer.flags()] { m_buffer.flags() = flags; });
313+
auto restore_flags = OnScopeEnd([this, flags=m_buffer.flags()] { m_buffer.flags() = flags; });
314314
m_buffer.flags() &= ~Buffer::Flags::ReadOnly;
315315
do
316316
{

src/command_manager.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void CommandManager::load_module(StringView module_name, Context& context)
8282

8383
{
8484
module->value.state = Module::State::Loading;
85-
auto restore_state = on_scope_end([&] { module->value.state = Module::State::Registered; });
85+
auto restore_state = OnScopeEnd([&] { module->value.state = Module::State::Registered; });
8686

8787
Context empty_context{Context::EmptyContextFlag{}};
8888
execute(module->value.commands, empty_context);
@@ -526,7 +526,7 @@ void CommandManager::execute_single_command(CommandParameters params,
526526
throw runtime_error("maximum nested command depth hit");
527527

528528
++m_command_depth;
529-
auto pop_depth = on_scope_end([this] { --m_command_depth; });
529+
auto pop_depth = OnScopeEnd([this] { --m_command_depth; });
530530

531531
auto command_it = m_commands.find(resolve_alias(context, params[0]));
532532
if (command_it == m_commands.end())

src/commands.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,7 +2069,7 @@ void context_wrap(const ParametersParser& parser, Context& context, StringView d
20692069
const auto& register_manager = RegisterManager::instance();
20702070
auto make_register_restorer = [&](char c) {
20712071
auto& reg = register_manager[c];
2072-
return on_scope_end([&, c, save=reg.save(context), d=ScopedSetBool{reg.modified_hook_disabled()}] {
2072+
return OnScopeEnd([&, c, save=reg.save(context), d=ScopedSetBool{reg.modified_hook_disabled()}] {
20732073
try
20742074
{
20752075
reg.restore(context, save);
@@ -2328,7 +2328,7 @@ const CommandDesc prompt_cmd = {
23282328
return;
23292329

23302330
sc.env_vars["text"_sv] = String{String::NoCopy{}, str};
2331-
auto remove_text = on_scope_end([&] {
2331+
auto remove_text = OnScopeEnd([&] {
23322332
sc.env_vars.erase("text"_sv);
23332333
});
23342334

src/debug.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void write_to_debug_buffer(StringView str)
2323
if (Buffer* buffer = BufferManager::instance().get_buffer_ifp(debug_buffer_name))
2424
{
2525
buffer->flags() &= ~Buffer::Flags::ReadOnly;
26-
auto restore = on_scope_end([buffer] { buffer->flags() |= Buffer::Flags::ReadOnly; });
26+
auto restore = OnScopeEnd([buffer] { buffer->flags() |= Buffer::Flags::ReadOnly; });
2727

2828
buffer->insert(buffer->back_coord(), eol_back ? str : str + "\n");
2929
}

src/file.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ String read_file(StringView filename, bool text)
194194
if (fd == -1)
195195
throw file_access_error(filename, strerror(errno));
196196

197-
auto close_fd = on_scope_end([fd]{ close(fd); });
197+
auto close_fd = OnScopeEnd([fd]{ close(fd); });
198198
return read_fd(fd, text);
199199
}
200200

@@ -204,7 +204,7 @@ MappedFile::MappedFile(StringView filename)
204204
int fd = open(filename.zstr(), O_RDONLY | O_NONBLOCK);
205205
if (fd == -1)
206206
throw file_access_error(filename, strerror(errno));
207-
auto close_fd = on_scope_end([&] { close(fd); });
207+
auto close_fd = OnScopeEnd([&] { close(fd); });
208208

209209
fstat(fd, &st);
210210
if (S_ISDIR(st.st_mode))
@@ -253,7 +253,7 @@ void write(int fd, StringView data)
253253
int flags = fcntl(fd, F_GETFL, 0);
254254
if (not atomic and EventManager::has_instance())
255255
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
256-
auto restore_flags = on_scope_end([&] { fcntl(fd, F_SETFL, flags); });
256+
auto restore_flags = OnScopeEnd([&] { fcntl(fd, F_SETFL, flags); });
257257

258258
while (count)
259259
{
@@ -291,7 +291,7 @@ void write_to_file(StringView filename, StringView data)
291291
int fd = create_file(filename.zstr());
292292
if (fd == -1)
293293
throw file_access_error(filename, strerror(errno));
294-
auto close_fd = on_scope_end([fd]{ close(fd); });
294+
auto close_fd = OnScopeEnd([fd]{ close(fd); });
295295
write(fd, data);
296296
}
297297

@@ -358,7 +358,7 @@ void make_directory(StringView dir, mode_t mode)
358358
else
359359
{
360360
auto old_mask = umask(0);
361-
auto restore_mask = on_scope_end([old_mask]() { umask(old_mask); });
361+
auto restore_mask = OnScopeEnd([old_mask]() { umask(old_mask); });
362362

363363
if (mkdir(dirname.zstr(), mode) != 0)
364364
throw runtime_error(format("mkdir failed for directory '{}' errno {}", dirname, errno));
@@ -374,7 +374,7 @@ void list_files(StringView dirname, FunctionRef<void (StringView, const struct s
374374
if (not dir)
375375
return;
376376

377-
auto close_dir = on_scope_end([dir]{ closedir(dir); });
377+
auto close_dir = OnScopeEnd([dir]{ closedir(dir); });
378378

379379
while (dirent* entry = readdir(dir))
380380
{

src/highlighters.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,7 @@ struct ReferenceHighlighter : Highlighter
16881688
return write_to_debug_buffer(format("highlighting recursion detected with ref to {}", m_name));
16891689

16901690
running_refs.push_back(desc);
1691-
auto pop_desc = on_scope_end([] { running_refs.pop_back(); });
1691+
auto pop_desc = OnScopeEnd([] { running_refs.pop_back(); });
16921692

16931693
try
16941694
{

src/hook_manager.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void HookManager::run_hook(Hook hook, StringView param, Context& context)
130130
}
131131

132132
m_running_hooks.emplace_back(hook, param);
133-
auto pop_running_hook = on_scope_end([this]{
133+
auto pop_running_hook = OnScopeEnd([this]{
134134
m_running_hooks.pop_back();
135135
if (m_running_hooks.empty())
136136
m_hooks_trash.clear();

src/input_handler.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ class Normal : public InputMode
288288
ScopedSetBool set_in_on_key{m_in_on_key};
289289

290290
bool do_restore_hooks = false;
291-
auto restore_hooks = on_scope_end([&, this]{
291+
auto restore_hooks = OnScopeEnd([&, this]{
292292
if (m_hooks_disabled and enabled() and do_restore_hooks)
293293
{
294294
context().hooks_disabled().unset();
@@ -340,7 +340,7 @@ class Normal : public InputMode
340340
}
341341
else
342342
{
343-
auto pop_if_single_command = on_scope_end([this] {
343+
auto pop_if_single_command = OnScopeEnd([this] {
344344
if (m_state == State::SingleCommand and enabled())
345345
pop_mode();
346346
else if (m_state == State::SingleCommand)
@@ -1682,7 +1682,7 @@ void InputHandler::handle_key(Key key, bool synthesized)
16821682
return;
16831683

16841684
++m_handle_key_level;
1685-
auto dec = on_scope_end([this]{ --m_handle_key_level;} );
1685+
auto dec = OnScopeEnd([this]{ --m_handle_key_level;} );
16861686

16871687
if (not synthesized)
16881688
current_mode().on_raw_key();

src/normal.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ void join_lines(Context& context, NormalParams params)
12291229
{
12301230
ScopedSelectionEdition selection_edition{context};
12311231
SelectionList sels{context.selections()};
1232-
auto restore_sels = on_scope_end([&]{
1232+
auto restore_sels = OnScopeEnd([&]{
12331233
sels.update();
12341234
context.selections_write_only() = std::move(sels);
12351235
});
@@ -1690,7 +1690,7 @@ void replay_macro(Context& context, NormalParams params)
16901690
throw runtime_error(format("register '{}' is empty", reg));
16911691

16921692
running_macros[idx] = true;
1693-
auto stop = on_scope_end([&]{ running_macros[idx] = false; });
1693+
auto stop = OnScopeEnd([&]{ running_macros[idx] = false; });
16941694

16951695
auto keys = parse_keys(reg_val[0]);
16961696
ScopedEdition edition(context);

src/remote.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ static int connect_to(StringView session)
650650
bool check_session(StringView session)
651651
{
652652
int sock = socket(AF_UNIX, SOCK_STREAM, 0);
653-
auto close_sock = on_scope_end([sock]{ close(sock); });
653+
auto close_sock = OnScopeEnd([sock]{ close(sock); });
654654
sockaddr_un addr = session_addr(session);
655655
return connect(sock, (sockaddr*)&addr, sizeof(addr.sun_path)) != -1;
656656
}
@@ -704,7 +704,7 @@ RemoteClient::RemoteClient(StringView session, StringView name, UniquePtr<UserIn
704704
if (not reader.ready())
705705
continue;
706706

707-
auto clear_reader = on_scope_end([&reader] { reader.reset(); });
707+
auto clear_reader = OnScopeEnd([&reader] { reader.reset(); });
708708
switch (reader.type())
709709
{
710710
case MessageType::MenuShow:
@@ -756,7 +756,7 @@ bool RemoteClient::is_ui_ok() const
756756
void send_command(StringView session, StringView command)
757757
{
758758
int sock = connect_to(session);
759-
auto close_sock = on_scope_end([sock]{ close(sock); });
759+
auto close_sock = OnScopeEnd([sock]{ close(sock); });
760760
RemoteBuffer buffer;
761761
{
762762
MsgWriter msg{buffer, MessageType::Command};
@@ -863,7 +863,7 @@ Server::Server(String session_name, bool is_daemon)
863863

864864
// Do not give any access to the socket to other users by default
865865
auto old_mask = umask(0077);
866-
auto restore_mask = on_scope_end([old_mask]() { umask(old_mask); });
866+
auto restore_mask = OnScopeEnd([old_mask]() { umask(old_mask); });
867867

868868
if (bind(listen_sock, (sockaddr*) &addr, sizeof(sockaddr_un)) == -1)
869869
throw runtime_error(format("unable to bind listen socket '{}': {}",

0 commit comments

Comments
 (0)