aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/undo.c
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-11-19 22:57:13 +0000
committerJosh Rahm <joshuarahm@gmail.com>2024-11-19 22:57:13 +0000
commit9be89f131f87608f224f0ee06d199fcd09d32176 (patch)
tree11022dcfa9e08cb4ac5581b16734196128688d48 /src/nvim/undo.c
parentff7ed8f586589d620a806c3758fac4a47a8e7e15 (diff)
parent88085c2e80a7e3ac29aabb6b5420377eed99b8b6 (diff)
downloadrneovim-9be89f131f87608f224f0ee06d199fcd09d32176.tar.gz
rneovim-9be89f131f87608f224f0ee06d199fcd09d32176.tar.bz2
rneovim-9be89f131f87608f224f0ee06d199fcd09d32176.zip
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'src/nvim/undo.c')
-rw-r--r--src/nvim/undo.c38
1 files changed, 11 insertions, 27 deletions
diff --git a/src/nvim/undo.c b/src/nvim/undo.c
index ba720c9f6a..15c8e0b283 100644
--- a/src/nvim/undo.c
+++ b/src/nvim/undo.c
@@ -92,6 +92,7 @@
#include "nvim/decoration.h"
#include "nvim/drawscreen.h"
#include "nvim/edit.h"
+#include "nvim/errors.h"
#include "nvim/eval/funcs.h"
#include "nvim/eval/typval.h"
#include "nvim/ex_cmds_defs.h"
@@ -342,8 +343,7 @@ static OptInt get_undolevel(buf_T *buf)
static inline void zero_fmark_additional_data(fmark_T *fmarks)
{
for (size_t i = 0; i < NMARKS; i++) {
- tv_dict_unref(fmarks[i].additional_data);
- fmarks[i].additional_data = NULL;
+ XFREE_CLEAR(fmarks[i].additional_data);
}
}
@@ -1131,17 +1131,11 @@ static void serialize_pos(bufinfo_T *bi, pos_T pos)
static void unserialize_pos(bufinfo_T *bi, pos_T *pos)
{
pos->lnum = undo_read_4c(bi);
- if (pos->lnum < 0) {
- pos->lnum = 0;
- }
+ pos->lnum = MAX(pos->lnum, 0);
pos->col = undo_read_4c(bi);
- if (pos->col < 0) {
- pos->col = 0;
- }
+ pos->col = MAX(pos->col, 0);
pos->coladd = undo_read_4c(bi);
- if (pos->coladd < 0) {
- pos->coladd = 0;
- }
+ pos->coladd = MAX(pos->coladd, 0);
}
/// Serializes "info".
@@ -1208,14 +1202,12 @@ void u_write_undo(const char *const name, const bool forceit, buf_T *const buf,
// Strip any sticky and executable bits.
perm = perm & 0666;
- int fd;
-
// If the undo file already exists, verify that it actually is an undo
// file, and delete it.
if (os_path_exists(file_name)) {
if (name == NULL || !forceit) {
// Check we can read it and it's an undo file.
- fd = os_open(file_name, O_RDONLY, 0);
+ int fd = os_open(file_name, O_RDONLY, 0);
if (fd < 0) {
if (name != NULL || p_verbose > 0) {
if (name == NULL) {
@@ -1260,7 +1252,7 @@ void u_write_undo(const char *const name, const bool forceit, buf_T *const buf,
goto theend;
}
- fd = os_open(file_name, O_CREAT|O_WRONLY|O_EXCL|O_NOFOLLOW, perm);
+ int fd = os_open(file_name, O_CREAT|O_WRONLY|O_EXCL|O_NOFOLLOW, perm);
if (fd < 0) {
semsg(_(e_not_open), file_name);
goto theend;
@@ -2000,9 +1992,7 @@ void undo_time(int step, bool sec, bool file, bool absolute)
target = curbuf->b_u_seq_cur + step;
}
if (step < 0) {
- if (target < 0) {
- target = 0;
- }
+ target = MAX(target, 0);
closest = -1;
} else {
if (dosec) {
@@ -2395,9 +2385,7 @@ static void u_undoredo(bool undo, bool do_buf_event)
}
// Set the '[ mark.
- if (top + 1 < curbuf->b_op_start.lnum) {
- curbuf->b_op_start.lnum = top + 1;
- }
+ curbuf->b_op_start.lnum = MIN(curbuf->b_op_start.lnum, top + 1);
// Set the '] mark.
if (newsize == 0 && top + 1 > curbuf->b_op_end.lnum) {
curbuf->b_op_end.lnum = top + 1;
@@ -2418,12 +2406,8 @@ static void u_undoredo(bool undo, bool do_buf_event)
}
// Ensure the '[ and '] marks are within bounds.
- if (curbuf->b_op_start.lnum > curbuf->b_ml.ml_line_count) {
- curbuf->b_op_start.lnum = curbuf->b_ml.ml_line_count;
- }
- if (curbuf->b_op_end.lnum > curbuf->b_ml.ml_line_count) {
- curbuf->b_op_end.lnum = curbuf->b_ml.ml_line_count;
- }
+ curbuf->b_op_start.lnum = MIN(curbuf->b_op_start.lnum, curbuf->b_ml.ml_line_count);
+ curbuf->b_op_end.lnum = MIN(curbuf->b_op_end.lnum, curbuf->b_ml.ml_line_count);
// Adjust Extmarks
if (undo) {