I think it would be nice if setpos() uses the bufnum part of the position it's
given when asked to set a lowercase mark.
Also, when it's given an invalid buffer number exist for uppercase and numbered
marks I think it should fail and return -1.
I have a suggested patch and test below.
diff --git a/src/mark.c b/src/mark.c
index 9c84bc40d..e28fd8b77 100644
--- a/src/mark.c
+++ b/src/mark.c
@@ -106,10 +106,16 @@ 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';
- curbuf->b_namedm[i] = *pos;
+ buf->b_namedm[i] = *pos;
return OK;
}
if (ASCII_ISUPPER(c) || VIM_ISDIGIT(c))
diff --git a/src/testdir/test_marks.vim b/src/testdir/test_marks.vim
index d00b1ddc8..edefff082 100644
--- a/src/testdir/test_marks.vim
+++ b/src/testdir/test_marks.vim
@@ -13,6 +13,28 @@ function! Test_Restore_DelMark()
enew!
endfunction
+" Test that setpos() can set a mark in another buffer.
+function! Test_Setpos_Mark()
+ enew!
+ let l:first_bufnr = bufnr('%')
+ call append(0, ["First line", "Second line", "Third line"])
+ new
+ let l:second_bufnr = bufnr('%')
+ call append(0, ["Line 1", "Line 2", "Line 3"])
+ call setpos("'d", [l:first_bufnr, 2, 1, 0])
+ for element in getpos("'d")
+ call assert_equal(0, element)
+ endfor
+ wincmd w
+ let pos = getpos("'d")
+ call assert_equal(2, pos[1])
+ call assert_equal(1, pos[2])
+ let retval = setpos("'d", [l:second_bufnr + 1, 2, 1, 0])
+ call assert_equal(-1 , retval)
+ quit!
+ enew!
+endfunction
+
" Test that CTRL-A and CTRL-X updates last changed mark '[, '].
function! Test_Incr_Marks()
enew!
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.