aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/arabic.c877
-rw-r--r--src/nvim/aucmd.c12
-rw-r--r--src/nvim/autocmd.c99
-rw-r--r--src/nvim/buffer.c626
-rw-r--r--src/nvim/buffer_updates.c68
-rw-r--r--src/nvim/change.c187
-rw-r--r--src/nvim/channel.c203
-rw-r--r--src/nvim/charset.c116
-rw-r--r--src/nvim/context.c4
-rw-r--r--src/nvim/cursor.c88
-rw-r--r--src/nvim/cursor_shape.c92
-rw-r--r--src/nvim/eval/funcs.c11
-rw-r--r--src/nvim/lua/converter.c730
-rw-r--r--src/nvim/lua/executor.c206
-rw-r--r--src/nvim/lua/treesitter.c132
-rw-r--r--src/nvim/lua/xdiff.c79
16 files changed, 1791 insertions, 1739 deletions
diff --git a/src/nvim/arabic.c b/src/nvim/arabic.c
index 7ea2e0cf9b..5dcc3d3d0d 100644
--- a/src/nvim/arabic.c
+++ b/src/nvim/arabic.c
@@ -15,9 +15,9 @@
#include <stdbool.h>
-#include "nvim/vim.h"
-#include "nvim/ascii.h"
#include "nvim/arabic.h"
+#include "nvim/ascii.h"
+#include "nvim/vim.h"
// Arabic ISO-10646-1 character set definition
@@ -253,44 +253,44 @@
static bool A_is_a(int cur_c)
{
switch (cur_c) {
- case a_HAMZA:
- case a_ALEF_MADDA:
- case a_ALEF_HAMZA_ABOVE:
- case a_WAW_HAMZA:
- case a_ALEF_HAMZA_BELOW:
- case a_YEH_HAMZA:
- case a_ALEF:
- case a_BEH:
- case a_TEH_MARBUTA:
- case a_TEH:
- case a_THEH:
- case a_JEEM:
- case a_HAH:
- case a_KHAH:
- case a_DAL:
- case a_THAL:
- case a_REH:
- case a_ZAIN:
- case a_SEEN:
- case a_SHEEN:
- case a_SAD:
- case a_DAD:
- case a_TAH:
- case a_ZAH:
- case a_AIN:
- case a_GHAIN:
- case a_TATWEEL:
- case a_FEH:
- case a_QAF:
- case a_KAF:
- case a_LAM:
- case a_MEEM:
- case a_NOON:
- case a_HEH:
- case a_WAW:
- case a_ALEF_MAKSURA:
- case a_YEH:
- return true;
+ case a_HAMZA:
+ case a_ALEF_MADDA:
+ case a_ALEF_HAMZA_ABOVE:
+ case a_WAW_HAMZA:
+ case a_ALEF_HAMZA_BELOW:
+ case a_YEH_HAMZA:
+ case a_ALEF:
+ case a_BEH:
+ case a_TEH_MARBUTA:
+ case a_TEH:
+ case a_THEH:
+ case a_JEEM:
+ case a_HAH:
+ case a_KHAH:
+ case a_DAL:
+ case a_THAL:
+ case a_REH:
+ case a_ZAIN:
+ case a_SEEN:
+ case a_SHEEN:
+ case a_SAD:
+ case a_DAD:
+ case a_TAH:
+ case a_ZAH:
+ case a_AIN:
+ case a_GHAIN:
+ case a_TATWEEL:
+ case a_FEH:
+ case a_QAF:
+ case a_KAF:
+ case a_LAM:
+ case a_MEEM:
+ case a_NOON:
+ case a_HEH:
+ case a_WAW:
+ case a_ALEF_MAKSURA:
+ case a_YEH:
+ return true;
}
return false;
@@ -300,43 +300,43 @@ static bool A_is_a(int cur_c)
static bool A_is_s(int cur_c)
{
switch (cur_c) {
- case a_s_HAMZA:
- case a_s_ALEF_MADDA:
- case a_s_ALEF_HAMZA_ABOVE:
- case a_s_WAW_HAMZA:
- case a_s_ALEF_HAMZA_BELOW:
- case a_s_YEH_HAMZA:
- case a_s_ALEF:
- case a_s_BEH:
- case a_s_TEH_MARBUTA:
- case a_s_TEH:
- case a_s_THEH:
- case a_s_JEEM:
- case a_s_HAH:
- case a_s_KHAH:
- case a_s_DAL:
- case a_s_THAL:
- case a_s_REH:
- case a_s_ZAIN:
- case a_s_SEEN:
- case a_s_SHEEN:
- case a_s_SAD:
- case a_s_DAD:
- case a_s_TAH:
- case a_s_ZAH:
- case a_s_AIN:
- case a_s_GHAIN:
- case a_s_FEH:
- case a_s_QAF:
- case a_s_KAF:
- case a_s_LAM:
- case a_s_MEEM:
- case a_s_NOON:
- case a_s_HEH:
- case a_s_WAW:
- case a_s_ALEF_MAKSURA:
- case a_s_YEH:
- return true;
+ case a_s_HAMZA:
+ case a_s_ALEF_MADDA:
+ case a_s_ALEF_HAMZA_ABOVE:
+ case a_s_WAW_HAMZA:
+ case a_s_ALEF_HAMZA_BELOW:
+ case a_s_YEH_HAMZA:
+ case a_s_ALEF:
+ case a_s_BEH:
+ case a_s_TEH_MARBUTA:
+ case a_s_TEH:
+ case a_s_THEH:
+ case a_s_JEEM:
+ case a_s_HAH:
+ case a_s_KHAH:
+ case a_s_DAL:
+ case a_s_THAL:
+ case a_s_REH:
+ case a_s_ZAIN:
+ case a_s_SEEN:
+ case a_s_SHEEN:
+ case a_s_SAD:
+ case a_s_DAD:
+ case a_s_TAH:
+ case a_s_ZAH:
+ case a_s_AIN:
+ case a_s_GHAIN:
+ case a_s_FEH:
+ case a_s_QAF:
+ case a_s_KAF:
+ case a_s_LAM:
+ case a_s_MEEM:
+ case a_s_NOON:
+ case a_s_HEH:
+ case a_s_WAW:
+ case a_s_ALEF_MAKSURA:
+ case a_s_YEH:
+ return true;
}
return false;
@@ -346,46 +346,46 @@ static bool A_is_s(int cur_c)
static bool A_is_f(int cur_c)
{
switch (cur_c) {
- case a_f_ALEF_MADDA:
- case a_f_ALEF_HAMZA_ABOVE:
- case a_f_WAW_HAMZA:
- case a_f_ALEF_HAMZA_BELOW:
- case a_f_YEH_HAMZA:
- case a_f_ALEF:
- case a_f_BEH:
- case a_f_TEH_MARBUTA:
- case a_f_TEH:
- case a_f_THEH:
- case a_f_JEEM:
- case a_f_HAH:
- case a_f_KHAH:
- case a_f_DAL:
- case a_f_THAL:
- case a_f_REH:
- case a_f_ZAIN:
- case a_f_SEEN:
- case a_f_SHEEN:
- case a_f_SAD:
- case a_f_DAD:
- case a_f_TAH:
- case a_f_ZAH:
- case a_f_AIN:
- case a_f_GHAIN:
- case a_f_FEH:
- case a_f_QAF:
- case a_f_KAF:
- case a_f_LAM:
- case a_f_MEEM:
- case a_f_NOON:
- case a_f_HEH:
- case a_f_WAW:
- case a_f_ALEF_MAKSURA:
- case a_f_YEH:
- case a_f_LAM_ALEF_MADDA_ABOVE:
- case a_f_LAM_ALEF_HAMZA_ABOVE:
- case a_f_LAM_ALEF_HAMZA_BELOW:
- case a_f_LAM_ALEF:
- return true;
+ case a_f_ALEF_MADDA:
+ case a_f_ALEF_HAMZA_ABOVE:
+ case a_f_WAW_HAMZA:
+ case a_f_ALEF_HAMZA_BELOW:
+ case a_f_YEH_HAMZA:
+ case a_f_ALEF:
+ case a_f_BEH:
+ case a_f_TEH_MARBUTA:
+ case a_f_TEH:
+ case a_f_THEH:
+ case a_f_JEEM:
+ case a_f_HAH:
+ case a_f_KHAH:
+ case a_f_DAL:
+ case a_f_THAL:
+ case a_f_REH:
+ case a_f_ZAIN:
+ case a_f_SEEN:
+ case a_f_SHEEN:
+ case a_f_SAD:
+ case a_f_DAD:
+ case a_f_TAH:
+ case a_f_ZAH:
+ case a_f_AIN:
+ case a_f_GHAIN:
+ case a_f_FEH:
+ case a_f_QAF:
+ case a_f_KAF:
+ case a_f_LAM:
+ case a_f_MEEM:
+ case a_f_NOON:
+ case a_f_HEH:
+ case a_f_WAW:
+ case a_f_ALEF_MAKSURA:
+ case a_f_YEH:
+ case a_f_LAM_ALEF_MADDA_ABOVE:
+ case a_f_LAM_ALEF_HAMZA_ABOVE:
+ case a_f_LAM_ALEF_HAMZA_BELOW:
+ case a_f_LAM_ALEF:
+ return true;
}
return false;
}
@@ -394,43 +394,80 @@ static bool A_is_f(int cur_c)
static int chg_c_a2s(int cur_c)
{
switch (cur_c) {
- case a_HAMZA: return a_s_HAMZA;
- case a_ALEF_MADDA: return a_s_ALEF_MADDA;
- case a_ALEF_HAMZA_ABOVE: return a_s_ALEF_HAMZA_ABOVE;
- case a_WAW_HAMZA: return a_s_WAW_HAMZA;
- case a_ALEF_HAMZA_BELOW: return a_s_ALEF_HAMZA_BELOW;
- case a_YEH_HAMZA: return a_s_YEH_HAMZA;
- case a_ALEF: return a_s_ALEF;
- case a_TEH_MARBUTA: return a_s_TEH_MARBUTA;
- case a_DAL: return a_s_DAL;
- case a_THAL: return a_s_THAL;
- case a_REH: return a_s_REH;
- case a_ZAIN: return a_s_ZAIN;
- case a_TATWEEL: return cur_c; // exceptions
- case a_WAW: return a_s_WAW;
- case a_ALEF_MAKSURA: return a_s_ALEF_MAKSURA;
- case a_BEH: return a_s_BEH;
- case a_TEH: return a_s_TEH;
- case a_THEH: return a_s_THEH;
- case a_JEEM: return a_s_JEEM;
- case a_HAH: return a_s_HAH;
- case a_KHAH: return a_s_KHAH;
- case a_SEEN: return a_s_SEEN;
- case a_SHEEN: return a_s_SHEEN;
- case a_SAD: return a_s_SAD;
- case a_DAD: return a_s_DAD;
- case a_TAH: return a_s_TAH;
- case a_ZAH: return a_s_ZAH;
- case a_AIN: return a_s_AIN;
- case a_GHAIN: return a_s_GHAIN;
- case a_FEH: return a_s_FEH;
- case a_QAF: return a_s_QAF;
- case a_KAF: return a_s_KAF;
- case a_LAM: return a_s_LAM;
- case a_MEEM: return a_s_MEEM;
- case a_NOON: return a_s_NOON;
- case a_HEH: return a_s_HEH;
- case a_YEH: return a_s_YEH;
+ case a_HAMZA:
+ return a_s_HAMZA;
+ case a_ALEF_MADDA:
+ return a_s_ALEF_MADDA;
+ case a_ALEF_HAMZA_ABOVE:
+ return a_s_ALEF_HAMZA_ABOVE;
+ case a_WAW_HAMZA:
+ return a_s_WAW_HAMZA;
+ case a_ALEF_HAMZA_BELOW:
+ return a_s_ALEF_HAMZA_BELOW;
+ case a_YEH_HAMZA:
+ return a_s_YEH_HAMZA;
+ case a_ALEF:
+ return a_s_ALEF;
+ case a_TEH_MARBUTA:
+ return a_s_TEH_MARBUTA;
+ case a_DAL:
+ return a_s_DAL;
+ case a_THAL:
+ return a_s_THAL;
+ case a_REH:
+ return a_s_REH;
+ case a_ZAIN:
+ return a_s_ZAIN;
+ case a_TATWEEL:
+ return cur_c; // exceptions
+ case a_WAW:
+ return a_s_WAW;
+ case a_ALEF_MAKSURA:
+ return a_s_ALEF_MAKSURA;
+ case a_BEH:
+ return a_s_BEH;
+ case a_TEH:
+ return a_s_TEH;
+ case a_THEH:
+ return a_s_THEH;
+ case a_JEEM:
+ return a_s_JEEM;
+ case a_HAH:
+ return a_s_HAH;
+ case a_KHAH:
+ return a_s_KHAH;
+ case a_SEEN:
+ return a_s_SEEN;
+ case a_SHEEN:
+ return a_s_SHEEN;
+ case a_SAD:
+ return a_s_SAD;
+ case a_DAD:
+ return a_s_DAD;
+ case a_TAH:
+ return a_s_TAH;
+ case a_ZAH:
+ return a_s_ZAH;
+ case a_AIN:
+ return a_s_AIN;
+ case a_GHAIN:
+ return a_s_GHAIN;
+ case a_FEH:
+ return a_s_FEH;
+ case a_QAF:
+ return a_s_QAF;
+ case a_KAF:
+ return a_s_KAF;
+ case a_LAM:
+ return a_s_LAM;
+ case a_MEEM:
+ return a_s_MEEM;
+ case a_NOON:
+ return a_s_NOON;
+ case a_HEH:
+ return a_s_HEH;
+ case a_YEH:
+ return a_s_YEH;
}
return 0;
}
@@ -439,43 +476,80 @@ static int chg_c_a2s(int cur_c)
static int chg_c_a2i(int cur_c)
{
switch (cur_c) {
- case a_YEH_HAMZA: return a_i_YEH_HAMZA;
- case a_HAMZA: return a_s_HAMZA; // exceptions
- case a_ALEF_MADDA: return a_s_ALEF_MADDA; // exceptions
- case a_ALEF_HAMZA_ABOVE: return a_s_ALEF_HAMZA_ABOVE; // exceptions
- case a_WAW_HAMZA: return a_s_WAW_HAMZA; // exceptions
- case a_ALEF_HAMZA_BELOW: return a_s_ALEF_HAMZA_BELOW; // exceptions
- case a_ALEF: return a_s_ALEF; // exceptions
- case a_TEH_MARBUTA: return a_s_TEH_MARBUTA; // exceptions
- case a_DAL: return a_s_DAL; // exceptions
- case a_THAL: return a_s_THAL; // exceptions
- case a_REH: return a_s_REH; // exceptions
- case a_ZAIN: return a_s_ZAIN; // exceptions
- case a_TATWEEL: return cur_c; // exceptions
- case a_WAW: return a_s_WAW; // exceptions
- case a_ALEF_MAKSURA: return a_s_ALEF_MAKSURA; // exceptions
- case a_BEH: return a_i_BEH;
- case a_TEH: return a_i_TEH;
- case a_THEH: return a_i_THEH;
- case a_JEEM: return a_i_JEEM;
- case a_HAH: return a_i_HAH;
- case a_KHAH: return a_i_KHAH;
- case a_SEEN: return a_i_SEEN;
- case a_SHEEN: return a_i_SHEEN;
- case a_SAD: return a_i_SAD;
- case a_DAD: return a_i_DAD;
- case a_TAH: return a_i_TAH;
- case a_ZAH: return a_i_ZAH;
- case a_AIN: return a_i_AIN;
- case a_GHAIN: return a_i_GHAIN;
- case a_FEH: return a_i_FEH;
- case a_QAF: return a_i_QAF;
- case a_KAF: return a_i_KAF;
- case a_LAM: return a_i_LAM;
- case a_MEEM: return a_i_MEEM;
- case a_NOON: return a_i_NOON;
- case a_HEH: return a_i_HEH;
- case a_YEH: return a_i_YEH;
+ case a_YEH_HAMZA:
+ return a_i_YEH_HAMZA;
+ case a_HAMZA:
+ return a_s_HAMZA; // exceptions
+ case a_ALEF_MADDA:
+ return a_s_ALEF_MADDA; // exceptions
+ case a_ALEF_HAMZA_ABOVE:
+ return a_s_ALEF_HAMZA_ABOVE; // exceptions
+ case a_WAW_HAMZA:
+ return a_s_WAW_HAMZA; // exceptions
+ case a_ALEF_HAMZA_BELOW:
+ return a_s_ALEF_HAMZA_BELOW; // exceptions
+ case a_ALEF:
+ return a_s_ALEF; // exceptions
+ case a_TEH_MARBUTA:
+ return a_s_TEH_MARBUTA; // exceptions
+ case a_DAL:
+ return a_s_DAL; // exceptions
+ case a_THAL:
+ return a_s_THAL; // exceptions
+ case a_REH:
+ return a_s_REH; // exceptions
+ case a_ZAIN:
+ return a_s_ZAIN; // exceptions
+ case a_TATWEEL:
+ return cur_c; // exceptions
+ case a_WAW:
+ return a_s_WAW; // exceptions
+ case a_ALEF_MAKSURA:
+ return a_s_ALEF_MAKSURA; // exceptions
+ case a_BEH:
+ return a_i_BEH;
+ case a_TEH:
+ return a_i_TEH;
+ case a_THEH:
+ return a_i_THEH;
+ case a_JEEM:
+ return a_i_JEEM;
+ case a_HAH:
+ return a_i_HAH;
+ case a_KHAH:
+ return a_i_KHAH;
+ case a_SEEN:
+ return a_i_SEEN;
+ case a_SHEEN:
+ return a_i_SHEEN;
+ case a_SAD:
+ return a_i_SAD;
+ case a_DAD:
+ return a_i_DAD;
+ case a_TAH:
+ return a_i_TAH;
+ case a_ZAH:
+ return a_i_ZAH;
+ case a_AIN:
+ return a_i_AIN;
+ case a_GHAIN:
+ return a_i_GHAIN;
+ case a_FEH:
+ return a_i_FEH;
+ case a_QAF:
+ return a_i_QAF;
+ case a_KAF:
+ return a_i_KAF;
+ case a_LAM:
+ return a_i_LAM;
+ case a_MEEM:
+ return a_i_MEEM;
+ case a_NOON:
+ return a_i_NOON;
+ case a_HEH:
+ return a_i_HEH;
+ case a_YEH:
+ return a_i_YEH;
}
return 0;
}
@@ -484,43 +558,80 @@ static int chg_c_a2i(int cur_c)
static int chg_c_a2m(int cur_c)
{
switch (cur_c) {
- case a_HAMZA: return a_s_HAMZA; // exception
- case a_ALEF_MADDA: return a_f_ALEF_MADDA; // exception
- case a_ALEF_HAMZA_ABOVE: return a_f_ALEF_HAMZA_ABOVE; // exception
- case a_WAW_HAMZA: return a_f_WAW_HAMZA; // exception
- case a_ALEF_HAMZA_BELOW: return a_f_ALEF_HAMZA_BELOW; // exception
- case a_YEH_HAMZA: return a_m_YEH_HAMZA;
- case a_ALEF: return a_f_ALEF; // exception
- case a_BEH: return a_m_BEH;
- case a_TEH_MARBUTA: return a_f_TEH_MARBUTA; // exception
- case a_TEH: return a_m_TEH;
- case a_THEH: return a_m_THEH;
- case a_JEEM: return a_m_JEEM;
- case a_HAH: return a_m_HAH;
- case a_KHAH: return a_m_KHAH;
- case a_DAL: return a_f_DAL; // exception
- case a_THAL: return a_f_THAL; // exception
- case a_REH: return a_f_REH; // exception
- case a_ZAIN: return a_f_ZAIN; // exception
- case a_SEEN: return a_m_SEEN;
- case a_SHEEN: return a_m_SHEEN;
- case a_SAD: return a_m_SAD;
- case a_DAD: return a_m_DAD;
- case a_TAH: return a_m_TAH;
- case a_ZAH: return a_m_ZAH;
- case a_AIN: return a_m_AIN;
- case a_GHAIN: return a_m_GHAIN;
- case a_TATWEEL: return cur_c; // exception
- case a_FEH: return a_m_FEH;
- case a_QAF: return a_m_QAF;
- case a_KAF: return a_m_KAF;
- case a_LAM: return a_m_LAM;
- case a_MEEM: return a_m_MEEM;
- case a_NOON: return a_m_NOON;
- case a_HEH: return a_m_HEH;
- case a_WAW: return a_f_WAW; // exception
- case a_ALEF_MAKSURA: return a_f_ALEF_MAKSURA; // exception
- case a_YEH: return a_m_YEH;
+ case a_HAMZA:
+ return a_s_HAMZA; // exception
+ case a_ALEF_MADDA:
+ return a_f_ALEF_MADDA; // exception
+ case a_ALEF_HAMZA_ABOVE:
+ return a_f_ALEF_HAMZA_ABOVE; // exception
+ case a_WAW_HAMZA:
+ return a_f_WAW_HAMZA; // exception
+ case a_ALEF_HAMZA_BELOW:
+ return a_f_ALEF_HAMZA_BELOW; // exception
+ case a_YEH_HAMZA:
+ return a_m_YEH_HAMZA;
+ case a_ALEF:
+ return a_f_ALEF; // exception
+ case a_BEH:
+ return a_m_BEH;
+ case a_TEH_MARBUTA:
+ return a_f_TEH_MARBUTA; // exception
+ case a_TEH:
+ return a_m_TEH;
+ case a_THEH:
+ return a_m_THEH;
+ case a_JEEM:
+ return a_m_JEEM;
+ case a_HAH:
+ return a_m_HAH;
+ case a_KHAH:
+ return a_m_KHAH;
+ case a_DAL:
+ return a_f_DAL; // exception
+ case a_THAL:
+ return a_f_THAL; // exception
+ case a_REH:
+ return a_f_REH; // exception
+ case a_ZAIN:
+ return a_f_ZAIN; // exception
+ case a_SEEN:
+ return a_m_SEEN;
+ case a_SHEEN:
+ return a_m_SHEEN;
+ case a_SAD:
+ return a_m_SAD;
+ case a_DAD:
+ return a_m_DAD;
+ case a_TAH:
+ return a_m_TAH;
+ case a_ZAH:
+ return a_m_ZAH;
+ case a_AIN:
+ return a_m_AIN;
+ case a_GHAIN:
+ return a_m_GHAIN;
+ case a_TATWEEL:
+ return cur_c; // exception
+ case a_FEH:
+ return a_m_FEH;
+ case a_QAF:
+ return a_m_QAF;
+ case a_KAF:
+ return a_m_KAF;
+ case a_LAM:
+ return a_m_LAM;
+ case a_MEEM:
+ return a_m_MEEM;
+ case a_NOON:
+ return a_m_NOON;
+ case a_HEH:
+ return a_m_HEH;
+ case a_WAW:
+ return a_f_WAW; // exception
+ case a_ALEF_MAKSURA:
+ return a_f_ALEF_MAKSURA; // exception
+ case a_YEH:
+ return a_m_YEH;
}
return 0;
}
@@ -538,43 +649,80 @@ static int chg_c_a2f(int cur_c)
// a_f_LAM_ALEF_HAMZA_BELOW;
switch (cur_c) {
- case a_HAMZA: return a_s_HAMZA; // exception
- case a_ALEF_MADDA: return a_f_ALEF_MADDA;
- case a_ALEF_HAMZA_ABOVE: return a_f_ALEF_HAMZA_ABOVE;
- case a_WAW_HAMZA: return a_f_WAW_HAMZA;
- case a_ALEF_HAMZA_BELOW: return a_f_ALEF_HAMZA_BELOW;
- case a_YEH_HAMZA: return a_f_YEH_HAMZA;
- case a_ALEF: return a_f_ALEF;
- case a_BEH: return a_f_BEH;
- case a_TEH_MARBUTA: return a_f_TEH_MARBUTA;
- case a_TEH: return a_f_TEH;
- case a_THEH: return a_f_THEH;
- case a_JEEM: return a_f_JEEM;
- case a_HAH: return a_f_HAH;
- case a_KHAH: return a_f_KHAH;
- case a_DAL: return a_f_DAL;
- case a_THAL: return a_f_THAL;
- case a_REH: return a_f_REH;
- case a_ZAIN: return a_f_ZAIN;
- case a_SEEN: return a_f_SEEN;
- case a_SHEEN: return a_f_SHEEN;
- case a_SAD: return a_f_SAD;
- case a_DAD: return a_f_DAD;
- case a_TAH: return a_f_TAH;
- case a_ZAH: return a_f_ZAH;
- case a_AIN: return a_f_AIN;
- case a_GHAIN: return a_f_GHAIN;
- case a_TATWEEL: return cur_c; // exception
- case a_FEH: return a_f_FEH;
- case a_QAF: return a_f_QAF;
- case a_KAF: return a_f_KAF;
- case a_LAM: return a_f_LAM;
- case a_MEEM: return a_f_MEEM;
- case a_NOON: return a_f_NOON;
- case a_HEH: return a_f_HEH;
- case a_WAW: return a_f_WAW;
- case a_ALEF_MAKSURA: return a_f_ALEF_MAKSURA;
- case a_YEH: return a_f_YEH;
+ case a_HAMZA:
+ return a_s_HAMZA; // exception
+ case a_ALEF_MADDA:
+ return a_f_ALEF_MADDA;
+ case a_ALEF_HAMZA_ABOVE:
+ return a_f_ALEF_HAMZA_ABOVE;
+ case a_WAW_HAMZA:
+ return a_f_WAW_HAMZA;
+ case a_ALEF_HAMZA_BELOW:
+ return a_f_ALEF_HAMZA_BELOW;
+ case a_YEH_HAMZA:
+ return a_f_YEH_HAMZA;
+ case a_ALEF:
+ return a_f_ALEF;
+ case a_BEH:
+ return a_f_BEH;
+ case a_TEH_MARBUTA:
+ return a_f_TEH_MARBUTA;
+ case a_TEH:
+ return a_f_TEH;
+ case a_THEH:
+ return a_f_THEH;
+ case a_JEEM:
+ return a_f_JEEM;
+ case a_HAH:
+ return a_f_HAH;
+ case a_KHAH:
+ return a_f_KHAH;
+ case a_DAL:
+ return a_f_DAL;
+ case a_THAL:
+ return a_f_THAL;
+ case a_REH:
+ return a_f_REH;
+ case a_ZAIN:
+ return a_f_ZAIN;
+ case a_SEEN:
+ return a_f_SEEN;
+ case a_SHEEN:
+ return a_f_SHEEN;
+ case a_SAD:
+ return a_f_SAD;
+ case a_DAD:
+ return a_f_DAD;
+ case a_TAH:
+ return a_f_TAH;
+ case a_ZAH:
+ return a_f_ZAH;
+ case a_AIN:
+ return a_f_AIN;
+ case a_GHAIN:
+ return a_f_GHAIN;
+ case a_TATWEEL:
+ return cur_c; // exception
+ case a_FEH:
+ return a_f_FEH;
+ case a_QAF:
+ return a_f_QAF;
+ case a_KAF:
+ return a_f_KAF;
+ case a_LAM:
+ return a_f_LAM;
+ case a_MEEM:
+ return a_f_MEEM;
+ case a_NOON:
+ return a_f_NOON;
+ case a_HEH:
+ return a_f_HEH;
+ case a_WAW:
+ return a_f_WAW;
+ case a_ALEF_MAKSURA:
+ return a_f_ALEF_MAKSURA;
+ case a_YEH:
+ return a_f_YEH;
}
return 0;
}
@@ -586,29 +734,52 @@ static int chg_c_a2f(int cur_c)
static int chg_c_i2m(int cur_c)
{
switch (cur_c) {
- case a_i_YEH_HAMZA: return a_m_YEH_HAMZA;
- case a_i_BEH: return a_m_BEH;
- case a_i_TEH: return a_m_TEH;
- case a_i_THEH: return a_m_THEH;
- case a_i_JEEM: return a_m_JEEM;
- case a_i_HAH: return a_m_HAH;
- case a_i_KHAH: return a_m_KHAH;
- case a_i_SEEN: return a_m_SEEN;
- case a_i_SHEEN: return a_m_SHEEN;
- case a_i_SAD: return a_m_SAD;
- case a_i_DAD: return a_m_DAD;
- case a_i_TAH: return a_m_TAH;
- case a_i_ZAH: return a_m_ZAH;
- case a_i_AIN: return a_m_AIN;
- case a_i_GHAIN: return a_m_GHAIN;
- case a_i_FEH: return a_m_FEH;
- case a_i_QAF: return a_m_QAF;
- case a_i_KAF: return a_m_KAF;
- case a_i_LAM: return a_m_LAM;
- case a_i_MEEM: return a_m_MEEM;
- case a_i_NOON: return a_m_NOON;
- case a_i_HEH: return a_m_HEH;
- case a_i_YEH: return a_m_YEH;
+ case a_i_YEH_HAMZA:
+ return a_m_YEH_HAMZA;
+ case a_i_BEH:
+ return a_m_BEH;
+ case a_i_TEH:
+ return a_m_TEH;
+ case a_i_THEH:
+ return a_m_THEH;
+ case a_i_JEEM:
+ return a_m_JEEM;
+ case a_i_HAH:
+ return a_m_HAH;
+ case a_i_KHAH:
+ return a_m_KHAH;
+ case a_i_SEEN:
+ return a_m_SEEN;
+ case a_i_SHEEN:
+ return a_m_SHEEN;
+ case a_i_SAD:
+ return a_m_SAD;
+ case a_i_DAD:
+ return a_m_DAD;
+ case a_i_TAH:
+ return a_m_TAH;
+ case a_i_ZAH:
+ return a_m_ZAH;
+ case a_i_AIN:
+ return a_m_AIN;
+ case a_i_GHAIN:
+ return a_m_GHAIN;
+ case a_i_FEH:
+ return a_m_FEH;
+ case a_i_QAF:
+ return a_m_QAF;
+ case a_i_KAF:
+ return a_m_KAF;
+ case a_i_LAM:
+ return a_m_LAM;
+ case a_i_MEEM:
+ return a_m_MEEM;
+ case a_i_NOON:
+ return a_m_NOON;
+ case a_i_HEH:
+ return a_m_HEH;
+ case a_i_YEH:
+ return a_m_YEH;
}
return 0;
}
@@ -618,43 +789,66 @@ static int chg_c_i2m(int cur_c)
static int chg_c_f2m(int cur_c)
{
switch (cur_c) {
- // NOTE: these encodings are multi-positional, no ?
- // case a_f_ALEF_MADDA:
- // case a_f_ALEF_HAMZA_ABOVE:
- // case a_f_ALEF_HAMZA_BELOW:
- case a_f_YEH_HAMZA: return a_m_YEH_HAMZA;
- case a_f_WAW_HAMZA: // exceptions
- case a_f_ALEF:
- case a_f_TEH_MARBUTA:
- case a_f_DAL:
- case a_f_THAL:
- case a_f_REH:
- case a_f_ZAIN:
- case a_f_WAW:
- case a_f_ALEF_MAKSURA:
- return cur_c;
- case a_f_BEH: return a_m_BEH;
- case a_f_TEH: return a_m_TEH;
- case a_f_THEH: return a_m_THEH;
- case a_f_JEEM: return a_m_JEEM;
- case a_f_HAH: return a_m_HAH;
- case a_f_KHAH: return a_m_KHAH;
- case a_f_SEEN: return a_m_SEEN;
- case a_f_SHEEN: return a_m_SHEEN;
- case a_f_SAD: return a_m_SAD;
- case a_f_DAD: return a_m_DAD;
- case a_f_TAH: return a_m_TAH;
- case a_f_ZAH: return a_m_ZAH;
- case a_f_AIN: return a_m_AIN;
- case a_f_GHAIN: return a_m_GHAIN;
- case a_f_FEH: return a_m_FEH;
- case a_f_QAF: return a_m_QAF;
- case a_f_KAF: return a_m_KAF;
- case a_f_LAM: return a_m_LAM;
- case a_f_MEEM: return a_m_MEEM;
- case a_f_NOON: return a_m_NOON;
- case a_f_HEH: return a_m_HEH;
- case a_f_YEH: return a_m_YEH;
+ // NOTE: these encodings are multi-positional, no ?
+ // case a_f_ALEF_MADDA:
+ // case a_f_ALEF_HAMZA_ABOVE:
+ // case a_f_ALEF_HAMZA_BELOW:
+ case a_f_YEH_HAMZA:
+ return a_m_YEH_HAMZA;
+ case a_f_WAW_HAMZA: // exceptions
+ case a_f_ALEF:
+ case a_f_TEH_MARBUTA:
+ case a_f_DAL:
+ case a_f_THAL:
+ case a_f_REH:
+ case a_f_ZAIN:
+ case a_f_WAW:
+ case a_f_ALEF_MAKSURA:
+ return cur_c;
+ case a_f_BEH:
+ return a_m_BEH;
+ case a_f_TEH:
+ return a_m_TEH;
+ case a_f_THEH:
+ return a_m_THEH;
+ case a_f_JEEM:
+ return a_m_JEEM;
+ case a_f_HAH:
+ return a_m_HAH;
+ case a_f_KHAH:
+ return a_m_KHAH;
+ case a_f_SEEN:
+ return a_m_SEEN;
+ case a_f_SHEEN:
+ return a_m_SHEEN;
+ case a_f_SAD:
+ return a_m_SAD;
+ case a_f_DAD:
+ return a_m_DAD;
+ case a_f_TAH:
+ return a_m_TAH;
+ case a_f_ZAH:
+ return a_m_ZAH;
+ case a_f_AIN:
+ return a_m_AIN;
+ case a_f_GHAIN:
+ return a_m_GHAIN;
+ case a_f_FEH:
+ return a_m_FEH;
+ case a_f_QAF:
+ return a_m_QAF;
+ case a_f_KAF:
+ return a_m_KAF;
+ case a_f_LAM:
+ return a_m_LAM;
+ case a_f_MEEM:
+ return a_m_MEEM;
+ case a_f_NOON:
+ return a_m_NOON;
+ case a_f_HEH:
+ return a_m_HEH;
+ case a_f_YEH:
+ return a_m_YEH;
// NOTE: these encodings are multi-positional, no ?
// case a_f_LAM_ALEF_MADDA_ABOVE:
// case a_f_LAM_ALEF_HAMZA_ABOVE:
@@ -668,10 +862,14 @@ static int chg_c_f2m(int cur_c)
static int chg_c_laa2i(int hid_c)
{
switch (hid_c) {
- case a_ALEF_MADDA: return a_s_LAM_ALEF_MADDA_ABOVE;
- case a_ALEF_HAMZA_ABOVE: return a_s_LAM_ALEF_HAMZA_ABOVE;
- case a_ALEF_HAMZA_BELOW: return a_s_LAM_ALEF_HAMZA_BELOW;
- case a_ALEF: return a_s_LAM_ALEF;
+ case a_ALEF_MADDA:
+ return a_s_LAM_ALEF_MADDA_ABOVE;
+ case a_ALEF_HAMZA_ABOVE:
+ return a_s_LAM_ALEF_HAMZA_ABOVE;
+ case a_ALEF_HAMZA_BELOW:
+ return a_s_LAM_ALEF_HAMZA_BELOW;
+ case a_ALEF:
+ return a_s_LAM_ALEF;
}
return 0;
}
@@ -680,10 +878,14 @@ static int chg_c_laa2i(int hid_c)
static int chg_c_laa2f(int hid_c)
{
switch (hid_c) {
- case a_ALEF_MADDA: return a_f_LAM_ALEF_MADDA_ABOVE;
- case a_ALEF_HAMZA_ABOVE: return a_f_LAM_ALEF_HAMZA_ABOVE;
- case a_ALEF_HAMZA_BELOW: return a_f_LAM_ALEF_HAMZA_BELOW;
- case a_ALEF: return a_f_LAM_ALEF;
+ case a_ALEF_MADDA:
+ return a_f_LAM_ALEF_MADDA_ABOVE;
+ case a_ALEF_HAMZA_ABOVE:
+ return a_f_LAM_ALEF_HAMZA_ABOVE;
+ case a_ALEF_HAMZA_BELOW:
+ return a_f_LAM_ALEF_HAMZA_BELOW;
+ case a_ALEF:
+ return a_f_LAM_ALEF;
}
return 0;
}
@@ -708,8 +910,7 @@ static int half_shape(int c)
// in: "prev_c1" is the first composing char for the previous char
// (not shaped)
// in: "next_c" is the next character (not shaped).
-int arabic_shape(int c, int *ccp, int *c1p, int prev_c, int prev_c1,
- int next_c)
+int arabic_shape(int c, int *ccp, int *c1p, int prev_c, int prev_c1, int next_c)
{
// Deal only with Arabic character, pass back all others
if (!A_is_ok(c)) {
@@ -786,9 +987,9 @@ bool arabic_maycombine(int two)
{
if (p_arshape && !p_tbidi) {
return two == a_ALEF_MADDA
- || two == a_ALEF_HAMZA_ABOVE
- || two == a_ALEF_HAMZA_BELOW
- || two == a_ALEF;
+ || two == a_ALEF_HAMZA_ABOVE
+ || two == a_ALEF_HAMZA_BELOW
+ || two == a_ALEF;
}
return false;
}
diff --git a/src/nvim/aucmd.c b/src/nvim/aucmd.c
index 802fc9de57..af519dcba9 100644
--- a/src/nvim/aucmd.c
+++ b/src/nvim/aucmd.c
@@ -1,16 +1,16 @@
// 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 "nvim/os/os.h"
-#include "nvim/fileio.h"
-#include "nvim/vim.h"
-#include "nvim/main.h"
-#include "nvim/ui.h"
#include "nvim/aucmd.h"
+#include "nvim/buffer.h"
#include "nvim/eval.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
-#include "nvim/buffer.h"
+#include "nvim/fileio.h"
+#include "nvim/main.h"
+#include "nvim/os/os.h"
+#include "nvim/ui.h"
+#include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "aucmd.c.generated.h"
diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c
index 417953eb14..4c502b53d4 100644
--- a/src/nvim/autocmd.c
+++ b/src/nvim/autocmd.c
@@ -3,10 +3,9 @@
// autocmd.c: Autocommand related functions
-#include "nvim/autocmd.h"
-
#include "nvim/api/private/helpers.h"
#include "nvim/ascii.h"
+#include "nvim/autocmd.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
@@ -326,8 +325,7 @@ static void au_del_group(char_u *name)
event = (event_T)((int)event + 1)) {
for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next) {
if (ap->group == i && ap->pat != NULL) {
- give_warning(
- (char_u *)_("W19: Deleting augroup that is still in use"), true);
+ give_warning((char_u *)_("W19: Deleting augroup that is still in use"), true);
in_use = true;
event = NUM_EVENTS;
break;
@@ -761,13 +759,8 @@ static int au_get_grouparg(char_u **argp)
// If *cmd == NUL: show entries.
// If forceit == true: delete entries.
// If group is not AUGROUP_ALL: only use this group.
-static int do_autocmd_event(event_T event,
- char_u *pat,
- bool once,
- int nested,
- char_u *cmd,
- int forceit,
- int group)
+static int do_autocmd_event(event_T event, char_u *pat, bool once, int nested, char_u *cmd,
+ int forceit, int group)
{
AutoPat *ap;
AutoPat **prev_ap;
@@ -847,11 +840,10 @@ static int do_autocmd_event(event_T event,
if (is_buflocal) {
// normalize pat into standard "<buffer>#N" form
- snprintf(
- (char *)buflocal_pat,
- BUFLOCAL_PAT_LEN,
- "<buffer=%d>",
- buflocal_nr);
+ snprintf((char *)buflocal_pat,
+ BUFLOCAL_PAT_LEN,
+ "<buffer=%d>",
+ buflocal_nr);
pat = buflocal_pat; // can modify pat and patlen
patlen = (int)STRLEN(buflocal_pat); // but not endpat
@@ -889,7 +881,6 @@ static int do_autocmd_event(event_T event,
} else if (*cmd == NUL) {
// Show autocmd's for this autopat, or buflocals <buffer=X>
show_autocmd(ap, event);
-
} else if (ap->next == NULL) {
// Add autocmd to this autopat, if it's the last one.
break;
@@ -967,8 +958,7 @@ static int do_autocmd_event(event_T event,
// Implementation of ":doautocmd [group] event [fname]".
// Return OK for success, FAIL for failure;
-int do_doautocmd(char_u *arg,
- bool do_msg, // give message for no matching autocmds?
+int do_doautocmd(char_u *arg, bool do_msg, // give message for no matching autocmds?
bool *did_something)
{
char_u *fname;
@@ -1188,7 +1178,7 @@ void aucmd_restbuf(aco_save_T *aco)
}
}
}
- win_found:
+win_found:
win_remove(curwin, NULL);
pmap_del(handle_T)(&window_handles, curwin->handle);
@@ -1268,11 +1258,7 @@ void aucmd_restbuf(aco_save_T *aco)
/// @param buf Buffer for <abuf>
///
/// @return true if some commands were executed.
-bool apply_autocmds(event_T event,
- char_u *fname,
- char_u *fname_io,
- bool force,
- buf_T *buf)
+bool apply_autocmds(event_T event, char_u *fname, char_u *fname_io, bool force, buf_T *buf)
{
return apply_autocmds_group(event, fname, fname_io, force, AUGROUP_ALL, buf,
NULL);
@@ -1289,11 +1275,7 @@ bool apply_autocmds(event_T event,
/// @param exarg Ex command arguments
///
/// @return true if some commands were executed.
-bool apply_autocmds_exarg(event_T event,
- char_u *fname,
- char_u *fname_io,
- bool force,
- buf_T *buf,
+bool apply_autocmds_exarg(event_T event, char_u *fname, char_u *fname_io, bool force, buf_T *buf,
exarg_T *eap)
{
return apply_autocmds_group(event, fname, fname_io, force, AUGROUP_ALL, buf,
@@ -1313,11 +1295,7 @@ bool apply_autocmds_exarg(event_T event,
/// @param[in,out] retval caller's retval
///
/// @return true if some autocommands were executed
-bool apply_autocmds_retval(event_T event,
- char_u *fname,
- char_u *fname_io,
- bool force,
- buf_T *buf,
+bool apply_autocmds_retval(event_T event, char_u *fname, char_u *fname_io, bool force, buf_T *buf,
int *retval)
{
if (should_abort(*retval)) {
@@ -1344,8 +1322,7 @@ bool has_event(event_T event) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
/// the current mode.
bool has_cursorhold(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
- return has_event(
- (get_real_state() == NORMAL_BUSY ? EVENT_CURSORHOLD : EVENT_CURSORHOLDI));
+ return has_event((get_real_state() == NORMAL_BUSY ? EVENT_CURSORHOLD : EVENT_CURSORHOLDI));
// return first_autopat[] != NULL;
}
@@ -1376,13 +1353,8 @@ bool trigger_cursorhold(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
/// @param eap Ex command arguments
///
/// @return true if some commands were executed.
-static bool apply_autocmds_group(event_T event,
- char_u *fname,
- char_u *fname_io,
- bool force,
- int group,
- buf_T *buf,
- exarg_T *eap)
+static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, bool force,
+ int group, buf_T *buf, exarg_T *eap)
{
char_u *sfname = NULL; // short file name
char_u *tail;
@@ -1769,19 +1741,18 @@ void auto_next_pat(AutoPatCmd *apc, int stop_at_last)
&& (apc->group == AUGROUP_ALL || apc->group == ap->group)) {
// execution-condition
if (ap->buflocal_nr == 0
- ? match_file_pat(
- NULL,
- &ap->reg_prog,
- apc->fname,
- apc->sfname,
- apc->tail,
- ap->allow_dirs)
+ ? match_file_pat(NULL,
+ &ap->reg_prog,
+ apc->fname,
+ apc->sfname,
+ apc->tail,
+ ap->allow_dirs)
: ap->buflocal_nr == apc->arg_bufnr) {
const char *const name = event_nr2name(apc->event);
s = _("%s Autocommands for \"%s\"");
const size_t sourcing_name_len
- = (STRLEN(s) + strlen(name) + (size_t)ap->patlen + 1);
+ = (STRLEN(s) + strlen(name) + (size_t)ap->patlen + 1);
sourcing_name = xmalloc(sourcing_name_len);
snprintf((char *)sourcing_name, sourcing_name_len, s, name,
@@ -1885,9 +1856,7 @@ char_u *getnextac(int c, void *cookie, int indent, bool do_concat)
/// @param event event that occurred.
/// @param sfname filename the event occurred in.
/// @param buf buffer the file is open in
-bool has_autocmd(event_T event,
- char_u *sfname,
- buf_T *buf) FUNC_ATTR_WARN_UNUSED_RESULT
+bool has_autocmd(event_T event, char_u *sfname, buf_T *buf) FUNC_ATTR_WARN_UNUSED_RESULT
{
AutoPat *ap;
char_u *fname;
@@ -1910,13 +1879,12 @@ bool has_autocmd(event_T event,
for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next) {
if (ap->pat != NULL && ap->cmds != NULL
&& (ap->buflocal_nr == 0
- ? match_file_pat(
- NULL,
- &ap->reg_prog,
- fname,
- sfname,
- tail,
- ap->allow_dirs)
+ ? match_file_pat(NULL,
+ &ap->reg_prog,
+ fname,
+ sfname,
+ tail,
+ ap->allow_dirs)
: buf != NULL && ap->buflocal_nr == buf->b_fnum)) {
retval = true;
break;
@@ -1948,11 +1916,8 @@ char_u *get_augroup_name(expand_T *xp, int idx)
return (char_u *)AUGROUP_NAME(idx);
}
-char_u *set_context_in_autocmd(
- expand_T *xp,
- char_u *arg,
- int doautocmd // true for :doauto*, false for :autocmd
-)
+char_u *set_context_in_autocmd(expand_T *xp, char_u *arg, int doautocmd // true for :doauto*, false for :autocmd
+ )
{
char_u *p;
int group;
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 55db72aa16..1893bdba0c 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -19,32 +19,34 @@
// The current implementation remembers all file names ever used.
//
+#include <assert.h>
+#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
-#include <inttypes.h>
-#include <assert.h>
#include "nvim/api/private/helpers.h"
#include "nvim/api/vim.h"
#include "nvim/ascii.h"
#include "nvim/assert.h"
-#include "nvim/channel.h"
-#include "nvim/vim.h"
#include "nvim/buffer.h"
+#include "nvim/buffer_updates.h"
#include "nvim/change.h"
+#include "nvim/channel.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/digraph.h"
#include "nvim/eval.h"
-#include "nvim/ex_cmds2.h"
#include "nvim/ex_cmds.h"
+#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_eval.h"
#include "nvim/ex_getln.h"
-#include "nvim/fileio.h"
+#include "nvim/extmark.h"
#include "nvim/file_search.h"
+#include "nvim/fileio.h"
#include "nvim/fold.h"
+#include "nvim/garray.h"
#include "nvim/getchar.h"
#include "nvim/hashtab.h"
#include "nvim/highlight.h"
@@ -52,19 +54,21 @@
#include "nvim/indent_c.h"
#include "nvim/main.h"
#include "nvim/mark.h"
-#include "nvim/extmark.h"
#include "nvim/mbyte.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/garray.h"
#include "nvim/move.h"
#include "nvim/option.h"
+#include "nvim/os/input.h"
+#include "nvim/os/os.h"
+#include "nvim/os/time.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/quickfix.h"
#include "nvim/regexp.h"
#include "nvim/screen.h"
+#include "nvim/shada.h"
#include "nvim/sign.h"
#include "nvim/spell.h"
#include "nvim/strings.h"
@@ -72,12 +76,8 @@
#include "nvim/ui.h"
#include "nvim/undo.h"
#include "nvim/version.h"
+#include "nvim/vim.h"
#include "nvim/window.h"
-#include "nvim/shada.h"
-#include "nvim/os/os.h"
-#include "nvim/os/time.h"
-#include "nvim/os/input.h"
-#include "nvim/buffer_updates.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "buffer.c.generated.h"
@@ -99,11 +99,9 @@ typedef enum {
} BufFreeFlags;
// Read data from buffer for retrying.
-static int
-read_buffer(
- int read_stdin, // read file from stdin, otherwise fifo
- exarg_T *eap, // for forced 'ff' and 'fenc' or NULL
- int flags) // extra flags for readfile()
+static int read_buffer(int read_stdin, // read file from stdin, otherwise fifo
+ exarg_T *eap, // for forced 'ff' and 'fenc' or NULL
+ int flags) // extra flags for readfile()
{
int retval = OK;
linenr_T line_count;
@@ -114,11 +112,10 @@ read_buffer(
// 'fileencoding' was guessed wrong.
//
line_count = curbuf->b_ml.ml_line_count;
- retval = readfile(
- read_stdin ? NULL : curbuf->b_ffname,
- read_stdin ? NULL : curbuf->b_fname,
- (linenr_T)line_count, (linenr_T)0, (linenr_T)MAXLNUM, eap,
- flags | READ_BUFFER);
+ retval = readfile(read_stdin ? NULL : curbuf->b_ffname,
+ read_stdin ? NULL : curbuf->b_fname,
+ (linenr_T)line_count, (linenr_T)0, (linenr_T)MAXLNUM, eap,
+ flags | READ_BUFFER);
if (retval == OK) {
// Delete the binary lines.
while (--line_count >= 0) {
@@ -152,11 +149,10 @@ read_buffer(
// Open current buffer, that is: open the memfile and read the file into
// memory.
// Return FAIL for failure, OK otherwise.
-int open_buffer(
- int read_stdin, // read file from stdin
- exarg_T *eap, // for forced 'ff' and 'fenc' or NULL
- int flags // extra flags for readfile()
-)
+int open_buffer(int read_stdin, // read file from stdin
+ exarg_T *eap, // for forced 'ff' and 'fenc' or NULL
+ int flags // extra flags for readfile()
+ )
{
int retval = OK;
bufref_T old_curbuf;
@@ -169,8 +165,9 @@ int open_buffer(
* user may have reset the flag by hand.
*/
if (readonlymode && curbuf->b_ffname != NULL
- && (curbuf->b_flags & BF_NEVERLOADED))
+ && (curbuf->b_flags & BF_NEVERLOADED)) {
curbuf->b_p_ro = true;
+ }
if (ml_open(curbuf) == FAIL) {
/*
@@ -227,8 +224,7 @@ int open_buffer(
|| (S_ISCHR(perm)
&& is_dev_fd_file(curbuf->b_ffname))
# endif
- )
- ) {
+ )) {
read_fifo = true;
}
if (read_fifo) {
@@ -267,8 +263,8 @@ int open_buffer(
*/
curbuf->b_p_bin = true;
retval = readfile(NULL, NULL, (linenr_T)0,
- (linenr_T)0, (linenr_T)MAXLNUM, NULL,
- flags | (READ_NEW + READ_STDIN));
+ (linenr_T)0, (linenr_T)MAXLNUM, NULL,
+ flags | (READ_NEW + READ_STDIN));
curbuf->b_p_bin = save_bin;
if (retval == OK) {
retval = read_buffer(true, eap, flags);
@@ -431,8 +427,9 @@ bool close_buffer(win_T *win, buf_T *buf, int action, bool abort_if_last)
del_buf = true;
unload_buf = true;
wipe_buf = true;
- } else if (buf->b_p_bh[0] == 'u') // 'bufhidden' == "unload"
+ } else if (buf->b_p_bh[0] == 'u') { // 'bufhidden' == "unload"
unload_buf = true;
+ }
}
if (buf->terminal && (unload_buf || del_buf || wipe_buf)) {
@@ -806,8 +803,8 @@ static void free_buffer_stuff(buf_T *buf, int free_flags)
// Avoid losing b:changedtick when deleting buffer: clearing variables
// implies using clear_tv() on b:changedtick and that sets changedtick to
// zero.
- hashitem_T *const changedtick_hi = hash_find(
- &buf->b_vars->dv_hashtab, (const char_u *)"changedtick");
+ hashitem_T *const changedtick_hi = hash_find(&buf->b_vars->dv_hashtab,
+ (const char_u *)"changedtick");
assert(changedtick_hi != NULL);
hash_remove(&buf->b_vars->dv_hashtab, changedtick_hi);
}
@@ -831,7 +828,7 @@ static void free_buffer_stuff(buf_T *buf, int free_flags)
*/
static void clear_wininfo(buf_T *buf)
{
- wininfo_T *wip;
+ wininfo_T *wip;
while (buf->b_wininfo != NULL) {
wip = buf->b_wininfo;
@@ -947,7 +944,7 @@ void handle_swap_exists(bufref_T *old_curbuf)
*
* addr_count == 0: ":bdel" - delete current buffer
* addr_count == 1: ":N bdel" or ":bdel N [N ..]" - first delete
- * buffer "end_bnr", then any other arguments.
+ * buffer "end_bnr", then any other arguments.
* addr_count == 2: ":N,N bdel" - delete buffers in range
*
* command can be DOBUF_UNLOAD (":bunload"), DOBUF_WIPE (":bwipeout") or
@@ -955,21 +952,16 @@ void handle_swap_exists(bufref_T *old_curbuf)
*
* Returns error message or NULL
*/
-char_u *
-do_bufdel(
- int command,
- char_u *arg, // pointer to extra arguments
- int addr_count,
- int start_bnr, // first buffer number in a range
- int end_bnr, // buffer nr or last buffer nr in a range
- int forceit
-)
+char_u *do_bufdel(int command, char_u *arg, // pointer to extra arguments
+ int addr_count, int start_bnr, // first buffer number in a range
+ int end_bnr, // buffer nr or last buffer nr in a range
+ int forceit)
{
int do_current = 0; // delete current buffer?
int deleted = 0; // number of buffers deleted
- char_u *errormsg = NULL; // return value
+ char_u *errormsg = NULL; // return value
int bnr; // buffer number
- char_u *p;
+ char_u *p;
if (addr_count == 0) {
(void)do_buffer(command, DOBUF_CURRENT, FORWARD, 0, forceit);
@@ -1073,7 +1065,7 @@ do_bufdel(
static int empty_curbuf(int close_others, int forceit, int action)
{
int retval;
- buf_T *buf = curbuf;
+ buf_T *buf = curbuf;
if (action == DOBUF_UNLOAD) {
EMSG(_("E90: Cannot unload last buffer"));
@@ -1090,7 +1082,7 @@ static int empty_curbuf(int close_others, int forceit, int action)
setpcmark();
retval = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE,
- forceit ? ECMD_FORCEIT : 0, curwin);
+ forceit ? ECMD_FORCEIT : 0, curwin);
// do_ecmd() may create a new buffer, then we have to delete
// the old one. But do_ecmd() may have done that already, check
@@ -1108,37 +1100,36 @@ static int empty_curbuf(int close_others, int forceit, int action)
/*
* Implementation of the commands for the buffer list.
*
- * action == DOBUF_GOTO go to specified buffer
+ * action == DOBUF_GOTO go to specified buffer
* action == DOBUF_SPLIT split window and go to specified buffer
* action == DOBUF_UNLOAD unload specified buffer(s)
- * action == DOBUF_DEL delete specified buffer(s) from buffer list
- * action == DOBUF_WIPE delete specified buffer(s) really
+ * action == DOBUF_DEL delete specified buffer(s) from buffer list
+ * action == DOBUF_WIPE delete specified buffer(s) really
*
* start == DOBUF_CURRENT go to "count" buffer from current buffer
- * start == DOBUF_FIRST go to "count" buffer from first buffer
- * start == DOBUF_LAST go to "count" buffer from last buffer
- * start == DOBUF_MOD go to "count" modified buffer from current buffer
+ * start == DOBUF_FIRST go to "count" buffer from first buffer
+ * start == DOBUF_LAST go to "count" buffer from last buffer
+ * start == DOBUF_MOD go to "count" modified buffer from current buffer
*
* Return FAIL or OK.
*/
-int
-do_buffer(
- int action,
- int start,
- int dir, // FORWARD or BACKWARD
- int count, // buffer number or number of buffers
- int forceit // true for :...!
-)
+int do_buffer(int action, int start, int dir, // FORWARD or BACKWARD
+ int count, // buffer number or number of buffers
+ int forceit // true for :...!
+ )
{
- buf_T *buf;
- buf_T *bp;
+ buf_T *buf;
+ buf_T *bp;
int unload = (action == DOBUF_UNLOAD || action == DOBUF_DEL
|| action == DOBUF_WIPE);
switch (start) {
- case DOBUF_FIRST: buf = firstbuf; break;
- case DOBUF_LAST: buf = lastbuf; break;
- default: buf = curbuf; break;
+ case DOBUF_FIRST:
+ buf = firstbuf; break;
+ case DOBUF_LAST:
+ buf = lastbuf; break;
+ default:
+ buf = curbuf; break;
}
if (start == DOBUF_MOD) { // find next modified buffer
while (count-- > 0) {
@@ -1459,15 +1450,15 @@ do_buffer(
/*
* Set current buffer to "buf". Executes autocommands and closes current
* buffer. "action" tells how to close the current buffer:
- * DOBUF_GOTO free or hide it
- * DOBUF_SPLIT nothing
- * DOBUF_UNLOAD unload it
- * DOBUF_DEL delete it
- * DOBUF_WIPE wipe it out
+ * DOBUF_GOTO free or hide it
+ * DOBUF_SPLIT nothing
+ * DOBUF_UNLOAD unload it
+ * DOBUF_DEL delete it
+ * DOBUF_WIPE wipe it out
*/
void set_curbuf(buf_T *buf, int action)
{
- buf_T *prevbuf;
+ buf_T *prevbuf;
int unload = (action == DOBUF_UNLOAD || action == DOBUF_DEL
|| action == DOBUF_WIPE);
long old_tw = curbuf->b_p_tw;
@@ -1500,7 +1491,7 @@ void set_curbuf(buf_T *buf, int action)
close_windows(prevbuf, false);
}
if (bufref_valid(&prevbufref) && !aborting()) {
- win_T *previouswin = curwin;
+ win_T *previouswin = curwin;
if (prevbuf == curbuf) {
u_sync(false);
}
@@ -1522,8 +1513,7 @@ void set_curbuf(buf_T *buf, int action)
* If curwin->w_buffer is null, enter_buffer() will make it valid again */
if ((buf_valid(buf) && buf != curbuf
&& !aborting()
- ) || curwin->w_buffer == NULL
- ) {
+ ) || curwin->w_buffer == NULL) {
enter_buffer(buf);
if (old_tw != curbuf->b_p_tw) {
check_colorcolumn(curwin);
@@ -1705,12 +1695,11 @@ static inline void buf_init_changedtick(buf_T *const buf)
/// @param bufnr
///
/// @return pointer to the buffer
-buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum,
- int flags)
+buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum, int flags)
{
char_u *ffname = ffname_arg;
char_u *sfname = sfname_arg;
- buf_T *buf;
+ buf_T *buf;
fname_expand(curbuf, &ffname, &sfname); // will allocate ffname
@@ -1750,7 +1739,7 @@ buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum,
/*
* If the current buffer has no name and no contents, use the current
- * buffer. Otherwise: Need to allocate a new buffer structure.
+ * buffer. Otherwise: Need to allocate a new buffer structure.
*
* This is the ONLY place where a new buffer structure is allocated!
* (A spell file buffer is allocated in spell.c, but that's not a normal
@@ -2005,9 +1994,9 @@ void free_buf_options(buf_T *buf, int free_p_ff)
/// Return FAIL for failure, OK for success.
int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
{
- buf_T *buf;
- win_T *wp = NULL;
- pos_T *fpos;
+ buf_T *buf;
+ win_T *wp = NULL;
+ pos_T *fpos;
colnr_T col;
buf = buflist_findnr(n);
@@ -2038,8 +2027,9 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
fpos = buflist_findfpos(buf);
lnum = fpos->lnum;
col = fpos->col;
- } else
+ } else {
col = 0;
+ }
if (options & GETF_SWITCH) {
// If 'switchbuf' contains "useopen": jump to first window containing
@@ -2089,7 +2079,7 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
// Go to the last known line number for the current buffer.
void buflist_getfpos(void)
{
- pos_T *fpos;
+ pos_T *fpos;
fpos = buflist_findfpos(curbuf);
@@ -2112,8 +2102,8 @@ void buflist_getfpos(void)
*/
buf_T *buflist_findname_exp(char_u *fname)
{
- char_u *ffname;
- buf_T *buf = NULL;
+ char_u *ffname;
+ buf_T *buf = NULL;
// First make the name into a full path name
ffname = (char_u *)FullName_save((char *)fname,
@@ -2123,7 +2113,7 @@ buf_T *buflist_findname_exp(char_u *fname)
#else
false
#endif
- );
+ );
if (ffname != NULL) {
buf = buflist_findname(ffname);
xfree(ffname);
@@ -2149,8 +2139,7 @@ buf_T *buflist_findname(char_u *ffname)
* getting it twice for the same file.
* Returns NULL if not found.
*/
-static buf_T *buflist_findname_file_id(char_u *ffname, FileID *file_id,
- bool file_id_valid)
+static buf_T *buflist_findname_file_id(char_u *ffname, FileID *file_id, bool file_id_valid)
{
// Start at the last buffer, expect to find a match sooner.
FOR_ALL_BUFFERS_BACKWARDS(buf) {
@@ -2165,21 +2154,19 @@ static buf_T *buflist_findname_file_id(char_u *ffname, FileID *file_id,
/// Find file in buffer list by a regexp pattern.
/// Return fnum of the found buffer.
/// Return < 0 for error.
-int buflist_findpat(
- const char_u *pattern,
- const char_u *pattern_end, // pointer to first char after pattern
- bool unlisted, // find unlisted buffers
- bool diffmode, // find diff-mode buffers only
- bool curtab_only // find buffers in current tab only
-)
+int buflist_findpat(const char_u *pattern, const char_u *pattern_end, // pointer to first char after pattern
+ bool unlisted, // find unlisted buffers
+ bool diffmode, // find diff-mode buffers only
+ bool curtab_only // find buffers in current tab only
+ )
FUNC_ATTR_NONNULL_ARG(1)
{
int match = -1;
int find_listed;
- char_u *pat;
- char_u *patend;
+ char_u *pat;
+ char_u *patend;
int attempt;
- char_u *p;
+ char_u *p;
int toggledollar;
if (pattern_end == pattern + 1 && (*pattern == '%' || *pattern == '#')) {
@@ -2283,13 +2270,12 @@ int buflist_findpat(
}
typedef struct {
- buf_T *buf;
- char_u *match;
+ buf_T *buf;
+ char_u *match;
} bufmatch_T;
/// Compare functions for qsort() below, that compares b_last_used.
-static int
-buf_time_compare(const void *s1, const void *s2)
+static int buf_time_compare(const void *s1, const void *s2)
{
buf_T *buf1 = *(buf_T **)s1;
buf_T *buf2 = *(buf_T **)s2;
@@ -2309,10 +2295,10 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options)
{
int count = 0;
int round;
- char_u *p;
+ char_u *p;
int attempt;
- char_u *patc;
- bufmatch_T *matches = NULL;
+ char_u *patc;
+ bufmatch_T *matches = NULL;
*num_file = 0; // return values in case of FAIL
*file = NULL;
@@ -2326,8 +2312,9 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options)
patc = xmalloc(STRLEN(pat) + 11);
STRCPY(patc, "\\(^\\|[\\/]\\)");
STRCPY(patc + 11, pat + 1);
- } else
+ } else {
patc = pat;
+ }
/*
* attempt == 0: try match with '\<', match at start of word
@@ -2448,8 +2435,8 @@ static char_u *buflist_match(regmatch_T *rmp, buf_T *buf, bool ignore_case)
/// @return "name" when there is a match, NULL when not.
static char_u *fname_match(regmatch_T *rmp, char_u *name, bool ignore_case)
{
- char_u *match = NULL;
- char_u *p;
+ char_u *match = NULL;
+ char_u *p;
if (name != NULL) {
// Ignore case when 'fileignorecase' or the argument is set.
@@ -2485,21 +2472,17 @@ buf_T *buflist_findnr(int nr)
* home_replace() is used to shorten the file name (used for marks).
* Returns a pointer to allocated memory, of NULL when failed.
*/
-char_u *
-buflist_nr2name(
- int n,
- int fullname,
- int helptail // for help buffers return tail only
-)
+char_u *buflist_nr2name(int n, int fullname, int helptail // for help buffers return tail only
+ )
{
- buf_T *buf;
+ buf_T *buf;
buf = buflist_findnr(n);
if (buf == NULL) {
return NULL;
}
return home_replace_save(helptail ? buf : NULL,
- fullname ? buf->b_ffname : buf->b_fname);
+ fullname ? buf->b_ffname : buf->b_fname);
}
/// Set the line and column numbers for the given buffer and window
@@ -2511,12 +2494,11 @@ buflist_nr2name(
/// options are touched.
/// @param[in] col Column number to be set.
/// @param[in] copy_options If true save the local window option values.
-void buflist_setfpos(buf_T *const buf, win_T *const win,
- linenr_T lnum, colnr_T col,
+void buflist_setfpos(buf_T *const buf, win_T *const win, linenr_T lnum, colnr_T col,
bool copy_options)
FUNC_ATTR_NONNULL_ARG(1)
{
- wininfo_T *wip;
+ wininfo_T *wip;
for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) {
if (wip->wi_win == win) {
@@ -2593,11 +2575,10 @@ static bool wininfo_other_tab_diff(wininfo_T *wip)
// When "skip_diff_buffer" is true avoid windows with 'diff' set that is in
// another tab page.
// Returns NULL when there isn't any info.
-static wininfo_T *find_wininfo(buf_T *buf, bool need_options,
- bool skip_diff_buffer)
+static wininfo_T *find_wininfo(buf_T *buf, bool need_options, bool skip_diff_buffer)
FUNC_ATTR_NONNULL_ALL
{
- wininfo_T *wip;
+ wininfo_T *wip;
for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) {
if (wip->wi_win == curwin
@@ -2654,8 +2635,9 @@ void get_winopts(buf_T *buf)
curwin->w_fold_manual = wip->wi_fold_manual;
curwin->w_foldinvalid = true;
cloneFoldGrowArray(&wip->wi_folds, &curwin->w_folds);
- } else
+ } else {
copy_winopt(&curwin->w_allbuf_opt, &curwin->w_onebuf_opt);
+ }
if (curwin->w_float_config.style == kWinStyleMinimal) {
didset_window_options(curwin);
@@ -2693,7 +2675,7 @@ linenr_T buflist_findlnum(buf_T *buf)
// List all known file names (for :files and :buffers command).
void buflist_list(exarg_T *eap)
{
- buf_T *buf = firstbuf;
+ buf_T *buf = firstbuf;
int len;
int i;
@@ -2719,7 +2701,7 @@ void buflist_list(exarg_T *eap)
buf != NULL && !got_int;
buf = buflist_data != NULL
? (++p < buflist_data + buflist.ga_len ? *p : NULL)
- : buf->b_next) {
+ : buf->b_next) {
const bool is_terminal = buf->terminal;
const bool job_running = buf->terminal && terminal_running(buf->terminal);
@@ -2761,18 +2743,17 @@ void buflist_list(exarg_T *eap)
}
msg_putchar('\n');
- len = vim_snprintf(
- (char *)IObuff, IOSIZE - 20, "%3d%c%c%c%c%c \"%s\"",
- buf->b_fnum,
- buf->b_p_bl ? ' ' : 'u',
- buf == curbuf ? '%' : (curwin->w_alt_fnum == buf->b_fnum ? '#' : ' '),
- buf->b_ml.ml_mfp == NULL ? ' ' : (buf->b_nwindows == 0 ? 'h' : 'a'),
- ro_char,
- changed_char,
- NameBuff);
+ len = vim_snprintf((char *)IObuff, IOSIZE - 20, "%3d%c%c%c%c%c \"%s\"",
+ buf->b_fnum,
+ buf->b_p_bl ? ' ' : 'u',
+ buf == curbuf ? '%' : (curwin->w_alt_fnum == buf->b_fnum ? '#' : ' '),
+ buf->b_ml.ml_mfp == NULL ? ' ' : (buf->b_nwindows == 0 ? 'h' : 'a'),
+ ro_char,
+ changed_char,
+ NameBuff);
if (len > IOSIZE - 20) {
- len = IOSIZE - 20;
+ len = IOSIZE - 20;
}
// put "line 999" in column 40 or after the file name
@@ -2786,7 +2767,7 @@ void buflist_list(exarg_T *eap)
vim_snprintf((char *)IObuff + len, (size_t)(IOSIZE - len),
_("line %" PRId64),
buf == curbuf ? (int64_t)curwin->w_cursor.lnum
- : (int64_t)buflist_findlnum(buf));
+ : (int64_t)buflist_findlnum(buf));
}
msg_outtrans(IObuff);
@@ -2806,7 +2787,7 @@ void buflist_list(exarg_T *eap)
*/
int buflist_name_nr(int fnum, char_u **fname, linenr_T *lnum)
{
- buf_T *buf;
+ buf_T *buf;
buf = buflist_findnr(fnum);
if (buf == NULL || buf->b_fname == NULL) {
@@ -2824,16 +2805,12 @@ int buflist_name_nr(int fnum, char_u **fname, linenr_T *lnum)
// The file name with the full path is also remembered, for when :cd is used.
// Returns FAIL for failure (file name already in use by other buffer)
// OK otherwise.
-int setfname(
- buf_T *buf,
- char_u *ffname_arg,
- char_u *sfname_arg,
- bool message // give message when buffer already exists
-)
+int setfname(buf_T *buf, char_u *ffname_arg, char_u *sfname_arg, bool message // give message when buffer already exists
+ )
{
char_u *ffname = ffname_arg;
char_u *sfname = sfname_arg;
- buf_T *obuf = NULL;
+ buf_T *obuf = NULL;
FileID file_id;
bool file_id_valid = false;
@@ -2900,7 +2877,7 @@ int setfname(
*/
void buf_set_name(int fnum, char_u *name)
{
- buf_T *buf;
+ buf_T *buf;
buf = buflist_findnr(fnum);
if (buf != NULL) {
@@ -2947,7 +2924,7 @@ void buf_name_changed(buf_T *buf)
*/
buf_T *setaltfname(char_u *ffname, char_u *sfname, linenr_T lnum)
{
- buf_T *buf;
+ buf_T *buf;
// Create a buffer. 'buflisted' is not set if it's a new buffer
buf = buflist_new(ffname, sfname, lnum, 0);
@@ -2961,11 +2938,10 @@ buf_T *setaltfname(char_u *ffname, char_u *sfname, linenr_T lnum)
* Get alternate file name for current window.
* Return NULL if there isn't any, and give error message if requested.
*/
-char_u * getaltfname(
- bool errmsg // give error message
-)
+char_u * getaltfname(bool errmsg // give error message
+ )
{
- char_u *fname;
+ char_u *fname;
linenr_T dummy;
if (buflist_name_nr(0, &fname, &dummy) == FAIL) {
@@ -2985,7 +2961,7 @@ char_u * getaltfname(
*/
int buflist_add(char_u *fname, int flags)
{
- buf_T *buf;
+ buf_T *buf;
buf = buflist_new(fname, NULL, (linenr_T)0, flags);
if (buf != NULL) {
@@ -3038,8 +3014,7 @@ bool otherfile(char_u *ffname)
/// @param ffname full path name to check
/// @param file_id_p information about the file at "ffname".
/// @param file_id_valid whether a valid "file_id_p" was passed in.
-static bool otherfile_buf(buf_T *buf, char_u *ffname, FileID *file_id_p,
- bool file_id_valid)
+static bool otherfile_buf(buf_T *buf, char_u *ffname, FileID *file_id_p, bool file_id_valid)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
// no name is different
@@ -3106,17 +3081,13 @@ static bool buf_same_file_id(buf_T *buf, FileID *file_id)
/*
* Print info about the current buffer.
*/
-void
-fileinfo(
- int fullname, // when non-zero print full path
- int shorthelp,
- int dont_truncate
-)
+void fileinfo(int fullname, // when non-zero print full path
+ int shorthelp, int dont_truncate)
{
- char_u *name;
+ char_u *name;
int n;
- char_u *p;
- char_u *buffer;
+ char_u *p;
+ char_u *buffer;
size_t len;
buffer = xmalloc(IOSIZE);
@@ -3124,8 +3095,9 @@ fileinfo(
if (fullname > 1) { // 2 CTRL-G: include buffer number
vim_snprintf((char *)buffer, IOSIZE, "buf %d: ", curbuf->b_fnum);
p = buffer + STRLEN(buffer);
- } else
+ } else {
p = buffer;
+ }
*p++ = '"';
if (buf_spname(curbuf) != NULL) {
@@ -3176,14 +3148,14 @@ fileinfo(
}
} else {
vim_snprintf_add((char *)buffer, IOSIZE,
- _("line %" PRId64 " of %" PRId64 " --%d%%-- col "),
- (int64_t)curwin->w_cursor.lnum,
- (int64_t)curbuf->b_ml.ml_line_count,
- n);
+ _("line %" PRId64 " of %" PRId64 " --%d%%-- col "),
+ (int64_t)curwin->w_cursor.lnum,
+ (int64_t)curbuf->b_ml.ml_line_count,
+ n);
validate_virtcol();
len = STRLEN(buffer);
col_print(buffer + len, IOSIZE - len,
- (int)curwin->w_cursor.col + 1, (int)curwin->w_virtcol + 1);
+ (int)curwin->w_cursor.col + 1, (int)curwin->w_virtcol + 1);
}
(void)append_arg_number(curwin, buffer, IOSIZE, !shortmess(SHM_FILE));
@@ -3291,15 +3263,22 @@ void maketitle(void)
switch (bufIsChanged(curbuf)
| (curbuf->b_p_ro << 1)
| (!MODIFIABLE(curbuf) << 2)) {
- case 0: break;
- case 1: buf_p = strappend(buf_p, " +"); break;
- case 2: buf_p = strappend(buf_p, " ="); break;
- case 3: buf_p = strappend(buf_p, " =+"); break;
- case 4:
- case 6: buf_p = strappend(buf_p, " -"); break;
- case 5:
- case 7: buf_p = strappend(buf_p, " -+"); break;
- default: abort();
+ case 0:
+ break;
+ case 1:
+ buf_p = strappend(buf_p, " +"); break;
+ case 2:
+ buf_p = strappend(buf_p, " ="); break;
+ case 3:
+ buf_p = strappend(buf_p, " =+"); break;
+ case 4:
+ case 6:
+ buf_p = strappend(buf_p, " -"); break;
+ case 5:
+ case 7:
+ buf_p = strappend(buf_p, " -+"); break;
+ default:
+ abort();
}
if (curbuf->b_fname != NULL) {
@@ -3485,17 +3464,8 @@ typedef enum {
/// @param tabtab Tab clicks definition (can be NULL).
///
/// @return The final width of the statusline
-int build_stl_str_hl(
- win_T *wp,
- char_u *out,
- size_t outlen,
- char_u *fmt,
- int use_sandbox,
- char_u fillchar,
- int maxwidth,
- stl_hlrec_t **hltab,
- StlClickRecord **tabtab
-)
+int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use_sandbox,
+ char_u fillchar, int maxwidth, stl_hlrec_t **hltab, StlClickRecord **tabtab)
{
static size_t stl_items_len = 20; // Initial value, grows as needed.
static stl_item_t *stl_items = NULL;
@@ -3507,7 +3477,7 @@ int build_stl_str_hl(
#define TMPLEN 70
char_u buf_tmp[TMPLEN];
char_u win_tmp[TMPLEN];
- char_u *usefmt = fmt;
+ char_u *usefmt = fmt;
const int save_must_redraw = must_redraw;
const int save_redr_type = curwin->w_redr_type;
@@ -3589,16 +3559,16 @@ int build_stl_str_hl(
// fmt_p is the current position in the input buffer
for (char_u *fmt_p = usefmt; *fmt_p; ) {
if (curitem == (int)stl_items_len) {
- size_t new_len = stl_items_len * 3 / 2;
+ size_t new_len = stl_items_len * 3 / 2;
- stl_items = xrealloc(stl_items, sizeof(stl_item_t) * new_len);
- stl_groupitems = xrealloc(stl_groupitems, sizeof(int) * new_len);
- stl_hltab = xrealloc(stl_hltab, sizeof(stl_hlrec_t) * new_len);
- stl_tabtab = xrealloc(stl_tabtab, sizeof(StlClickRecord) * new_len);
- stl_separator_locations =
- xrealloc(stl_separator_locations, sizeof(int) * new_len);
+ stl_items = xrealloc(stl_items, sizeof(stl_item_t) * new_len);
+ stl_groupitems = xrealloc(stl_groupitems, sizeof(int) * new_len);
+ stl_hltab = xrealloc(stl_hltab, sizeof(stl_hlrec_t) * new_len);
+ stl_tabtab = xrealloc(stl_tabtab, sizeof(StlClickRecord) * new_len);
+ stl_separator_locations =
+ xrealloc(stl_separator_locations, sizeof(int) * new_len);
- stl_items_len = new_len;
+ stl_items_len = new_len;
}
if (*fmt_p != NUL && *fmt_p != '%') {
@@ -3608,8 +3578,9 @@ int build_stl_str_hl(
// Copy the formatting verbatim until we reach the end of the string
// or find a formatting item (denoted by `%`)
// or run out of room in our output buffer.
- while (*fmt_p != NUL && *fmt_p != '%' && out_p < out_end_p)
+ while (*fmt_p != NUL && *fmt_p != '%' && out_p < out_end_p) {
*out_p++ = *fmt_p++;
+ }
// If we have processed the entire format string or run out of
// room in our output buffer, exit the loop.
@@ -3752,17 +3723,18 @@ int build_stl_str_hl(
stl_items[idx].start = t;
}
}
- // If the group is shorter than the minimum width, add padding characters.
+ // If the group is shorter than the minimum width, add padding characters.
} else if (
- abs(stl_items[stl_groupitems[groupdepth]].minwid) > group_len) {
+ abs(stl_items[stl_groupitems[groupdepth]].minwid) > group_len) {
long min_group_width = stl_items[stl_groupitems[groupdepth]].minwid;
// If the group is left-aligned, add characters to the right.
if (min_group_width < 0) {
min_group_width = 0 - min_group_width;
- while (group_len++ < min_group_width && out_p < out_end_p)
+ while (group_len++ < min_group_width && out_p < out_end_p) {
*out_p++ = fillchar;
- // If the group is right-aligned, shift everything to the right and
- // prepend with filler characters.
+ }
+ // If the group is right-aligned, shift everything to the right and
+ // prepend with filler characters.
} else {
// { Move the group to the right
memmove(t + min_group_width - group_len, t, (size_t)(out_p - t));
@@ -3867,7 +3839,7 @@ int build_stl_str_hl(
if (*fmt_p == STL_CLICK_FUNC) {
fmt_p++;
- char *t = (char *) fmt_p;
+ char *t = (char *)fmt_p;
while (*fmt_p != STL_CLICK_FUNC && *fmt_p) {
fmt_p++;
}
@@ -3910,9 +3882,9 @@ int build_stl_str_hl(
// Denotes end of expanded %{} block
if (*fmt_p == '}' && evaldepth > 0) {
- fmt_p++;
- evaldepth--;
- continue;
+ fmt_p++;
+ evaldepth--;
+ continue;
}
// An invalid item was specified.
@@ -3935,7 +3907,6 @@ int build_stl_str_hl(
case STL_FILEPATH:
case STL_FULLPATH:
case STL_FILENAME:
- {
// Set fillable to false so that ' ' in the filename will not
// get replaced with the fillchar
fillable = false;
@@ -3943,7 +3914,7 @@ int build_stl_str_hl(
STRLCPY(NameBuff, buf_spname(wp->w_buffer), MAXPATHL);
} else {
char_u *t = (opt == STL_FULLPATH) ? wp->w_buffer->b_ffname
- : wp->w_buffer->b_fname;
+ : wp->w_buffer->b_fname;
home_replace(wp->w_buffer, t, NameBuff, MAXPATHL, true);
}
trans_characters(NameBuff, MAXPATHL);
@@ -3953,7 +3924,6 @@ int build_stl_str_hl(
str = path_tail(NameBuff);
}
break;
- }
case STL_VIM_EXPR: // '{'
{
char_u *block_start = fmt_p - 1;
@@ -4036,17 +4006,17 @@ int build_stl_str_hl(
size_t str_length = strlen((const char *)str);
size_t fmt_length = strlen((const char *)fmt_p);
size_t new_fmt_len = parsed_usefmt
- + str_length + fmt_length + 3;
+ + str_length + fmt_length + 3;
char_u *new_fmt = (char_u *)xmalloc(new_fmt_len * sizeof(char_u));
char_u *new_fmt_p = new_fmt;
new_fmt_p = (char_u *)memcpy(new_fmt_p, usefmt, parsed_usefmt)
- + parsed_usefmt;
- new_fmt_p = (char_u *)memcpy(new_fmt_p , str, str_length)
- + str_length;
+ + parsed_usefmt;
+ new_fmt_p = (char_u *)memcpy(new_fmt_p, str, str_length)
+ + str_length;
new_fmt_p = (char_u *)memcpy(new_fmt_p, "%}", 2) + 2;
- new_fmt_p = (char_u *)memcpy(new_fmt_p , fmt_p, fmt_length)
- + fmt_length;
+ new_fmt_p = (char_u *)memcpy(new_fmt_p, fmt_p, fmt_length)
+ + fmt_length;
*new_fmt_p = 0;
new_fmt_p = NULL;
@@ -4077,8 +4047,7 @@ int build_stl_str_hl(
break;
case STL_VIRTCOL:
- case STL_VIRTCOL_ALT:
- {
+ case STL_VIRTCOL_ALT: {
// In list mode virtcol needs to be recomputed
colnr_T virtcol = wp->w_virtcol;
if (wp->w_p_list && wp->w_p_lcs_chars.tab1 == NUL) {
@@ -4090,8 +4059,9 @@ int build_stl_str_hl(
// Don't display %V if it's the same as %c.
if (opt == STL_VIRTCOL_ALT
&& (virtcol == (colnr_T)(!(State & INSERT) && empty_line
- ? 0 : (int)wp->w_cursor.col + 1)))
+ ? 0 : (int)wp->w_cursor.col + 1))) {
break;
+ }
num = (long)virtcol;
break;
}
@@ -4142,8 +4112,7 @@ int build_stl_str_hl(
case STL_OFFSET_X:
base = kNumBaseHexadecimal;
FALLTHROUGH;
- case STL_OFFSET:
- {
+ case STL_OFFSET: {
long l = ml_find_line_or_offset(wp->w_buffer, wp->w_cursor.lnum, NULL,
false);
num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) || l < 0 ?
@@ -4174,9 +4143,10 @@ int build_stl_str_hl(
case STL_HELPFLAG:
case STL_HELPFLAG_ALT:
itemisflag = true;
- if (wp->w_buffer->b_help)
+ if (wp->w_buffer->b_help) {
str = (char_u *)((opt == STL_HELPFLAG_ALT) ? ",HLP"
- : _("[Help]"));
+ : _("[Help]"));
+ }
break;
case STL_FILETYPE:
@@ -4192,7 +4162,6 @@ int build_stl_str_hl(
break;
case STL_FILETYPE_ALT:
- {
itemisflag = true;
// Copy the filetype if it is not null and the formatted string will fit
// in the temporary buffer
@@ -4208,20 +4177,21 @@ int build_stl_str_hl(
str = buf_tmp;
}
break;
- }
case STL_PREVIEWFLAG:
case STL_PREVIEWFLAG_ALT:
itemisflag = true;
- if (wp->w_p_pvw)
+ if (wp->w_p_pvw) {
str = (char_u *)((opt == STL_PREVIEWFLAG_ALT) ? ",PRV"
- : _("[Preview]"));
+ : _("[Preview]"));
+ }
break;
case STL_QUICKFIX:
- if (bt_quickfix(wp->w_buffer))
+ if (bt_quickfix(wp->w_buffer)) {
str = (char_u *)(wp->w_llist_ref
? _(msg_loclist)
: _(msg_qflist));
+ }
break;
case STL_MODIFIED:
@@ -4230,17 +4200,22 @@ int build_stl_str_hl(
switch ((opt == STL_MODIFIED_ALT)
+ bufIsChanged(wp->w_buffer) * 2
+ (!MODIFIABLE(wp->w_buffer)) * 4) {
- case 2: str = (char_u *)"[+]"; break;
- case 3: str = (char_u *)",+"; break;
- case 4: str = (char_u *)"[-]"; break;
- case 5: str = (char_u *)",-"; break;
- case 6: str = (char_u *)"[+-]"; break;
- case 7: str = (char_u *)",+-"; break;
+ case 2:
+ str = (char_u *)"[+]"; break;
+ case 3:
+ str = (char_u *)",+"; break;
+ case 4:
+ str = (char_u *)"[-]"; break;
+ case 5:
+ str = (char_u *)",-"; break;
+ case 6:
+ str = (char_u *)"[+-]"; break;
+ case 7:
+ str = (char_u *)",+-"; break;
}
break;
- case STL_HIGHLIGHT:
- {
+ case STL_HIGHLIGHT: {
// { The name of the highlight is surrounded by `#`
char_u *t = fmt_p;
while (*fmt_p != '#' && *fmt_p != NUL) {
@@ -4274,8 +4249,9 @@ int build_stl_str_hl(
if (itemisflag) {
if ((t[0] && t[1])
&& ((!prevchar_isitem && *t == ',')
- || (prevchar_isflag && *t == ' ')))
+ || (prevchar_isflag && *t == ' '))) {
t++;
+ }
prevchar_isflag = true;
}
// }
@@ -4328,8 +4304,9 @@ int build_stl_str_hl(
// Change a space by fillchar, unless fillchar is '-' and a
// digit follows.
if (fillable && out_p[-1] == ' '
- && (!ascii_isdigit(*t) || fillchar != '-'))
+ && (!ascii_isdigit(*t) || fillchar != '-')) {
out_p[-1] = fillchar;
+ }
}
// }
@@ -4338,7 +4315,7 @@ int build_stl_str_hl(
*out_p++ = fillchar;
}
- // Otherwise if the item is a number, copy that to the output buffer.
+ // Otherwise if the item is a number, copy that to the output buffer.
} else if (num >= 0) {
if (out_p + 20 > out_end_p) {
break; // not sufficient space
@@ -4367,7 +4344,7 @@ int build_stl_str_hl(
// Note: We have to cast the base because the compiler uses
// unsigned ints for the enum values.
long num_chars = 1;
- for (long n = num; n >= (int) base; n /= (int) base) {
+ for (long n = num; n >= (int)base; n /= (int)base) {
num_chars++;
}
@@ -4407,17 +4384,17 @@ int build_stl_str_hl(
// }
vim_snprintf((char *)out_p, remaining_buf_len, (char *)nstr,
- 0, num, n);
+ 0, num, n);
} else {
vim_snprintf((char *)out_p, remaining_buf_len, (char *)nstr,
- minwid, num);
+ minwid, num);
}
// Advance the output buffer position to the end of the
// number we just printed
out_p += STRLEN(out_p);
- // Otherwise, there was nothing to print so mark the item as empty
+ // Otherwise, there was nothing to print so mark the item as empty
} else {
stl_items[curitem].type = Empty;
}
@@ -4457,7 +4434,7 @@ int build_stl_str_hl(
if (itemcnt == 0) {
trunc_p = out;
- // Otherwise, look for the truncation item
+ // Otherwise, look for the truncation item
} else {
// Default to truncating at the first item
trunc_p = stl_items[0].start;
@@ -4504,7 +4481,7 @@ int build_stl_str_hl(
*trunc_p++ = '>';
*trunc_p = 0;
- // Truncate at the truncation point we found
+ // Truncate at the truncation point we found
} else {
// { Determine how many bytes to remove
long trunc_len = 0;
@@ -4545,8 +4522,8 @@ int build_stl_str_hl(
// to be moved backwards.
if (stl_items[i].start >= trunc_end_p) {
stl_items[i].start -= item_offset;
- // Anything inside the truncated area is set to start
- // at the `<` truncation character.
+ // Anything inside the truncated area is set to start
+ // at the `<` truncation character.
} else {
stl_items[i].start = trunc_p;
}
@@ -4555,9 +4532,9 @@ int build_stl_str_hl(
}
width = maxwidth;
- // If there is room left in our statusline, and room left in our buffer,
- // add characters at the separate marker (if there is one) to
- // fill up the available space.
+ // If there is room left in our statusline, and room left in our buffer,
+ // add characters at the separate marker (if there is one) to
+ // fill up the available space.
} else if (width < maxwidth
&& STRLEN(out) + (size_t)(maxwidth - width) + 1 < outlen) {
// Find how many separators there are, which we will use when
@@ -4576,7 +4553,7 @@ int build_stl_str_hl(
if (num_separators) {
int standard_spaces = (maxwidth - width) / num_separators;
int final_spaces = (maxwidth - width) -
- standard_spaces * (num_separators - 1);
+ standard_spaces * (num_separators - 1);
for (int i = 0; i < num_separators; i++) {
int dislocation = (i == (num_separators - 1))
@@ -4763,7 +4740,7 @@ void fname_expand(buf_T *buf, char_u **ffname, char_u **sfname)
*/
char_u *alist_name(aentry_T *aep)
{
- buf_T *bp;
+ buf_T *bp;
// Use the name from the associated buffer if it exists.
bp = buflist_findnr(aep->ae_fnum);
@@ -4776,32 +4753,29 @@ char_u *alist_name(aentry_T *aep)
/*
* do_arg_all(): Open up to 'count' windows, one for each argument.
*/
-void
-do_arg_all(
- int count,
- int forceit, // hide buffers in current windows
- int keep_tabs // keep current tabs, for ":tab drop file"
-)
+void do_arg_all(int count, int forceit, // hide buffers in current windows
+ int keep_tabs // keep current tabs, for ":tab drop file"
+ )
{
- char_u *opened; // Array of weight for which args are open:
- // 0: not opened
- // 1: opened in other tab
- // 2: opened in curtab
- // 3: opened in curtab and curwin
+ char_u *opened; // Array of weight for which args are open:
+ // 0: not opened
+ // 1: opened in other tab
+ // 2: opened in curtab
+ // 3: opened in curtab and curwin
int opened_len; // length of opened[]
int use_firstwin = false; // use first window for arglist
bool tab_drop_empty_window = false;
int split_ret = OK;
bool p_ea_save;
- alist_T *alist; // argument list to be used
- buf_T *buf;
- tabpage_T *tpnext;
+ alist_T *alist; // argument list to be used
+ buf_T *buf;
+ tabpage_T *tpnext;
int had_tab = cmdmod.tab;
- win_T *old_curwin, *last_curwin;
- tabpage_T *old_curtab, *last_curtab;
- win_T *new_curwin = NULL;
- tabpage_T *new_curtab = NULL;
+ win_T *old_curwin, *last_curwin;
+ tabpage_T *old_curtab, *last_curtab;
+ win_T *new_curwin = NULL;
+ tabpage_T *new_curtab = NULL;
assert(firstwin != NULL); // satisfy coverity
@@ -5046,7 +5020,7 @@ do_arg_all(
/// @return true if "buf" is a prompt buffer.
bool bt_prompt(buf_T *buf)
{
- return buf != NULL && buf->b_p_bt[0] == 'p';
+ return buf != NULL && buf->b_p_bt[0] == 'p';
}
/*
@@ -5054,8 +5028,8 @@ bool bt_prompt(buf_T *buf)
*/
void ex_buffer_all(exarg_T *eap)
{
- buf_T *buf;
- win_T *wp, *wpnext;
+ buf_T *buf;
+ win_T *wp, *wpnext;
int split_ret = OK;
bool p_ea_save;
int open_wins = 0;
@@ -5063,7 +5037,7 @@ void ex_buffer_all(exarg_T *eap)
long count; // Maximum number of windows to open.
int all; // When true also load inactive buffers.
int had_tab = cmdmod.tab;
- tabpage_T *tpnext;
+ tabpage_T *tpnext;
if (eap->addr_count == 0) { // make as many windows as possible
count = 9999;
@@ -5097,8 +5071,8 @@ void ex_buffer_all(exarg_T *eap)
: wp->w_width != Columns)
|| (had_tab > 0 && wp != firstwin))
&& !ONE_WINDOW
- && !(wp->w_closing || wp->w_buffer->b_locked > 0)
- ) {
+ && !(wp->w_closing ||
+ wp->w_buffer->b_locked > 0)) {
win_close(wp, false);
wpnext = firstwin; // just in case an autocommand does
// something strange with windows
@@ -5189,8 +5163,9 @@ void ex_buffer_all(exarg_T *eap)
* discarded by a new aborting error, interrupt, or uncaught
* exception. */
leave_cleanup(&cs);
- } else
+ } else {
handle_swap_exists(NULL);
+ }
}
os_breakcheck();
@@ -5239,8 +5214,8 @@ void ex_buffer_all(exarg_T *eap)
* do_modelines() - process mode lines for the current file
*
* "flags" can be:
- * OPT_WINONLY only set options local to window
- * OPT_NOWIN don't set options local to window
+ * OPT_WINONLY only set options local to window
+ * OPT_NOWIN don't set options local to window
*
* Returns immediately if the "ml" option isn't set.
*/
@@ -5282,28 +5257,26 @@ void do_modelines(int flags)
* chk_modeline() - check a single line for a mode string
* Return FAIL if an error encountered.
*/
-static int
-chk_modeline(
- linenr_T lnum,
- int flags // Same as for do_modelines().
-)
+static int chk_modeline(linenr_T lnum, int flags // Same as for do_modelines().
+ )
{
- char_u *s;
- char_u *e;
- char_u *linecopy; // local copy of any modeline found
+ char_u *s;
+ char_u *e;
+ char_u *linecopy; // local copy of any modeline found
int prev;
intmax_t vers;
int end;
int retval = OK;
- char_u *save_sourcing_name;
+ char_u *save_sourcing_name;
linenr_T save_sourcing_lnum;
prev = -1;
for (s = ml_get(lnum); *s != NUL; s++) {
if (prev == -1 || ascii_isspace(prev)) {
if ((prev != -1 && STRNCMP(s, "ex:", (size_t)3) == 0)
- || STRNCMP(s, "vi:", (size_t)3) == 0)
+ || STRNCMP(s, "vi:", (size_t)3) == 0) {
break;
+ }
// Accept both "vim" and "Vim".
if ((s[0] == 'v' || s[0] == 'V') && s[1] == 'i' && s[2] == 'm') {
if (s[3] == '<' || s[3] == '=' || s[3] == '>') {
@@ -5477,8 +5450,10 @@ bool buf_hide(const buf_T *const buf)
switch (buf->b_p_bh[0]) {
case 'u': // "unload"
case 'w': // "wipe"
- case 'd': return false; // "delete"
- case 'h': return true; // "hide"
+ case 'd':
+ return false; // "delete"
+ case 'h':
+ return true; // "hide"
}
return p_hid || cmdmod.hide;
}
@@ -5544,38 +5519,38 @@ bool find_win_for_buf(buf_T *buf, win_T **wp, tabpage_T **tp)
int buf_signcols(buf_T *buf)
{
- if (!buf->b_signcols_valid) {
- sign_entry_T *sign; // a sign in the sign list
- int signcols = 0;
- int linesum = 0;
- linenr_T curline = 0;
-
- FOR_ALL_SIGNS_IN_BUF(buf, sign) {
- if (sign->se_lnum > curline) {
- if (linesum > signcols) {
- signcols = linesum;
- }
- curline = sign->se_lnum;
- linesum = 0;
- }
- if (sign->se_has_text_or_icon) {
- linesum++;
- }
- }
+ if (!buf->b_signcols_valid) {
+ sign_entry_T *sign; // a sign in the sign list
+ int signcols = 0;
+ int linesum = 0;
+ linenr_T curline = 0;
+
+ FOR_ALL_SIGNS_IN_BUF(buf, sign) {
+ if (sign->se_lnum > curline) {
if (linesum > signcols) {
signcols = linesum;
}
+ curline = sign->se_lnum;
+ linesum = 0;
+ }
+ if (sign->se_has_text_or_icon) {
+ linesum++;
+ }
+ }
+ if (linesum > signcols) {
+ signcols = linesum;
+ }
- // Check if we need to redraw
- if (signcols != buf->b_signcols) {
- buf->b_signcols = signcols;
- redraw_buf_later(buf, NOT_VALID);
- }
-
- buf->b_signcols_valid = true;
+ // Check if we need to redraw
+ if (signcols != buf->b_signcols) {
+ buf->b_signcols = signcols;
+ redraw_buf_later(buf, NOT_VALID);
}
- return buf->b_signcols;
+ buf->b_signcols_valid = true;
+ }
+
+ return buf->b_signcols;
}
// Get "buf->b_fname", use "[No Name]" if it is NULL.
@@ -5660,11 +5635,8 @@ bool buf_contents_changed(buf_T *buf)
* this buffer. Call this to wipe out a temp buffer that does not contain any
* marks.
*/
-void
-wipe_buffer(
- buf_T *buf,
- bool aucmd // When true trigger autocommands.
-)
+void wipe_buffer(buf_T *buf, bool aucmd // When true trigger autocommands.
+ )
{
if (!aucmd) {
// Don't trigger BufDelete autocommands here.
diff --git a/src/nvim/buffer_updates.c b/src/nvim/buffer_updates.c
index 1d131cc4b1..ee1b7ebc95 100644
--- a/src/nvim/buffer_updates.c
+++ b/src/nvim/buffer_updates.c
@@ -1,14 +1,14 @@
// 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 "nvim/api/private/helpers.h"
+#include "nvim/assert.h"
+#include "nvim/buffer.h"
#include "nvim/buffer_updates.h"
#include "nvim/extmark.h"
+#include "nvim/lua/executor.h"
#include "nvim/memline.h"
-#include "nvim/api/private/helpers.h"
#include "nvim/msgpack_rpc/channel.h"
-#include "nvim/lua/executor.h"
-#include "nvim/assert.h"
-#include "nvim/buffer.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "buffer_updates.c.generated.h"
@@ -17,8 +17,7 @@
// Register a channel. Return True if the channel was added, or already added.
// Return False if the channel couldn't be added because the buffer is
// unloaded.
-bool buf_updates_register(buf_T *buf, uint64_t channel_id,
- BufUpdateCallbacks cb, bool send_buffer)
+bool buf_updates_register(buf_T *buf, uint64_t channel_id, BufUpdateCallbacks cb, bool send_buffer)
{
// must fail if the buffer isn't loaded
if (buf->b_ml.ml_mfp == NULL) {
@@ -86,16 +85,16 @@ bool buf_updates_register(buf_T *buf, uint64_t channel_id,
bool buf_updates_active(buf_T *buf)
{
- return kv_size(buf->update_channels) || kv_size(buf->update_callbacks);
+ return kv_size(buf->update_channels) || kv_size(buf->update_callbacks);
}
void buf_updates_send_end(buf_T *buf, uint64_t channelid)
{
- Array args = ARRAY_DICT_INIT;
- args.size = 1;
- args.items = xcalloc(args.size, sizeof(Object));
- args.items[0] = BUFFER_OBJ(buf->handle);
- rpc_send_event(channelid, "nvim_buf_detach_event", args);
+ Array args = ARRAY_DICT_INIT;
+ args.size = 1;
+ args.items = xcalloc(args.size, sizeof(Object));
+ args.items[0] = BUFFER_OBJ(buf->handle);
+ rpc_send_event(channelid, "nvim_buf_detach_event", args);
}
void buf_updates_unregister(buf_T *buf, uint64_t channelid)
@@ -187,11 +186,8 @@ void buf_updates_unload(buf_T *buf, bool can_reload)
}
-void buf_updates_send_changes(buf_T *buf,
- linenr_T firstline,
- int64_t num_added,
- int64_t num_removed,
- bool send_tick)
+void buf_updates_send_changes(buf_T *buf, linenr_T firstline, int64_t num_added,
+ int64_t num_removed, bool send_tick)
{
size_t deleted_codepoints, deleted_codeunits;
size_t deleted_bytes = ml_flush_deleted_bytes(buf, &deleted_codepoints,
@@ -228,11 +224,11 @@ void buf_updates_send_changes(buf_T *buf,
// linedata of lines being swapped in
Array linedata = ARRAY_DICT_INIT;
if (num_added > 0) {
- STATIC_ASSERT(SIZE_MAX >= MAXLNUM, "size_t smaller than MAXLNUM");
- linedata.size = (size_t)num_added;
- linedata.items = xcalloc((size_t)num_added, sizeof(Object));
- buf_collect_lines(buf, (size_t)num_added, firstline, true, &linedata,
- NULL);
+ STATIC_ASSERT(SIZE_MAX >= MAXLNUM, "size_t smaller than MAXLNUM");
+ linedata.size = (size_t)num_added;
+ linedata.items = xcalloc((size_t)num_added, sizeof(Object));
+ buf_collect_lines(buf, (size_t)num_added, firstline, true, &linedata,
+ NULL);
}
args.items[4] = ARRAY_OBJ(linedata);
args.items[5] = BOOLEAN_OBJ(false);
@@ -248,7 +244,7 @@ void buf_updates_send_changes(buf_T *buf,
// change notifications are so frequent that many dead channels will be
// cleared up quickly.
if (badchannelid != 0) {
- ELOG("Disabling buffer updates for dead channel %"PRIu64, badchannelid);
+ ELOG("Disabling buffer updates for dead channel %" PRIu64, badchannelid);
buf_updates_unregister(buf, badchannelid);
}
@@ -302,11 +298,9 @@ void buf_updates_send_changes(buf_T *buf,
kv_size(buf->update_callbacks) = j;
}
-void buf_updates_send_splice(
- buf_T *buf,
- int start_row, colnr_T start_col, bcount_t start_byte,
- int old_row, colnr_T old_col, bcount_t old_byte,
- int new_row, colnr_T new_col, bcount_t new_byte)
+void buf_updates_send_splice(buf_T *buf, int start_row, colnr_T start_col, bcount_t start_byte,
+ int old_row, colnr_T old_col, bcount_t old_byte, int new_row,
+ colnr_T new_col, bcount_t new_byte)
{
if (!buf_updates_active(buf)
|| (old_byte == 0 && new_byte == 0)) {
@@ -392,18 +386,18 @@ void buf_updates_changedtick(buf_T *buf)
void buf_updates_changedtick_single(buf_T *buf, uint64_t channel_id)
{
- Array args = ARRAY_DICT_INIT;
- args.size = 2;
- args.items = xcalloc(args.size, sizeof(Object));
+ Array args = ARRAY_DICT_INIT;
+ args.size = 2;
+ args.items = xcalloc(args.size, sizeof(Object));
- // the first argument is always the buffer handle
- args.items[0] = BUFFER_OBJ(buf->handle);
+ // the first argument is always the buffer handle
+ args.items[0] = BUFFER_OBJ(buf->handle);
- // next argument is b:changedtick
- args.items[1] = INTEGER_OBJ(buf_get_changedtick(buf));
+ // next argument is b:changedtick
+ args.items[1] = INTEGER_OBJ(buf_get_changedtick(buf));
- // don't try and clean up dead channels here
- rpc_send_event(channel_id, "nvim_buf_changedtick_event", args);
+ // don't try and clean up dead channels here
+ rpc_send_event(channel_id, "nvim_buf_changedtick_event", args);
}
void buffer_update_callbacks_free(BufUpdateCallbacks cb)
diff --git a/src/nvim/change.c b/src/nvim/change.c
index 13b86e9244..ccceb0e320 100644
--- a/src/nvim/change.c
+++ b/src/nvim/change.c
@@ -12,12 +12,12 @@
#include "nvim/diff.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
+#include "nvim/extmark.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/indent.h"
#include "nvim/indent_c.h"
#include "nvim/mark.h"
-#include "nvim/extmark.h"
#include "nvim/memline.h"
#include "nvim/misc1.h"
#include "nvim/move.h"
@@ -53,13 +53,13 @@ void change_warning(buf_T *buf, int col)
apply_autocmds(EVENT_FILECHANGEDRO, NULL, NULL, false, buf);
buf->b_ro_locked--;
if (!buf->b_p_ro) {
- return;
+ return;
}
// Do what msg() does, but with a column offset if the warning should
// be after the mode message.
msg_start();
if (msg_row == Rows - 1) {
- msg_col = col;
+ msg_col = col;
}
msg_source(HL_ATTR(HLF_W));
msg_ext_set_kind("wmsg");
@@ -74,7 +74,7 @@ void change_warning(buf_T *buf, int col)
buf->b_did_warn = true;
redraw_cmdline = false; // don't redraw and erase the message
if (msg_row < Rows - 1) {
- showmode();
+ showmode();
}
}
}
@@ -97,8 +97,7 @@ void changed(void)
// Create a swap file if that is wanted.
// Don't do this for "nofile" and "nowrite" buffer types.
if (curbuf->b_may_swap
- && !bt_dontwrite(curbuf)
- ) {
+ && !bt_dontwrite(curbuf)) {
bool save_need_wait_return = need_wait_return;
need_wait_return = false;
@@ -140,11 +139,10 @@ void changed_internal(void)
/// Common code for when a change was made.
/// See changed_lines() for the arguments.
/// Careful: may trigger autocommands that reload the buffer.
-static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume,
- long xtra)
+static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra)
{
int i;
- pos_T *p;
+ pos_T *p;
int add;
// mark the buffer as modified
@@ -162,18 +160,18 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume,
// don't have an entry yet.
if (curbuf->b_new_change || curbuf->b_changelistlen == 0) {
if (curbuf->b_changelistlen == 0) {
- add = true;
+ add = true;
} else {
// Don't create a new entry when the line number is the same
// as the last one and the column is not too far away. Avoids
// creating many entries for typing "xxxxx".
p = &curbuf->b_changelist[curbuf->b_changelistlen - 1].mark;
if (p->lnum != lnum) {
- add = true;
+ add = true;
} else {
int cols = comp_textwidth(false);
if (cols == 0) {
- cols = 79;
+ cols = 79;
}
add = (p->col + cols < col || col + cols < p->col);
}
@@ -219,7 +217,7 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume,
if (wp->w_buffer == curbuf) {
// Mark this window to be redrawn later.
if (wp->w_redr_type < VALID) {
- wp->w_redr_type = VALID;
+ wp->w_redr_type = VALID;
}
// Check if a change in the buffer has invalidated the cached
@@ -235,11 +233,11 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume,
// inserting lines just above a closed fold. */
bool folded = hasFoldingWin(wp, lnum, &lnum, NULL, false, NULL);
if (wp->w_cursor.lnum == lnum) {
- wp->w_cline_folded = folded;
+ wp->w_cline_folded = folded;
}
folded = hasFoldingWin(wp, lnume, NULL, &lnume, false, NULL);
if (wp->w_cursor.lnum == lnume) {
- wp->w_cline_folded = folded;
+ wp->w_cline_folded = folded;
}
// If the changed line is in a range of previously folded lines,
@@ -247,14 +245,14 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume,
if (wp->w_cursor.lnum <= lnum) {
i = find_wl_entry(wp, lnum);
if (i >= 0 && wp->w_cursor.lnum > wp->w_lines[i].wl_lnum) {
- changed_line_abv_curs_win(wp);
+ changed_line_abv_curs_win(wp);
}
}
if (wp->w_cursor.lnum > lnum) {
- changed_line_abv_curs_win(wp);
+ changed_line_abv_curs_win(wp);
} else if (wp->w_cursor.lnum == lnum && wp->w_cursor.col >= col) {
- changed_cline_bef_curs_win(wp);
+ changed_cline_bef_curs_win(wp);
}
if (wp->w_botline >= lnum) {
// Assume that botline doesn't change (inserted lines make
@@ -327,9 +325,9 @@ static void changedOneline(buf_T *buf, linenr_T lnum)
if (buf->b_mod_set) {
// find the maximum area that must be redisplayed
if (lnum < buf->b_mod_top) {
- buf->b_mod_top = lnum;
+ buf->b_mod_top = lnum;
} else if (lnum >= buf->b_mod_bot) {
- buf->b_mod_bot = lnum + 1;
+ buf->b_mod_bot = lnum + 1;
}
} else {
// set the area that must be redisplayed to one line
@@ -361,7 +359,7 @@ void changed_bytes(linenr_T lnum, colnr_T col)
redraw_later(wp, VALID);
wlnum = diff_lnum_win(lnum, wp);
if (wlnum > 0) {
- changedOneline(wp->w_buffer, wlnum);
+ changedOneline(wp->w_buffer, wlnum);
}
}
}
@@ -463,17 +461,15 @@ void changed_lines_buf(buf_T *buf, linenr_T lnum, linenr_T lnume, long xtra)
/// When only inserting lines, "lnum" and "lnume" are equal.
/// Takes care of calling changed() and updating b_mod_*.
/// Careful: may trigger autocommands that reload the buffer.
-void
-changed_lines(
- linenr_T lnum, // first line with change
- colnr_T col, // column in first line with change
- linenr_T lnume, // line below last changed line
- long xtra, // number of extra lines (negative when deleting)
- bool do_buf_event // some callers like undo/redo call changed_lines()
- // and then increment changedtick *again*. This flag
- // allows these callers to send the nvim_buf_lines_event
- // events after they're done modifying changedtick.
-)
+void changed_lines(linenr_T lnum, // first line with change
+ colnr_T col, // column in first line with change
+ linenr_T lnume, // line below last changed line
+ long xtra, // number of extra lines (negative when deleting)
+ bool do_buf_event // some callers like undo/redo call changed_lines()
+ // and then increment changedtick *again*. This flag
+ // allows these callers to send the nvim_buf_lines_event
+ // events after they're done modifying changedtick.
+ )
{
changed_lines_buf(curbuf, lnum, lnume, xtra);
@@ -609,7 +605,7 @@ void ins_char_bytes(char_u *buf, size_t charlen)
}
}
curwin->w_p_list = old_list;
- } else if (oldp[col] != NUL) {
+ } else if (oldp[col] != NUL) {
// normal replace
oldlen = (size_t)(*mb_ptr2len)(oldp + col);
}
@@ -657,8 +653,7 @@ void ins_char_bytes(char_u *buf, size_t charlen)
// show the match for right parens and braces.
if (p_sm && (State & INSERT)
&& msg_silent == 0
- && !ins_compl_active()
- ) {
+ && !ins_compl_active()) {
showmatch(utf_ptr2char(buf));
}
@@ -674,7 +669,7 @@ void ins_char_bytes(char_u *buf, size_t charlen)
/// Caller must have prepared for undo.
void ins_str(char_u *s)
{
- char_u *oldp, *newp;
+ char_u *oldp, *newp;
int newlen = (int)STRLEN(s);
int oldlen;
colnr_T col;
@@ -721,7 +716,7 @@ int del_chars(long count, int fixpos)
{
int bytes = 0;
long i;
- char_u *p;
+ char_u *p;
int l;
p = get_cursor_pos_ptr();
@@ -791,8 +786,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine)
// fixpos is true, we don't want to end up positioned at the NUL,
// unless "restart_edit" is set or 'virtualedit' contains "onemore".
if (col > 0 && fixpos && restart_edit == 0
- && (ve_flags & VE_ONEMORE) == 0
- ) {
+ && (ve_flags & VE_ONEMORE) == 0) {
curwin->w_cursor.col--;
curwin->w_cursor.coladd = 0;
curwin->w_cursor.col -= utf_head_off(oldp, oldp + curwin->w_cursor.col);
@@ -957,11 +951,8 @@ int copy_indent(int size, char_u *src)
/// OPENLINE_COM_LIST
///
/// @return true on success, false on failure
-int open_line(
- int dir, // FORWARD or BACKWARD
- int flags,
- int second_line_indent
-)
+int open_line(int dir, // FORWARD or BACKWARD
+ int flags, int second_line_indent)
{
char_u *next_line = NULL; // copy of the next line
char_u *p_extra = NULL; // what goes to next line
@@ -1003,9 +994,9 @@ int open_line(
// the line, replacing what was there before and pushing the right
// stuff onto the replace stack. -- webb.
if (curwin->w_cursor.lnum < orig_line_count) {
- next_line = vim_strsave(ml_get(curwin->w_cursor.lnum + 1));
+ next_line = vim_strsave(ml_get(curwin->w_cursor.lnum + 1));
} else {
- next_line = vim_strsave((char_u *)"");
+ next_line = vim_strsave((char_u *)"");
}
// In VREPLACE mode, a NL replaces the rest of the line, and starts
@@ -1023,8 +1014,7 @@ int open_line(
}
if ((State & INSERT)
- && !(State & VREPLACE_FLAG)
- ) {
+ && !(State & VREPLACE_FLAG)) {
p_extra = saved_line + curwin->w_cursor.col;
if (do_si) { // need first char after new line break
p = skipwhite(p_extra);
@@ -1043,14 +1033,13 @@ int open_line(
// the prior line, and it should be truncated. Do this even if 'ai' is not
// set because automatically inserting a comment leader also sets did_ai.
if (dir == FORWARD && did_ai) {
- trunc_line = true;
+ trunc_line = true;
}
// If 'autoindent' and/or 'smartindent' is set, try to figure out what
// indent to use for the new line.
if (curbuf->b_p_ai
- || do_si
- ) {
+ || do_si) {
// count white space on current line
newindent = get_indent_str_vtab(saved_line,
curbuf->b_p_ts,
@@ -1066,15 +1055,15 @@ int open_line(
// "if (condition) {"
if (!trunc_line && do_si && *saved_line != NUL
&& (p_extra == NULL || first_char != '{')) {
- char_u *ptr;
+ char_u *ptr;
char_u last_char;
old_cursor = curwin->w_cursor;
ptr = saved_line;
if (flags & OPENLINE_DO_COM) {
- lead_len = get_leader_len(ptr, NULL, false, true);
+ lead_len = get_leader_len(ptr, NULL, false, true);
} else {
- lead_len = 0;
+ lead_len = 0;
}
if (dir == FORWARD) {
// Skip preprocessor directives, unless they are
@@ -1119,17 +1108,17 @@ int open_line(
// Find last non-blank in line
p = ptr + STRLEN(ptr) - 1;
while (p > ptr && ascii_iswhite(*p)) {
- p--;
+ p--;
}
last_char = *p;
// find the character just before the '{' or ';'
if (last_char == '{' || last_char == ';') {
if (p > ptr) {
- p--;
+ p--;
}
while (p > ptr && ascii_iswhite(*p)) {
- p--;
+ p--;
}
}
// Try to catch lines that are split over multiple
@@ -1151,12 +1140,12 @@ int open_line(
if (last_char == '{') {
did_si = true; // do indent
no_si = true; // don't delete it when '{' typed
- // Look for "if" and the like, use 'cinwords'.
- // Don't do this if the previous line ended in ';' or
- // '}'.
+ // Look for "if" and the like, use 'cinwords'.
+ // Don't do this if the previous line ended in ';' or
+ // '}'.
} else if (last_char != ';' && last_char != '}'
&& cin_is_cinword(ptr)) {
- did_si = true;
+ did_si = true;
}
}
} else { // dir == BACKWARD
@@ -1205,15 +1194,15 @@ int open_line(
lead_len = 0;
}
if (lead_len > 0) {
- char_u *lead_repl = NULL; // replaces comment leader
+ char_u *lead_repl = NULL; // replaces comment leader
int lead_repl_len = 0; // length of *lead_repl
char_u lead_middle[COM_MAX_LEN]; // middle-comment string
char_u lead_end[COM_MAX_LEN]; // end-comment string
- char_u *comment_end = NULL; // where lead_end has been found
+ char_u *comment_end = NULL; // where lead_end has been found
int extra_space = false; // append extra space
int current_flag;
int require_blank = false; // requires blank after middle
- char_u *p2;
+ char_u *p2;
// If the comment leader has the start, middle or end flag, it may not
// be used or may be replaced with the middle leader.
@@ -1304,7 +1293,7 @@ int open_line(
// Doing "O" on the end of a comment inserts the middle leader.
// Find the string for the middle leader, searching backwards.
while (p > curbuf->b_p_com && *p != ',') {
- p--;
+ p--;
}
for (lead_repl = p; lead_repl > curbuf->b_p_com
&& lead_repl[-1] != ':'; lead_repl--) {
@@ -1318,13 +1307,13 @@ int open_line(
// Check whether we allow automatic ending of comments
for (p2 = p; *p2 && *p2 != ':'; p2++) {
if (*p2 == COM_AUTO_END) {
- end_comment_pending = -1; // means we want to set it
+ end_comment_pending = -1; // means we want to set it
}
}
if (end_comment_pending == -1) {
// Find last character in end-comment string
while (*p2 && *p2 != ',') {
- p2++;
+ p2++;
}
end_comment_pending = p2[-1];
}
@@ -1334,7 +1323,7 @@ int open_line(
// Comment leader for first line only: Don't repeat leader
// when using "O", blank out leader when using "o".
if (dir == BACKWARD) {
- lead_len = 0;
+ lead_len = 0;
} else {
lead_repl = (char_u *)"";
lead_repl_len = 0;
@@ -1345,11 +1334,11 @@ int open_line(
if (lead_len > 0) {
// allocate buffer (may concatenate p_extra later)
int bytes = lead_len
- + lead_repl_len
- + extra_space
- + extra_len
- + (second_line_indent > 0 ? second_line_indent : 0)
- + 1;
+ + lead_repl_len
+ + extra_space
+ + extra_len
+ + (second_line_indent > 0 ? second_line_indent : 0)
+ + 1;
assert(bytes >= 0);
leader = xmalloc((size_t)bytes);
allocated = leader; // remember to free it later
@@ -1363,11 +1352,11 @@ int open_line(
for (p = lead_flags; *p != NUL && *p != ':'; ) {
if (*p == COM_RIGHT || *p == COM_LEFT) {
- c = *p++;
+ c = *p++;
} else if (ascii_isdigit(*p) || *p == '-') {
- off = getdigits_int(&p, true, 0);
+ off = getdigits_int(&p, true, 0);
} else {
- p++;
+ p++;
}
}
if (c == COM_RIGHT) { // right adjusted leader
@@ -1383,7 +1372,7 @@ int open_line(
int repl_size = vim_strnsize(lead_repl,
lead_repl_len);
int old_size = 0;
- char_u *endp = p;
+ char_u *endp = p;
int l;
while (old_size < repl_size && p > leader) {
@@ -1392,14 +1381,14 @@ int open_line(
}
l = lead_repl_len - (int)(endp - p);
if (l != 0) {
- memmove(endp + l, endp,
- (size_t)((leader + lead_len) - endp));
+ memmove(endp + l, endp,
+ (size_t)((leader + lead_len) - endp));
}
lead_len += l;
}
memmove(p, lead_repl, (size_t)lead_repl_len);
if (p + lead_repl_len > leader + lead_len) {
- p[lead_repl_len] = NUL;
+ p[lead_repl_len] = NUL;
}
// blank-out any other chars from the old leader.
@@ -1417,7 +1406,7 @@ int open_line(
lead_len -= l;
*p = ' ';
} else if (!ascii_iswhite(*p)) {
- *p = ' ';
+ *p = ' ';
}
}
} else { // left adjusted leader
@@ -1434,12 +1423,12 @@ int open_line(
for (i = 0; i < lead_len && p[i] != NUL; i += l) {
l = (*mb_ptr2len)(p + i);
if (vim_strnsize(p, i + l) > repl_size) {
- break;
+ break;
}
}
if (i != lead_repl_len) {
- memmove(p + lead_repl_len, p + i,
- (size_t)(lead_len - i - (p - leader)));
+ memmove(p + lead_repl_len, p + i,
+ (size_t)(lead_len - i - (p - leader)));
lead_len += lead_repl_len - i;
}
}
@@ -1476,8 +1465,7 @@ int open_line(
// Recompute the indent, it may have changed.
if (curbuf->b_p_ai
- || do_si
- ) {
+ || do_si) {
newindent = get_indent_str_vtab(leader,
curbuf->b_p_ts,
curbuf->b_p_vts_array, false);
@@ -1497,7 +1485,7 @@ int open_line(
&& leader[lead_len - 1] == ' ') {
// Don't do it when there is a tab before the space
if (vim_strchr(skipwhite(leader), '\t') != NULL) {
- break;
+ break;
}
lead_len--;
off--;
@@ -1506,7 +1494,7 @@ int open_line(
// If the leader ends in white space, don't add an
// extra space
if (lead_len > 0 && ascii_iswhite(leader[lead_len - 1])) {
- extra_space = false;
+ extra_space = false;
}
leader[lead_len] = NUL;
}
@@ -1521,8 +1509,7 @@ int open_line(
// if a new indent will be set below, remove the indent that
// is in the comment leader
if (newindent
- || did_si
- ) {
+ || did_si) {
while (lead_len && ascii_iswhite(*leader)) {
lead_len--;
newcol--;
@@ -1559,7 +1546,7 @@ int open_line(
// When in REPLACE mode, put the deleted blanks on the replace stack,
// preceded by a NUL, so they can be put back when a BS is entered.
if (REPLACE_NORMAL(State)) {
- replace_push(NUL); // end of extra blanks
+ replace_push(NUL); // end of extra blanks
}
if (curbuf->b_p_ai || (flags & OPENLINE_DELSPACES)) {
while ((*p_extra == ' ' || *p_extra == '\t')
@@ -1577,7 +1564,7 @@ int open_line(
}
if (p_extra == NULL) {
- p_extra = (char_u *)""; // append empty line
+ p_extra = (char_u *)""; // append empty line
}
// concatenate leader and p_extra, if there is a leader
@@ -1641,8 +1628,7 @@ int open_line(
inhibit_delete_count++;
if (newindent
- || did_si
- ) {
+ || did_si) {
curwin->w_cursor.lnum++;
if (did_si) {
int sw = get_sw_value(curbuf);
@@ -1706,9 +1692,8 @@ int open_line(
// TODO(vigoux): maybe there is issues there with expandtabs ?
int cols_spliced = 0;
if (new_len < curwin->w_cursor.col) {
- extmark_splice_cols(
- curbuf, (int)curwin->w_cursor.lnum - 1,
- new_len, curwin->w_cursor.col - new_len, 0, kExtmarkUndo);
+ extmark_splice_cols(curbuf, (int)curwin->w_cursor.lnum - 1,
+ new_len, curwin->w_cursor.col - new_len, 0, kExtmarkUndo);
cols_spliced = curwin->w_cursor.col - new_len;
}
@@ -1815,7 +1800,7 @@ theend:
/// If "fixpos" is true fix the cursor position when done.
void truncate_line(int fixpos)
{
- char_u *newp;
+ char_u *newp;
linenr_T lnum = curwin->w_cursor.lnum;
colnr_T col = curwin->w_cursor.col;
@@ -1843,12 +1828,12 @@ void del_lines(long nlines, bool undo)
linenr_T first = curwin->w_cursor.lnum;
if (nlines <= 0) {
- return;
+ return;
}
// save the deleted lines for undo
if (undo && u_savedel(first, nlines) == FAIL) {
- return;
+ return;
}
for (n = 0; n < nlines; ) {
@@ -1861,7 +1846,7 @@ void del_lines(long nlines, bool undo)
// If we delete the last line in the file, stop
if (first > curbuf->b_ml.ml_line_count) {
- break;
+ break;
}
}
diff --git a/src/nvim/channel.c b/src/nvim/channel.c
index 54a59f6cc1..30243a3102 100644
--- a/src/nvim/channel.c
+++ b/src/nvim/channel.c
@@ -12,11 +12,11 @@
#include "nvim/msgpack_rpc/server.h"
#include "nvim/os/shell.h"
#ifdef WIN32
-# include "nvim/os/pty_conpty_win.h"
# include "nvim/os/os_win_console.h"
+# include "nvim/os/pty_conpty_win.h"
#endif
-#include "nvim/path.h"
#include "nvim/ascii.h"
+#include "nvim/path.h"
static bool did_stdio = false;
@@ -66,7 +66,7 @@ bool channel_close(uint64_t id, ChannelPart part, const char **error)
if (part == kChannelPartRpc || part == kChannelPartAll) {
close_main = true;
if (chan->is_rpc) {
- rpc_close(chan);
+ rpc_close(chan);
} else if (part == kChannelPartRpc) {
*error = (const char *)e_invstream;
return false;
@@ -78,68 +78,68 @@ bool channel_close(uint64_t id, ChannelPart part, const char **error)
}
switch (chan->streamtype) {
- case kChannelStreamSocket:
- if (!close_main) {
- *error = (const char *)e_invstream;
- return false;
- }
- stream_may_close(&chan->stream.socket);
- break;
+ case kChannelStreamSocket:
+ if (!close_main) {
+ *error = (const char *)e_invstream;
+ return false;
+ }
+ stream_may_close(&chan->stream.socket);
+ break;
- case kChannelStreamProc:
- proc = (Process *)&chan->stream.proc;
- if (part == kChannelPartStdin || close_main) {
- stream_may_close(&proc->in);
- }
- if (part == kChannelPartStdout || close_main) {
- stream_may_close(&proc->out);
- }
- if (part == kChannelPartStderr || part == kChannelPartAll) {
- stream_may_close(&proc->err);
- }
- if (proc->type == kProcessTypePty && part == kChannelPartAll) {
- pty_process_close_master(&chan->stream.pty);
- }
+ case kChannelStreamProc:
+ proc = (Process *)&chan->stream.proc;
+ if (part == kChannelPartStdin || close_main) {
+ stream_may_close(&proc->in);
+ }
+ if (part == kChannelPartStdout || close_main) {
+ stream_may_close(&proc->out);
+ }
+ if (part == kChannelPartStderr || part == kChannelPartAll) {
+ stream_may_close(&proc->err);
+ }
+ if (proc->type == kProcessTypePty && part == kChannelPartAll) {
+ pty_process_close_master(&chan->stream.pty);
+ }
- break;
+ break;
- case kChannelStreamStdio:
- if (part == kChannelPartStdin || close_main) {
- stream_may_close(&chan->stream.stdio.in);
- }
- if (part == kChannelPartStdout || close_main) {
- stream_may_close(&chan->stream.stdio.out);
- }
- if (part == kChannelPartStderr) {
- *error = (const char *)e_invstream;
- return false;
- }
- break;
+ case kChannelStreamStdio:
+ if (part == kChannelPartStdin || close_main) {
+ stream_may_close(&chan->stream.stdio.in);
+ }
+ if (part == kChannelPartStdout || close_main) {
+ stream_may_close(&chan->stream.stdio.out);
+ }
+ if (part == kChannelPartStderr) {
+ *error = (const char *)e_invstream;
+ return false;
+ }
+ break;
- case kChannelStreamStderr:
- if (part != kChannelPartAll && part != kChannelPartStderr) {
- *error = (const char *)e_invstream;
- return false;
- }
- if (!chan->stream.err.closed) {
- chan->stream.err.closed = true;
- // Don't close on exit, in case late error messages
- if (!exiting) {
- fclose(stderr);
- }
- channel_decref(chan);
+ case kChannelStreamStderr:
+ if (part != kChannelPartAll && part != kChannelPartStderr) {
+ *error = (const char *)e_invstream;
+ return false;
+ }
+ if (!chan->stream.err.closed) {
+ chan->stream.err.closed = true;
+ // Don't close on exit, in case late error messages
+ if (!exiting) {
+ fclose(stderr);
}
- break;
+ channel_decref(chan);
+ }
+ break;
- case kChannelStreamInternal:
- if (!close_main) {
- *error = (const char *)e_invstream;
- return false;
- }
- break;
+ case kChannelStreamInternal:
+ if (!close_main) {
+ *error = (const char *)e_invstream;
+ return false;
+ }
+ break;
- default:
- abort();
+ default:
+ abort();
}
return true;
@@ -301,12 +301,10 @@ static void close_cb(Stream *stream, void *data)
/// < 0 if the job can't start
///
/// @returns [allocated] channel
-Channel *channel_job_start(char **argv, CallbackReader on_stdout,
- CallbackReader on_stderr, Callback on_exit,
- bool pty, bool rpc, bool overlapped, bool detach,
- ChannelStdinMode stdin_mode, const char *cwd,
- uint16_t pty_width, uint16_t pty_height,
- dict_T *env, varnumber_T *status_out)
+Channel *channel_job_start(char **argv, CallbackReader on_stdout, CallbackReader on_stderr,
+ Callback on_exit, bool pty, bool rpc, bool overlapped, bool detach,
+ ChannelStdinMode stdin_mode, const char *cwd, uint16_t pty_width,
+ uint16_t pty_height, dict_T *env, varnumber_T *status_out)
{
assert(cwd == NULL || os_isdir_executable(cwd));
@@ -409,8 +407,7 @@ Channel *channel_job_start(char **argv, CallbackReader on_stdout,
}
-uint64_t channel_connect(bool tcp, const char *address,
- bool rpc, CallbackReader on_output,
+uint64_t channel_connect(bool tcp, const char *address, bool rpc, CallbackReader on_output,
int timeout, const char **error)
{
Channel *channel;
@@ -470,8 +467,7 @@ void channel_from_connection(SocketWatcher *watcher)
/// Creates an API channel from stdin/stdout. This is used when embedding
/// Neovim
-uint64_t channel_from_stdio(bool rpc, CallbackReader on_output,
- const char **error)
+uint64_t channel_from_stdio(bool rpc, CallbackReader on_output, const char **error)
FUNC_ATTR_NONNULL_ALL
{
if (!headless_mode && !embedded_mode) {
@@ -514,8 +510,7 @@ uint64_t channel_from_stdio(bool rpc, CallbackReader on_output,
}
/// @param data will be consumed
-size_t channel_send(uint64_t id, char *data, size_t len,
- bool data_owned, const char **error)
+size_t channel_send(uint64_t id, char *data, size_t len, bool data_owned, const char **error)
FUNC_ATTR_NONNULL_ALL
{
Channel *chan = find_channel(id);
@@ -584,22 +579,20 @@ static inline list_T *buffer_to_tv_list(const char *const buf, const size_t len)
return l;
}
-void on_channel_data(Stream *stream, RBuffer *buf, size_t count,
- void *data, bool eof)
+void on_channel_data(Stream *stream, RBuffer *buf, size_t count, void *data, bool eof)
{
Channel *chan = data;
on_channel_output(stream, chan, buf, count, eof, &chan->on_data);
}
-void on_job_stderr(Stream *stream, RBuffer *buf, size_t count,
- void *data, bool eof)
+void on_job_stderr(Stream *stream, RBuffer *buf, size_t count, void *data, bool eof)
{
Channel *chan = data;
on_channel_output(stream, chan, buf, count, eof, &chan->on_stderr);
}
-static void on_channel_output(Stream *stream, Channel *chan, RBuffer *buf,
- size_t count, bool eof, CallbackReader *reader)
+static void on_channel_output(Stream *stream, Channel *chan, RBuffer *buf, size_t count, bool eof,
+ CallbackReader *reader)
{
// stub variable, to keep reading consistent with the order of events, only
// consider the count parameter.
@@ -852,43 +845,43 @@ Dictionary channel_info(uint64_t id)
const char *stream_desc, *mode_desc;
switch (chan->streamtype) {
- case kChannelStreamProc: {
- stream_desc = "job";
- if (chan->stream.proc.type == kProcessTypePty) {
- const char *name = pty_process_tty_name(&chan->stream.pty);
- PUT(info, "pty", STRING_OBJ(cstr_to_string(name)));
- }
+ case kChannelStreamProc: {
+ stream_desc = "job";
+ if (chan->stream.proc.type == kProcessTypePty) {
+ const char *name = pty_process_tty_name(&chan->stream.pty);
+ PUT(info, "pty", STRING_OBJ(cstr_to_string(name)));
+ }
- char **p = chan->stream.proc.argv;
- Array argv = ARRAY_DICT_INIT;
- if (p != NULL) {
- while (*p != NULL) {
- ADD(argv, STRING_OBJ(cstr_to_string(*p)));
- p++;
- }
+ char **p = chan->stream.proc.argv;
+ Array argv = ARRAY_DICT_INIT;
+ if (p != NULL) {
+ while (*p != NULL) {
+ ADD(argv, STRING_OBJ(cstr_to_string(*p)));
+ p++;
}
- PUT(info, "argv", ARRAY_OBJ(argv));
- break;
}
+ PUT(info, "argv", ARRAY_OBJ(argv));
+ break;
+ }
- case kChannelStreamStdio:
- stream_desc = "stdio";
- break;
+ case kChannelStreamStdio:
+ stream_desc = "stdio";
+ break;
- case kChannelStreamStderr:
- stream_desc = "stderr";
- break;
+ case kChannelStreamStderr:
+ stream_desc = "stderr";
+ break;
- case kChannelStreamInternal:
- PUT(info, "internal", BOOLEAN_OBJ(true));
- FALLTHROUGH;
+ case kChannelStreamInternal:
+ PUT(info, "internal", BOOLEAN_OBJ(true));
+ FALLTHROUGH;
- case kChannelStreamSocket:
- stream_desc = "socket";
- break;
+ case kChannelStreamSocket:
+ stream_desc = "socket";
+ break;
- default:
- abort();
+ default:
+ abort();
}
PUT(info, "stream", STRING_OBJ(cstr_to_string(stream_desc)));
diff --git a/src/nvim/charset.c b/src/nvim/charset.c
index e029973386..21e04128dc 100644
--- a/src/nvim/charset.c
+++ b/src/nvim/charset.c
@@ -6,14 +6,15 @@
/// Code related to character sets.
#include <assert.h>
+#include <inttypes.h>
#include <string.h>
#include <wctype.h>
-#include <inttypes.h>
-#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
#include "nvim/func_attr.h"
+#include "nvim/garray.h"
#include "nvim/indent.h"
#include "nvim/main.h"
#include "nvim/mark.h"
@@ -21,15 +22,14 @@
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/misc1.h"
-#include "nvim/garray.h"
#include "nvim/move.h"
#include "nvim/option.h"
#include "nvim/os_unix.h"
+#include "nvim/path.h"
#include "nvim/plines.h"
#include "nvim/state.h"
#include "nvim/strings.h"
-#include "nvim/path.h"
-#include "nvim/cursor.h"
+#include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "charset.c.generated.h"
@@ -41,11 +41,11 @@ static bool chartab_initialized = false;
// b_chartab[] is an array with 256 bits, each bit representing one of the
// characters 0-255.
#define SET_CHARTAB(buf, c) \
- (buf)->b_chartab[(unsigned)(c) >> 6] |= (1ull << ((c) & 0x3f))
+ (buf)->b_chartab[(unsigned)(c) >> 6] |= (1ull << ((c) & 0x3f))
#define RESET_CHARTAB(buf, c) \
- (buf)->b_chartab[(unsigned)(c) >> 6] &= ~(1ull << ((c) & 0x3f))
+ (buf)->b_chartab[(unsigned)(c) >> 6] &= ~(1ull << ((c) & 0x3f))
#define GET_CHARTAB_TAB(chartab, c) \
- ((chartab)[(unsigned)(c) >> 6] & (1ull << ((c) & 0x3f)))
+ ((chartab)[(unsigned)(c) >> 6] & (1ull << ((c) & 0x3f)))
// Table used below, see init_chartab() for an explanation
static char_u g_chartab[256];
@@ -212,7 +212,7 @@ int buf_init_chartab(buf_T *buf, int global)
if (i == 0) {
// (re)set ID flag
if (tilde) {
- g_chartab[c] &= (uint8_t)~CT_ID_CHAR;
+ g_chartab[c] &= (uint8_t) ~CT_ID_CHAR;
} else {
g_chartab[c] |= CT_ID_CHAR;
}
@@ -224,7 +224,7 @@ int buf_init_chartab(buf_T *buf, int global)
if (tilde) {
g_chartab[c] = (uint8_t)((g_chartab[c] & ~CT_CELL_MASK)
+ ((dy_flags & DY_UHEX) ? 4 : 2));
- g_chartab[c] &= (uint8_t)~CT_PRINT_CHAR;
+ g_chartab[c] &= (uint8_t) ~CT_PRINT_CHAR;
} else {
g_chartab[c] = (uint8_t)((g_chartab[c] & ~CT_CELL_MASK) + 1);
g_chartab[c] |= CT_PRINT_CHAR;
@@ -233,7 +233,7 @@ int buf_init_chartab(buf_T *buf, int global)
} else if (i == 2) {
// (re)set fname flag
if (tilde) {
- g_chartab[c] &= (uint8_t)~CT_FNAME_CHAR;
+ g_chartab[c] &= (uint8_t) ~CT_FNAME_CHAR;
} else {
g_chartab[c] |= CT_FNAME_CHAR;
}
@@ -417,7 +417,7 @@ char *transstr(const char *const s)
///
/// When "buf" is NULL, return an allocated string.
/// Otherwise, put the result in buf, limited by buflen, and return buf.
-char_u* str_foldcase(char_u *str, int orglen, char_u *buf, int buflen)
+char_u * str_foldcase(char_u *str, int orglen, char_u *buf, int buflen)
FUNC_ATTR_NONNULL_RET
{
garray_T ga;
@@ -906,12 +906,11 @@ bool in_win_border(win_T *wp, colnr_T vcol)
/// @param start
/// @param cursor
/// @param end
-void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor,
- colnr_T *end)
+void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *end)
{
colnr_T vcol;
char_u *ptr; // points to current char
- char_u *posptr; // points to char at pos->col
+ char_u *posptr; // points to char at pos->col
char_u *line; // start of the line
int incr;
int head;
@@ -1059,8 +1058,7 @@ colnr_T getvcol_nolist(pos_T *posp)
/// @param start
/// @param cursor
/// @param end
-void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor,
- colnr_T *end)
+void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *end)
{
colnr_T col;
colnr_T coladd;
@@ -1115,8 +1113,7 @@ void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor,
/// @param pos2
/// @param left
/// @param right
-void getvcols(win_T *wp, pos_T *pos1, pos_T *pos2, colnr_T *left,
- colnr_T *right)
+void getvcols(win_T *wp, pos_T *pos1, pos_T *pos2, colnr_T *left, colnr_T *right)
{
colnr_T from1;
colnr_T from2;
@@ -1212,7 +1209,7 @@ char_u *skipdigits(const char_u *q)
/// @param q pointer to string
///
/// @return Pointer to the character after the skipped digits.
-const char* skipbin(const char *q)
+const char * skipbin(const char *q)
FUNC_ATTR_PURE
FUNC_ATTR_NONNULL_ALL
FUNC_ATTR_NONNULL_RET
@@ -1231,7 +1228,7 @@ const char* skipbin(const char *q)
///
/// @return Pointer to the character after the skipped digits and hex
/// characters.
-char_u* skiphex(char_u *q)
+char_u * skiphex(char_u *q)
{
char_u *p = q;
while (ascii_isxdigit(*p)) {
@@ -1246,7 +1243,7 @@ char_u* skiphex(char_u *q)
/// @param q
///
/// @return Pointer to the digit or (NUL after the string).
-char_u* skiptodigit(char_u *q)
+char_u * skiptodigit(char_u *q)
{
char_u *p = q;
while (*p != NUL && !ascii_isdigit(*p)) {
@@ -1261,7 +1258,7 @@ char_u* skiptodigit(char_u *q)
/// @param q pointer to string
///
/// @return Pointer to the binary character or (NUL after the string).
-const char* skiptobin(const char *q)
+const char * skiptobin(const char *q)
FUNC_ATTR_PURE
FUNC_ATTR_NONNULL_ALL
FUNC_ATTR_NONNULL_RET
@@ -1279,7 +1276,7 @@ const char* skiptobin(const char *q)
/// @param q
///
/// @return Pointer to the hex character or (NUL after the string).
-char_u* skiptohex(char_u *q)
+char_u * skiptohex(char_u *q)
{
char_u *p = q;
while (*p != NUL && !ascii_isxdigit(*p)) {
@@ -1308,7 +1305,7 @@ char_u *skiptowhite(const char_u *p)
/// @param p
///
/// @return Pointer to the next whitespace character.
-char_u* skiptowhite_esc(char_u *p) {
+char_u * skiptowhite_esc(char_u *p) {
while (*p != ' ' && *p != '\t' && *p != NUL) {
if (((*p == '\\') || (*p == Ctrl_V)) && (*(p + 1) != NUL)) {
++p;
@@ -1440,14 +1437,14 @@ bool vim_isblankline(char_u *lbuf)
/// @param strict If true, fail if the number has unexpected trailing
/// alpha-numeric chars: *len is set to 0 and nothing else is
/// returned.
-void vim_str2nr(const char_u *const start, int *const prep, int *const len,
- const int what, varnumber_T *const nptr,
- uvarnumber_T *const unptr, const int maxlen, const bool strict)
+void vim_str2nr(const char_u *const start, int *const prep, int *const len, const int what,
+ varnumber_T *const nptr, uvarnumber_T *const unptr, const int maxlen,
+ const bool strict)
FUNC_ATTR_NONNULL_ARG(1)
{
const char *ptr = (const char *)start;
#define STRING_ENDED(ptr) \
- (!(maxlen == 0 || (int)((ptr) - (const char *)start) < maxlen))
+ (!(maxlen == 0 || (int)((ptr) - (const char *)start) < maxlen))
int pre = 0; // default is decimal
const bool negative = (ptr[0] == '-');
uvarnumber_T un = 0;
@@ -1464,42 +1461,37 @@ void vim_str2nr(const char_u *const start, int *const prep, int *const len,
// When forcing main consideration is skipping the prefix. Decimal numbers
// have no prefixes to skip. pre is not set.
switch (what & ~(STR2NR_FORCE | STR2NR_QUOTE)) {
- case STR2NR_HEX: {
- if (!STRING_ENDED(ptr + 2)
- && ptr[0] == '0'
- && (ptr[1] == 'x' || ptr[1] == 'X')
- && ascii_isxdigit(ptr[2])) {
- ptr += 2;
- }
- goto vim_str2nr_hex;
- }
- case STR2NR_BIN: {
- if (!STRING_ENDED(ptr + 2)
- && ptr[0] == '0'
- && (ptr[1] == 'b' || ptr[1] == 'B')
- && ascii_isbdigit(ptr[2])) {
- ptr += 2;
- }
- goto vim_str2nr_bin;
- }
- // Make STR2NR_OOCT work the same as STR2NR_OCT when forcing.
- case STR2NR_OCT:
- case STR2NR_OOCT:
- case STR2NR_OCT | STR2NR_OOCT: {
- if (!STRING_ENDED(ptr + 2)
- && ptr[0] == '0'
- && (ptr[1] == 'o' || ptr[1] == 'O')
- && ascii_isodigit(ptr[2])) {
- ptr += 2;
- }
- goto vim_str2nr_oct;
+ case STR2NR_HEX:
+ if (!STRING_ENDED(ptr + 2)
+ && ptr[0] == '0'
+ && (ptr[1] == 'x' || ptr[1] == 'X')
+ && ascii_isxdigit(ptr[2])) {
+ ptr += 2;
}
- case 0: {
- goto vim_str2nr_dec;
+ goto vim_str2nr_hex;
+ case STR2NR_BIN:
+ if (!STRING_ENDED(ptr + 2)
+ && ptr[0] == '0'
+ && (ptr[1] == 'b' || ptr[1] == 'B')
+ && ascii_isbdigit(ptr[2])) {
+ ptr += 2;
}
- default: {
- abort();
+ goto vim_str2nr_bin;
+ // Make STR2NR_OOCT work the same as STR2NR_OCT when forcing.
+ case STR2NR_OCT:
+ case STR2NR_OOCT:
+ case STR2NR_OCT | STR2NR_OOCT:
+ if (!STRING_ENDED(ptr + 2)
+ && ptr[0] == '0'
+ && (ptr[1] == 'o' || ptr[1] == 'O')
+ && ascii_isodigit(ptr[2])) {
+ ptr += 2;
}
+ goto vim_str2nr_oct;
+ case 0:
+ goto vim_str2nr_dec;
+ default:
+ abort();
}
} else if ((what & (STR2NR_HEX | STR2NR_OCT | STR2NR_OOCT | STR2NR_BIN))
&& !STRING_ENDED(ptr + 1) && ptr[0] == '0' && ptr[1] != '8'
diff --git a/src/nvim/context.c b/src/nvim/context.c
index 4162daa6ca..1db7938ef4 100644
--- a/src/nvim/context.c
+++ b/src/nvim/context.c
@@ -3,13 +3,13 @@
// Context: snapshot of the entire editor state as one big object/map
+#include "nvim/api/private/helpers.h"
+#include "nvim/api/vim.h"
#include "nvim/context.h"
#include "nvim/eval/encode.h"
#include "nvim/ex_docmd.h"
#include "nvim/option.h"
#include "nvim/shada.h"
-#include "nvim/api/vim.h"
-#include "nvim/api/private/helpers.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "context.c.generated.h"
diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c
index 21f23b7fd4..2eced03c03 100644
--- a/src/nvim/cursor.c
+++ b/src/nvim/cursor.c
@@ -1,25 +1,25 @@
// 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 <inttypes.h>
+#include <stdbool.h>
+#include "nvim/ascii.h"
#include "nvim/assert.h"
#include "nvim/change.h"
-#include "nvim/cursor.h"
#include "nvim/charset.h"
+#include "nvim/cursor.h"
+#include "nvim/extmark.h"
#include "nvim/fold.h"
+#include "nvim/mark.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/misc1.h"
#include "nvim/move.h"
#include "nvim/plines.h"
#include "nvim/screen.h"
-#include "nvim/extmark.h"
#include "nvim/state.h"
#include "nvim/vim.h"
-#include "nvim/ascii.h"
-#include "nvim/mark.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "cursor.c.generated.h"
@@ -63,7 +63,7 @@ int coladvance_force(colnr_T wcol)
if (wcol == MAXCOL) {
curwin->w_valid &= ~VALID_VIRTCOL;
} else {
- /* Virtcol is valid */
+ // Virtcol is valid
curwin->w_valid |= VALID_VIRTCOL;
curwin->w_virtcol = wcol;
}
@@ -83,27 +83,25 @@ int coladvance(colnr_T wcol)
{
int rc = getvpos(&curwin->w_cursor, wcol);
- if (wcol == MAXCOL || rc == FAIL)
+ if (wcol == MAXCOL || rc == FAIL) {
curwin->w_valid &= ~VALID_VIRTCOL;
- else if (*get_cursor_pos_ptr() != TAB) {
- /* Virtcol is valid when not on a TAB */
+ } else if (*get_cursor_pos_ptr() != TAB) {
+ // Virtcol is valid when not on a TAB
curwin->w_valid |= VALID_VIRTCOL;
curwin->w_virtcol = wcol;
}
return rc;
}
-static int coladvance2(
- pos_T *pos,
- bool addspaces, // change the text to achieve our goal?
- bool finetune, // change char offset for the exact column
- colnr_T wcol_arg // column to move to (can be negative)
-)
+static int coladvance2(pos_T *pos, bool addspaces, // change the text to achieve our goal?
+ bool finetune, // change char offset for the exact column
+ colnr_T wcol_arg // column to move to (can be negative)
+ )
{
colnr_T wcol = wcol_arg;
int idx;
- char_u *ptr;
- char_u *line;
+ char_u *ptr;
+ char_u *line;
colnr_T col = 0;
int csize = 0;
int one_more;
@@ -121,8 +119,9 @@ static int coladvance2(
if ((addspaces || finetune) && !VIsual_active) {
curwin->w_curswant = linetabsize(line) + one_more;
- if (curwin->w_curswant > 0)
+ if (curwin->w_curswant > 0) {
--curwin->w_curswant;
+ }
}
} else {
int width = curwin->w_width_inner - win_col_off(curwin);
@@ -133,8 +132,9 @@ static int coladvance2(
&& wcol >= (colnr_T)width
&& width > 0) {
csize = linetabsize(line);
- if (csize > 0)
+ if (csize > 0) {
csize--;
+ }
if (wcol / width > (colnr_T)csize / width
&& ((State & INSERT) == 0 || (int)wcol > csize + 1)) {
@@ -148,7 +148,7 @@ static int coladvance2(
ptr = line;
while (col <= wcol && *ptr != NUL) {
- /* Count a tab for what it's worth (if list mode not on) */
+ // Count a tab for what it's worth (if list mode not on)
csize = win_lbr_chartabsize(curwin, line, ptr, col, &head);
MB_PTR_ADV(ptr);
col += csize;
@@ -162,7 +162,7 @@ static int coladvance2(
*/
if (col > wcol || (!virtual_active() && one_more == 0)) {
idx -= 1;
- /* Don't count the chars from 'showbreak'. */
+ // Don't count the chars from 'showbreak'.
csize -= head;
col -= csize;
}
@@ -175,7 +175,7 @@ static int coladvance2(
* filled with spaces. */
if (line[idx] == NUL) {
- /* Append spaces */
+ // Append spaces
int correct = wcol - col;
size_t newline_size;
STRICT_ADD(idx, correct, &newline_size, size_t);
@@ -188,13 +188,14 @@ static int coladvance2(
idx += correct;
col = wcol;
} else {
- /* Break a tab */
+ // Break a tab
int linelen = (int)STRLEN(line);
- int correct = wcol - col - csize + 1; /* negative!! */
- char_u *newline;
+ int correct = wcol - col - csize + 1; // negative!!
+ char_u *newline;
- if (-correct > csize)
+ if (-correct > csize) {
return FAIL;
+ }
size_t n;
STRICT_ADD(linelen - 1, csize, &n, size_t);
@@ -216,16 +217,17 @@ static int coladvance2(
}
}
- if (idx < 0)
+ if (idx < 0) {
pos->col = 0;
- else
+ } else {
pos->col = idx;
+ }
pos->coladd = 0;
if (finetune) {
if (wcol == MAXCOL) {
- /* The width of the last character is used to set coladd. */
+ // The width of the last character is used to set coladd.
if (!one_more) {
colnr_T scol, ecol;
@@ -319,15 +321,15 @@ void check_pos(buf_T *buf, pos_T *pos)
colnr_T len;
if (pos->lnum > buf->b_ml.ml_line_count) {
- pos->lnum = buf->b_ml.ml_line_count;
+ pos->lnum = buf->b_ml.ml_line_count;
}
if (pos->col > 0) {
- line = ml_get_buf(buf, pos->lnum, false);
- len = (colnr_T)STRLEN(line);
- if (pos->col > len) {
- pos->col = len;
- }
+ line = ml_get_buf(buf, pos->lnum, false);
+ len = (colnr_T)STRLEN(line);
+ if (pos->col > len) {
+ pos->col = len;
+ }
}
}
@@ -340,11 +342,13 @@ void check_cursor_lnum(void)
/* If there is a closed fold at the end of the file, put the cursor in
* its first line. Otherwise in the last line. */
if (!hasFolding(curbuf->b_ml.ml_line_count,
- &curwin->w_cursor.lnum, NULL))
+ &curwin->w_cursor.lnum, NULL)) {
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
+ }
}
- if (curwin->w_cursor.lnum <= 0)
+ if (curwin->w_cursor.lnum <= 0) {
curwin->w_cursor.lnum = 1;
+ }
}
/*
@@ -430,8 +434,9 @@ void adjust_cursor_col(void)
{
if (curwin->w_cursor.col > 0
&& (!VIsual_active || *p_sel == 'o')
- && gchar_cursor() == NUL)
+ && gchar_cursor() == NUL) {
--curwin->w_cursor.col;
+ }
}
/*
@@ -473,14 +478,15 @@ bool leftcol_changed(void)
coladvance(s - 1);
} else if (s < curwin->w_leftcol) {
retval = true;
- if (coladvance(e + 1) == FAIL) { /* there isn't another character */
- curwin->w_leftcol = s; /* adjust w_leftcol instead */
+ if (coladvance(e + 1) == FAIL) { // there isn't another character
+ curwin->w_leftcol = s; // adjust w_leftcol instead
changed_cline_bef_curs();
}
}
- if (retval)
+ if (retval) {
curwin->w_set_curswant = true;
+ }
redraw_later(curwin, NOT_VALID);
return retval;
}
diff --git a/src/nvim/cursor_shape.c b/src/nvim/cursor_shape.c
index 0d21080aa5..128bc480da 100644
--- a/src/nvim/cursor_shape.c
+++ b/src/nvim/cursor_shape.c
@@ -3,15 +3,16 @@
#include <assert.h>
#include <stdint.h>
-#include "nvim/vim.h"
+
+#include "nvim/api/private/helpers.h"
#include "nvim/ascii.h"
+#include "nvim/charset.h"
#include "nvim/cursor_shape.h"
#include "nvim/ex_getln.h"
-#include "nvim/charset.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
-#include "nvim/api/private/helpers.h"
#include "nvim/ui.h"
+#include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "cursor_shape.c.generated.h"
@@ -56,10 +57,14 @@ Array mode_style_array(void)
if (cur->used_for & SHAPE_CURSOR) {
String shape_str;
switch (cur->shape) {
- case SHAPE_BLOCK: shape_str = cstr_to_string("block"); break;
- case SHAPE_VER: shape_str = cstr_to_string("vertical"); break;
- case SHAPE_HOR: shape_str = cstr_to_string("horizontal"); break;
- default: shape_str = cstr_to_string("unknown");
+ case SHAPE_BLOCK:
+ shape_str = cstr_to_string("block"); break;
+ case SHAPE_VER:
+ shape_str = cstr_to_string("vertical"); break;
+ case SHAPE_HOR:
+ shape_str = cstr_to_string("horizontal"); break;
+ default:
+ shape_str = cstr_to_string("unknown");
}
PUT(dic, "cursor_shape", STRING_OBJ(shape_str));
PUT(dic, "cell_percentage", INTEGER_OBJ(cur->percentage));
@@ -90,12 +95,12 @@ Array mode_style_array(void)
/// @returns error message for an illegal option, NULL otherwise.
char_u *parse_shape_opt(int what)
{
- char_u *modep;
- char_u *colonp;
- char_u *commap;
- char_u *slashp;
- char_u *p = NULL;
- char_u *endp;
+ char_u *modep;
+ char_u *colonp;
+ char_u *commap;
+ char_u *slashp;
+ char_u *p = NULL;
+ char_u *endp;
int idx = 0; // init for GCC
int all_idx;
int len;
@@ -142,14 +147,18 @@ char_u *parse_shape_opt(int what)
if (len == 1 && TOLOWER_ASC(modep[0]) == 'a') {
all_idx = SHAPE_IDX_COUNT - 1;
} else {
- for (idx = 0; idx < SHAPE_IDX_COUNT; ++idx)
- if (STRNICMP(modep, shape_table[idx].name, len) == 0)
+ for (idx = 0; idx < SHAPE_IDX_COUNT; ++idx) {
+ if (STRNICMP(modep, shape_table[idx].name, len) == 0) {
break;
+ }
+ }
if (idx == SHAPE_IDX_COUNT
- || (shape_table[idx].used_for & what) == 0)
+ || (shape_table[idx].used_for & what) == 0) {
return (char_u *)N_("E546: Illegal mode");
- if (len == 2 && modep[0] == 'v' && modep[1] == 'e')
+ }
+ if (len == 2 && modep[0] == 'v' && modep[1] == 'e') {
found_ve = true;
+ }
}
modep += len + 1;
}
@@ -158,7 +167,7 @@ char_u *parse_shape_opt(int what)
idx = all_idx--;
}
- /* Parse the part after the colon */
+ // Parse the part after the colon
for (p = colonp + 1; *p && *p != ','; ) {
{
/*
@@ -166,20 +175,22 @@ char_u *parse_shape_opt(int what)
*/
i = *p;
len = 0;
- if (STRNICMP(p, "ver", 3) == 0)
+ if (STRNICMP(p, "ver", 3) == 0) {
len = 3;
- else if (STRNICMP(p, "hor", 3) == 0)
+ } else if (STRNICMP(p, "hor", 3) == 0) {
len = 3;
- else if (STRNICMP(p, "blinkwait", 9) == 0)
+ } else if (STRNICMP(p, "blinkwait", 9) == 0) {
len = 9;
- else if (STRNICMP(p, "blinkon", 7) == 0)
+ } else if (STRNICMP(p, "blinkon", 7) == 0) {
len = 7;
- else if (STRNICMP(p, "blinkoff", 8) == 0)
+ } else if (STRNICMP(p, "blinkoff", 8) == 0) {
len = 8;
+ }
if (len != 0) {
p += len;
- if (!ascii_isdigit(*p))
+ if (!ascii_isdigit(*p)) {
return (char_u *)N_("E548: digit expected");
+ }
int n = getdigits_int(&p, false, 0);
if (len == 3) { // "ver" or "hor"
if (n == 0) {
@@ -194,44 +205,49 @@ char_u *parse_shape_opt(int what)
shape_table[idx].percentage = n;
}
} else if (round == 2) {
- if (len == 9)
+ if (len == 9) {
shape_table[idx].blinkwait = n;
- else if (len == 7)
+ } else if (len == 7) {
shape_table[idx].blinkon = n;
- else
+ } else {
shape_table[idx].blinkoff = n;
+ }
}
} else if (STRNICMP(p, "block", 5) == 0) {
- if (round == 2)
+ if (round == 2) {
shape_table[idx].shape = SHAPE_BLOCK;
+ }
p += 5;
- } else { /* must be a highlight group name then */
+ } else { // must be a highlight group name then
endp = vim_strchr(p, '-');
- if (commap == NULL) { /* last part */
- if (endp == NULL)
- endp = p + STRLEN(p); /* find end of part */
+ if (commap == NULL) { // last part
+ if (endp == NULL) {
+ endp = p + STRLEN(p); // find end of part
+ }
} else if (endp > commap || endp == NULL) {
endp = commap;
}
slashp = vim_strchr(p, '/');
if (slashp != NULL && slashp < endp) {
- /* "group/langmap_group" */
+ // "group/langmap_group"
i = syn_check_group(p, (int)(slashp - p));
p = slashp + 1;
}
if (round == 2) {
shape_table[idx].id = syn_check_group(p,
- (int)(endp - p));
+ (int)(endp - p));
shape_table[idx].id_lm = shape_table[idx].id;
- if (slashp != NULL && slashp < endp)
+ if (slashp != NULL && slashp < endp) {
shape_table[idx].id = i;
+ }
}
p = endp;
}
- } /* if (what != SHAPE_MOUSE) */
+ } // if (what != SHAPE_MOUSE)
- if (*p == '-')
+ if (*p == '-') {
++p;
+ }
}
}
modep = p;
@@ -241,7 +257,7 @@ char_u *parse_shape_opt(int what)
}
}
- /* If the 's' flag is not given, use the 'v' cursor for 's' */
+ // If the 's' flag is not given, use the 'v' cursor for 's'
if (!found_ve) {
{
shape_table[SHAPE_IDX_VE].shape = shape_table[SHAPE_IDX_V].shape;
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index a71e33dada..b17b462ed0 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -4251,8 +4251,8 @@ static void f_glob(typval_T *argvars, typval_T *rettv, FunPtr fptr)
options += WILD_ICASE;
}
if (rettv->v_type == VAR_STRING) {
- rettv->vval.v_string = ExpandOne(&xpc, (char_u *)tv_get_string(
- &argvars[0]), NULL, options, WILD_ALL);
+ rettv->vval.v_string = ExpandOne(&xpc, (char_u *)tv_get_string(&argvars[0]), NULL, options,
+ WILD_ALL);
} else {
ExpandOne(&xpc, (char_u *)tv_get_string(&argvars[0]), NULL, options,
WILD_ALL_KEEP);
@@ -6564,8 +6564,8 @@ static void msgpackparse_unpack_list(const list_T *const list, list_T *const ret
goto end;
}
size_t read_bytes;
- const int rlret = encode_read_from_list(&lrstate, msgpack_unpacker_buffer(
- unpacker), IOSIZE, &read_bytes);
+ const int rlret = encode_read_from_list(&lrstate, msgpack_unpacker_buffer(unpacker), IOSIZE,
+ &read_bytes);
if (rlret == FAIL) {
EMSG2(_(e_invarg2), "List item is not a string");
goto end;
@@ -9275,7 +9275,8 @@ static void f_shellescape(typval_T *argvars, typval_T *rettv, FunPtr fptr)
const bool do_special = non_zero_arg(&argvars[1]);
rettv->vval.v_string = vim_strsave_shellescape((const char_u *)tv_get_string(
- &argvars[0]), do_special, do_special);
+ &argvars[0]), do_special,
+ do_special);
rettv->v_type = VAR_STRING;
}
diff --git a/src/nvim/lua/converter.c b/src/nvim/lua/converter.c
index 0adbbdb953..07c53299fa 100644
--- a/src/nvim/lua/converter.c
+++ b/src/nvim/lua/converter.c
@@ -1,33 +1,31 @@
// 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 <assert.h>
+#include <lauxlib.h>
#include <lua.h>
#include <lualib.h>
-#include <lauxlib.h>
-#include <assert.h>
-#include <stdint.h>
#include <stdbool.h>
+#include <stdint.h>
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
+#include "nvim/assert.h"
#include "nvim/func_attr.h"
#include "nvim/memory.h"
-#include "nvim/assert.h"
// FIXME: vim.h is not actually needed, but otherwise it states MAXPATHL is
// redefined
-#include "nvim/vim.h"
-#include "nvim/globals.h"
-#include "nvim/message.h"
+#include "nvim/ascii.h"
+#include "nvim/eval/decode.h"
#include "nvim/eval/typval.h"
#include "nvim/eval/userfunc.h"
-#include "nvim/ascii.h"
-#include "nvim/macros.h"
-
+#include "nvim/globals.h"
#include "nvim/lib/kvec.h"
-#include "nvim/eval/decode.h"
-
#include "nvim/lua/converter.h"
#include "nvim/lua/executor.h"
+#include "nvim/macros.h"
+#include "nvim/message.h"
+#include "nvim/vim.h"
/// Determine, which keys lua table contains
typedef struct {
@@ -49,7 +47,7 @@ typedef struct {
#define VAL_IDX_VALUE false
#define LUA_PUSH_STATIC_STRING(lstate, s) \
- lua_pushlstring(lstate, s, sizeof(s) - 1)
+ lua_pushlstring(lstate, s, sizeof(s) - 1)
static LuaTableProps nlua_traverse_table(lua_State *const lstate)
@@ -71,57 +69,56 @@ static LuaTableProps nlua_traverse_table(lua_State *const lstate)
lua_pushnil(lstate);
while (lua_next(lstate, -2)) {
switch (lua_type(lstate, -2)) {
- case LUA_TSTRING: {
- size_t len;
- const char *s = lua_tolstring(lstate, -2, &len);
- if (memchr(s, NUL, len) != NULL) {
- ret.has_string_with_nul = true;
- }
- ret.string_keys_num++;
- break;
+ case LUA_TSTRING: {
+ size_t len;
+ const char *s = lua_tolstring(lstate, -2, &len);
+ if (memchr(s, NUL, len) != NULL) {
+ ret.has_string_with_nul = true;
}
- case LUA_TNUMBER: {
- const lua_Number n = lua_tonumber(lstate, -2);
- if (n > (lua_Number)SIZE_MAX || n <= 0
- || ((lua_Number)((size_t)n)) != n) {
- other_keys_num++;
- } else {
- const size_t idx = (size_t)n;
- if (idx > ret.maxidx) {
- ret.maxidx = idx;
- }
+ ret.string_keys_num++;
+ break;
+ }
+ case LUA_TNUMBER: {
+ const lua_Number n = lua_tonumber(lstate, -2);
+ if (n > (lua_Number)SIZE_MAX || n <= 0
+ || ((lua_Number)((size_t)n)) != n) {
+ other_keys_num++;
+ } else {
+ const size_t idx = (size_t)n;
+ if (idx > ret.maxidx) {
+ ret.maxidx = idx;
}
- break;
}
- case LUA_TBOOLEAN: {
- const bool b = lua_toboolean(lstate, -2);
- if (b == TYPE_IDX_VALUE) {
- if (lua_type(lstate, -1) == LUA_TNUMBER) {
- lua_Number n = lua_tonumber(lstate, -1);
- if (n == (lua_Number)kObjectTypeFloat
- || n == (lua_Number)kObjectTypeArray
- || n == (lua_Number)kObjectTypeDictionary) {
- ret.has_type_key = true;
- ret.type = (ObjectType)n;
- } else {
- other_keys_num++;
- }
+ break;
+ }
+ case LUA_TBOOLEAN: {
+ const bool b = lua_toboolean(lstate, -2);
+ if (b == TYPE_IDX_VALUE) {
+ if (lua_type(lstate, -1) == LUA_TNUMBER) {
+ lua_Number n = lua_tonumber(lstate, -1);
+ if (n == (lua_Number)kObjectTypeFloat
+ || n == (lua_Number)kObjectTypeArray
+ || n == (lua_Number)kObjectTypeDictionary) {
+ ret.has_type_key = true;
+ ret.type = (ObjectType)n;
} else {
other_keys_num++;
}
} else {
- has_val_key = true;
- val_type = lua_type(lstate, -1);
- if (val_type == LUA_TNUMBER) {
- ret.val = lua_tonumber(lstate, -1);
- }
+ other_keys_num++;
+ }
+ } else {
+ has_val_key = true;
+ val_type = lua_type(lstate, -1);
+ if (val_type == LUA_TNUMBER) {
+ ret.val = lua_tonumber(lstate, -1);
}
- break;
- }
- default: {
- other_keys_num++;
- break;
}
+ break;
+ }
+ default:
+ other_keys_num++;
+ break;
}
tsize++;
lua_pop(lstate, 1);
@@ -283,153 +280,143 @@ bool nlua_pop_typval(lua_State *lstate, typval_T *ret_tv)
.vval = { .v_number = 0 },
};
switch (lua_type(lstate, -1)) {
- case LUA_TNIL: {
- cur.tv->v_type = VAR_SPECIAL;
- cur.tv->vval.v_special = kSpecialVarNull;
- break;
- }
- case LUA_TBOOLEAN: {
- cur.tv->v_type = VAR_BOOL;
- cur.tv->vval.v_bool = (lua_toboolean(lstate, -1)
+ case LUA_TNIL:
+ cur.tv->v_type = VAR_SPECIAL;
+ cur.tv->vval.v_special = kSpecialVarNull;
+ break;
+ case LUA_TBOOLEAN:
+ cur.tv->v_type = VAR_BOOL;
+ cur.tv->vval.v_bool = (lua_toboolean(lstate, -1)
? kBoolVarTrue
: kBoolVarFalse);
- break;
+ break;
+ case LUA_TSTRING: {
+ size_t len;
+ const char *s = lua_tolstring(lstate, -1, &len);
+ *cur.tv = decode_string(s, len, kNone, true, false);
+ if (cur.tv->v_type == VAR_UNKNOWN) {
+ ret = false;
}
- case LUA_TSTRING: {
- size_t len;
- const char *s = lua_tolstring(lstate, -1, &len);
- *cur.tv = decode_string(s, len, kNone, true, false);
- if (cur.tv->v_type == VAR_UNKNOWN) {
- ret = false;
- }
- break;
+ break;
+ }
+ case LUA_TNUMBER: {
+ const lua_Number n = lua_tonumber(lstate, -1);
+ if (n > (lua_Number)VARNUMBER_MAX || n < (lua_Number)VARNUMBER_MIN
+ || ((lua_Number)((varnumber_T)n)) != n) {
+ cur.tv->v_type = VAR_FLOAT;
+ cur.tv->vval.v_float = (float_T)n;
+ } else {
+ cur.tv->v_type = VAR_NUMBER;
+ cur.tv->vval.v_number = (varnumber_T)n;
}
- case LUA_TNUMBER: {
- const lua_Number n = lua_tonumber(lstate, -1);
- if (n > (lua_Number)VARNUMBER_MAX || n < (lua_Number)VARNUMBER_MIN
- || ((lua_Number)((varnumber_T)n)) != n) {
- cur.tv->v_type = VAR_FLOAT;
- cur.tv->vval.v_float = (float_T)n;
- } else {
- cur.tv->v_type = VAR_NUMBER;
- cur.tv->vval.v_number = (varnumber_T)n;
- }
- break;
+ break;
+ }
+ case LUA_TTABLE: {
+ // Only need to track table refs if we have a metatable associated.
+ LuaRef table_ref = LUA_NOREF;
+ if (lua_getmetatable(lstate, -1)) {
+ lua_pop(lstate, 1);
+ table_ref = nlua_ref(lstate, -1);
}
- case LUA_TTABLE: {
- // Only need to track table refs if we have a metatable associated.
- LuaRef table_ref = LUA_NOREF;
- if (lua_getmetatable(lstate, -1)) {
- lua_pop(lstate, 1);
- table_ref = nlua_ref(lstate, -1);
- }
- const LuaTableProps table_props = nlua_traverse_table(lstate);
+ const LuaTableProps table_props = nlua_traverse_table(lstate);
- for (size_t i = 0; i < kv_size(stack); i++) {
- const TVPopStackItem item = kv_A(stack, i);
- if (item.container && lua_rawequal(lstate, -1, item.idx)) {
- tv_copy(item.tv, cur.tv);
- cur.container = false;
- goto nlua_pop_typval_table_processing_end;
- }
+ for (size_t i = 0; i < kv_size(stack); i++) {
+ const TVPopStackItem item = kv_A(stack, i);
+ if (item.container && lua_rawequal(lstate, -1, item.idx)) {
+ tv_copy(item.tv, cur.tv);
+ cur.container = false;
+ goto nlua_pop_typval_table_processing_end;
}
+ }
- switch (table_props.type) {
- case kObjectTypeArray: {
- cur.tv->v_type = VAR_LIST;
- cur.tv->vval.v_list = tv_list_alloc((ptrdiff_t)table_props.maxidx);
+ switch (table_props.type) {
+ case kObjectTypeArray:
+ cur.tv->v_type = VAR_LIST;
+ cur.tv->vval.v_list = tv_list_alloc((ptrdiff_t)table_props.maxidx);
+ cur.tv->vval.v_list->lua_table_ref = table_ref;
+ tv_list_ref(cur.tv->vval.v_list);
+ if (table_props.maxidx != 0) {
+ cur.container = true;
+ cur.idx = lua_gettop(lstate);
+ kvi_push(stack, cur);
+ }
+ break;
+ case kObjectTypeDictionary:
+ if (table_props.string_keys_num == 0) {
+ cur.tv->v_type = VAR_DICT;
+ cur.tv->vval.v_dict = tv_dict_alloc();
+ cur.tv->vval.v_dict->dv_refcount++;
+ cur.tv->vval.v_dict->lua_table_ref = table_ref;
+ } else {
+ cur.special = table_props.has_string_with_nul;
+ if (table_props.has_string_with_nul) {
+ decode_create_map_special_dict(cur.tv, (ptrdiff_t)table_props.string_keys_num);
+ assert(cur.tv->v_type == VAR_DICT);
+ dictitem_T *const val_di = tv_dict_find(cur.tv->vval.v_dict,
+ S_LEN("_VAL"));
+ assert(val_di != NULL);
+ cur.tv = &val_di->di_tv;
cur.tv->vval.v_list->lua_table_ref = table_ref;
- tv_list_ref(cur.tv->vval.v_list);
- if (table_props.maxidx != 0) {
- cur.container = true;
- cur.idx = lua_gettop(lstate);
- kvi_push(stack, cur);
- }
- break;
- }
- case kObjectTypeDictionary: {
- if (table_props.string_keys_num == 0) {
- cur.tv->v_type = VAR_DICT;
- cur.tv->vval.v_dict = tv_dict_alloc();
- cur.tv->vval.v_dict->dv_refcount++;
- cur.tv->vval.v_dict->lua_table_ref = table_ref;
- } else {
- cur.special = table_props.has_string_with_nul;
- if (table_props.has_string_with_nul) {
- decode_create_map_special_dict(
- cur.tv, (ptrdiff_t)table_props.string_keys_num);
- assert(cur.tv->v_type == VAR_DICT);
- dictitem_T *const val_di = tv_dict_find(cur.tv->vval.v_dict,
- S_LEN("_VAL"));
- assert(val_di != NULL);
- cur.tv = &val_di->di_tv;
- cur.tv->vval.v_list->lua_table_ref = table_ref;
- assert(cur.tv->v_type == VAR_LIST);
- } else {
- cur.tv->v_type = VAR_DICT;
- cur.tv->vval.v_dict = tv_dict_alloc();
- cur.tv->vval.v_dict->dv_refcount++;
- cur.tv->vval.v_dict->lua_table_ref = table_ref;
- }
- cur.container = true;
- cur.idx = lua_gettop(lstate);
- kvi_push(stack, cur);
- lua_pushnil(lstate);
- }
- break;
- }
- case kObjectTypeFloat: {
- cur.tv->v_type = VAR_FLOAT;
- cur.tv->vval.v_float = (float_T)table_props.val;
- break;
- }
- case kObjectTypeNil: {
- EMSG(_("E5100: Cannot convert given lua table: table "
- "should either have a sequence of positive integer keys "
- "or contain only string keys"));
- ret = false;
- break;
- }
- default: {
- abort();
+ assert(cur.tv->v_type == VAR_LIST);
+ } else {
+ cur.tv->v_type = VAR_DICT;
+ cur.tv->vval.v_dict = tv_dict_alloc();
+ cur.tv->vval.v_dict->dv_refcount++;
+ cur.tv->vval.v_dict->lua_table_ref = table_ref;
}
+ cur.container = true;
+ cur.idx = lua_gettop(lstate);
+ kvi_push(stack, cur);
+ lua_pushnil(lstate);
}
-nlua_pop_typval_table_processing_end:
break;
- }
- case LUA_TFUNCTION: {
- LuaCFunctionState *state = xmalloc(sizeof(LuaCFunctionState));
- state->lua_callable.func_ref = nlua_ref(lstate, -1);
-
- char_u *name = register_cfunc(
- &nlua_CFunction_func_call,
- &nlua_CFunction_func_free,
- state);
-
- cur.tv->v_type = VAR_FUNC;
- cur.tv->vval.v_string = vim_strsave(name);
+ case kObjectTypeFloat:
+ cur.tv->v_type = VAR_FLOAT;
+ cur.tv->vval.v_float = (float_T)table_props.val;
break;
- }
- case LUA_TUSERDATA: {
- // TODO(bfredl): check mt.__call and convert to function?
- nlua_pushref(lstate, nlua_nil_ref);
- bool is_nil = lua_rawequal(lstate, -2, -1);
- lua_pop(lstate, 1);
- if (is_nil) {
- cur.tv->v_type = VAR_SPECIAL;
- cur.tv->vval.v_special = kSpecialVarNull;
- } else {
- EMSG(_("E5101: Cannot convert given lua type"));
- ret = false;
- }
+ case kObjectTypeNil:
+ EMSG(_("E5100: Cannot convert given lua table: table "
+ "should either have a sequence of positive integer keys "
+ "or contain only string keys"));
+ ret = false;
break;
+ default:
+ abort();
}
- default: {
+nlua_pop_typval_table_processing_end:
+ break;
+ }
+ case LUA_TFUNCTION: {
+ LuaCFunctionState *state = xmalloc(sizeof(LuaCFunctionState));
+ state->lua_callable.func_ref = nlua_ref(lstate, -1);
+
+ char_u *name = register_cfunc(&nlua_CFunction_func_call,
+ &nlua_CFunction_func_free,
+ state);
+
+ cur.tv->v_type = VAR_FUNC;
+ cur.tv->vval.v_string = vim_strsave(name);
+ break;
+ }
+ case LUA_TUSERDATA: {
+ // TODO(bfredl): check mt.__call and convert to function?
+ nlua_pushref(lstate, nlua_nil_ref);
+ bool is_nil = lua_rawequal(lstate, -2, -1);
+ lua_pop(lstate, 1);
+ if (is_nil) {
+ cur.tv->v_type = VAR_SPECIAL;
+ cur.tv->vval.v_special = kSpecialVarNull;
+ } else {
EMSG(_("E5101: Cannot convert given lua type"));
ret = false;
- break;
}
+ break;
+ }
+ default:
+ EMSG(_("E5101: Cannot convert given lua type"));
+ ret = false;
+ break;
}
if (!cur.container) {
lua_pop(lstate, 1);
@@ -454,97 +441,97 @@ static bool typval_conv_special = false;
#define TYPVAL_ENCODE_ALLOW_SPECIALS true
#define TYPVAL_ENCODE_CONV_NIL(tv) \
- do { \
- if (typval_conv_special) { \
- lua_pushnil(lstate); \
- } else { \
- nlua_pushref(lstate, nlua_nil_ref); \
- } \
- } while (0)
+ do { \
+ if (typval_conv_special) { \
+ lua_pushnil(lstate); \
+ } else { \
+ nlua_pushref(lstate, nlua_nil_ref); \
+ } \
+ } while (0)
#define TYPVAL_ENCODE_CONV_BOOL(tv, num) \
- lua_pushboolean(lstate, (bool)(num))
+ lua_pushboolean(lstate, (bool)(num))
#define TYPVAL_ENCODE_CONV_NUMBER(tv, num) \
- lua_pushnumber(lstate, (lua_Number)(num))
+ lua_pushnumber(lstate, (lua_Number)(num))
#define TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER TYPVAL_ENCODE_CONV_NUMBER
#define TYPVAL_ENCODE_CONV_FLOAT(tv, flt) \
- TYPVAL_ENCODE_CONV_NUMBER(tv, flt)
+ TYPVAL_ENCODE_CONV_NUMBER(tv, flt)
#define TYPVAL_ENCODE_CONV_STRING(tv, str, len) \
- lua_pushlstring(lstate, (const char *)(str), (len))
+ lua_pushlstring(lstate, (const char *)(str), (len))
#define TYPVAL_ENCODE_CONV_STR_STRING TYPVAL_ENCODE_CONV_STRING
#define TYPVAL_ENCODE_CONV_EXT_STRING(tv, str, len, type) \
- TYPVAL_ENCODE_CONV_NIL(tv)
+ TYPVAL_ENCODE_CONV_NIL(tv)
#define TYPVAL_ENCODE_CONV_BLOB(tv, blob, len) \
- do { \
- const blob_T *const blob_ = (blob); \
- lua_pushlstring(lstate, \
- blob_ != NULL ? (const char *)blob_->bv_ga.ga_data : "", \
- (size_t)(len)); \
- } while (0)
+ do { \
+ const blob_T *const blob_ = (blob); \
+ lua_pushlstring(lstate, \
+ blob_ != NULL ? (const char *)blob_->bv_ga.ga_data : "", \
+ (size_t)(len)); \
+ } while (0)
#define TYPVAL_ENCODE_CONV_FUNC_START(tv, fun) \
- do { \
- TYPVAL_ENCODE_CONV_NIL(tv); \
- goto typval_encode_stop_converting_one_item; \
- } while (0)
+ do { \
+ TYPVAL_ENCODE_CONV_NIL(tv); \
+ goto typval_encode_stop_converting_one_item; \
+ } while (0)
#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS(tv, len)
#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF(tv, len)
#define TYPVAL_ENCODE_CONV_FUNC_END(tv)
#define TYPVAL_ENCODE_CONV_EMPTY_LIST(tv) \
- lua_createtable(lstate, 0, 0)
+ lua_createtable(lstate, 0, 0)
#define TYPVAL_ENCODE_CONV_EMPTY_DICT(tv, dict) \
- do { \
- if (typval_conv_special) { \
- nlua_create_typed_table(lstate, 0, 0, kObjectTypeDictionary); \
- } else { \
- lua_createtable(lstate, 0, 0); \
- nlua_pushref(lstate, nlua_empty_dict_ref); \
- lua_setmetatable(lstate, -2); \
- } \
- } while (0)
+ do { \
+ if (typval_conv_special) { \
+ nlua_create_typed_table(lstate, 0, 0, kObjectTypeDictionary); \
+ } else { \
+ lua_createtable(lstate, 0, 0); \
+ nlua_pushref(lstate, nlua_empty_dict_ref); \
+ lua_setmetatable(lstate, -2); \
+ } \
+ } while (0)
#define TYPVAL_ENCODE_CONV_LIST_START(tv, len) \
- do { \
- if (!lua_checkstack(lstate, lua_gettop(lstate) + 3)) { \
- emsgf(_("E5102: Lua failed to grow stack to %i"), \
- lua_gettop(lstate) + 3); \
- return false; \
- } \
- lua_createtable(lstate, (int)(len), 0); \
- lua_pushnumber(lstate, 1); \
- } while (0)
+ do { \
+ if (!lua_checkstack(lstate, lua_gettop(lstate) + 3)) { \
+ emsgf(_("E5102: Lua failed to grow stack to %i"), \
+ lua_gettop(lstate) + 3); \
+ return false; \
+ } \
+ lua_createtable(lstate, (int)(len), 0); \
+ lua_pushnumber(lstate, 1); \
+ } while (0)
#define TYPVAL_ENCODE_CONV_REAL_LIST_AFTER_START(tv, mpsv)
#define TYPVAL_ENCODE_CONV_LIST_BETWEEN_ITEMS(tv) \
- do { \
- lua_Number idx = lua_tonumber(lstate, -2); \
- lua_rawset(lstate, -3); \
- lua_pushnumber(lstate, idx + 1); \
- } while (0)
+ do { \
+ lua_Number idx = lua_tonumber(lstate, -2); \
+ lua_rawset(lstate, -3); \
+ lua_pushnumber(lstate, idx + 1); \
+ } while (0)
#define TYPVAL_ENCODE_CONV_LIST_END(tv) \
- lua_rawset(lstate, -3)
+ lua_rawset(lstate, -3)
#define TYPVAL_ENCODE_CONV_DICT_START(tv, dict, len) \
- do { \
- if (!lua_checkstack(lstate, lua_gettop(lstate) + 3)) { \
- emsgf(_("E5102: Lua failed to grow stack to %i"), \
- lua_gettop(lstate) + 3); \
- return false; \
- } \
- lua_createtable(lstate, 0, (int)(len)); \
- } while (0)
+ do { \
+ if (!lua_checkstack(lstate, lua_gettop(lstate) + 3)) { \
+ emsgf(_("E5102: Lua failed to grow stack to %i"), \
+ lua_gettop(lstate) + 3); \
+ return false; \
+ } \
+ lua_createtable(lstate, 0, (int)(len)); \
+ } while (0)
#define TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK(label, kv_pair)
@@ -553,26 +540,26 @@ static bool typval_conv_special = false;
#define TYPVAL_ENCODE_CONV_DICT_AFTER_KEY(tv, dict)
#define TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS(tv, dict) \
- lua_rawset(lstate, -3)
+ lua_rawset(lstate, -3)
#define TYPVAL_ENCODE_CONV_DICT_END(tv, dict) \
- TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS(tv, dict)
+ TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS(tv, dict)
#define TYPVAL_ENCODE_CONV_RECURSE(val, conv_type) \
- do { \
- for (size_t backref = kv_size(*mpstack); backref; backref--) { \
- const MPConvStackVal mpval = kv_A(*mpstack, backref - 1); \
- if (mpval.type == conv_type) { \
- if (conv_type == kMPConvDict \
+ do { \
+ for (size_t backref = kv_size(*mpstack); backref; backref--) { \
+ const MPConvStackVal mpval = kv_A(*mpstack, backref - 1); \
+ if (mpval.type == conv_type) { \
+ if (conv_type == kMPConvDict \
? (void *)mpval.data.d.dict == (void *)(val) \
: (void *)mpval.data.l.list == (void *)(val)) { \
- lua_pushvalue(lstate, \
- -((int)((kv_size(*mpstack) - backref + 1) * 2))); \
- break; \
- } \
+ lua_pushvalue(lstate, \
+ -((int)((kv_size(*mpstack) - backref + 1) * 2))); \
+ break; \
} \
} \
- } while (0)
+ } \
+ } while (0)
#define TYPVAL_ENCODE_SCOPE static
#define TYPVAL_ENCODE_NAME lua
@@ -674,9 +661,7 @@ static inline void nlua_push_type(lua_State *lstate, ObjectType type)
/// @param[in] narr Number of “array” entries to be populated later.
/// @param[in] nrec Number of “dictionary” entries to be populated later.
/// @param[in] type Type of the table.
-static inline void nlua_create_typed_table(lua_State *lstate,
- const size_t narr,
- const size_t nrec,
+static inline void nlua_create_typed_table(lua_State *lstate, const size_t narr, const size_t nrec,
const ObjectType type)
FUNC_ATTR_NONNULL_ALL
{
@@ -733,8 +718,7 @@ void nlua_push_Boolean(lua_State *lstate, const Boolean b, bool special)
/// Convert given Dictionary to lua table
///
/// Leaves converted table on top of the stack.
-void nlua_push_Dictionary(lua_State *lstate, const Dictionary dict,
- bool special)
+void nlua_push_Dictionary(lua_State *lstate, const Dictionary dict, bool special)
FUNC_ATTR_NONNULL_ALL
{
if (dict.size == 0 && special) {
@@ -767,10 +751,10 @@ void nlua_push_Array(lua_State *lstate, const Array array, bool special)
}
#define GENERATE_INDEX_FUNCTION(type) \
-void nlua_push_##type(lua_State *lstate, const type item, bool special) \
+ void nlua_push_##type(lua_State *lstate, const type item, bool special) \
FUNC_ATTR_NONNULL_ALL \
-{ \
- lua_pushnumber(lstate, (lua_Number)(item)); \
+ { \
+ lua_pushnumber(lstate, (lua_Number)(item)); \
}
GENERATE_INDEX_FUNCTION(Buffer)
@@ -786,23 +770,22 @@ void nlua_push_Object(lua_State *lstate, const Object obj, bool special)
FUNC_ATTR_NONNULL_ALL
{
switch (obj.type) {
- case kObjectTypeNil: {
- if (special) {
- lua_pushnil(lstate);
- } else {
- nlua_pushref(lstate, nlua_nil_ref);
- }
- break;
- }
- case kObjectTypeLuaRef: {
- nlua_pushref(lstate, obj.data.luaref);
- break;
+ case kObjectTypeNil:
+ if (special) {
+ lua_pushnil(lstate);
+ } else {
+ nlua_pushref(lstate, nlua_nil_ref);
}
+ break;
+ case kObjectTypeLuaRef: {
+ nlua_pushref(lstate, obj.data.luaref);
+ break;
+ }
#define ADD_TYPE(type, data_key) \
- case kObjectType##type: { \
- nlua_push_##type(lstate, obj.data.data_key, special); \
- break; \
- }
+case kObjectType##type: { \
+ nlua_push_##type(lstate, obj.data.data_key, special); \
+ break; \
+}
ADD_TYPE(Boolean, boolean)
ADD_TYPE(Integer, integer)
ADD_TYPE(Float, floating)
@@ -811,10 +794,10 @@ void nlua_push_Object(lua_State *lstate, const Object obj, bool special)
ADD_TYPE(Dictionary, dictionary)
#undef ADD_TYPE
#define ADD_REMOTE_TYPE(type) \
- case kObjectType##type: { \
- nlua_push_##type(lstate, (type)obj.data.integer, special); \
- break; \
- }
+case kObjectType##type: { \
+ nlua_push_##type(lstate, (type)obj.data.integer, special); \
+ break; \
+}
ADD_REMOTE_TYPE(Buffer)
ADD_REMOTE_TYPE(Window)
ADD_REMOTE_TYPE(Tabpage)
@@ -883,8 +866,7 @@ Boolean nlua_pop_Boolean(lua_State *lstate, Error *err)
/// @param[in] type Type to check.
///
/// @return @see nlua_traverse_table().
-static inline LuaTableProps nlua_check_type(lua_State *const lstate,
- Error *const err,
+static inline LuaTableProps nlua_check_type(lua_State *const lstate, Error *const err,
const ObjectType type)
FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_WARN_UNUSED_RESULT
{
@@ -937,8 +919,7 @@ Float nlua_pop_Float(lua_State *lstate, Error *err)
/// @param lstate Lua state.
/// @param[in] table_props nlua_traverse_table() output.
/// @param[out] err Location where error will be saved.
-static Array nlua_pop_Array_unchecked(lua_State *const lstate,
- const LuaTableProps table_props,
+static Array nlua_pop_Array_unchecked(lua_State *const lstate, const LuaTableProps table_props,
Error *const err)
{
Array ret = { .size = table_props.maxidx, .items = NULL };
@@ -990,10 +971,8 @@ Array nlua_pop_Array(lua_State *lstate, Error *err)
/// @param lstate Lua interpreter state.
/// @param[in] table_props nlua_traverse_table() output.
/// @param[out] err Location where error will be saved.
-static Dictionary nlua_pop_Dictionary_unchecked(lua_State *lstate,
- const LuaTableProps table_props,
- bool ref,
- Error *err)
+static Dictionary nlua_pop_Dictionary_unchecked(lua_State *lstate, const LuaTableProps table_props,
+ bool ref, Error *err)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
Dictionary ret = { .size = table_props.string_keys_num, .items = NULL };
@@ -1138,113 +1117,104 @@ Object nlua_pop_Object(lua_State *const lstate, bool ref, Error *const err)
assert(!cur.container);
*cur.obj = NIL;
switch (lua_type(lstate, -1)) {
- case LUA_TNIL: {
- break;
- }
- case LUA_TBOOLEAN: {
- *cur.obj = BOOLEAN_OBJ(lua_toboolean(lstate, -1));
- break;
- }
- case LUA_TSTRING: {
- size_t len;
- const char *s = lua_tolstring(lstate, -1, &len);
- *cur.obj = STRING_OBJ(((String) {
- .data = xmemdupz(s, len),
- .size = len,
- }));
- break;
- }
- case LUA_TNUMBER: {
- const lua_Number n = lua_tonumber(lstate, -1);
- if (n > (lua_Number)API_INTEGER_MAX || n < (lua_Number)API_INTEGER_MIN
- || ((lua_Number)((Integer)n)) != n) {
- *cur.obj = FLOAT_OBJ((Float)n);
- } else {
- *cur.obj = INTEGER_OBJ((Integer)n);
- }
- break;
+ case LUA_TNIL:
+ break;
+ case LUA_TBOOLEAN:
+ *cur.obj = BOOLEAN_OBJ(lua_toboolean(lstate, -1));
+ break;
+ case LUA_TSTRING: {
+ size_t len;
+ const char *s = lua_tolstring(lstate, -1, &len);
+ *cur.obj = STRING_OBJ(((String) {
+ .data = xmemdupz(s, len),
+ .size = len,
+ }));
+ break;
+ }
+ case LUA_TNUMBER: {
+ const lua_Number n = lua_tonumber(lstate, -1);
+ if (n > (lua_Number)API_INTEGER_MAX || n < (lua_Number)API_INTEGER_MIN
+ || ((lua_Number)((Integer)n)) != n) {
+ *cur.obj = FLOAT_OBJ((Float)n);
+ } else {
+ *cur.obj = INTEGER_OBJ((Integer)n);
}
- case LUA_TTABLE: {
- const LuaTableProps table_props = nlua_traverse_table(lstate);
+ break;
+ }
+ case LUA_TTABLE: {
+ const LuaTableProps table_props = nlua_traverse_table(lstate);
- switch (table_props.type) {
- case kObjectTypeArray: {
- *cur.obj = ARRAY_OBJ(((Array) {
+ switch (table_props.type) {
+ case kObjectTypeArray:
+ *cur.obj = ARRAY_OBJ(((Array) {
.items = NULL,
.size = 0,
.capacity = 0,
}));
- if (table_props.maxidx != 0) {
- cur.obj->data.array.items =
- xcalloc(table_props.maxidx,
- sizeof(cur.obj->data.array.items[0]));
- cur.obj->data.array.capacity = table_props.maxidx;
- cur.container = true;
- kvi_push(stack, cur);
- }
- break;
- }
- case kObjectTypeDictionary: {
- *cur.obj = DICTIONARY_OBJ(((Dictionary) {
+ if (table_props.maxidx != 0) {
+ cur.obj->data.array.items =
+ xcalloc(table_props.maxidx,
+ sizeof(cur.obj->data.array.items[0]));
+ cur.obj->data.array.capacity = table_props.maxidx;
+ cur.container = true;
+ kvi_push(stack, cur);
+ }
+ break;
+ case kObjectTypeDictionary:
+ *cur.obj = DICTIONARY_OBJ(((Dictionary) {
.items = NULL,
.size = 0,
.capacity = 0,
}));
- if (table_props.string_keys_num != 0) {
- cur.obj->data.dictionary.items =
- xcalloc(table_props.string_keys_num,
- sizeof(cur.obj->data.dictionary.items[0]));
- cur.obj->data.dictionary.capacity = table_props.string_keys_num;
- cur.container = true;
- kvi_push(stack, cur);
- lua_pushnil(lstate);
- }
- break;
- }
- case kObjectTypeFloat: {
- *cur.obj = FLOAT_OBJ((Float)table_props.val);
- break;
- }
- case kObjectTypeNil: {
- api_set_error(err, kErrorTypeValidation,
- "Cannot convert given lua table");
- break;
- }
- default: {
- abort();
- }
+ if (table_props.string_keys_num != 0) {
+ cur.obj->data.dictionary.items =
+ xcalloc(table_props.string_keys_num,
+ sizeof(cur.obj->data.dictionary.items[0]));
+ cur.obj->data.dictionary.capacity = table_props.string_keys_num;
+ cur.container = true;
+ kvi_push(stack, cur);
+ lua_pushnil(lstate);
}
break;
- }
-
- case LUA_TFUNCTION: {
- if (ref) {
- *cur.obj = LUAREF_OBJ(nlua_ref(lstate, -1));
- } else {
- goto type_error;
- }
+ case kObjectTypeFloat:
+ *cur.obj = FLOAT_OBJ((Float)table_props.val);
+ break;
+ case kObjectTypeNil:
+ api_set_error(err, kErrorTypeValidation,
+ "Cannot convert given lua table");
break;
+ default:
+ abort();
}
+ break;
+ }
- case LUA_TUSERDATA: {
- nlua_pushref(lstate, nlua_nil_ref);
- bool is_nil = lua_rawequal(lstate, -2, -1);
- lua_pop(lstate, 1);
- if (is_nil) {
- *cur.obj = NIL;
- } else {
- api_set_error(err, kErrorTypeValidation,
- "Cannot convert userdata");
- }
- break;
+ case LUA_TFUNCTION:
+ if (ref) {
+ *cur.obj = LUAREF_OBJ(nlua_ref(lstate, -1));
+ } else {
+ goto type_error;
}
+ break;
- default: {
-type_error:
+ case LUA_TUSERDATA: {
+ nlua_pushref(lstate, nlua_nil_ref);
+ bool is_nil = lua_rawequal(lstate, -2, -1);
+ lua_pop(lstate, 1);
+ if (is_nil) {
+ *cur.obj = NIL;
+ } else {
api_set_error(err, kErrorTypeValidation,
- "Cannot convert given lua type");
- break;
+ "Cannot convert userdata");
}
+ break;
+ }
+
+ default:
+type_error:
+ api_set_error(err, kErrorTypeValidation,
+ "Cannot convert given lua type");
+ break;
}
if (!cur.container) {
lua_pop(lstate, 1);
@@ -1268,14 +1238,14 @@ LuaRef nlua_pop_LuaRef(lua_State *const lstate, Error *err)
}
#define GENERATE_INDEX_FUNCTION(type) \
-type nlua_pop_##type(lua_State *lstate, Error *err) \
+ type nlua_pop_##type(lua_State *lstate, Error *err) \
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT \
-{ \
- type ret; \
- ret = (type)lua_tonumber(lstate, -1); \
- lua_pop(lstate, 1); \
- return ret; \
-}
+ { \
+ type ret; \
+ ret = (type)lua_tonumber(lstate, -1); \
+ lua_pop(lstate, 1); \
+ return ret; \
+ }
GENERATE_INDEX_FUNCTION(Buffer)
GENERATE_INDEX_FUNCTION(Window)
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index ce5bfabd9f..8c7dc90111 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -1,48 +1,45 @@
// 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 <lauxlib.h>
#include <lua.h>
#include <lualib.h>
-#include <lauxlib.h>
-#include "nvim/assert.h"
-#include "nvim/version.h"
-#include "nvim/misc1.h"
-#include "nvim/getchar.h"
-#include "nvim/garray.h"
-#include "nvim/func_attr.h"
+#include "luv/luv.h"
+#include "mpack/lmpack.h"
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/api/vim.h"
-#include "nvim/msgpack_rpc/channel.h"
-#include "nvim/vim.h"
-#include "nvim/extmark.h"
-#include "nvim/ex_getln.h"
-#include "nvim/ex_cmds2.h"
-#include "nvim/map.h"
-#include "nvim/message.h"
-#include "nvim/memline.h"
-#include "nvim/buffer_defs.h"
-#include "nvim/regexp.h"
-#include "nvim/macros.h"
-#include "nvim/screen.h"
-#include "nvim/cursor.h"
-#include "nvim/undo.h"
#include "nvim/ascii.h"
+#include "nvim/assert.h"
+#include "nvim/buffer_defs.h"
#include "nvim/change.h"
+#include "nvim/cursor.h"
#include "nvim/eval/userfunc.h"
-#include "nvim/event/time.h"
#include "nvim/event/loop.h"
-#include "mpack/lmpack.h"
-
-#include "nvim/os/os.h"
-
+#include "nvim/event/time.h"
+#include "nvim/ex_cmds2.h"
+#include "nvim/ex_getln.h"
+#include "nvim/extmark.h"
+#include "nvim/func_attr.h"
+#include "nvim/garray.h"
+#include "nvim/getchar.h"
#include "nvim/lua/converter.h"
#include "nvim/lua/executor.h"
#include "nvim/lua/treesitter.h"
#include "nvim/lua/xdiff.h"
-
-#include "luv/luv.h"
+#include "nvim/macros.h"
+#include "nvim/map.h"
+#include "nvim/memline.h"
+#include "nvim/message.h"
+#include "nvim/misc1.h"
+#include "nvim/msgpack_rpc/channel.h"
+#include "nvim/os/os.h"
+#include "nvim/regexp.h"
+#include "nvim/screen.h"
+#include "nvim/undo.h"
+#include "nvim/version.h"
+#include "nvim/vim.h"
static int in_fast_callback = 0;
@@ -55,8 +52,8 @@ typedef struct {
} LuaError;
#ifdef INCLUDE_GENERATED_DECLARATIONS
-# include "lua/vim_module.generated.h"
# include "lua/executor.c.generated.h"
+# include "lua/vim_module.generated.h"
#endif
#define PUSH_ALL_TYPVALS(lstate, args, argcount, special) \
@@ -69,8 +66,8 @@ typedef struct {
}
#if __has_feature(address_sanitizer)
- static PMap(handle_T) nlua_ref_markers = MAP_INIT;
- static bool nlua_track_refs = false;
+static PMap(handle_T) nlua_ref_markers = MAP_INIT;
+static bool nlua_track_refs = false;
# define NLUA_TRACK_REFS
#endif
@@ -216,8 +213,7 @@ static void nlua_luv_error_event(void **argv)
xfree(error);
}
-static int nlua_luv_cfpcall(lua_State *lstate, int nargs, int nresult,
- int flags)
+static int nlua_luv_cfpcall(lua_State *lstate, int nargs, int nresult, int flags)
FUNC_ATTR_NONNULL_ALL
{
int retval;
@@ -300,8 +296,7 @@ static void dummy_timer_close_cb(TimeWatcher *tw, void *data)
xfree(tw);
}
-static bool nlua_wait_condition(lua_State *lstate, int *status,
- bool *callback_result)
+static bool nlua_wait_condition(lua_State *lstate, int *status, bool *callback_result)
{
lua_pushvalue(lstate, 2);
*status = lua_pcall(lstate, 0, 1, 0);
@@ -336,9 +331,8 @@ static int nlua_wait(lua_State *lstate)
}
if (!is_function) {
- lua_pushliteral(
- lstate,
- "vim.wait: if passed, condition must be a function");
+ lua_pushliteral(lstate,
+ "vim.wait: if passed, condition must be a function");
return lua_error(lstate);
}
}
@@ -365,23 +359,20 @@ static int nlua_wait(lua_State *lstate)
time_watcher_init(&main_loop, tw, NULL);
tw->events = loop_events;
tw->blockable = true;
- time_watcher_start(
- tw,
- dummy_timer_due_cb,
- (uint64_t)interval,
- (uint64_t)interval);
+ time_watcher_start(tw,
+ dummy_timer_due_cb,
+ (uint64_t)interval,
+ (uint64_t)interval);
int pcall_status = 0;
bool callback_result = false;
- LOOP_PROCESS_EVENTS_UNTIL(
- &main_loop,
- loop_events,
- (int)timeout,
- is_function ? nlua_wait_condition(
- lstate,
- &pcall_status,
- &callback_result) : false || got_int);
+ LOOP_PROCESS_EVENTS_UNTIL(&main_loop,
+ loop_events,
+ (int)timeout,
+ is_function ? nlua_wait_condition(lstate,
+ &pcall_status,
+ &callback_result) : false || got_int);
// Stop dummy timer
time_watcher_stop(tw);
@@ -663,22 +654,19 @@ static void nlua_print_event(void **argv)
const size_t start = i;
while (i < len) {
switch (str[i]) {
- case NUL: {
- str[i] = NL;
- i++;
- continue;
- }
- case NL: {
- // TODO(bfredl): use proper multiline msg? Probably should implement
- // print() in lua in terms of nvim_message(), when it is available.
- str[i] = NUL;
- i++;
- break;
- }
- default: {
- i++;
- continue;
- }
+ case NUL:
+ str[i] = NL;
+ i++;
+ continue;
+ case NL:
+ // TODO(bfredl): use proper multiline msg? Probably should implement
+ // print() in lua in terms of nvim_message(), when it is available.
+ str[i] = NUL;
+ i++;
+ break;
+ default:
+ i++;
+ continue;
}
break;
}
@@ -719,8 +707,7 @@ static int nlua_print(lua_State *const lstate)
size_t len;
const char *const s = lua_tolstring(lstate, -1, &len);
if (s == NULL) {
- PRINT_ERROR(
- "<Unknown error: lua_tolstring returned NULL for tostring result>");
+ PRINT_ERROR("<Unknown error: lua_tolstring returned NULL for tostring result>");
}
ga_concat_len(&msg_ga, s, len);
if (curargidx < nargs) {
@@ -893,7 +880,7 @@ static int nlua_rpc(lua_State *lstate, bool request)
} else {
if (!rpc_send_event(chan_id, name, args)) {
api_set_error(&err, kErrorTypeValidation,
- "Invalid channel: %"PRIu64, chan_id);
+ "Invalid channel: %" PRIu64, chan_id);
}
}
@@ -1045,10 +1032,10 @@ LuaRef nlua_ref(lua_State *lstate, int index)
if (ref > 0) {
nlua_refcount++;
#ifdef NLUA_TRACK_REFS
- if (nlua_track_refs) {
- // dummy allocation to make LeakSanitizer track our luarefs
- pmap_put(handle_T)(&nlua_ref_markers, ref, xmalloc(3));
- }
+ if (nlua_track_refs) {
+ // dummy allocation to make LeakSanitizer track our luarefs
+ pmap_put(handle_T)(&nlua_ref_markers, ref, xmalloc(3));
+ }
#endif
}
return ref;
@@ -1108,8 +1095,7 @@ LuaRef api_new_luaref(LuaRef original_ref)
/// @param[out] ret_tv Location where result will be saved.
///
/// @return Result of the execution.
-void nlua_typval_eval(const String str, typval_T *const arg,
- typval_T *const ret_tv)
+void nlua_typval_eval(const String str, typval_T *const arg, typval_T *const ret_tv)
FUNC_ATTR_NONNULL_ALL
{
#define EVALHEADER "local _A=select(1,...) return ("
@@ -1131,8 +1117,8 @@ void nlua_typval_eval(const String str, typval_T *const arg,
}
}
-void nlua_typval_call(const char *str, size_t len, typval_T *const args,
- int argcount, typval_T *ret_tv)
+void nlua_typval_call(const char *str, size_t len, typval_T *const args, int argcount,
+ typval_T *ret_tv)
FUNC_ATTR_NONNULL_ALL
{
#define CALLHEADER "return "
@@ -1158,9 +1144,8 @@ void nlua_typval_call(const char *str, size_t len, typval_T *const args,
}
}
-static void nlua_typval_exec(const char *lcmd, size_t lcmd_len,
- const char *name, typval_T *const args,
- int argcount, bool special, typval_T *ret_tv)
+static void nlua_typval_exec(const char *lcmd, size_t lcmd_len, const char *name,
+ typval_T *const args, int argcount, bool special, typval_T *ret_tv)
{
if (check_secure()) {
if (ret_tv) {
@@ -1188,8 +1173,7 @@ static void nlua_typval_exec(const char *lcmd, size_t lcmd_len,
}
}
-int nlua_source_using_linegetter(LineGetter fgetline,
- void *cookie, char *name)
+int nlua_source_using_linegetter(LineGetter fgetline, void *cookie, char *name)
{
const linenr_T save_sourcing_lnum = sourcing_lnum;
const sctx_T save_current_sctx = current_sctx;
@@ -1225,13 +1209,8 @@ int nlua_source_using_linegetter(LineGetter fgetline,
/// @param[in] argcount Count of typval arguments
/// @param[in] argvars Typval Arguments
/// @param[out] rettv The return value from the called function.
-int typval_exec_lua_callable(
- lua_State *lstate,
- LuaCallable lua_cb,
- int argcount,
- typval_T *argvars,
- typval_T *rettv
-)
+int typval_exec_lua_callable(lua_State *lstate, LuaCallable lua_cb, int argcount, typval_T *argvars,
+ typval_T *rettv)
{
LuaRef cb = lua_cb.func_ref;
@@ -1294,8 +1273,7 @@ Object nlua_exec(const String str, const Array args, Error *err)
/// if false, discard return value
/// @param err Error details, if any (if NULL, errors are echoed)
/// @return Return value of function, if retval was set. Otherwise NIL.
-Object nlua_call_ref(LuaRef ref, const char *name, Array args,
- bool retval, Error *err)
+Object nlua_call_ref(LuaRef ref, const char *name, Array args, bool retval, Error *err)
{
lua_State *const lstate = global_lstate;
nlua_pushref(lstate, ref);
@@ -1502,10 +1480,7 @@ static void nlua_add_treesitter(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
lua_setfield(lstate, -2, "_ts_get_language_version");
}
-int nlua_expand_pat(expand_T *xp,
- char_u *pat,
- int *num_results,
- char_u ***results)
+int nlua_expand_pat(expand_T *xp, char_u *pat, int *num_results, char_u ***results)
{
lua_State *const lstate = global_lstate;
int ret = OK;
@@ -1521,9 +1496,8 @@ int nlua_expand_pat(expand_T *xp,
lua_pushlstring(lstate, (const char *)pat, STRLEN(pat));
if (lua_pcall(lstate, 1, 2, 0) != 0) {
- nlua_error(
- lstate,
- _("Error executing vim._expand_pat: %.*s"));
+ nlua_error(lstate,
+ _("Error executing vim._expand_pat: %.*s"));
return FAIL;
}
@@ -1554,10 +1528,9 @@ int nlua_expand_pat(expand_T *xp,
goto cleanup_array;
}
- GA_APPEND(
- char_u *,
- &result_array,
- vim_strsave((char_u *)v.data.string.data));
+ GA_APPEND(char_u *,
+ &result_array,
+ vim_strsave((char_u *)v.data.string.data));
}
xp->xp_pattern += prefix_len;
@@ -1711,26 +1684,22 @@ static int regex_match_line(lua_State *lstate)
// Required functions for lua c functions as VimL callbacks
-int nlua_CFunction_func_call(
- int argcount,
- typval_T *argvars,
- typval_T *rettv,
- void *state)
+int nlua_CFunction_func_call(int argcount, typval_T *argvars, typval_T *rettv, void *state)
{
- lua_State *const lstate = global_lstate;
- LuaCFunctionState *funcstate = (LuaCFunctionState *)state;
+ lua_State *const lstate = global_lstate;
+ LuaCFunctionState *funcstate = (LuaCFunctionState *)state;
- return typval_exec_lua_callable(lstate, funcstate->lua_callable,
- argcount, argvars, rettv);
+ return typval_exec_lua_callable(lstate, funcstate->lua_callable,
+ argcount, argvars, rettv);
}
void nlua_CFunction_func_free(void *state)
{
- lua_State *const lstate = global_lstate;
- LuaCFunctionState *funcstate = (LuaCFunctionState *)state;
+ lua_State *const lstate = global_lstate;
+ LuaCFunctionState *funcstate = (LuaCFunctionState *)state;
- nlua_unref(lstate, funcstate->lua_callable.func_ref);
- xfree(funcstate);
+ nlua_unref(lstate, funcstate->lua_callable.func_ref);
+ xfree(funcstate);
}
bool nlua_is_table_from_lua(typval_T *const arg)
@@ -1813,9 +1782,8 @@ void nlua_execute_on_key(int c)
lua_pushlstring(lstate, (const char *)buf, buf_len);
if (lua_pcall(lstate, 1, 0, 0)) {
- nlua_error(
- lstate,
- _("Error executing vim.on_key Lua callback: %.*s"));
+ nlua_error(lstate,
+ _("Error executing vim.on_key Lua callback: %.*s"));
}
// [ vim ]
diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c
index ed475c324f..e19274ced9 100644
--- a/src/nvim/lua/treesitter.c
+++ b/src/nvim/lua/treesitter.c
@@ -5,22 +5,20 @@
// NB: this file mostly contains a generic lua interface for tree-sitter
// trees and nodes, and could be broken out as a reusable lua package
-#include <stdbool.h>
-#include <stdlib.h>
-#include <string.h>
-#include <inttypes.h>
#include <assert.h>
-
+#include <inttypes.h>
+#include <lauxlib.h>
#include <lua.h>
#include <lualib.h>
-#include <lauxlib.h>
-
-#include "tree_sitter/api.h"
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
-#include "nvim/lua/treesitter.h"
#include "nvim/api/private/helpers.h"
-#include "nvim/memline.h"
#include "nvim/buffer.h"
+#include "nvim/lua/treesitter.h"
+#include "nvim/memline.h"
+#include "tree_sitter/api.h"
#define TS_META_PARSER "treesitter_parser"
#define TS_META_TREE "treesitter_tree"
@@ -179,12 +177,11 @@ int tslua_add_language(lua_State *L)
uint32_t lang_version = ts_language_version(lang);
if (lang_version < TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION
|| lang_version > TREE_SITTER_LANGUAGE_VERSION) {
- return luaL_error(
- L,
- "ABI version mismatch for %s: supported between %d and %d, found %d",
- path,
- TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION,
- TREE_SITTER_LANGUAGE_VERSION, lang_version);
+ return luaL_error(L,
+ "ABI version mismatch for %s: supported between %d and %d, found %d",
+ path,
+ TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION,
+ TREE_SITTER_LANGUAGE_VERSION, lang_version);
}
pmap_put(cstr_t)(&langs, xstrdup(lang_name), lang);
@@ -285,8 +282,8 @@ static int parser_tostring(lua_State *L)
return 1;
}
-static const char *input_cb(void *payload, uint32_t byte_index,
- TSPoint position, uint32_t *bytes_read)
+static const char *input_cb(void *payload, uint32_t byte_index, TSPoint position,
+ uint32_t *bytes_read)
{
buf_T *bp = payload;
#define BUFSIZE 256
@@ -318,9 +315,7 @@ static const char *input_cb(void *payload, uint32_t byte_index,
#undef BUFSIZE
}
-static void push_ranges(lua_State *L,
- const TSRange *ranges,
- const unsigned int length)
+static void push_ranges(lua_State *L, const TSRange *ranges, const unsigned int length)
{
lua_createtable(L, length, 0);
for (size_t i = 0; i < length; i++) {
@@ -361,26 +356,26 @@ static int parser_parse(lua_State *L)
// This switch is necessary because of the behavior of lua_isstring, that
// consider numbers as strings...
switch (lua_type(L, 3)) {
- case LUA_TSTRING:
- str = lua_tolstring(L, 3, &len);
- new_tree = ts_parser_parse_string(*p, old_tree, str, len);
- break;
+ case LUA_TSTRING:
+ str = lua_tolstring(L, 3, &len);
+ new_tree = ts_parser_parse_string(*p, old_tree, str, len);
+ break;
- case LUA_TNUMBER:
- bufnr = lua_tointeger(L, 3);
- buf = handle_get_buffer(bufnr);
+ case LUA_TNUMBER:
+ bufnr = lua_tointeger(L, 3);
+ buf = handle_get_buffer(bufnr);
- if (!buf) {
- return luaL_error(L, "invalid buffer handle: %d", bufnr);
- }
+ if (!buf) {
+ return luaL_error(L, "invalid buffer handle: %d", bufnr);
+ }
- input = (TSInput){ (void *)buf, input_cb, TSInputEncodingUTF8 };
- new_tree = ts_parser_parse(*p, old_tree, input);
+ input = (TSInput){ (void *)buf, input_cb, TSInputEncodingUTF8 };
+ new_tree = ts_parser_parse(*p, old_tree, input);
- break;
+ break;
- default:
- return luaL_error(L, "invalid argument to parser:parse()");
+ default:
+ return luaL_error(L, "invalid argument to parser:parse()");
}
// Sometimes parsing fails (timeout, or wrong parser ABI)
@@ -393,8 +388,7 @@ static int parser_parse(lua_State *L)
// the lua GC.
// Old tree is still owned by the lua GC.
uint32_t n_ranges = 0;
- TSRange *changed = old_tree ? ts_tree_get_changed_ranges(
- old_tree, new_tree, &n_ranges) : NULL;
+ TSRange *changed = old_tree ? ts_tree_get_changed_ranges(old_tree, new_tree, &n_ranges) : NULL;
push_tree(L, new_tree, false); // [tree]
@@ -504,17 +498,15 @@ static void range_from_lua(lua_State *L, TSRange *range)
}
return;
error:
- luaL_error(
- L,
- "Ranges can only be made from 6 element long tables or nodes.");
+ luaL_error(L,
+ "Ranges can only be made from 6 element long tables or nodes.");
}
static int parser_set_ranges(lua_State *L)
{
if (lua_gettop(L) < 2) {
- return luaL_error(
- L,
- "not enough args to parser:set_included_ranges()");
+ return luaL_error(L,
+ "not enough args to parser:set_included_ranges()");
}
TSParser **p = parser_check(L, 1);
@@ -523,9 +515,8 @@ static int parser_set_ranges(lua_State *L)
}
if (!lua_istable(L, 2)) {
- return luaL_error(
- L,
- "argument for parser:set_included_ranges() should be a table.");
+ return luaL_error(L,
+ "argument for parser:set_included_ranges() should be a table.");
}
size_t tbl_len = lua_objlen(L, 2);
@@ -890,9 +881,9 @@ static int node_descendant_for_range(lua_State *L)
return 0;
}
TSPoint start = { (uint32_t)lua_tointeger(L, 2),
- (uint32_t)lua_tointeger(L, 3) };
+ (uint32_t)lua_tointeger(L, 3) };
TSPoint end = { (uint32_t)lua_tointeger(L, 4),
- (uint32_t)lua_tointeger(L, 5) };
+ (uint32_t)lua_tointeger(L, 5) };
TSNode child = ts_node_descendant_for_point_range(node, start, end);
push_node(L, child, 1);
@@ -906,9 +897,9 @@ static int node_named_descendant_for_range(lua_State *L)
return 0;
}
TSPoint start = { (uint32_t)lua_tointeger(L, 2),
- (uint32_t)lua_tointeger(L, 3) };
+ (uint32_t)lua_tointeger(L, 3) };
TSPoint end = { (uint32_t)lua_tointeger(L, 4),
- (uint32_t)lua_tointeger(L, 5) };
+ (uint32_t)lua_tointeger(L, 5) };
TSNode child = ts_node_named_descendant_for_point_range(node, start, end);
push_node(L, child, 1);
@@ -917,8 +908,7 @@ static int node_named_descendant_for_range(lua_State *L)
static int node_next_child(lua_State *L)
{
- TSTreeCursor *ud = luaL_checkudata(
- L, lua_upvalueindex(1), TS_META_TREECURSOR);
+ TSTreeCursor *ud = luaL_checkudata(L, lua_upvalueindex(1), TS_META_TREECURSOR);
if (!ud) {
return 0;
}
@@ -939,19 +929,18 @@ static int node_next_child(lua_State *L)
if (ts_tree_cursor_goto_next_sibling(ud)) {
push:
- push_node(
- L,
- ts_tree_cursor_current_node(ud),
- lua_upvalueindex(2)); // [node]
+ push_node(L,
+ ts_tree_cursor_current_node(ud),
+ lua_upvalueindex(2)); // [node]
- const char * field = ts_tree_cursor_current_field_name(ud);
+ const char * field = ts_tree_cursor_current_field_name(ud);
- if (field != NULL) {
- lua_pushstring(L, ts_tree_cursor_current_field_name(ud));
- } else {
- lua_pushnil(L);
- } // [node, field_name_or_nil]
- return 2;
+ if (field != NULL) {
+ lua_pushstring(L, ts_tree_cursor_current_field_name(ud));
+ } else {
+ lua_pushnil(L);
+ } // [node, field_name_or_nil]
+ return 2;
}
end:
@@ -1200,11 +1189,16 @@ int tslua_parse_query(lua_State *L)
static const char *query_err_string(TSQueryError err) {
switch (err) {
- case TSQueryErrorSyntax: return "invalid syntax";
- case TSQueryErrorNodeType: return "invalid node type";
- case TSQueryErrorField: return "invalid field";
- case TSQueryErrorCapture: return "invalid capture";
- default: return "error";
+ case TSQueryErrorSyntax:
+ return "invalid syntax";
+ case TSQueryErrorNodeType:
+ return "invalid node type";
+ case TSQueryErrorField:
+ return "invalid field";
+ case TSQueryErrorCapture:
+ return "invalid capture";
+ default:
+ return "error";
}
}
diff --git a/src/nvim/lua/xdiff.c b/src/nvim/lua/xdiff.c
index ae0ea00765..dc2675a1fe 100644
--- a/src/nvim/lua/xdiff.c
+++ b/src/nvim/lua/xdiff.c
@@ -1,18 +1,17 @@
+#include <errno.h>
+#include <lauxlib.h>
#include <lua.h>
#include <lualib.h>
-#include <lauxlib.h>
-
-#include <stdlib.h>
#include <stdio.h>
-#include <errno.h>
+#include <stdlib.h>
#include <string.h>
-#include "nvim/vim.h"
-#include "xdiff/xdiff.h"
-#include "nvim/lua/xdiff.h"
+#include "nvim/api/private/helpers.h"
#include "nvim/lua/converter.h"
#include "nvim/lua/executor.h"
-#include "nvim/api/private/helpers.h"
+#include "nvim/lua/xdiff.h"
+#include "nvim/vim.h"
+#include "xdiff/xdiff.h"
typedef enum {
kNluaXdiffModeUnified = 0,
@@ -22,7 +21,7 @@ typedef enum {
typedef struct {
lua_State *lstate;
- Error *err;
+ Error *err;
} hunkpriv_t;
#ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -48,8 +47,7 @@ static int write_string(void *priv, mmbuffer_t *mb, int nbuf)
}
// hunk_func callback used when opts.hunk_lines = true
-static int hunk_locations_cb(long start_a, long count_a,
- long start_b, long count_b, void *cb_data)
+static int hunk_locations_cb(long start_a, long count_a, long start_b, long count_b, void *cb_data)
{
// Mimic extra offsets done by xdiff, see:
// src/nvim/xdiff/xemit.c:284
@@ -79,8 +77,7 @@ static int hunk_locations_cb(long start_a, long count_a,
}
// hunk_func callback used when opts.on_hunk is given
-static int call_on_hunk_cb(long start_a, long count_a,
- long start_b, long count_b, void *cb_data)
+static int call_on_hunk_cb(long start_a, long count_a, long start_b, long count_b, void *cb_data)
{
// Mimic extra offsets done by xdiff, see:
// src/nvim/xdiff/xemit.c:284
@@ -130,8 +127,7 @@ static mmfile_t get_string_arg(lua_State *lstate, int idx)
}
// Helper function for validating option types
-static bool check_xdiff_opt(ObjectType actType, ObjectType expType,
- const char *name, Error *err)
+static bool check_xdiff_opt(ObjectType actType, ObjectType expType, const char *name, Error *err)
{
if (actType != expType) {
const char * type_str =
@@ -139,7 +135,7 @@ static bool check_xdiff_opt(ObjectType actType, ObjectType expType,
expType == kObjectTypeInteger ? "integer" :
expType == kObjectTypeBoolean ? "boolean" :
expType == kObjectTypeLuaRef ? "function" :
- "NA";
+ "NA";
api_set_error(err, kErrorTypeValidation, "%s is not a %s", name,
type_str);
@@ -149,9 +145,8 @@ static bool check_xdiff_opt(ObjectType actType, ObjectType expType,
return false;
}
-static NluaXdiffMode process_xdl_diff_opts(lua_State *lstate,
- xdemitconf_t *cfg,
- xpparam_t *params, Error *err)
+static NluaXdiffMode process_xdl_diff_opts(lua_State *lstate, xdemitconf_t *cfg, xpparam_t *params,
+ Error *err)
{
const DictionaryOf(LuaRef) opts = nlua_pop_Dictionary(lstate, true, err);
@@ -211,13 +206,13 @@ static NluaXdiffMode process_xdl_diff_opts(lua_State *lstate,
const char *name;
unsigned long value;
} flags[] = {
- { "ignore_whitespace" , XDF_IGNORE_WHITESPACE },
- { "ignore_whitespace_change" , XDF_IGNORE_WHITESPACE_CHANGE },
+ { "ignore_whitespace", XDF_IGNORE_WHITESPACE },
+ { "ignore_whitespace_change", XDF_IGNORE_WHITESPACE_CHANGE },
{ "ignore_whitespace_change_at_eol", XDF_IGNORE_WHITESPACE_AT_EOL },
- { "ignore_cr_at_eol" , XDF_IGNORE_CR_AT_EOL },
- { "ignore_blank_lines" , XDF_IGNORE_BLANK_LINES },
- { "indent_heuristic" , XDF_INDENT_HEURISTIC },
- { NULL , 0 },
+ { "ignore_cr_at_eol", XDF_IGNORE_CR_AT_EOL },
+ { "ignore_blank_lines", XDF_IGNORE_BLANK_LINES },
+ { "indent_heuristic", XDF_INDENT_HEURISTIC },
+ { NULL, 0 },
};
bool key_used = false;
for (size_t j = 0; flags[j].name; j++) {
@@ -270,9 +265,9 @@ int nlua_xdl_diff(lua_State *lstate)
xpparam_t params;
xdemitcb_t ecb;
- memset(&cfg , 0, sizeof(cfg));
+ memset(&cfg, 0, sizeof(cfg));
memset(&params, 0, sizeof(params));
- memset(&ecb , 0, sizeof(ecb));
+ memset(&ecb, 0, sizeof(ecb));
NluaXdiffMode mode = kNluaXdiffModeUnified;
@@ -291,21 +286,21 @@ int nlua_xdl_diff(lua_State *lstate)
luaL_Buffer buf;
hunkpriv_t *priv = NULL;
switch (mode) {
- case kNluaXdiffModeUnified:
- luaL_buffinit(lstate, &buf);
- ecb.priv = &buf;
- ecb.out_line = write_string;
- break;
- case kNluaXdiffModeOnHunkCB:
- priv = xmalloc(sizeof(*priv));
- priv->lstate = lstate;
- priv->err = &err;
- ecb.priv = priv;
- break;
- case kNluaXdiffModeLocations:
- lua_createtable(lstate, 0, 0);
- ecb.priv = lstate;
- break;
+ case kNluaXdiffModeUnified:
+ luaL_buffinit(lstate, &buf);
+ ecb.priv = &buf;
+ ecb.out_line = write_string;
+ break;
+ case kNluaXdiffModeOnHunkCB:
+ priv = xmalloc(sizeof(*priv));
+ priv->lstate = lstate;
+ priv->err = &err;
+ ecb.priv = priv;
+ break;
+ case kNluaXdiffModeLocations:
+ lua_createtable(lstate, 0, 0);
+ ecb.priv = lstate;
+ break;
}
if (xdl_diff(&ma, &mb, &params, &cfg, &ecb) == -1) {