From b5560a69b12be5342358bc5528912ab887b678c8 Mon Sep 17 00:00:00 2001 From: Matthew Malcomson Date: Sun, 15 Jan 2017 20:36:29 +0000 Subject: setpos(): Set lowercase mark in other buffers (#5753) Also make setpos("'A", [999, 1, 1, 0]) fail, i.e. return -1 (assuming there is no buffer 999). Fixes #5713 Background: `:help setpos()` mentions an argument `"bufnum"` that determines the buffer a mark should be put in. This argument is respected for uppercase marks, but not for lowercase marks. This is reasonable (though I personally would like `setpos()` to be able to set marks in other buffers), but the help doesn't mention this anywhere. It's also strange that attempting to change buffers with `setpos('.', [bufnr('#'), 1, 1, 0])` alerts the user that having a different buffer is an error, while attempting to set a mark with `setpos("'d", [bufnr('#'), 1, 1, 0])` doesn't tell the user that the `"bufnum"` argument is an error. --- src/nvim/mark.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/mark.c b/src/nvim/mark.c index bb5b8e8178..4e05845eb5 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -130,9 +130,15 @@ int setmark_pos(int c, pos_T *pos, int fnum) return OK; } + buf_T *buf = buflist_findnr(fnum); + // Can't set a mark in a non-existant buffer. + if (buf == NULL) { + return FAIL; + } + if (ASCII_ISLOWER(c)) { i = c - 'a'; - RESET_FMARK(curbuf->b_namedm + i, *pos, curbuf->b_fnum); + RESET_FMARK(buf->b_namedm + i, *pos, fnum); return OK; } if (ASCII_ISUPPER(c) || ascii_isdigit(c)) { -- cgit