fish-shell/src/kill.cpp
Aaron Gyes 14d2a6d8ff IWYU-guided #include rejiggering.
Let's hope this doesn't causes build failures for e.g. musl: I just
know it's good on macOS and our Linux CI.

It's been a long time.

One fix this brings, is I discovered we #include assert.h or cassert
in a lot of places. If those ever happen to be in a file that doesn't
include common.h, or we are before common.h gets included, we're
unawaringly working with the system 'assert' macro again, which
may get disabled for debug builds or at least has different
behavior on crash. We undef 'assert' and redefine it in common.h.

Those were all eliminated, except in one catch-22 spot for
maybe.h: it can't include common.h. A fix might be to
make a fish_assert.h that *usually* common.h exports.
2022-08-20 23:55:18 -07:00

59 lines
1.4 KiB
C++

// The killring.
//
// Works like the killring in emacs and readline. The killring is cut and paste with a memory of
// previous cuts.
#include "config.h" // IWYU pragma: keep
#include "kill.h"
#include <algorithm>
#include <list>
#include <string>
#include <utility>
#include "common.h"
#include "fallback.h" // IWYU pragma: keep
/** Kill ring */
static owning_lock<std::list<wcstring>> s_kill_list;
void kill_add(wcstring str) {
if (!str.empty()) {
s_kill_list.acquire()->push_front(std::move(str));
}
}
void kill_replace(const wcstring &old, const wcstring &newv) {
auto kill_list = s_kill_list.acquire();
// Remove old.
auto iter = std::find(kill_list->begin(), kill_list->end(), old);
if (iter != kill_list->end()) kill_list->erase(iter);
// Add new.
if (!newv.empty()) {
kill_list->push_front(newv);
}
}
wcstring kill_yank_rotate() {
auto kill_list = s_kill_list.acquire();
// Move the first element to the end.
if (kill_list->empty()) {
return {};
}
kill_list->splice(kill_list->end(), *kill_list, kill_list->begin());
return kill_list->front();
}
wcstring kill_yank() {
auto kill_list = s_kill_list.acquire();
if (kill_list->empty()) {
return {};
}
return kill_list->front();
}
wcstring_list_t kill_entries() {
auto kill_list = s_kill_list.acquire();
return wcstring_list_t{kill_list->begin(), kill_list->end()};
}