aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/msgpack_rpc.txt21
-rw-r--r--runtime/doc/options.txt36
-rw-r--r--scripts/gendispatch.lua6
-rw-r--r--src/nvim/api/buffer.c4
-rw-r--r--src/nvim/cursor_shape.c6
-rw-r--r--src/nvim/func_attr.h1
-rw-r--r--src/nvim/options.lua2
-rw-r--r--src/nvim/tui/tui.c29
-rw-r--r--test/functional/ui/cursor_spec.lua141
9 files changed, 144 insertions, 102 deletions
diff --git a/runtime/doc/msgpack_rpc.txt b/runtime/doc/msgpack_rpc.txt
index 261e68cfb1..8d013dceb2 100644
--- a/runtime/doc/msgpack_rpc.txt
+++ b/runtime/doc/msgpack_rpc.txt
@@ -197,7 +197,7 @@ prefix is stripped off.
5. Types *rpc-types*
The Nvim C API uses custom types for all functions. |api-types|
-For the purpose of mapping to msgpack, the types can be split into two groups:
+At the RPC layer, the types can be split into two groups:
- Basic types that map natively to msgpack (and probably have a default
representation in msgpack-supported programming languages)
@@ -219,15 +219,16 @@ Special types (msgpack EXT) ~
Window -> enum value kObjectTypeWindow
Tabpage -> enum value kObjectTypeTabpage
-An API method expecting one of these types may be passed an integer instead,
-although they are not interchangeable. For example, a Buffer may be passed as
-an integer, but not a Window or Tabpage.
+API functions expecting one of the special EXT types may be passed an integer
+instead, but not another EXT type. E.g. Buffer may be passed as an integer but
+not as a Window or Tabpage. The EXT object data is the object id encoded as
+a msgpack integer: For buffers this is the |bufnr()| and for windows the
+|window-ID|. For tabpages the id is an internal handle, not the tabpage
+number.
+
+To determine the type codes of the special EXT types, inspect the `types` key
+of the |api-metadata| at runtime. Example JSON representation: >
-The most reliable way of determining the type codes for the special Nvim types
-is to inspect the `types` key of metadata dictionary returned by the
-`nvim_get_api_info` method at runtime. Here's a sample JSON representation of
-the `types` object:
->
"types": {
"Buffer": {
"id": 0,
@@ -242,7 +243,7 @@ the `types` object:
"prefix": "nvim_tabpage_"
}
}
-<
+
Even for statically compiled clients it is good practice to avoid hardcoding
the type codes, because a client may be built against one Nvim version but
connect to another with different type codes.
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 93ab956471..d3683f5135 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -2756,23 +2756,24 @@ A jump table for the options with a short description can be found at |Q_op|.
security reasons.
*'guicursor'* *'gcr'* *E545* *E546* *E548* *E549*
-'guicursor' 'gcr' string (default "n-v-c:block-Cursor/lCursor,
- ve:ver35-Cursor,
- o:hor50-Cursor,
- i-ci:ver25-Cursor/lCursor,
- r-cr:hor20-Cursor/lCursor,
- sm:block-Cursor
- -blinkwait175-blinkoff150-blinkon175")
+'guicursor' 'gcr' string (default "n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20")
global
Configures the cursor style for each mode. Works in the GUI and some
- terminals. Unset to disable: >
- :set guicursor=
-<
+ terminals.
+
With tmux you might need this in ~/.tmux.conf (see terminal-overrides
in the tmux(1) manual page): >
set -ga terminal-overrides ',*:Ss=\E[%p1%d q:Se=\E[2 q'
-<
- The option is a comma separated list of parts. Each part consists of a
+
+< To disable cursor-styling, reset the option: >
+ :set guicursor=
+
+< To enable mode shapes, "Cursor" highlight, and blinking: >
+ :set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr:hor20,o:hor50
+ \,a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor
+ \,sm:block-blinkwait175-blinkoff150-blinkon175
+
+< The option is a comma separated list of parts. Each part consists of a
mode-list and an argument-list:
mode-list:argument-list,mode-list:argument-list,..
The mode-list is a dash separated list of these modes:
@@ -2800,14 +2801,9 @@ A jump table for the options with a short description can be found at |Q_op|.
the cursor starts blinking, blinkon is the time that
the cursor is shown and blinkoff is the time that the
cursor is not shown. The times are in msec. When one
- of the numbers is zero, there is no blinking. The
- default is: "blinkwait700-blinkon400-blinkoff250".
- These numbers are used for a missing entry. This
- means that blinking is enabled by default. To switch
- blinking off you can use "blinkon0". The cursor only
- blinks when Vim is waiting for input, not while
- executing a command.
- {group-name}
+ of the numbers is zero, there is no blinking. E.g.: >
+ :set guicursor=n:blinkon0
+< {group-name}
a highlight group name, that sets the color and font
for the cursor
{group-name}/{group-name}
diff --git a/scripts/gendispatch.lua b/scripts/gendispatch.lua
index 0ee3ae6475..c0291c55d3 100644
--- a/scripts/gendispatch.lua
+++ b/scripts/gendispatch.lua
@@ -37,6 +37,8 @@ c_proto = Ct(
fill * P('(') * fill * Cg(c_params, 'parameters') * fill * P(')') *
Cg(Cc(false), 'async') *
(fill * Cg((P('FUNC_API_SINCE(') * C(num ^ 1)) * P(')'), 'since') ^ -1) *
+ (fill * Cg((P('FUNC_API_DEPRECATED_SINCE(') * C(num ^ 1)) * P(')'),
+ 'deprecated_since') ^ -1) *
(fill * Cg((P('FUNC_API_ASYNC') * Cc(true)), 'async') ^ -1) *
(fill * Cg((P('FUNC_API_NOEXPORT') * Cc(true)), 'noexport') ^ -1) *
(fill * Cg((P('FUNC_API_NOEVAL') * Cc(true)), 'noeval') ^ -1) *
@@ -122,6 +124,10 @@ for i,f in ipairs(shallowcopy(functions)) do
os.exit(1)
end
f.since = tonumber(f.since)
+ if f.deprecated_since ~= nil then
+ f.deprecated_since = tonumber(f.deprecated_since)
+ end
+
if startswith(f.name, "nvim_buf_") then
ismethod = true
elseif startswith(f.name, "nvim_win_") then
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index ae5728ee21..5de1535bce 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -567,11 +567,15 @@ void nvim_buf_set_option(Buffer buffer, String name, Object value, Error *err)
/// Gets the buffer number
///
+/// @deprecated The buffer number now is equal to the object id,
+/// so there is no need to use this function.
+///
/// @param buffer Buffer handle
/// @param[out] err Error details, if any
/// @return Buffer number
Integer nvim_buf_get_number(Buffer buffer, Error *err)
FUNC_API_SINCE(1)
+ FUNC_API_DEPRECATED_SINCE(2)
{
Integer rv = 0;
buf_T *buf = find_buffer_by_handle(buffer, err);
diff --git a/src/nvim/cursor_shape.c b/src/nvim/cursor_shape.c
index dcc680f806..e302d5aa4c 100644
--- a/src/nvim/cursor_shape.c
+++ b/src/nvim/cursor_shape.c
@@ -142,9 +142,9 @@ char_u *parse_shape_opt(int what)
{
// Set the defaults, for the missing parts
shape_table[idx].shape = SHAPE_BLOCK;
- shape_table[idx].blinkwait = 700L;
- shape_table[idx].blinkon = 400L;
- shape_table[idx].blinkoff = 250L;
+ shape_table[idx].blinkwait = 0L;
+ shape_table[idx].blinkon = 0L;
+ shape_table[idx].blinkoff = 0L;
}
}
diff --git a/src/nvim/func_attr.h b/src/nvim/func_attr.h
index 18410445e1..756c6d05ee 100644
--- a/src/nvim/func_attr.h
+++ b/src/nvim/func_attr.h
@@ -187,6 +187,7 @@
# define FUNC_API_NOEXPORT
# define FUNC_API_NOEVAL
# define FUNC_API_SINCE(X)
+# define FUNC_API_DEPRECATED_SINCE(X)
# define FUNC_ATTR_MALLOC REAL_FATTR_MALLOC
# define FUNC_ATTR_ALLOC_SIZE(x) REAL_FATTR_ALLOC_SIZE(x)
# define FUNC_ATTR_ALLOC_SIZE_PROD(x, y) REAL_FATTR_ALLOC_SIZE_PROD(x, y)
diff --git a/src/nvim/options.lua b/src/nvim/options.lua
index 4e7be63b63..ba7bf5bafb 100644
--- a/src/nvim/options.lua
+++ b/src/nvim/options.lua
@@ -1000,7 +1000,7 @@ return {
deny_duplicates=true,
vi_def=true,
varname='p_guicursor',
- defaults={if_true={vi="n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175"}}
+ defaults={if_true={vi="n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20"}}
},
{
full_name='guifont', abbreviation='gfn',
diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c
index 5653924154..522f7d59f2 100644
--- a/src/nvim/tui/tui.c
+++ b/src/nvim/tui/tui.c
@@ -44,6 +44,7 @@
#define TOO_MANY_EVENTS 1000000
#define STARTS_WITH(str, prefix) (!memcmp(str, prefix, sizeof(prefix) - 1))
+#define TMUX_WRAP(seq) (is_tmux ? "\x1bPtmux;\x1b" seq "\x1b\\" : seq)
typedef enum TermType {
kTermUnknown,
@@ -95,6 +96,7 @@ typedef struct {
static bool volatile got_winch = false;
static bool cursor_style_enabled = false;
+static bool is_tmux = false;
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "tui/tui.c.generated.h"
@@ -545,13 +547,20 @@ static void tui_set_mode(UI *ui, ModeShape mode)
TUIData *data = ui->data;
cursorentry_T c = data->cursor_shapes[mode];
int shape = c.shape;
- bool is_tmux = os_getenv("TMUX") != NULL;
unibi_var_t vars[26 + 26] = { { 0 } };
-# define TMUX_WRAP(seq) (is_tmux ? "\x1bPtmux;\x1b" seq "\x1b\\" : seq)
// Support changing cursor shape on some popular terminals.
const char *vte_version = os_getenv("VTE_VERSION");
+ if (c.id != 0 && ui->rgb) {
+ int attr = syn_id2attr(c.id);
+ if (attr > 0) {
+ attrentry_T *aep = syn_cterm_attr2entry(attr);
+ data->params[0].i = aep->rgb_bg_color;
+ unibi_out(ui, data->unibi_ext.set_cursor_color);
+ }
+ }
+
if (data->term == kTermKonsole) {
// Konsole uses a proprietary escape code to set the cursor shape
// and does not support DECSCUSR.
@@ -575,23 +584,14 @@ static void tui_set_mode(UI *ui, ModeShape mode)
switch (shape) {
case SHAPE_BLOCK: shape = 1; break;
- case SHAPE_VER: shape = 5; break;
case SHAPE_HOR: shape = 3; break;
+ case SHAPE_VER: shape = 5; break;
default: WLOG("Unknown shape value %d", shape); break;
}
- data->params[0].i = shape + (c.blinkon ==0);
+ data->params[0].i = shape + (int)(c.blinkon == 0);
unibi_format(vars, vars + 26, "\x1b[%p1%d q",
data->params, out, ui, NULL, NULL);
}
-
- if (c.id != 0 && ui->rgb) {
- int attr = syn_id2attr(c.id);
- if (attr > 0) {
- attrentry_T *aep = syn_cterm_attr2entry(attr);
- data->params[0].i = aep->rgb_bg_color;
- unibi_out(ui, data->unibi_ext.set_cursor_color);
- }
- }
}
/// @param mode editor mode
@@ -952,6 +952,7 @@ static TermType detect_term(const char *term, const char *colorterm)
static void fix_terminfo(TUIData *data)
{
unibi_term *ut = data->ut;
+ is_tmux = os_getenv("TMUX") != NULL;
const char *term = os_getenv("TERM");
const char *colorterm = os_getenv("COLORTERM");
@@ -1019,7 +1020,7 @@ end:
// Fill some empty slots with common terminal strings
if (data->term == kTermiTerm) {
data->unibi_ext.set_cursor_color = (int)unibi_add_ext_str(
- ut, NULL, "\033]Pl%p1%06x\033\\");
+ ut, NULL, TMUX_WRAP("\033]Pl%p1%06x\033\\"));
} else {
data->unibi_ext.set_cursor_color = (int)unibi_add_ext_str(
ut, NULL, "\033]12;#%p1%06x\007");
diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua
index abe0e0b1fd..e6036a6b79 100644
--- a/test/functional/ui/cursor_spec.lua
+++ b/test/functional/ui/cursor_spec.lua
@@ -20,102 +20,102 @@ describe('ui/cursor', function()
it("'guicursor' is published as a UI event", function()
local expected_mode_info = {
[1] = {
- blinkoff = 250,
- blinkon = 400,
- blinkwait = 700,
+ blinkoff = 0,
+ blinkon = 0,
+ blinkwait = 0,
cell_percentage = 0,
cursor_shape = 'block',
name = 'normal',
- hl_id = 46,
- id_lm = 47,
+ hl_id = 0,
+ id_lm = 0,
mouse_shape = 0,
short_name = 'n' },
[2] = {
- blinkoff = 250,
- blinkon = 400,
- blinkwait = 700,
+ blinkoff = 0,
+ blinkon = 0,
+ blinkwait = 0,
cell_percentage = 0,
cursor_shape = 'block',
name = 'visual',
- hl_id = 46,
- id_lm = 47,
+ hl_id = 0,
+ id_lm = 0,
mouse_shape = 0,
short_name = 'v' },
[3] = {
- blinkoff = 250,
- blinkon = 400,
- blinkwait = 700,
+ blinkoff = 0,
+ blinkon = 0,
+ blinkwait = 0,
cell_percentage = 25,
cursor_shape = 'vertical',
name = 'insert',
- hl_id = 46,
- id_lm = 47,
+ hl_id = 0,
+ id_lm = 0,
mouse_shape = 0,
short_name = 'i' },
[4] = {
- blinkoff = 250,
- blinkon = 400,
- blinkwait = 700,
+ blinkoff = 0,
+ blinkon = 0,
+ blinkwait = 0,
cell_percentage = 20,
cursor_shape = 'horizontal',
name = 'replace',
- hl_id = 46,
- id_lm = 47,
+ hl_id = 0,
+ id_lm = 0,
mouse_shape = 0,
short_name = 'r' },
[5] = {
- blinkoff = 250,
- blinkon = 400,
- blinkwait = 700,
+ blinkoff = 0,
+ blinkon = 0,
+ blinkwait = 0,
cell_percentage = 0,
cursor_shape = 'block',
name = 'cmdline_normal',
- hl_id = 46,
- id_lm = 47,
+ hl_id = 0,
+ id_lm = 0,
mouse_shape = 0,
short_name = 'c' },
[6] = {
- blinkoff = 250,
- blinkon = 400,
- blinkwait = 700,
+ blinkoff = 0,
+ blinkon = 0,
+ blinkwait = 0,
cell_percentage = 25,
cursor_shape = 'vertical',
name = 'cmdline_insert',
- hl_id = 46,
- id_lm = 47,
+ hl_id = 0,
+ id_lm = 0,
mouse_shape = 0,
short_name = 'ci' },
[7] = {
- blinkoff = 250,
- blinkon = 400,
- blinkwait = 700,
+ blinkoff = 0,
+ blinkon = 0,
+ blinkwait = 0,
cell_percentage = 20,
cursor_shape = 'horizontal',
name = 'cmdline_replace',
- hl_id = 46,
- id_lm = 47,
+ hl_id = 0,
+ id_lm = 0,
mouse_shape = 0,
short_name = 'cr' },
[8] = {
- blinkoff = 250,
- blinkon = 400,
- blinkwait = 700,
- cell_percentage = 50,
+ blinkoff = 0,
+ blinkon = 0,
+ blinkwait = 0,
+ cell_percentage = 20,
cursor_shape = 'horizontal',
name = 'operator',
- hl_id = 46,
- id_lm = 46,
+ hl_id = 0,
+ id_lm = 0,
mouse_shape = 0,
short_name = 'o' },
[9] = {
- blinkoff = 250,
- blinkon = 400,
- blinkwait = 700,
- cell_percentage = 35,
+ blinkoff = 0,
+ blinkon = 0,
+ blinkwait = 0,
+ cell_percentage = 25,
cursor_shape = 'vertical',
name = 'visual_select',
- hl_id = 46,
- id_lm = 46,
+ hl_id = 0,
+ id_lm = 0,
mouse_shape = 0,
short_name = 've' },
[10] = {
@@ -147,19 +147,19 @@ describe('ui/cursor', function()
mouse_shape = 0,
short_name = 'ml' },
[17] = {
- blinkoff = 150,
- blinkon = 175,
- blinkwait = 175,
+ blinkoff = 0,
+ blinkon = 0,
+ blinkwait = 0,
cell_percentage = 0,
cursor_shape = 'block',
name = 'showmatch',
- hl_id = 46,
- id_lm = 46,
+ hl_id = 0,
+ id_lm = 0,
short_name = 'sm' },
}
screen:expect(function()
- -- Default 'guicursor' published on startup.
+ -- Default 'guicursor', published on startup.
eq(expected_mode_info, screen._mode_info)
eq(true, screen._cursor_style_enabled)
eq('normal', screen.mode)
@@ -179,20 +179,53 @@ describe('ui/cursor', function()
end)
-- Change the cursor style.
- meths.set_option('guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173,ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42')
+ helpers.command('set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr-o:hor20'
+ ..',a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor'
+ ..',sm:block-blinkwait175-blinkoff150-blinkon175')
+
+ -- Update the expected values.
+ for _, m in ipairs(expected_mode_info) do
+ if m.name == 'showmatch' then
+ if m.blinkon then m.blinkon = 175 end
+ if m.blinkoff then m.blinkoff = 150 end
+ if m.blinkwait then m.blinkwait = 175 end
+ else
+ if m.blinkon then m.blinkon = 250 end
+ if m.blinkoff then m.blinkoff = 400 end
+ if m.blinkwait then m.blinkwait = 700 end
+ end
+ if m.hl_id then m.hl_id = 46 end
+ if m.id_lm then m.id_lm = 47 end
+ end
+
+ -- Assert the new expectation.
+ screen:expect(function()
+ eq(expected_mode_info, screen._mode_info)
+ eq(true, screen._cursor_style_enabled)
+ eq('normal', screen.mode)
+ end)
+
+ -- Another cursor style.
+ meths.set_option('guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173'
+ ..',ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42')
screen:expect(function()
local named = {}
for _, m in ipairs(screen._mode_info) do
named[m.name] = m
end
eq('vertical', named.normal.cursor_shape)
+ eq(35, named.normal.cell_percentage)
eq('horizontal', named.visual_select.cursor_shape)
+ eq(35, named.visual_select.cell_percentage)
eq('vertical', named.operator.cursor_shape)
+ eq(50, named.operator.cell_percentage)
eq('block', named.insert.cursor_shape)
eq('vertical', named.showmatch.cursor_shape)
+ eq(90, named.cmdline_replace.cell_percentage)
eq(171, named.normal.blinkwait)
eq(172, named.normal.blinkoff)
eq(173, named.normal.blinkon)
+ eq(42, named.showmatch.cell_percentage)
end)
end)