aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/shada.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/shada.c')
-rw-r--r--src/nvim/shada.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/nvim/shada.c b/src/nvim/shada.c
index f8643fe655..e21c6f17fe 100644
--- a/src/nvim/shada.c
+++ b/src/nvim/shada.c
@@ -43,6 +43,7 @@
#include "nvim/path.h"
#include "nvim/fileio.h"
#include "nvim/strings.h"
+#include "nvim/quickfix.h"
#include "nvim/lib/khash.h"
#include "nvim/lib/kvec.h"
@@ -98,6 +99,7 @@ KHASH_SET_INIT_STR(strset)
#define SEARCH_KEY_HIGHLIGHTED "sh"
#define SEARCH_KEY_OFFSET "so"
#define SEARCH_KEY_PAT "sp"
+#define SEARCH_KEY_BACKWARD "sb"
#define REG_KEY_TYPE "rt"
#define REG_KEY_WIDTH "rw"
@@ -263,6 +265,7 @@ typedef struct {
bool is_last_used;
bool is_substitute_pattern;
bool highlighted;
+ bool search_backward;
char *pat;
dict_T *additional_data;
} search_pattern;
@@ -455,6 +458,7 @@ static const ShadaEntry sd_default_values[] = {
.is_last_used = true,
.is_substitute_pattern = false,
.highlighted = false,
+ .search_backward = false,
.pat = NULL,
.additional_data = NULL),
DEF_SDE(SubString, sub_string, .sub = NULL, .additional_elements = NULL),
@@ -812,7 +816,7 @@ static ShaDaReadResult sd_reader_skip(ShaDaReadDef *const sd_reader,
///
/// All arguments are passed to os_open().
///
-/// @return file descriptor or -errno on failure.
+/// @return file descriptor or libuv error on failure.
static int open_file(const char *const fname, const int flags, const int mode)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
@@ -822,15 +826,15 @@ open_file_start:
fd = os_open(fname, flags, mode);
if (fd < 0) {
- if (-fd == ENOENT) {
+ if (fd == UV_ENOENT) {
return fd;
}
- if (-fd == ENOMEM && !did_try_to_free) {
+ if (fd == UV_ENOMEM && !did_try_to_free) {
try_to_free_memory();
did_try_to_free = true;
goto open_file_start;
}
- if (-fd != EEXIST) {
+ if (fd != UV_EEXIST) {
emsg3(_(SERR "System error while opening ShaDa file %s: %s"),
fname, os_strerror(fd));
}
@@ -844,7 +848,7 @@ open_file_start:
/// @param[in] fname File name to open.
/// @param[out] sd_reader Location where reader structure will be saved.
///
-/// @return -errno in case of error, 0 otherwise.
+/// @return libuv error in case of error, 0 otherwise.
static int open_shada_file_for_reading(const char *const fname,
ShaDaReadDef *sd_reader)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
@@ -962,7 +966,7 @@ static int shada_read_file(const char *const file, const int flags)
}
if (of_ret != 0) {
- if (-of_ret == ENOENT && (flags & kShaDaMissingError)) {
+ if (of_ret == UV_ENOENT && (flags & kShaDaMissingError)) {
emsg3(_(SERR "System error while opening ShaDa file %s for reading: %s"),
fname, os_strerror(of_ret));
}
@@ -1338,6 +1342,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags)
.magic = cur_entry.data.search_pattern.magic,
.no_scs = !cur_entry.data.search_pattern.smartcase,
.off = {
+ .dir = cur_entry.data.search_pattern.search_backward ? '?' : '/',
.line = cur_entry.data.search_pattern.has_line_offset,
.end = cur_entry.data.search_pattern.place_cursor_at_end,
.off = cur_entry.data.search_pattern.offset,
@@ -1754,6 +1759,7 @@ static bool shada_pack_entry(msgpack_packer *const packer,
+ ONE_IF_NOT_DEFAULT(entry, search_pattern.is_substitute_pattern)
+ ONE_IF_NOT_DEFAULT(entry, search_pattern.highlighted)
+ ONE_IF_NOT_DEFAULT(entry, search_pattern.offset)
+ + ONE_IF_NOT_DEFAULT(entry, search_pattern.search_backward)
// finally, additional data:
+ (size_t) (
entry.data.search_pattern.additional_data
@@ -1780,6 +1786,7 @@ static bool shada_pack_entry(msgpack_packer *const packer,
PACK_BOOL(entry, SEARCH_KEY_PLACE_CURSOR_AT_END, place_cursor_at_end);
PACK_BOOL(entry, SEARCH_KEY_IS_SUBSTITUTE_PATTERN, is_substitute_pattern);
PACK_BOOL(entry, SEARCH_KEY_HIGHLIGHTED, highlighted);
+ PACK_BOOL(entry, SEARCH_KEY_BACKWARD, search_backward);
if (!CHECK_DEFAULT(entry, search_pattern.offset)) {
PACK_STATIC_STR(SEARCH_KEY_OFFSET);
msgpack_pack_int64(spacker, entry.data.search_pattern.offset);
@@ -2478,8 +2485,11 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
// Write buffer list
if (find_shada_parameter('%') != NULL) {
size_t buf_count = 0;
+#define IGNORE_BUF(buf)\
+ (buf->b_ffname == NULL || !buf->b_p_bl || bt_quickfix(buf) \
+ || in_bufset(&removable_bufs, buf))
FOR_ALL_BUFFERS(buf) {
- if (buf->b_ffname != NULL && !in_bufset(&removable_bufs, buf)) {
+ if (!IGNORE_BUF(buf)) {
buf_count++;
}
}
@@ -2497,7 +2507,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
};
size_t i = 0;
FOR_ALL_BUFFERS(buf) {
- if (buf->b_ffname == NULL || in_bufset(&removable_bufs, buf)) {
+ if (IGNORE_BUF(buf)) {
continue;
}
buflist_entry.data.buffer_list.buffers[i] = (struct buffer_list_buffer) {
@@ -2513,6 +2523,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
goto shada_write_exit;
}
xfree(buflist_entry.data.buffer_list.buffers);
+#undef IGNORE_BUF
}
// Write some of the variables
@@ -2581,6 +2592,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
&& search_highlighted), \
.pat = (char *) pat.pat, \
.additional_data = pat.additional_data, \
+ .search_backward = (!is_sub && pat.off.dir == '?'), \
} \
} \
} \
@@ -2957,9 +2969,9 @@ shada_write_file_open:
fd = (intptr_t) open_file(tempname, O_CREAT|O_WRONLY|O_NOFOLLOW|O_EXCL,
perm);
if (fd < 0) {
- if (-fd == EEXIST
+ if (fd == UV_EEXIST
#ifdef ELOOP
- || -fd == ELOOP
+ || fd == UV_ELOOP
#endif
) {
// File already exists, try another name
@@ -3633,6 +3645,9 @@ shada_read_next_item_start:
BOOLEAN_KEY("search pattern", SEARCH_KEY_HIGHLIGHTED,
entry->data.search_pattern.highlighted)
else
+ BOOLEAN_KEY("search pattern", SEARCH_KEY_BACKWARD,
+ entry->data.search_pattern.search_backward)
+ else
INTEGER_KEY("search pattern", SEARCH_KEY_OFFSET,
entry->data.search_pattern.offset)
else