1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <stdbool.h>
#include <stdlib.h>
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/api/tabpage.h"
#include "nvim/api/vim.h"
#include "nvim/buffer_defs.h"
#include "nvim/globals.h"
#include "nvim/memory.h"
#include "nvim/window.h"
/// Gets the windows in a tabpage
///
/// @param tabpage Tabpage handle, or 0 for current tabpage
/// @param[out] err Error details, if any
/// @return List of windows in `tabpage`
ArrayOf(Window) nvim_tabpage_list_wins(Tabpage tabpage, Error *err)
FUNC_API_SINCE(1)
{
Array rv = ARRAY_DICT_INIT;
tabpage_T *tab = find_tab_by_handle(tabpage, err);
if (!tab || !valid_tabpage(tab)) {
return rv;
}
FOR_ALL_WINDOWS_IN_TAB(wp, tab) {
rv.size++;
}
rv.items = xmalloc(sizeof(Object) * rv.size);
size_t i = 0;
FOR_ALL_WINDOWS_IN_TAB(wp, tab) {
rv.items[i++] = WINDOW_OBJ(wp->handle);
}
return rv;
}
/// Gets a tab-scoped (t:) variable
///
/// @param tabpage Tabpage handle, or 0 for current tabpage
/// @param name Variable name
/// @param[out] err Error details, if any
/// @return Variable value
Object nvim_tabpage_get_var(Tabpage tabpage, String name, Error *err)
FUNC_API_SINCE(1)
{
tabpage_T *tab = find_tab_by_handle(tabpage, err);
if (!tab) {
return (Object)OBJECT_INIT;
}
return dict_get_value(tab->tp_vars, name, err);
}
/// Sets a tab-scoped (t:) variable
///
/// @param tabpage Tabpage handle, or 0 for current tabpage
/// @param name Variable name
/// @param value Variable value
/// @param[out] err Error details, if any
void nvim_tabpage_set_var(Tabpage tabpage, String name, Object value, Error *err)
FUNC_API_SINCE(1)
{
tabpage_T *tab = find_tab_by_handle(tabpage, err);
if (!tab) {
return;
}
dict_set_var(tab->tp_vars, name, value, false, false, err);
}
/// Removes a tab-scoped (t:) variable
///
/// @param tabpage Tabpage handle, or 0 for current tabpage
/// @param name Variable name
/// @param[out] err Error details, if any
void nvim_tabpage_del_var(Tabpage tabpage, String name, Error *err)
FUNC_API_SINCE(1)
{
tabpage_T *tab = find_tab_by_handle(tabpage, err);
if (!tab) {
return;
}
dict_set_var(tab->tp_vars, name, NIL, true, false, err);
}
/// Gets the current window in a tabpage
///
/// @param tabpage Tabpage handle, or 0 for current tabpage
/// @param[out] err Error details, if any
/// @return Window handle
Window nvim_tabpage_get_win(Tabpage tabpage, Error *err)
FUNC_API_SINCE(1)
{
tabpage_T *tab = find_tab_by_handle(tabpage, err);
if (!tab || !valid_tabpage(tab)) {
return 0;
}
if (tab == curtab) {
return nvim_get_current_win();
}
FOR_ALL_WINDOWS_IN_TAB(wp, tab) {
if (wp == tab->tp_curwin) {
return wp->handle;
}
}
// There should always be a current window for a tabpage
abort();
}
/// Gets the tabpage number
///
/// @param tabpage Tabpage handle, or 0 for current tabpage
/// @param[out] err Error details, if any
/// @return Tabpage number
Integer nvim_tabpage_get_number(Tabpage tabpage, Error *err)
FUNC_API_SINCE(1)
{
tabpage_T *tab = find_tab_by_handle(tabpage, err);
if (!tab) {
return 0;
}
return tabpage_index(tab);
}
/// Checks if a tabpage is valid
///
/// @param tabpage Tabpage handle, or 0 for current tabpage
/// @return true if the tabpage is valid, false otherwise
Boolean nvim_tabpage_is_valid(Tabpage tabpage)
FUNC_API_SINCE(1)
{
Error stub = ERROR_INIT;
Boolean ret = find_tab_by_handle(tabpage, &stub) != NULL;
api_clear_error(&stub);
return ret;
}
|