blob: 40dc5ecef547792811ef0d7e13e7de8915f8af1b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
// 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 <stddef.h>
#include <algorithm>
#include <list>
#include <memory>
#include <string>
#include "common.h"
#include "fallback.h" // IWYU pragma: keep
/** Kill ring */
typedef std::list<wcstring> kill_list_t;
static kill_list_t kill_list;
void kill_add(const wcstring &str) {
ASSERT_IS_MAIN_THREAD();
if (str.empty()) return;
kill_list.push_front(str);
}
/// Remove first match for specified string from circular list.
static void kill_remove(const wcstring &s) {
ASSERT_IS_MAIN_THREAD();
kill_list_t::iterator iter = std::find(kill_list.begin(), kill_list.end(), s);
if (iter != kill_list.end()) kill_list.erase(iter);
}
void kill_replace(const wcstring &old, const wcstring &newv) {
kill_remove(old);
kill_add(newv);
}
const wchar_t *kill_yank_rotate() {
ASSERT_IS_MAIN_THREAD();
// Move the first element to the end.
if (kill_list.empty()) {
return NULL;
}
kill_list.splice(kill_list.end(), kill_list, kill_list.begin());
return kill_list.front().c_str();
}
const wchar_t *kill_yank() {
if (kill_list.empty()) {
return L"";
}
return kill_list.front().c_str();
}
void kill_sanity_check() {}
void kill_init() {}
void kill_destroy() {}
|