2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
|
|
|
|
|
|
|
local setpos = n.fn.setpos
|
|
|
|
local getpos = n.fn.getpos
|
|
|
|
local insert = n.insert
|
|
|
|
local clear = n.clear
|
|
|
|
local command = n.command
|
|
|
|
local eval = n.eval
|
2024-04-08 02:03:20 -07:00
|
|
|
local eq = t.eq
|
2024-04-20 08:44:13 -07:00
|
|
|
local exc_exec = n.exc_exec
|
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.
2017-01-15 13:36:29 -07:00
|
|
|
|
|
|
|
describe('setpos() function', function()
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
insert([[
|
|
|
|
First line of text
|
|
|
|
Second line of text
|
|
|
|
Third line of text]])
|
2017-04-08 14:12:26 -07:00
|
|
|
command('new')
|
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.
2017-01-15 13:36:29 -07:00
|
|
|
insert([[
|
|
|
|
Line of text 1
|
|
|
|
Line of text 2
|
|
|
|
Line of text 3]])
|
|
|
|
end)
|
|
|
|
it('can set the current cursor position', function()
|
|
|
|
setpos('.', { 0, 2, 1, 0 })
|
2022-04-25 20:35:05 -07:00
|
|
|
eq({ 0, 2, 1, 0 }, getpos('.'))
|
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.
2017-01-15 13:36:29 -07:00
|
|
|
setpos('.', { 2, 1, 1, 0 })
|
2022-04-25 20:35:05 -07:00
|
|
|
eq({ 0, 1, 1, 0 }, getpos('.'))
|
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.
2017-01-15 13:36:29 -07:00
|
|
|
local ret = exc_exec('call setpos(".", [1, 1, 1, 0])')
|
2018-06-06 14:58:02 -07:00
|
|
|
eq(0, ret)
|
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.
2017-01-15 13:36:29 -07:00
|
|
|
end)
|
|
|
|
it('can set lowercase marks in the current buffer', function()
|
|
|
|
setpos("'d", { 0, 2, 1, 0 })
|
2022-04-25 20:35:05 -07:00
|
|
|
eq({ 0, 2, 1, 0 }, getpos("'d"))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('undo')
|
|
|
|
command('call setpos("\'d", [2, 3, 1, 0])')
|
2022-04-25 20:35:05 -07:00
|
|
|
eq({ 0, 3, 1, 0 }, getpos("'d"))
|
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.
2017-01-15 13:36:29 -07:00
|
|
|
end)
|
|
|
|
it('can set lowercase marks in other buffers', function()
|
|
|
|
local retval = setpos("'d", { 1, 2, 1, 0 })
|
|
|
|
eq(0, retval)
|
|
|
|
setpos("'d", { 1, 2, 1, 0 })
|
2022-04-25 20:35:05 -07:00
|
|
|
eq({ 0, 0, 0, 0 }, getpos("'d"))
|
2017-04-08 14:12:26 -07:00
|
|
|
command('wincmd w')
|
2022-04-25 20:35:05 -07:00
|
|
|
eq(1, eval('bufnr("%")'))
|
|
|
|
eq({ 0, 2, 1, 0 }, getpos("'d"))
|
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.
2017-01-15 13:36:29 -07:00
|
|
|
end)
|
|
|
|
it("fails when setting a mark in a buffer that doesn't exist", function()
|
|
|
|
local retval = setpos("'d", { 3, 2, 1, 0 })
|
|
|
|
eq(-1, retval)
|
2022-04-25 20:35:05 -07:00
|
|
|
eq({ 0, 0, 0, 0 }, getpos("'d"))
|
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.
2017-01-15 13:36:29 -07:00
|
|
|
retval = setpos("'D", { 3, 2, 1, 0 })
|
|
|
|
eq(-1, retval)
|
2022-04-25 20:35:05 -07:00
|
|
|
eq({ 0, 0, 0, 0 }, getpos("'D"))
|
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.
2017-01-15 13:36:29 -07:00
|
|
|
end)
|
|
|
|
it('can set uppercase marks', function()
|
|
|
|
setpos("'D", { 2, 2, 3, 0 })
|
2022-04-25 20:35:05 -07:00
|
|
|
eq({ 2, 2, 3, 0 }, getpos("'D"))
|
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.
2017-01-15 13:36:29 -07:00
|
|
|
-- Can set a mark in another buffer
|
|
|
|
setpos("'D", { 1, 2, 2, 0 })
|
2022-04-25 20:35:05 -07:00
|
|
|
eq({ 1, 2, 2, 0 }, getpos("'D"))
|
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.
2017-01-15 13:36:29 -07:00
|
|
|
end)
|
|
|
|
end)
|