summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2025-07-08 11:52:44 +1000
committerMaxime Coste <mawww@kakoune.org>2025-07-08 12:07:33 +1000
commitde1516a8d822f72bddfb158126b6e609afc63c64 (patch)
tree9765b18349657a766b92046cd23976ad26815acf /src
parentce1d512a0c1922ab5f43f28e7bae573508c98601 (diff)
Replace on_scope_end with CTAD with OnScopeEnd directly
Diffstat (limited to 'src')
-rw-r--r--src/buffer_utils.cc4
-rw-r--r--src/command_manager.cc4
-rw-r--r--src/commands.cc4
-rw-r--r--src/debug.cc2
-rw-r--r--src/file.cc12
-rw-r--r--src/highlighters.cc2
-rw-r--r--src/hook_manager.cc2
-rw-r--r--src/input_handler.cc6
-rw-r--r--src/normal.cc4
-rw-r--r--src/remote.cc8
-rw-r--r--src/shell_manager.cc2
-rw-r--r--src/terminal_ui.cc2
-rw-r--r--src/utils.hh10
13 files changed, 28 insertions, 34 deletions
diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc
index dca1a372..cd6cd939 100644
--- a/src/buffer_utils.cc
+++ b/src/buffer_utils.cc
@@ -221,7 +221,7 @@ void write_buffer_to_file(Buffer& buffer, StringView filename,
}
{
- auto close_fd = on_scope_end([fd]{ close(fd); });
+ auto close_fd = OnScopeEnd([fd]{ close(fd); });
write_buffer_to_fd(buffer, fd);
if (flags & WriteFlags::Sync)
::fsync(fd);
@@ -310,7 +310,7 @@ Buffer* create_fifo_buffer(String name, int fd, Buffer::Flags flags, AutoScroll
const int fifo = fd();
{
- auto restore_flags = on_scope_end([this, flags=m_buffer.flags()] { m_buffer.flags() = flags; });
+ auto restore_flags = OnScopeEnd([this, flags=m_buffer.flags()] { m_buffer.flags() = flags; });
m_buffer.flags() &= ~Buffer::Flags::ReadOnly;
do
{
diff --git a/src/command_manager.cc b/src/command_manager.cc
index 0db97e94..28c9f075 100644
--- a/src/command_manager.cc
+++ b/src/command_manager.cc
@@ -82,7 +82,7 @@ void CommandManager::load_module(StringView module_name, Context& context)
{
module->value.state = Module::State::Loading;
- auto restore_state = on_scope_end([&] { module->value.state = Module::State::Registered; });
+ auto restore_state = OnScopeEnd([&] { module->value.state = Module::State::Registered; });
Context empty_context{Context::EmptyContextFlag{}};
execute(module->value.commands, empty_context);
@@ -526,7 +526,7 @@ void CommandManager::execute_single_command(CommandParameters params,
throw runtime_error("maximum nested command depth hit");
++m_command_depth;
- auto pop_depth = on_scope_end([this] { --m_command_depth; });
+ auto pop_depth = OnScopeEnd([this] { --m_command_depth; });
auto command_it = m_commands.find(resolve_alias(context, params[0]));
if (command_it == m_commands.end())
diff --git a/src/commands.cc b/src/commands.cc
index 351134f2..a190bb7b 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -2069,7 +2069,7 @@ void context_wrap(const ParametersParser& parser, Context& context, StringView d
const auto& register_manager = RegisterManager::instance();
auto make_register_restorer = [&](char c) {
auto& reg = register_manager[c];
- return on_scope_end([&, c, save=reg.save(context), d=ScopedSetBool{reg.modified_hook_disabled()}] {
+ return OnScopeEnd([&, c, save=reg.save(context), d=ScopedSetBool{reg.modified_hook_disabled()}] {
try
{
reg.restore(context, save);
@@ -2328,7 +2328,7 @@ const CommandDesc prompt_cmd = {
return;
sc.env_vars["text"_sv] = String{String::NoCopy{}, str};
- auto remove_text = on_scope_end([&] {
+ auto remove_text = OnScopeEnd([&] {
sc.env_vars.erase("text"_sv);
});
diff --git a/src/debug.cc b/src/debug.cc
index 55f7e4d3..19180f5f 100644
--- a/src/debug.cc
+++ b/src/debug.cc
@@ -23,7 +23,7 @@ void write_to_debug_buffer(StringView str)
if (Buffer* buffer = BufferManager::instance().get_buffer_ifp(debug_buffer_name))
{
buffer->flags() &= ~Buffer::Flags::ReadOnly;
- auto restore = on_scope_end([buffer] { buffer->flags() |= Buffer::Flags::ReadOnly; });
+ auto restore = OnScopeEnd([buffer] { buffer->flags() |= Buffer::Flags::ReadOnly; });
buffer->insert(buffer->back_coord(), eol_back ? str : str + "\n");
}
diff --git a/src/file.cc b/src/file.cc
index 67781044..eb17379c 100644
--- a/src/file.cc
+++ b/src/file.cc
@@ -194,7 +194,7 @@ String read_file(StringView filename, bool text)
if (fd == -1)
throw file_access_error(filename, strerror(errno));
- auto close_fd = on_scope_end([fd]{ close(fd); });
+ auto close_fd = OnScopeEnd([fd]{ close(fd); });
return read_fd(fd, text);
}
@@ -204,7 +204,7 @@ MappedFile::MappedFile(StringView filename)
int fd = open(filename.zstr(), O_RDONLY | O_NONBLOCK);
if (fd == -1)
throw file_access_error(filename, strerror(errno));
- auto close_fd = on_scope_end([&] { close(fd); });
+ auto close_fd = OnScopeEnd([&] { close(fd); });
fstat(fd, &st);
if (S_ISDIR(st.st_mode))
@@ -253,7 +253,7 @@ void write(int fd, StringView data)
int flags = fcntl(fd, F_GETFL, 0);
if (not atomic and EventManager::has_instance())
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
- auto restore_flags = on_scope_end([&] { fcntl(fd, F_SETFL, flags); });
+ auto restore_flags = OnScopeEnd([&] { fcntl(fd, F_SETFL, flags); });
while (count)
{
@@ -291,7 +291,7 @@ void write_to_file(StringView filename, StringView data)
int fd = create_file(filename.zstr());
if (fd == -1)
throw file_access_error(filename, strerror(errno));
- auto close_fd = on_scope_end([fd]{ close(fd); });
+ auto close_fd = OnScopeEnd([fd]{ close(fd); });
write(fd, data);
}
@@ -358,7 +358,7 @@ void make_directory(StringView dir, mode_t mode)
else
{
auto old_mask = umask(0);
- auto restore_mask = on_scope_end([old_mask]() { umask(old_mask); });
+ auto restore_mask = OnScopeEnd([old_mask]() { umask(old_mask); });
if (mkdir(dirname.zstr(), mode) != 0)
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
if (not dir)
return;
- auto close_dir = on_scope_end([dir]{ closedir(dir); });
+ auto close_dir = OnScopeEnd([dir]{ closedir(dir); });
while (dirent* entry = readdir(dir))
{
diff --git a/src/highlighters.cc b/src/highlighters.cc
index 9787b487..9494ba8a 100644
--- a/src/highlighters.cc
+++ b/src/highlighters.cc
@@ -1688,7 +1688,7 @@ private:
return write_to_debug_buffer(format("highlighting recursion detected with ref to {}", m_name));
running_refs.push_back(desc);
- auto pop_desc = on_scope_end([] { running_refs.pop_back(); });
+ auto pop_desc = OnScopeEnd([] { running_refs.pop_back(); });
try
{
diff --git a/src/hook_manager.cc b/src/hook_manager.cc
index 31634e9d..7a48d585 100644
--- a/src/hook_manager.cc
+++ b/src/hook_manager.cc
@@ -130,7 +130,7 @@ void HookManager::run_hook(Hook hook, StringView param, Context& context)
}
m_running_hooks.emplace_back(hook, param);
- auto pop_running_hook = on_scope_end([this]{
+ auto pop_running_hook = OnScopeEnd([this]{
m_running_hooks.pop_back();
if (m_running_hooks.empty())
m_hooks_trash.clear();
diff --git a/src/input_handler.cc b/src/input_handler.cc
index 0c501edb..edaf75f9 100644
--- a/src/input_handler.cc
+++ b/src/input_handler.cc
@@ -288,7 +288,7 @@ public:
ScopedSetBool set_in_on_key{m_in_on_key};
bool do_restore_hooks = false;
- auto restore_hooks = on_scope_end([&, this]{
+ auto restore_hooks = OnScopeEnd([&, this]{
if (m_hooks_disabled and enabled() and do_restore_hooks)
{
context().hooks_disabled().unset();
@@ -340,7 +340,7 @@ public:
}
else
{
- auto pop_if_single_command = on_scope_end([this] {
+ auto pop_if_single_command = OnScopeEnd([this] {
if (m_state == State::SingleCommand and enabled())
pop_mode();
else if (m_state == State::SingleCommand)
@@ -1682,7 +1682,7 @@ void InputHandler::handle_key(Key key, bool synthesized)
return;
++m_handle_key_level;
- auto dec = on_scope_end([this]{ --m_handle_key_level;} );
+ auto dec = OnScopeEnd([this]{ --m_handle_key_level;} );
if (not synthesized)
current_mode().on_raw_key();
diff --git a/src/normal.cc b/src/normal.cc
index 37bbbb2a..96940a90 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -1229,7 +1229,7 @@ void join_lines(Context& context, NormalParams params)
{
ScopedSelectionEdition selection_edition{context};
SelectionList sels{context.selections()};
- auto restore_sels = on_scope_end([&]{
+ auto restore_sels = OnScopeEnd([&]{
sels.update();
context.selections_write_only() = std::move(sels);
});
@@ -1690,7 +1690,7 @@ void replay_macro(Context& context, NormalParams params)
throw runtime_error(format("register '{}' is empty", reg));
running_macros[idx] = true;
- auto stop = on_scope_end([&]{ running_macros[idx] = false; });
+ auto stop = OnScopeEnd([&]{ running_macros[idx] = false; });
auto keys = parse_keys(reg_val[0]);
ScopedEdition edition(context);
diff --git a/src/remote.cc b/src/remote.cc
index 871b967e..ba684f37 100644
--- a/src/remote.cc
+++ b/src/remote.cc
@@ -650,7 +650,7 @@ static int connect_to(StringView session)
bool check_session(StringView session)
{
int sock = socket(AF_UNIX, SOCK_STREAM, 0);
- auto close_sock = on_scope_end([sock]{ close(sock); });
+ auto close_sock = OnScopeEnd([sock]{ close(sock); });
sockaddr_un addr = session_addr(session);
return connect(sock, (sockaddr*)&addr, sizeof(addr.sun_path)) != -1;
}
@@ -704,7 +704,7 @@ RemoteClient::RemoteClient(StringView session, StringView name, UniquePtr<UserIn
if (not reader.ready())
continue;
- auto clear_reader = on_scope_end([&reader] { reader.reset(); });
+ auto clear_reader = OnScopeEnd([&reader] { reader.reset(); });
switch (reader.type())
{
case MessageType::MenuShow:
@@ -756,7 +756,7 @@ bool RemoteClient::is_ui_ok() const
void send_command(StringView session, StringView command)
{
int sock = connect_to(session);
- auto close_sock = on_scope_end([sock]{ close(sock); });
+ auto close_sock = OnScopeEnd([sock]{ close(sock); });
RemoteBuffer buffer;
{
MsgWriter msg{buffer, MessageType::Command};
@@ -863,7 +863,7 @@ Server::Server(String session_name, bool is_daemon)
// Do not give any access to the socket to other users by default
auto old_mask = umask(0077);
- auto restore_mask = on_scope_end([old_mask]() { umask(old_mask); });
+ auto restore_mask = OnScopeEnd([old_mask]() { umask(old_mask); });
if (bind(listen_sock, (sockaddr*) &addr, sizeof(sockaddr_un)) == -1)
throw runtime_error(format("unable to bind listen socket '{}': {}",
diff --git a/src/shell_manager.cc b/src/shell_manager.cc
index 0baf77c8..687e2c30 100644
--- a/src/shell_manager.cc
+++ b/src/shell_manager.cc
@@ -309,7 +309,7 @@ std::pair<String, int> ShellManager::eval(
sigemptyset(&mask);
sigaddset(&mask, SIGCHLD);
sigprocmask(SIG_BLOCK, &mask, &orig_mask);
- auto restore_mask = on_scope_end([&] { sigprocmask(SIG_SETMASK, &orig_mask, nullptr); });
+ auto restore_mask = OnScopeEnd([&] { sigprocmask(SIG_SETMASK, &orig_mask, nullptr); });
int status = 0;
// check for termination now that SIGCHLD is blocked
diff --git a/src/terminal_ui.cc b/src/terminal_ui.cc
index c55d0763..3d963e82 100644
--- a/src/terminal_ui.cc
+++ b/src/terminal_ui.cc
@@ -637,7 +637,7 @@ void TerminalUI::check_resize(bool force)
const int fd = open("/dev/tty", O_RDWR);
if (fd < 0)
return;
- auto close_fd = on_scope_end([fd]{ ::close(fd); });
+ auto close_fd = OnScopeEnd([fd]{ ::close(fd); });
DisplayCoord terminal_size{24_line, 80_col};
if (winsize ws; ioctl(fd, TIOCGWINSZ, &ws) == 0 and ws.ws_row > 0 and ws.ws_col > 0)
diff --git a/src/utils.hh b/src/utils.hh
index ba8cf737..5ec5b334 100644
--- a/src/utils.hh
+++ b/src/utils.hh
@@ -51,11 +51,11 @@ Singleton<T>* Singleton<T>::ms_instance = nullptr;
// *** On scope end ***
//
-// on_scope_end provides a way to register some code to be
+// OnScopeEnd provides a way to register some code to be
// executed when current scope closes.
//
// usage:
-// auto cleaner = on_scope_end([]() { ... });
+// auto cleaner = OnScopeEnd([]() { ... });
//
// This permits to cleanup c-style resources without implementing
// a wrapping class
@@ -82,12 +82,6 @@ private:
T m_func;
};
-template<typename T>
-OnScopeEnd<T> on_scope_end(T t)
-{
- return OnScopeEnd<T>{std::move(t)};
-}
-
// bool that can be set (to true) multiple times, and will
// be false only when unset the same time;
struct NestedBool