refactor: format with uncrustify #15722

This commit is contained in:
dundargoc
2021-09-19 22:07:42 +02:00
committed by GitHub
parent 6565adcbff
commit 853346a94d
16 changed files with 1806 additions and 1754 deletions

View File

@@ -15,9 +15,9 @@
#include <stdbool.h> #include <stdbool.h>
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/arabic.h" #include "nvim/arabic.h"
#include "nvim/ascii.h"
#include "nvim/vim.h"
// Arabic ISO-10646-1 character set definition // Arabic ISO-10646-1 character set definition
@@ -253,44 +253,44 @@
static bool A_is_a(int cur_c) static bool A_is_a(int cur_c)
{ {
switch (cur_c) { switch (cur_c) {
case a_HAMZA: case a_HAMZA:
case a_ALEF_MADDA: case a_ALEF_MADDA:
case a_ALEF_HAMZA_ABOVE: case a_ALEF_HAMZA_ABOVE:
case a_WAW_HAMZA: case a_WAW_HAMZA:
case a_ALEF_HAMZA_BELOW: case a_ALEF_HAMZA_BELOW:
case a_YEH_HAMZA: case a_YEH_HAMZA:
case a_ALEF: case a_ALEF:
case a_BEH: case a_BEH:
case a_TEH_MARBUTA: case a_TEH_MARBUTA:
case a_TEH: case a_TEH:
case a_THEH: case a_THEH:
case a_JEEM: case a_JEEM:
case a_HAH: case a_HAH:
case a_KHAH: case a_KHAH:
case a_DAL: case a_DAL:
case a_THAL: case a_THAL:
case a_REH: case a_REH:
case a_ZAIN: case a_ZAIN:
case a_SEEN: case a_SEEN:
case a_SHEEN: case a_SHEEN:
case a_SAD: case a_SAD:
case a_DAD: case a_DAD:
case a_TAH: case a_TAH:
case a_ZAH: case a_ZAH:
case a_AIN: case a_AIN:
case a_GHAIN: case a_GHAIN:
case a_TATWEEL: case a_TATWEEL:
case a_FEH: case a_FEH:
case a_QAF: case a_QAF:
case a_KAF: case a_KAF:
case a_LAM: case a_LAM:
case a_MEEM: case a_MEEM:
case a_NOON: case a_NOON:
case a_HEH: case a_HEH:
case a_WAW: case a_WAW:
case a_ALEF_MAKSURA: case a_ALEF_MAKSURA:
case a_YEH: case a_YEH:
return true; return true;
} }
return false; return false;
@@ -300,43 +300,43 @@ static bool A_is_a(int cur_c)
static bool A_is_s(int cur_c) static bool A_is_s(int cur_c)
{ {
switch (cur_c) { switch (cur_c) {
case a_s_HAMZA: case a_s_HAMZA:
case a_s_ALEF_MADDA: case a_s_ALEF_MADDA:
case a_s_ALEF_HAMZA_ABOVE: case a_s_ALEF_HAMZA_ABOVE:
case a_s_WAW_HAMZA: case a_s_WAW_HAMZA:
case a_s_ALEF_HAMZA_BELOW: case a_s_ALEF_HAMZA_BELOW:
case a_s_YEH_HAMZA: case a_s_YEH_HAMZA:
case a_s_ALEF: case a_s_ALEF:
case a_s_BEH: case a_s_BEH:
case a_s_TEH_MARBUTA: case a_s_TEH_MARBUTA:
case a_s_TEH: case a_s_TEH:
case a_s_THEH: case a_s_THEH:
case a_s_JEEM: case a_s_JEEM:
case a_s_HAH: case a_s_HAH:
case a_s_KHAH: case a_s_KHAH:
case a_s_DAL: case a_s_DAL:
case a_s_THAL: case a_s_THAL:
case a_s_REH: case a_s_REH:
case a_s_ZAIN: case a_s_ZAIN:
case a_s_SEEN: case a_s_SEEN:
case a_s_SHEEN: case a_s_SHEEN:
case a_s_SAD: case a_s_SAD:
case a_s_DAD: case a_s_DAD:
case a_s_TAH: case a_s_TAH:
case a_s_ZAH: case a_s_ZAH:
case a_s_AIN: case a_s_AIN:
case a_s_GHAIN: case a_s_GHAIN:
case a_s_FEH: case a_s_FEH:
case a_s_QAF: case a_s_QAF:
case a_s_KAF: case a_s_KAF:
case a_s_LAM: case a_s_LAM:
case a_s_MEEM: case a_s_MEEM:
case a_s_NOON: case a_s_NOON:
case a_s_HEH: case a_s_HEH:
case a_s_WAW: case a_s_WAW:
case a_s_ALEF_MAKSURA: case a_s_ALEF_MAKSURA:
case a_s_YEH: case a_s_YEH:
return true; return true;
} }
return false; return false;
@@ -346,46 +346,46 @@ static bool A_is_s(int cur_c)
static bool A_is_f(int cur_c) static bool A_is_f(int cur_c)
{ {
switch (cur_c) { switch (cur_c) {
case a_f_ALEF_MADDA: case a_f_ALEF_MADDA:
case a_f_ALEF_HAMZA_ABOVE: case a_f_ALEF_HAMZA_ABOVE:
case a_f_WAW_HAMZA: case a_f_WAW_HAMZA:
case a_f_ALEF_HAMZA_BELOW: case a_f_ALEF_HAMZA_BELOW:
case a_f_YEH_HAMZA: case a_f_YEH_HAMZA:
case a_f_ALEF: case a_f_ALEF:
case a_f_BEH: case a_f_BEH:
case a_f_TEH_MARBUTA: case a_f_TEH_MARBUTA:
case a_f_TEH: case a_f_TEH:
case a_f_THEH: case a_f_THEH:
case a_f_JEEM: case a_f_JEEM:
case a_f_HAH: case a_f_HAH:
case a_f_KHAH: case a_f_KHAH:
case a_f_DAL: case a_f_DAL:
case a_f_THAL: case a_f_THAL:
case a_f_REH: case a_f_REH:
case a_f_ZAIN: case a_f_ZAIN:
case a_f_SEEN: case a_f_SEEN:
case a_f_SHEEN: case a_f_SHEEN:
case a_f_SAD: case a_f_SAD:
case a_f_DAD: case a_f_DAD:
case a_f_TAH: case a_f_TAH:
case a_f_ZAH: case a_f_ZAH:
case a_f_AIN: case a_f_AIN:
case a_f_GHAIN: case a_f_GHAIN:
case a_f_FEH: case a_f_FEH:
case a_f_QAF: case a_f_QAF:
case a_f_KAF: case a_f_KAF:
case a_f_LAM: case a_f_LAM:
case a_f_MEEM: case a_f_MEEM:
case a_f_NOON: case a_f_NOON:
case a_f_HEH: case a_f_HEH:
case a_f_WAW: case a_f_WAW:
case a_f_ALEF_MAKSURA: case a_f_ALEF_MAKSURA:
case a_f_YEH: case a_f_YEH:
case a_f_LAM_ALEF_MADDA_ABOVE: case a_f_LAM_ALEF_MADDA_ABOVE:
case a_f_LAM_ALEF_HAMZA_ABOVE: case a_f_LAM_ALEF_HAMZA_ABOVE:
case a_f_LAM_ALEF_HAMZA_BELOW: case a_f_LAM_ALEF_HAMZA_BELOW:
case a_f_LAM_ALEF: case a_f_LAM_ALEF:
return true; return true;
} }
return false; return false;
} }
@@ -394,43 +394,80 @@ static bool A_is_f(int cur_c)
static int chg_c_a2s(int cur_c) static int chg_c_a2s(int cur_c)
{ {
switch (cur_c) { switch (cur_c) {
case a_HAMZA: return a_s_HAMZA; case a_HAMZA:
case a_ALEF_MADDA: return a_s_ALEF_MADDA; return a_s_HAMZA;
case a_ALEF_HAMZA_ABOVE: return a_s_ALEF_HAMZA_ABOVE; case a_ALEF_MADDA:
case a_WAW_HAMZA: return a_s_WAW_HAMZA; return a_s_ALEF_MADDA;
case a_ALEF_HAMZA_BELOW: return a_s_ALEF_HAMZA_BELOW; case a_ALEF_HAMZA_ABOVE:
case a_YEH_HAMZA: return a_s_YEH_HAMZA; return a_s_ALEF_HAMZA_ABOVE;
case a_ALEF: return a_s_ALEF; case a_WAW_HAMZA:
case a_TEH_MARBUTA: return a_s_TEH_MARBUTA; return a_s_WAW_HAMZA;
case a_DAL: return a_s_DAL; case a_ALEF_HAMZA_BELOW:
case a_THAL: return a_s_THAL; return a_s_ALEF_HAMZA_BELOW;
case a_REH: return a_s_REH; case a_YEH_HAMZA:
case a_ZAIN: return a_s_ZAIN; return a_s_YEH_HAMZA;
case a_TATWEEL: return cur_c; // exceptions case a_ALEF:
case a_WAW: return a_s_WAW; return a_s_ALEF;
case a_ALEF_MAKSURA: return a_s_ALEF_MAKSURA; case a_TEH_MARBUTA:
case a_BEH: return a_s_BEH; return a_s_TEH_MARBUTA;
case a_TEH: return a_s_TEH; case a_DAL:
case a_THEH: return a_s_THEH; return a_s_DAL;
case a_JEEM: return a_s_JEEM; case a_THAL:
case a_HAH: return a_s_HAH; return a_s_THAL;
case a_KHAH: return a_s_KHAH; case a_REH:
case a_SEEN: return a_s_SEEN; return a_s_REH;
case a_SHEEN: return a_s_SHEEN; case a_ZAIN:
case a_SAD: return a_s_SAD; return a_s_ZAIN;
case a_DAD: return a_s_DAD; case a_TATWEEL:
case a_TAH: return a_s_TAH; return cur_c; // exceptions
case a_ZAH: return a_s_ZAH; case a_WAW:
case a_AIN: return a_s_AIN; return a_s_WAW;
case a_GHAIN: return a_s_GHAIN; case a_ALEF_MAKSURA:
case a_FEH: return a_s_FEH; return a_s_ALEF_MAKSURA;
case a_QAF: return a_s_QAF; case a_BEH:
case a_KAF: return a_s_KAF; return a_s_BEH;
case a_LAM: return a_s_LAM; case a_TEH:
case a_MEEM: return a_s_MEEM; return a_s_TEH;
case a_NOON: return a_s_NOON; case a_THEH:
case a_HEH: return a_s_HEH; return a_s_THEH;
case a_YEH: return a_s_YEH; 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; return 0;
} }
@@ -439,43 +476,80 @@ static int chg_c_a2s(int cur_c)
static int chg_c_a2i(int cur_c) static int chg_c_a2i(int cur_c)
{ {
switch (cur_c) { switch (cur_c) {
case a_YEH_HAMZA: return a_i_YEH_HAMZA; case a_YEH_HAMZA:
case a_HAMZA: return a_s_HAMZA; // exceptions return a_i_YEH_HAMZA;
case a_ALEF_MADDA: return a_s_ALEF_MADDA; // exceptions case a_HAMZA:
case a_ALEF_HAMZA_ABOVE: return a_s_ALEF_HAMZA_ABOVE; // exceptions return a_s_HAMZA; // exceptions
case a_WAW_HAMZA: return a_s_WAW_HAMZA; // exceptions case a_ALEF_MADDA:
case a_ALEF_HAMZA_BELOW: return a_s_ALEF_HAMZA_BELOW; // exceptions return a_s_ALEF_MADDA; // exceptions
case a_ALEF: return a_s_ALEF; // exceptions case a_ALEF_HAMZA_ABOVE:
case a_TEH_MARBUTA: return a_s_TEH_MARBUTA; // exceptions return a_s_ALEF_HAMZA_ABOVE; // exceptions
case a_DAL: return a_s_DAL; // exceptions case a_WAW_HAMZA:
case a_THAL: return a_s_THAL; // exceptions return a_s_WAW_HAMZA; // exceptions
case a_REH: return a_s_REH; // exceptions case a_ALEF_HAMZA_BELOW:
case a_ZAIN: return a_s_ZAIN; // exceptions return a_s_ALEF_HAMZA_BELOW; // exceptions
case a_TATWEEL: return cur_c; // exceptions case a_ALEF:
case a_WAW: return a_s_WAW; // exceptions return a_s_ALEF; // exceptions
case a_ALEF_MAKSURA: return a_s_ALEF_MAKSURA; // exceptions case a_TEH_MARBUTA:
case a_BEH: return a_i_BEH; return a_s_TEH_MARBUTA; // exceptions
case a_TEH: return a_i_TEH; case a_DAL:
case a_THEH: return a_i_THEH; return a_s_DAL; // exceptions
case a_JEEM: return a_i_JEEM; case a_THAL:
case a_HAH: return a_i_HAH; return a_s_THAL; // exceptions
case a_KHAH: return a_i_KHAH; case a_REH:
case a_SEEN: return a_i_SEEN; return a_s_REH; // exceptions
case a_SHEEN: return a_i_SHEEN; case a_ZAIN:
case a_SAD: return a_i_SAD; return a_s_ZAIN; // exceptions
case a_DAD: return a_i_DAD; case a_TATWEEL:
case a_TAH: return a_i_TAH; return cur_c; // exceptions
case a_ZAH: return a_i_ZAH; case a_WAW:
case a_AIN: return a_i_AIN; return a_s_WAW; // exceptions
case a_GHAIN: return a_i_GHAIN; case a_ALEF_MAKSURA:
case a_FEH: return a_i_FEH; return a_s_ALEF_MAKSURA; // exceptions
case a_QAF: return a_i_QAF; case a_BEH:
case a_KAF: return a_i_KAF; return a_i_BEH;
case a_LAM: return a_i_LAM; case a_TEH:
case a_MEEM: return a_i_MEEM; return a_i_TEH;
case a_NOON: return a_i_NOON; case a_THEH:
case a_HEH: return a_i_HEH; return a_i_THEH;
case a_YEH: return a_i_YEH; 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; return 0;
} }
@@ -484,43 +558,80 @@ static int chg_c_a2i(int cur_c)
static int chg_c_a2m(int cur_c) static int chg_c_a2m(int cur_c)
{ {
switch (cur_c) { switch (cur_c) {
case a_HAMZA: return a_s_HAMZA; // exception case a_HAMZA:
case a_ALEF_MADDA: return a_f_ALEF_MADDA; // exception return a_s_HAMZA; // exception
case a_ALEF_HAMZA_ABOVE: return a_f_ALEF_HAMZA_ABOVE; // exception case a_ALEF_MADDA:
case a_WAW_HAMZA: return a_f_WAW_HAMZA; // exception return a_f_ALEF_MADDA; // exception
case a_ALEF_HAMZA_BELOW: return a_f_ALEF_HAMZA_BELOW; // exception case a_ALEF_HAMZA_ABOVE:
case a_YEH_HAMZA: return a_m_YEH_HAMZA; return a_f_ALEF_HAMZA_ABOVE; // exception
case a_ALEF: return a_f_ALEF; // exception case a_WAW_HAMZA:
case a_BEH: return a_m_BEH; return a_f_WAW_HAMZA; // exception
case a_TEH_MARBUTA: return a_f_TEH_MARBUTA; // exception case a_ALEF_HAMZA_BELOW:
case a_TEH: return a_m_TEH; return a_f_ALEF_HAMZA_BELOW; // exception
case a_THEH: return a_m_THEH; case a_YEH_HAMZA:
case a_JEEM: return a_m_JEEM; return a_m_YEH_HAMZA;
case a_HAH: return a_m_HAH; case a_ALEF:
case a_KHAH: return a_m_KHAH; return a_f_ALEF; // exception
case a_DAL: return a_f_DAL; // exception case a_BEH:
case a_THAL: return a_f_THAL; // exception return a_m_BEH;
case a_REH: return a_f_REH; // exception case a_TEH_MARBUTA:
case a_ZAIN: return a_f_ZAIN; // exception return a_f_TEH_MARBUTA; // exception
case a_SEEN: return a_m_SEEN; case a_TEH:
case a_SHEEN: return a_m_SHEEN; return a_m_TEH;
case a_SAD: return a_m_SAD; case a_THEH:
case a_DAD: return a_m_DAD; return a_m_THEH;
case a_TAH: return a_m_TAH; case a_JEEM:
case a_ZAH: return a_m_ZAH; return a_m_JEEM;
case a_AIN: return a_m_AIN; case a_HAH:
case a_GHAIN: return a_m_GHAIN; return a_m_HAH;
case a_TATWEEL: return cur_c; // exception case a_KHAH:
case a_FEH: return a_m_FEH; return a_m_KHAH;
case a_QAF: return a_m_QAF; case a_DAL:
case a_KAF: return a_m_KAF; return a_f_DAL; // exception
case a_LAM: return a_m_LAM; case a_THAL:
case a_MEEM: return a_m_MEEM; return a_f_THAL; // exception
case a_NOON: return a_m_NOON; case a_REH:
case a_HEH: return a_m_HEH; return a_f_REH; // exception
case a_WAW: return a_f_WAW; // exception case a_ZAIN:
case a_ALEF_MAKSURA: return a_f_ALEF_MAKSURA; // exception return a_f_ZAIN; // exception
case a_YEH: return a_m_YEH; 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; return 0;
} }
@@ -538,43 +649,80 @@ static int chg_c_a2f(int cur_c)
// a_f_LAM_ALEF_HAMZA_BELOW; // a_f_LAM_ALEF_HAMZA_BELOW;
switch (cur_c) { switch (cur_c) {
case a_HAMZA: return a_s_HAMZA; // exception case a_HAMZA:
case a_ALEF_MADDA: return a_f_ALEF_MADDA; return a_s_HAMZA; // exception
case a_ALEF_HAMZA_ABOVE: return a_f_ALEF_HAMZA_ABOVE; case a_ALEF_MADDA:
case a_WAW_HAMZA: return a_f_WAW_HAMZA; return a_f_ALEF_MADDA;
case a_ALEF_HAMZA_BELOW: return a_f_ALEF_HAMZA_BELOW; case a_ALEF_HAMZA_ABOVE:
case a_YEH_HAMZA: return a_f_YEH_HAMZA; return a_f_ALEF_HAMZA_ABOVE;
case a_ALEF: return a_f_ALEF; case a_WAW_HAMZA:
case a_BEH: return a_f_BEH; return a_f_WAW_HAMZA;
case a_TEH_MARBUTA: return a_f_TEH_MARBUTA; case a_ALEF_HAMZA_BELOW:
case a_TEH: return a_f_TEH; return a_f_ALEF_HAMZA_BELOW;
case a_THEH: return a_f_THEH; case a_YEH_HAMZA:
case a_JEEM: return a_f_JEEM; return a_f_YEH_HAMZA;
case a_HAH: return a_f_HAH; case a_ALEF:
case a_KHAH: return a_f_KHAH; return a_f_ALEF;
case a_DAL: return a_f_DAL; case a_BEH:
case a_THAL: return a_f_THAL; return a_f_BEH;
case a_REH: return a_f_REH; case a_TEH_MARBUTA:
case a_ZAIN: return a_f_ZAIN; return a_f_TEH_MARBUTA;
case a_SEEN: return a_f_SEEN; case a_TEH:
case a_SHEEN: return a_f_SHEEN; return a_f_TEH;
case a_SAD: return a_f_SAD; case a_THEH:
case a_DAD: return a_f_DAD; return a_f_THEH;
case a_TAH: return a_f_TAH; case a_JEEM:
case a_ZAH: return a_f_ZAH; return a_f_JEEM;
case a_AIN: return a_f_AIN; case a_HAH:
case a_GHAIN: return a_f_GHAIN; return a_f_HAH;
case a_TATWEEL: return cur_c; // exception case a_KHAH:
case a_FEH: return a_f_FEH; return a_f_KHAH;
case a_QAF: return a_f_QAF; case a_DAL:
case a_KAF: return a_f_KAF; return a_f_DAL;
case a_LAM: return a_f_LAM; case a_THAL:
case a_MEEM: return a_f_MEEM; return a_f_THAL;
case a_NOON: return a_f_NOON; case a_REH:
case a_HEH: return a_f_HEH; return a_f_REH;
case a_WAW: return a_f_WAW; case a_ZAIN:
case a_ALEF_MAKSURA: return a_f_ALEF_MAKSURA; return a_f_ZAIN;
case a_YEH: return a_f_YEH; 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; return 0;
} }
@@ -586,29 +734,52 @@ static int chg_c_a2f(int cur_c)
static int chg_c_i2m(int cur_c) static int chg_c_i2m(int cur_c)
{ {
switch (cur_c) { switch (cur_c) {
case a_i_YEH_HAMZA: return a_m_YEH_HAMZA; case a_i_YEH_HAMZA:
case a_i_BEH: return a_m_BEH; return a_m_YEH_HAMZA;
case a_i_TEH: return a_m_TEH; case a_i_BEH:
case a_i_THEH: return a_m_THEH; return a_m_BEH;
case a_i_JEEM: return a_m_JEEM; case a_i_TEH:
case a_i_HAH: return a_m_HAH; return a_m_TEH;
case a_i_KHAH: return a_m_KHAH; case a_i_THEH:
case a_i_SEEN: return a_m_SEEN; return a_m_THEH;
case a_i_SHEEN: return a_m_SHEEN; case a_i_JEEM:
case a_i_SAD: return a_m_SAD; return a_m_JEEM;
case a_i_DAD: return a_m_DAD; case a_i_HAH:
case a_i_TAH: return a_m_TAH; return a_m_HAH;
case a_i_ZAH: return a_m_ZAH; case a_i_KHAH:
case a_i_AIN: return a_m_AIN; return a_m_KHAH;
case a_i_GHAIN: return a_m_GHAIN; case a_i_SEEN:
case a_i_FEH: return a_m_FEH; return a_m_SEEN;
case a_i_QAF: return a_m_QAF; case a_i_SHEEN:
case a_i_KAF: return a_m_KAF; return a_m_SHEEN;
case a_i_LAM: return a_m_LAM; case a_i_SAD:
case a_i_MEEM: return a_m_MEEM; return a_m_SAD;
case a_i_NOON: return a_m_NOON; case a_i_DAD:
case a_i_HEH: return a_m_HEH; return a_m_DAD;
case a_i_YEH: return a_m_YEH; 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; return 0;
} }
@@ -618,43 +789,66 @@ static int chg_c_i2m(int cur_c)
static int chg_c_f2m(int cur_c) static int chg_c_f2m(int cur_c)
{ {
switch (cur_c) { switch (cur_c) {
// NOTE: these encodings are multi-positional, no ? // NOTE: these encodings are multi-positional, no ?
// case a_f_ALEF_MADDA: // case a_f_ALEF_MADDA:
// case a_f_ALEF_HAMZA_ABOVE: // case a_f_ALEF_HAMZA_ABOVE:
// case a_f_ALEF_HAMZA_BELOW: // case a_f_ALEF_HAMZA_BELOW:
case a_f_YEH_HAMZA: return a_m_YEH_HAMZA; case a_f_YEH_HAMZA:
case a_f_WAW_HAMZA: // exceptions return a_m_YEH_HAMZA;
case a_f_ALEF: case a_f_WAW_HAMZA: // exceptions
case a_f_TEH_MARBUTA: case a_f_ALEF:
case a_f_DAL: case a_f_TEH_MARBUTA:
case a_f_THAL: case a_f_DAL:
case a_f_REH: case a_f_THAL:
case a_f_ZAIN: case a_f_REH:
case a_f_WAW: case a_f_ZAIN:
case a_f_ALEF_MAKSURA: case a_f_WAW:
return cur_c; case a_f_ALEF_MAKSURA:
case a_f_BEH: return a_m_BEH; return cur_c;
case a_f_TEH: return a_m_TEH; case a_f_BEH:
case a_f_THEH: return a_m_THEH; return a_m_BEH;
case a_f_JEEM: return a_m_JEEM; case a_f_TEH:
case a_f_HAH: return a_m_HAH; return a_m_TEH;
case a_f_KHAH: return a_m_KHAH; case a_f_THEH:
case a_f_SEEN: return a_m_SEEN; return a_m_THEH;
case a_f_SHEEN: return a_m_SHEEN; case a_f_JEEM:
case a_f_SAD: return a_m_SAD; return a_m_JEEM;
case a_f_DAD: return a_m_DAD; case a_f_HAH:
case a_f_TAH: return a_m_TAH; return a_m_HAH;
case a_f_ZAH: return a_m_ZAH; case a_f_KHAH:
case a_f_AIN: return a_m_AIN; return a_m_KHAH;
case a_f_GHAIN: return a_m_GHAIN; case a_f_SEEN:
case a_f_FEH: return a_m_FEH; return a_m_SEEN;
case a_f_QAF: return a_m_QAF; case a_f_SHEEN:
case a_f_KAF: return a_m_KAF; return a_m_SHEEN;
case a_f_LAM: return a_m_LAM; case a_f_SAD:
case a_f_MEEM: return a_m_MEEM; return a_m_SAD;
case a_f_NOON: return a_m_NOON; case a_f_DAD:
case a_f_HEH: return a_m_HEH; return a_m_DAD;
case a_f_YEH: return a_m_YEH; 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 ? // NOTE: these encodings are multi-positional, no ?
// case a_f_LAM_ALEF_MADDA_ABOVE: // case a_f_LAM_ALEF_MADDA_ABOVE:
// case a_f_LAM_ALEF_HAMZA_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) static int chg_c_laa2i(int hid_c)
{ {
switch (hid_c) { switch (hid_c) {
case a_ALEF_MADDA: return a_s_LAM_ALEF_MADDA_ABOVE; case a_ALEF_MADDA:
case a_ALEF_HAMZA_ABOVE: return a_s_LAM_ALEF_HAMZA_ABOVE; return a_s_LAM_ALEF_MADDA_ABOVE;
case a_ALEF_HAMZA_BELOW: return a_s_LAM_ALEF_HAMZA_BELOW; case a_ALEF_HAMZA_ABOVE:
case a_ALEF: return a_s_LAM_ALEF; 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; return 0;
} }
@@ -680,10 +878,14 @@ static int chg_c_laa2i(int hid_c)
static int chg_c_laa2f(int hid_c) static int chg_c_laa2f(int hid_c)
{ {
switch (hid_c) { switch (hid_c) {
case a_ALEF_MADDA: return a_f_LAM_ALEF_MADDA_ABOVE; case a_ALEF_MADDA:
case a_ALEF_HAMZA_ABOVE: return a_f_LAM_ALEF_HAMZA_ABOVE; return a_f_LAM_ALEF_MADDA_ABOVE;
case a_ALEF_HAMZA_BELOW: return a_f_LAM_ALEF_HAMZA_BELOW; case a_ALEF_HAMZA_ABOVE:
case a_ALEF: return a_f_LAM_ALEF; 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; return 0;
} }
@@ -708,8 +910,7 @@ static int half_shape(int c)
// in: "prev_c1" is the first composing char for the previous char // in: "prev_c1" is the first composing char for the previous char
// (not shaped) // (not shaped)
// in: "next_c" is the next character (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 arabic_shape(int c, int *ccp, int *c1p, int prev_c, int prev_c1, int next_c)
int next_c)
{ {
// Deal only with Arabic character, pass back all others // Deal only with Arabic character, pass back all others
if (!A_is_ok(c)) { if (!A_is_ok(c)) {
@@ -786,9 +987,9 @@ bool arabic_maycombine(int two)
{ {
if (p_arshape && !p_tbidi) { if (p_arshape && !p_tbidi) {
return two == a_ALEF_MADDA return two == a_ALEF_MADDA
|| two == a_ALEF_HAMZA_ABOVE || two == a_ALEF_HAMZA_ABOVE
|| two == a_ALEF_HAMZA_BELOW || two == a_ALEF_HAMZA_BELOW
|| two == a_ALEF; || two == a_ALEF;
} }
return false; return false;
} }

View File

@@ -1,16 +1,16 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check // 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 // 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/aucmd.h"
#include "nvim/buffer.h"
#include "nvim/eval.h" #include "nvim/eval.h"
#include "nvim/ex_docmd.h" #include "nvim/ex_docmd.h"
#include "nvim/ex_getln.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 #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "aucmd.c.generated.h" # include "aucmd.c.generated.h"

View File

@@ -3,10 +3,9 @@
// autocmd.c: Autocommand related functions // autocmd.c: Autocommand related functions
#include "nvim/autocmd.h"
#include "nvim/api/private/helpers.h" #include "nvim/api/private/helpers.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/autocmd.h"
#include "nvim/buffer.h" #include "nvim/buffer.h"
#include "nvim/charset.h" #include "nvim/charset.h"
#include "nvim/cursor.h" #include "nvim/cursor.h"
@@ -326,8 +325,7 @@ static void au_del_group(char_u *name)
event = (event_T)((int)event + 1)) { event = (event_T)((int)event + 1)) {
for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next) { for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next) {
if (ap->group == i && ap->pat != NULL) { if (ap->group == i && ap->pat != NULL) {
give_warning( give_warning((char_u *)_("W19: Deleting augroup that is still in use"), true);
(char_u *)_("W19: Deleting augroup that is still in use"), true);
in_use = true; in_use = true;
event = NUM_EVENTS; event = NUM_EVENTS;
break; break;
@@ -761,13 +759,8 @@ static int au_get_grouparg(char_u **argp)
// If *cmd == NUL: show entries. // If *cmd == NUL: show entries.
// If forceit == true: delete entries. // If forceit == true: delete entries.
// If group is not AUGROUP_ALL: only use this group. // If group is not AUGROUP_ALL: only use this group.
static int do_autocmd_event(event_T event, static int do_autocmd_event(event_T event, char_u *pat, bool once, int nested, char_u *cmd,
char_u *pat, int forceit, int group)
bool once,
int nested,
char_u *cmd,
int forceit,
int group)
{ {
AutoPat *ap; AutoPat *ap;
AutoPat **prev_ap; AutoPat **prev_ap;
@@ -847,11 +840,10 @@ static int do_autocmd_event(event_T event,
if (is_buflocal) { if (is_buflocal) {
// normalize pat into standard "<buffer>#N" form // normalize pat into standard "<buffer>#N" form
snprintf( snprintf((char *)buflocal_pat,
(char *)buflocal_pat, BUFLOCAL_PAT_LEN,
BUFLOCAL_PAT_LEN, "<buffer=%d>",
"<buffer=%d>", buflocal_nr);
buflocal_nr);
pat = buflocal_pat; // can modify pat and patlen pat = buflocal_pat; // can modify pat and patlen
patlen = (int)STRLEN(buflocal_pat); // but not endpat patlen = (int)STRLEN(buflocal_pat); // but not endpat
@@ -889,7 +881,6 @@ static int do_autocmd_event(event_T event,
} else if (*cmd == NUL) { } else if (*cmd == NUL) {
// Show autocmd's for this autopat, or buflocals <buffer=X> // Show autocmd's for this autopat, or buflocals <buffer=X>
show_autocmd(ap, event); show_autocmd(ap, event);
} else if (ap->next == NULL) { } else if (ap->next == NULL) {
// Add autocmd to this autopat, if it's the last one. // Add autocmd to this autopat, if it's the last one.
break; break;
@@ -967,8 +958,7 @@ static int do_autocmd_event(event_T event,
// Implementation of ":doautocmd [group] event [fname]". // Implementation of ":doautocmd [group] event [fname]".
// Return OK for success, FAIL for failure; // Return OK for success, FAIL for failure;
int do_doautocmd(char_u *arg, int do_doautocmd(char_u *arg, bool do_msg, // give message for no matching autocmds?
bool do_msg, // give message for no matching autocmds?
bool *did_something) bool *did_something)
{ {
char_u *fname; char_u *fname;
@@ -1188,7 +1178,7 @@ void aucmd_restbuf(aco_save_T *aco)
} }
} }
} }
win_found: win_found:
win_remove(curwin, NULL); win_remove(curwin, NULL);
pmap_del(handle_T)(&window_handles, curwin->handle); pmap_del(handle_T)(&window_handles, curwin->handle);
@@ -1268,11 +1258,7 @@ void aucmd_restbuf(aco_save_T *aco)
/// @param buf Buffer for <abuf> /// @param buf Buffer for <abuf>
/// ///
/// @return true if some commands were executed. /// @return true if some commands were executed.
bool apply_autocmds(event_T event, bool apply_autocmds(event_T event, char_u *fname, char_u *fname_io, bool force, buf_T *buf)
char_u *fname,
char_u *fname_io,
bool force,
buf_T *buf)
{ {
return apply_autocmds_group(event, fname, fname_io, force, AUGROUP_ALL, buf, return apply_autocmds_group(event, fname, fname_io, force, AUGROUP_ALL, buf,
NULL); NULL);
@@ -1289,11 +1275,7 @@ bool apply_autocmds(event_T event,
/// @param exarg Ex command arguments /// @param exarg Ex command arguments
/// ///
/// @return true if some commands were executed. /// @return true if some commands were executed.
bool apply_autocmds_exarg(event_T event, bool apply_autocmds_exarg(event_T event, char_u *fname, char_u *fname_io, bool force, buf_T *buf,
char_u *fname,
char_u *fname_io,
bool force,
buf_T *buf,
exarg_T *eap) exarg_T *eap)
{ {
return apply_autocmds_group(event, fname, fname_io, force, AUGROUP_ALL, buf, 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 /// @param[in,out] retval caller's retval
/// ///
/// @return true if some autocommands were executed /// @return true if some autocommands were executed
bool apply_autocmds_retval(event_T event, bool apply_autocmds_retval(event_T event, char_u *fname, char_u *fname_io, bool force, buf_T *buf,
char_u *fname,
char_u *fname_io,
bool force,
buf_T *buf,
int *retval) int *retval)
{ {
if (should_abort(*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. /// the current mode.
bool has_cursorhold(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT bool has_cursorhold(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{ {
return has_event( return has_event((get_real_state() == NORMAL_BUSY ? EVENT_CURSORHOLD : EVENT_CURSORHOLDI));
(get_real_state() == NORMAL_BUSY ? EVENT_CURSORHOLD : EVENT_CURSORHOLDI));
// return first_autopat[] != NULL; // 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 /// @param eap Ex command arguments
/// ///
/// @return true if some commands were executed. /// @return true if some commands were executed.
static bool apply_autocmds_group(event_T event, static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, bool force,
char_u *fname, int group, buf_T *buf, exarg_T *eap)
char_u *fname_io,
bool force,
int group,
buf_T *buf,
exarg_T *eap)
{ {
char_u *sfname = NULL; // short file name char_u *sfname = NULL; // short file name
char_u *tail; 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)) { && (apc->group == AUGROUP_ALL || apc->group == ap->group)) {
// execution-condition // execution-condition
if (ap->buflocal_nr == 0 if (ap->buflocal_nr == 0
? match_file_pat( ? match_file_pat(NULL,
NULL, &ap->reg_prog,
&ap->reg_prog, apc->fname,
apc->fname, apc->sfname,
apc->sfname, apc->tail,
apc->tail, ap->allow_dirs)
ap->allow_dirs)
: ap->buflocal_nr == apc->arg_bufnr) { : ap->buflocal_nr == apc->arg_bufnr) {
const char *const name = event_nr2name(apc->event); const char *const name = event_nr2name(apc->event);
s = _("%s Autocommands for \"%s\""); s = _("%s Autocommands for \"%s\"");
const size_t sourcing_name_len 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); sourcing_name = xmalloc(sourcing_name_len);
snprintf((char *)sourcing_name, sourcing_name_len, s, name, 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 event event that occurred.
/// @param sfname filename the event occurred in. /// @param sfname filename the event occurred in.
/// @param buf buffer the file is open in /// @param buf buffer the file is open in
bool has_autocmd(event_T event, bool has_autocmd(event_T event, char_u *sfname, buf_T *buf) FUNC_ATTR_WARN_UNUSED_RESULT
char_u *sfname,
buf_T *buf) FUNC_ATTR_WARN_UNUSED_RESULT
{ {
AutoPat *ap; AutoPat *ap;
char_u *fname; char_u *fname;
@@ -1910,13 +1879,12 @@ bool has_autocmd(event_T event,
for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next) { for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next) {
if (ap->pat != NULL && ap->cmds != NULL if (ap->pat != NULL && ap->cmds != NULL
&& (ap->buflocal_nr == 0 && (ap->buflocal_nr == 0
? match_file_pat( ? match_file_pat(NULL,
NULL, &ap->reg_prog,
&ap->reg_prog, fname,
fname, sfname,
sfname, tail,
tail, ap->allow_dirs)
ap->allow_dirs)
: buf != NULL && ap->buflocal_nr == buf->b_fnum)) { : buf != NULL && ap->buflocal_nr == buf->b_fnum)) {
retval = true; retval = true;
break; break;
@@ -1948,11 +1916,8 @@ char_u *get_augroup_name(expand_T *xp, int idx)
return (char_u *)AUGROUP_NAME(idx); return (char_u *)AUGROUP_NAME(idx);
} }
char_u *set_context_in_autocmd( char_u *set_context_in_autocmd(expand_T *xp, char_u *arg, int doautocmd // true for :doauto*, false for :autocmd
expand_T *xp, )
char_u *arg,
int doautocmd // true for :doauto*, false for :autocmd
)
{ {
char_u *p; char_u *p;
int group; int group;

File diff suppressed because it is too large Load Diff

View File

@@ -1,14 +1,14 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check // 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 // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "nvim/buffer_updates.h"
#include "nvim/extmark.h"
#include "nvim/memline.h"
#include "nvim/api/private/helpers.h" #include "nvim/api/private/helpers.h"
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/lua/executor.h"
#include "nvim/assert.h" #include "nvim/assert.h"
#include "nvim/buffer.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/msgpack_rpc/channel.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "buffer_updates.c.generated.h" # include "buffer_updates.c.generated.h"
@@ -17,8 +17,7 @@
// Register a channel. Return True if the channel was added, or already added. // 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 // Return False if the channel couldn't be added because the buffer is
// unloaded. // unloaded.
bool buf_updates_register(buf_T *buf, uint64_t channel_id, bool buf_updates_register(buf_T *buf, uint64_t channel_id, BufUpdateCallbacks cb, bool send_buffer)
BufUpdateCallbacks cb, bool send_buffer)
{ {
// must fail if the buffer isn't loaded // must fail if the buffer isn't loaded
if (buf->b_ml.ml_mfp == NULL) { 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) 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) void buf_updates_send_end(buf_T *buf, uint64_t channelid)
{ {
Array args = ARRAY_DICT_INIT; Array args = ARRAY_DICT_INIT;
args.size = 1; args.size = 1;
args.items = xcalloc(args.size, sizeof(Object)); args.items = xcalloc(args.size, sizeof(Object));
args.items[0] = BUFFER_OBJ(buf->handle); args.items[0] = BUFFER_OBJ(buf->handle);
rpc_send_event(channelid, "nvim_buf_detach_event", args); rpc_send_event(channelid, "nvim_buf_detach_event", args);
} }
void buf_updates_unregister(buf_T *buf, uint64_t channelid) 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, void buf_updates_send_changes(buf_T *buf, linenr_T firstline, int64_t num_added,
linenr_T firstline, int64_t num_removed, bool send_tick)
int64_t num_added,
int64_t num_removed,
bool send_tick)
{ {
size_t deleted_codepoints, deleted_codeunits; size_t deleted_codepoints, deleted_codeunits;
size_t deleted_bytes = ml_flush_deleted_bytes(buf, &deleted_codepoints, 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 // linedata of lines being swapped in
Array linedata = ARRAY_DICT_INIT; Array linedata = ARRAY_DICT_INIT;
if (num_added > 0) { if (num_added > 0) {
STATIC_ASSERT(SIZE_MAX >= MAXLNUM, "size_t smaller than MAXLNUM"); STATIC_ASSERT(SIZE_MAX >= MAXLNUM, "size_t smaller than MAXLNUM");
linedata.size = (size_t)num_added; linedata.size = (size_t)num_added;
linedata.items = xcalloc((size_t)num_added, sizeof(Object)); linedata.items = xcalloc((size_t)num_added, sizeof(Object));
buf_collect_lines(buf, (size_t)num_added, firstline, true, &linedata, buf_collect_lines(buf, (size_t)num_added, firstline, true, &linedata,
NULL); NULL);
} }
args.items[4] = ARRAY_OBJ(linedata); args.items[4] = ARRAY_OBJ(linedata);
args.items[5] = BOOLEAN_OBJ(false); 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 // change notifications are so frequent that many dead channels will be
// cleared up quickly. // cleared up quickly.
if (badchannelid != 0) { 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); buf_updates_unregister(buf, badchannelid);
} }
@@ -302,11 +298,9 @@ void buf_updates_send_changes(buf_T *buf,
kv_size(buf->update_callbacks) = j; kv_size(buf->update_callbacks) = j;
} }
void buf_updates_send_splice( void buf_updates_send_splice(buf_T *buf, int start_row, colnr_T start_col, bcount_t start_byte,
buf_T *buf, int old_row, colnr_T old_col, bcount_t old_byte, int new_row,
int start_row, colnr_T start_col, bcount_t start_byte, colnr_T new_col, bcount_t new_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) if (!buf_updates_active(buf)
|| (old_byte == 0 && new_byte == 0)) { || (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) void buf_updates_changedtick_single(buf_T *buf, uint64_t channel_id)
{ {
Array args = ARRAY_DICT_INIT; Array args = ARRAY_DICT_INIT;
args.size = 2; args.size = 2;
args.items = xcalloc(args.size, sizeof(Object)); args.items = xcalloc(args.size, sizeof(Object));
// the first argument is always the buffer handle // the first argument is always the buffer handle
args.items[0] = BUFFER_OBJ(buf->handle); args.items[0] = BUFFER_OBJ(buf->handle);
// next argument is b:changedtick // next argument is b:changedtick
args.items[1] = INTEGER_OBJ(buf_get_changedtick(buf)); args.items[1] = INTEGER_OBJ(buf_get_changedtick(buf));
// don't try and clean up dead channels here // don't try and clean up dead channels here
rpc_send_event(channel_id, "nvim_buf_changedtick_event", args); rpc_send_event(channel_id, "nvim_buf_changedtick_event", args);
} }
void buffer_update_callbacks_free(BufUpdateCallbacks cb) void buffer_update_callbacks_free(BufUpdateCallbacks cb)

View File

@@ -12,12 +12,12 @@
#include "nvim/diff.h" #include "nvim/diff.h"
#include "nvim/edit.h" #include "nvim/edit.h"
#include "nvim/eval.h" #include "nvim/eval.h"
#include "nvim/extmark.h"
#include "nvim/fileio.h" #include "nvim/fileio.h"
#include "nvim/fold.h" #include "nvim/fold.h"
#include "nvim/indent.h" #include "nvim/indent.h"
#include "nvim/indent_c.h" #include "nvim/indent_c.h"
#include "nvim/mark.h" #include "nvim/mark.h"
#include "nvim/extmark.h"
#include "nvim/memline.h" #include "nvim/memline.h"
#include "nvim/misc1.h" #include "nvim/misc1.h"
#include "nvim/move.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); apply_autocmds(EVENT_FILECHANGEDRO, NULL, NULL, false, buf);
buf->b_ro_locked--; buf->b_ro_locked--;
if (!buf->b_p_ro) { if (!buf->b_p_ro) {
return; return;
} }
// Do what msg() does, but with a column offset if the warning should // Do what msg() does, but with a column offset if the warning should
// be after the mode message. // be after the mode message.
msg_start(); msg_start();
if (msg_row == Rows - 1) { if (msg_row == Rows - 1) {
msg_col = col; msg_col = col;
} }
msg_source(HL_ATTR(HLF_W)); msg_source(HL_ATTR(HLF_W));
msg_ext_set_kind("wmsg"); msg_ext_set_kind("wmsg");
@@ -74,7 +74,7 @@ void change_warning(buf_T *buf, int col)
buf->b_did_warn = true; buf->b_did_warn = true;
redraw_cmdline = false; // don't redraw and erase the message redraw_cmdline = false; // don't redraw and erase the message
if (msg_row < Rows - 1) { if (msg_row < Rows - 1) {
showmode(); showmode();
} }
} }
} }
@@ -97,8 +97,7 @@ void changed(void)
// Create a swap file if that is wanted. // Create a swap file if that is wanted.
// Don't do this for "nofile" and "nowrite" buffer types. // Don't do this for "nofile" and "nowrite" buffer types.
if (curbuf->b_may_swap if (curbuf->b_may_swap
&& !bt_dontwrite(curbuf) && !bt_dontwrite(curbuf)) {
) {
bool save_need_wait_return = need_wait_return; bool save_need_wait_return = need_wait_return;
need_wait_return = false; need_wait_return = false;
@@ -140,11 +139,10 @@ void changed_internal(void)
/// Common code for when a change was made. /// Common code for when a change was made.
/// See changed_lines() for the arguments. /// See changed_lines() for the arguments.
/// Careful: may trigger autocommands that reload the buffer. /// Careful: may trigger autocommands that reload the buffer.
static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra)
long xtra)
{ {
int i; int i;
pos_T *p; pos_T *p;
int add; int add;
// mark the buffer as modified // 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. // don't have an entry yet.
if (curbuf->b_new_change || curbuf->b_changelistlen == 0) { if (curbuf->b_new_change || curbuf->b_changelistlen == 0) {
if (curbuf->b_changelistlen == 0) { if (curbuf->b_changelistlen == 0) {
add = true; add = true;
} else { } else {
// Don't create a new entry when the line number is the same // 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 // as the last one and the column is not too far away. Avoids
// creating many entries for typing "xxxxx". // creating many entries for typing "xxxxx".
p = &curbuf->b_changelist[curbuf->b_changelistlen - 1].mark; p = &curbuf->b_changelist[curbuf->b_changelistlen - 1].mark;
if (p->lnum != lnum) { if (p->lnum != lnum) {
add = true; add = true;
} else { } else {
int cols = comp_textwidth(false); int cols = comp_textwidth(false);
if (cols == 0) { if (cols == 0) {
cols = 79; cols = 79;
} }
add = (p->col + cols < col || col + cols < p->col); 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) { if (wp->w_buffer == curbuf) {
// Mark this window to be redrawn later. // Mark this window to be redrawn later.
if (wp->w_redr_type < VALID) { 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 // 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. */ // inserting lines just above a closed fold. */
bool folded = hasFoldingWin(wp, lnum, &lnum, NULL, false, NULL); bool folded = hasFoldingWin(wp, lnum, &lnum, NULL, false, NULL);
if (wp->w_cursor.lnum == lnum) { if (wp->w_cursor.lnum == lnum) {
wp->w_cline_folded = folded; wp->w_cline_folded = folded;
} }
folded = hasFoldingWin(wp, lnume, NULL, &lnume, false, NULL); folded = hasFoldingWin(wp, lnume, NULL, &lnume, false, NULL);
if (wp->w_cursor.lnum == lnume) { 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, // 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) { if (wp->w_cursor.lnum <= lnum) {
i = find_wl_entry(wp, lnum); i = find_wl_entry(wp, lnum);
if (i >= 0 && wp->w_cursor.lnum > wp->w_lines[i].wl_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) { 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) { } 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) { if (wp->w_botline >= lnum) {
// Assume that botline doesn't change (inserted lines make // 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) { if (buf->b_mod_set) {
// find the maximum area that must be redisplayed // find the maximum area that must be redisplayed
if (lnum < buf->b_mod_top) { if (lnum < buf->b_mod_top) {
buf->b_mod_top = lnum; buf->b_mod_top = lnum;
} else if (lnum >= buf->b_mod_bot) { } else if (lnum >= buf->b_mod_bot) {
buf->b_mod_bot = lnum + 1; buf->b_mod_bot = lnum + 1;
} }
} else { } else {
// set the area that must be redisplayed to one line // 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); redraw_later(wp, VALID);
wlnum = diff_lnum_win(lnum, wp); wlnum = diff_lnum_win(lnum, wp);
if (wlnum > 0) { 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. /// When only inserting lines, "lnum" and "lnume" are equal.
/// Takes care of calling changed() and updating b_mod_*. /// Takes care of calling changed() and updating b_mod_*.
/// Careful: may trigger autocommands that reload the buffer. /// Careful: may trigger autocommands that reload the buffer.
void void changed_lines(linenr_T lnum, // first line with change
changed_lines( colnr_T col, // column in first line with change
linenr_T lnum, // first line with change linenr_T lnume, // line below last changed line
colnr_T col, // column in first line with change long xtra, // number of extra lines (negative when deleting)
linenr_T lnume, // line below last changed line bool do_buf_event // some callers like undo/redo call changed_lines()
long xtra, // number of extra lines (negative when deleting) // and then increment changedtick *again*. This flag
bool do_buf_event // some callers like undo/redo call changed_lines() // allows these callers to send the nvim_buf_lines_event
// and then increment changedtick *again*. This flag // events after they're done modifying changedtick.
// allows these callers to send the nvim_buf_lines_event )
// events after they're done modifying changedtick.
)
{ {
changed_lines_buf(curbuf, lnum, lnume, xtra); 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; curwin->w_p_list = old_list;
} else if (oldp[col] != NUL) { } else if (oldp[col] != NUL) {
// normal replace // normal replace
oldlen = (size_t)(*mb_ptr2len)(oldp + col); 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. // show the match for right parens and braces.
if (p_sm && (State & INSERT) if (p_sm && (State & INSERT)
&& msg_silent == 0 && msg_silent == 0
&& !ins_compl_active() && !ins_compl_active()) {
) {
showmatch(utf_ptr2char(buf)); showmatch(utf_ptr2char(buf));
} }
@@ -674,7 +669,7 @@ void ins_char_bytes(char_u *buf, size_t charlen)
/// Caller must have prepared for undo. /// Caller must have prepared for undo.
void ins_str(char_u *s) void ins_str(char_u *s)
{ {
char_u *oldp, *newp; char_u *oldp, *newp;
int newlen = (int)STRLEN(s); int newlen = (int)STRLEN(s);
int oldlen; int oldlen;
colnr_T col; colnr_T col;
@@ -721,7 +716,7 @@ int del_chars(long count, int fixpos)
{ {
int bytes = 0; int bytes = 0;
long i; long i;
char_u *p; char_u *p;
int l; int l;
p = get_cursor_pos_ptr(); 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, // fixpos is true, we don't want to end up positioned at the NUL,
// unless "restart_edit" is set or 'virtualedit' contains "onemore". // unless "restart_edit" is set or 'virtualedit' contains "onemore".
if (col > 0 && fixpos && restart_edit == 0 if (col > 0 && fixpos && restart_edit == 0
&& (ve_flags & VE_ONEMORE) == 0 && (ve_flags & VE_ONEMORE) == 0) {
) {
curwin->w_cursor.col--; curwin->w_cursor.col--;
curwin->w_cursor.coladd = 0; curwin->w_cursor.coladd = 0;
curwin->w_cursor.col -= utf_head_off(oldp, oldp + curwin->w_cursor.col); 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 /// OPENLINE_COM_LIST
/// ///
/// @return true on success, false on failure /// @return true on success, false on failure
int open_line( int open_line(int dir, // FORWARD or BACKWARD
int dir, // FORWARD or BACKWARD int flags, int second_line_indent)
int flags,
int second_line_indent
)
{ {
char_u *next_line = NULL; // copy of the next line char_u *next_line = NULL; // copy of the next line
char_u *p_extra = NULL; // what goes to 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 // the line, replacing what was there before and pushing the right
// stuff onto the replace stack. -- webb. // stuff onto the replace stack. -- webb.
if (curwin->w_cursor.lnum < orig_line_count) { 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 { } 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 // In VREPLACE mode, a NL replaces the rest of the line, and starts
@@ -1023,8 +1014,7 @@ int open_line(
} }
if ((State & INSERT) if ((State & INSERT)
&& !(State & VREPLACE_FLAG) && !(State & VREPLACE_FLAG)) {
) {
p_extra = saved_line + curwin->w_cursor.col; p_extra = saved_line + curwin->w_cursor.col;
if (do_si) { // need first char after new line break if (do_si) { // need first char after new line break
p = skipwhite(p_extra); 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 // 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. // set because automatically inserting a comment leader also sets did_ai.
if (dir == FORWARD && 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 // If 'autoindent' and/or 'smartindent' is set, try to figure out what
// indent to use for the new line. // indent to use for the new line.
if (curbuf->b_p_ai if (curbuf->b_p_ai
|| do_si || do_si) {
) {
// count white space on current line // count white space on current line
newindent = get_indent_str_vtab(saved_line, newindent = get_indent_str_vtab(saved_line,
curbuf->b_p_ts, curbuf->b_p_ts,
@@ -1066,15 +1055,15 @@ int open_line(
// "if (condition) {" // "if (condition) {"
if (!trunc_line && do_si && *saved_line != NUL if (!trunc_line && do_si && *saved_line != NUL
&& (p_extra == NULL || first_char != '{')) { && (p_extra == NULL || first_char != '{')) {
char_u *ptr; char_u *ptr;
char_u last_char; char_u last_char;
old_cursor = curwin->w_cursor; old_cursor = curwin->w_cursor;
ptr = saved_line; ptr = saved_line;
if (flags & OPENLINE_DO_COM) { if (flags & OPENLINE_DO_COM) {
lead_len = get_leader_len(ptr, NULL, false, true); lead_len = get_leader_len(ptr, NULL, false, true);
} else { } else {
lead_len = 0; lead_len = 0;
} }
if (dir == FORWARD) { if (dir == FORWARD) {
// Skip preprocessor directives, unless they are // Skip preprocessor directives, unless they are
@@ -1119,17 +1108,17 @@ int open_line(
// Find last non-blank in line // Find last non-blank in line
p = ptr + STRLEN(ptr) - 1; p = ptr + STRLEN(ptr) - 1;
while (p > ptr && ascii_iswhite(*p)) { while (p > ptr && ascii_iswhite(*p)) {
p--; p--;
} }
last_char = *p; last_char = *p;
// find the character just before the '{' or ';' // find the character just before the '{' or ';'
if (last_char == '{' || last_char == ';') { if (last_char == '{' || last_char == ';') {
if (p > ptr) { if (p > ptr) {
p--; p--;
} }
while (p > ptr && ascii_iswhite(*p)) { while (p > ptr && ascii_iswhite(*p)) {
p--; p--;
} }
} }
// Try to catch lines that are split over multiple // Try to catch lines that are split over multiple
@@ -1151,12 +1140,12 @@ int open_line(
if (last_char == '{') { if (last_char == '{') {
did_si = true; // do indent did_si = true; // do indent
no_si = true; // don't delete it when '{' typed no_si = true; // don't delete it when '{' typed
// Look for "if" and the like, use 'cinwords'. // Look for "if" and the like, use 'cinwords'.
// Don't do this if the previous line ended in ';' or // Don't do this if the previous line ended in ';' or
// '}'. // '}'.
} else if (last_char != ';' && last_char != '}' } else if (last_char != ';' && last_char != '}'
&& cin_is_cinword(ptr)) { && cin_is_cinword(ptr)) {
did_si = true; did_si = true;
} }
} }
} else { // dir == BACKWARD } else { // dir == BACKWARD
@@ -1205,15 +1194,15 @@ int open_line(
lead_len = 0; lead_len = 0;
} }
if (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 int lead_repl_len = 0; // length of *lead_repl
char_u lead_middle[COM_MAX_LEN]; // middle-comment string char_u lead_middle[COM_MAX_LEN]; // middle-comment string
char_u lead_end[COM_MAX_LEN]; // end-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 extra_space = false; // append extra space
int current_flag; int current_flag;
int require_blank = false; // requires blank after middle 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 // If the comment leader has the start, middle or end flag, it may not
// be used or may be replaced with the middle leader. // 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. // Doing "O" on the end of a comment inserts the middle leader.
// Find the string for the middle leader, searching backwards. // Find the string for the middle leader, searching backwards.
while (p > curbuf->b_p_com && *p != ',') { while (p > curbuf->b_p_com && *p != ',') {
p--; p--;
} }
for (lead_repl = p; lead_repl > curbuf->b_p_com for (lead_repl = p; lead_repl > curbuf->b_p_com
&& lead_repl[-1] != ':'; lead_repl--) { && lead_repl[-1] != ':'; lead_repl--) {
@@ -1318,13 +1307,13 @@ int open_line(
// Check whether we allow automatic ending of comments // Check whether we allow automatic ending of comments
for (p2 = p; *p2 && *p2 != ':'; p2++) { for (p2 = p; *p2 && *p2 != ':'; p2++) {
if (*p2 == COM_AUTO_END) { 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) { if (end_comment_pending == -1) {
// Find last character in end-comment string // Find last character in end-comment string
while (*p2 && *p2 != ',') { while (*p2 && *p2 != ',') {
p2++; p2++;
} }
end_comment_pending = p2[-1]; end_comment_pending = p2[-1];
} }
@@ -1334,7 +1323,7 @@ int open_line(
// Comment leader for first line only: Don't repeat leader // Comment leader for first line only: Don't repeat leader
// when using "O", blank out leader when using "o". // when using "O", blank out leader when using "o".
if (dir == BACKWARD) { if (dir == BACKWARD) {
lead_len = 0; lead_len = 0;
} else { } else {
lead_repl = (char_u *)""; lead_repl = (char_u *)"";
lead_repl_len = 0; lead_repl_len = 0;
@@ -1345,11 +1334,11 @@ int open_line(
if (lead_len > 0) { if (lead_len > 0) {
// allocate buffer (may concatenate p_extra later) // allocate buffer (may concatenate p_extra later)
int bytes = lead_len int bytes = lead_len
+ lead_repl_len + lead_repl_len
+ extra_space + extra_space
+ extra_len + extra_len
+ (second_line_indent > 0 ? second_line_indent : 0) + (second_line_indent > 0 ? second_line_indent : 0)
+ 1; + 1;
assert(bytes >= 0); assert(bytes >= 0);
leader = xmalloc((size_t)bytes); leader = xmalloc((size_t)bytes);
allocated = leader; // remember to free it later allocated = leader; // remember to free it later
@@ -1363,11 +1352,11 @@ int open_line(
for (p = lead_flags; *p != NUL && *p != ':'; ) { for (p = lead_flags; *p != NUL && *p != ':'; ) {
if (*p == COM_RIGHT || *p == COM_LEFT) { if (*p == COM_RIGHT || *p == COM_LEFT) {
c = *p++; c = *p++;
} else if (ascii_isdigit(*p) || *p == '-') { } else if (ascii_isdigit(*p) || *p == '-') {
off = getdigits_int(&p, true, 0); off = getdigits_int(&p, true, 0);
} else { } else {
p++; p++;
} }
} }
if (c == COM_RIGHT) { // right adjusted leader if (c == COM_RIGHT) { // right adjusted leader
@@ -1383,7 +1372,7 @@ int open_line(
int repl_size = vim_strnsize(lead_repl, int repl_size = vim_strnsize(lead_repl,
lead_repl_len); lead_repl_len);
int old_size = 0; int old_size = 0;
char_u *endp = p; char_u *endp = p;
int l; int l;
while (old_size < repl_size && p > leader) { while (old_size < repl_size && p > leader) {
@@ -1392,14 +1381,14 @@ int open_line(
} }
l = lead_repl_len - (int)(endp - p); l = lead_repl_len - (int)(endp - p);
if (l != 0) { if (l != 0) {
memmove(endp + l, endp, memmove(endp + l, endp,
(size_t)((leader + lead_len) - endp)); (size_t)((leader + lead_len) - endp));
} }
lead_len += l; lead_len += l;
} }
memmove(p, lead_repl, (size_t)lead_repl_len); memmove(p, lead_repl, (size_t)lead_repl_len);
if (p + lead_repl_len > leader + lead_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. // blank-out any other chars from the old leader.
@@ -1417,7 +1406,7 @@ int open_line(
lead_len -= l; lead_len -= l;
*p = ' '; *p = ' ';
} else if (!ascii_iswhite(*p)) { } else if (!ascii_iswhite(*p)) {
*p = ' '; *p = ' ';
} }
} }
} else { // left adjusted leader } else { // left adjusted leader
@@ -1434,12 +1423,12 @@ int open_line(
for (i = 0; i < lead_len && p[i] != NUL; i += l) { for (i = 0; i < lead_len && p[i] != NUL; i += l) {
l = (*mb_ptr2len)(p + i); l = (*mb_ptr2len)(p + i);
if (vim_strnsize(p, i + l) > repl_size) { if (vim_strnsize(p, i + l) > repl_size) {
break; break;
} }
} }
if (i != lead_repl_len) { if (i != lead_repl_len) {
memmove(p + lead_repl_len, p + i, memmove(p + lead_repl_len, p + i,
(size_t)(lead_len - i - (p - leader))); (size_t)(lead_len - i - (p - leader)));
lead_len += lead_repl_len - i; lead_len += lead_repl_len - i;
} }
} }
@@ -1476,8 +1465,7 @@ int open_line(
// Recompute the indent, it may have changed. // Recompute the indent, it may have changed.
if (curbuf->b_p_ai if (curbuf->b_p_ai
|| do_si || do_si) {
) {
newindent = get_indent_str_vtab(leader, newindent = get_indent_str_vtab(leader,
curbuf->b_p_ts, curbuf->b_p_ts,
curbuf->b_p_vts_array, false); curbuf->b_p_vts_array, false);
@@ -1497,7 +1485,7 @@ int open_line(
&& leader[lead_len - 1] == ' ') { && leader[lead_len - 1] == ' ') {
// Don't do it when there is a tab before the space // Don't do it when there is a tab before the space
if (vim_strchr(skipwhite(leader), '\t') != NULL) { if (vim_strchr(skipwhite(leader), '\t') != NULL) {
break; break;
} }
lead_len--; lead_len--;
off--; off--;
@@ -1506,7 +1494,7 @@ int open_line(
// If the leader ends in white space, don't add an // If the leader ends in white space, don't add an
// extra space // extra space
if (lead_len > 0 && ascii_iswhite(leader[lead_len - 1])) { if (lead_len > 0 && ascii_iswhite(leader[lead_len - 1])) {
extra_space = false; extra_space = false;
} }
leader[lead_len] = NUL; leader[lead_len] = NUL;
} }
@@ -1521,8 +1509,7 @@ int open_line(
// if a new indent will be set below, remove the indent that // if a new indent will be set below, remove the indent that
// is in the comment leader // is in the comment leader
if (newindent if (newindent
|| did_si || did_si) {
) {
while (lead_len && ascii_iswhite(*leader)) { while (lead_len && ascii_iswhite(*leader)) {
lead_len--; lead_len--;
newcol--; newcol--;
@@ -1559,7 +1546,7 @@ int open_line(
// When in REPLACE mode, put the deleted blanks on the replace stack, // 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. // preceded by a NUL, so they can be put back when a BS is entered.
if (REPLACE_NORMAL(State)) { 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)) { if (curbuf->b_p_ai || (flags & OPENLINE_DELSPACES)) {
while ((*p_extra == ' ' || *p_extra == '\t') while ((*p_extra == ' ' || *p_extra == '\t')
@@ -1577,7 +1564,7 @@ int open_line(
} }
if (p_extra == NULL) { 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 // concatenate leader and p_extra, if there is a leader
@@ -1641,8 +1628,7 @@ int open_line(
inhibit_delete_count++; inhibit_delete_count++;
if (newindent if (newindent
|| did_si || did_si) {
) {
curwin->w_cursor.lnum++; curwin->w_cursor.lnum++;
if (did_si) { if (did_si) {
int sw = get_sw_value(curbuf); int sw = get_sw_value(curbuf);
@@ -1706,9 +1692,8 @@ int open_line(
// TODO(vigoux): maybe there is issues there with expandtabs ? // TODO(vigoux): maybe there is issues there with expandtabs ?
int cols_spliced = 0; int cols_spliced = 0;
if (new_len < curwin->w_cursor.col) { if (new_len < curwin->w_cursor.col) {
extmark_splice_cols( extmark_splice_cols(curbuf, (int)curwin->w_cursor.lnum - 1,
curbuf, (int)curwin->w_cursor.lnum - 1, new_len, curwin->w_cursor.col - new_len, 0, kExtmarkUndo);
new_len, curwin->w_cursor.col - new_len, 0, kExtmarkUndo);
cols_spliced = curwin->w_cursor.col - new_len; cols_spliced = curwin->w_cursor.col - new_len;
} }
@@ -1815,7 +1800,7 @@ theend:
/// If "fixpos" is true fix the cursor position when done. /// If "fixpos" is true fix the cursor position when done.
void truncate_line(int fixpos) void truncate_line(int fixpos)
{ {
char_u *newp; char_u *newp;
linenr_T lnum = curwin->w_cursor.lnum; linenr_T lnum = curwin->w_cursor.lnum;
colnr_T col = curwin->w_cursor.col; 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; linenr_T first = curwin->w_cursor.lnum;
if (nlines <= 0) { if (nlines <= 0) {
return; return;
} }
// save the deleted lines for undo // save the deleted lines for undo
if (undo && u_savedel(first, nlines) == FAIL) { if (undo && u_savedel(first, nlines) == FAIL) {
return; return;
} }
for (n = 0; n < nlines; ) { 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 we delete the last line in the file, stop
if (first > curbuf->b_ml.ml_line_count) { if (first > curbuf->b_ml.ml_line_count) {
break; break;
} }
} }

View File

@@ -12,11 +12,11 @@
#include "nvim/msgpack_rpc/server.h" #include "nvim/msgpack_rpc/server.h"
#include "nvim/os/shell.h" #include "nvim/os/shell.h"
#ifdef WIN32 #ifdef WIN32
# include "nvim/os/pty_conpty_win.h"
# include "nvim/os/os_win_console.h" # include "nvim/os/os_win_console.h"
# include "nvim/os/pty_conpty_win.h"
#endif #endif
#include "nvim/path.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/path.h"
static bool did_stdio = false; 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) { if (part == kChannelPartRpc || part == kChannelPartAll) {
close_main = true; close_main = true;
if (chan->is_rpc) { if (chan->is_rpc) {
rpc_close(chan); rpc_close(chan);
} else if (part == kChannelPartRpc) { } else if (part == kChannelPartRpc) {
*error = (const char *)e_invstream; *error = (const char *)e_invstream;
return false; return false;
@@ -78,68 +78,68 @@ bool channel_close(uint64_t id, ChannelPart part, const char **error)
} }
switch (chan->streamtype) { switch (chan->streamtype) {
case kChannelStreamSocket: case kChannelStreamSocket:
if (!close_main) { if (!close_main) {
*error = (const char *)e_invstream; *error = (const char *)e_invstream;
return false; return false;
} }
stream_may_close(&chan->stream.socket); stream_may_close(&chan->stream.socket);
break; break;
case kChannelStreamProc: case kChannelStreamProc:
proc = (Process *)&chan->stream.proc; proc = (Process *)&chan->stream.proc;
if (part == kChannelPartStdin || close_main) { if (part == kChannelPartStdin || close_main) {
stream_may_close(&proc->in); stream_may_close(&proc->in);
} }
if (part == kChannelPartStdout || close_main) { if (part == kChannelPartStdout || close_main) {
stream_may_close(&proc->out); stream_may_close(&proc->out);
} }
if (part == kChannelPartStderr || part == kChannelPartAll) { if (part == kChannelPartStderr || part == kChannelPartAll) {
stream_may_close(&proc->err); stream_may_close(&proc->err);
} }
if (proc->type == kProcessTypePty && part == kChannelPartAll) { if (proc->type == kProcessTypePty && part == kChannelPartAll) {
pty_process_close_master(&chan->stream.pty); pty_process_close_master(&chan->stream.pty);
} }
break; break;
case kChannelStreamStdio: case kChannelStreamStdio:
if (part == kChannelPartStdin || close_main) { if (part == kChannelPartStdin || close_main) {
stream_may_close(&chan->stream.stdio.in); stream_may_close(&chan->stream.stdio.in);
} }
if (part == kChannelPartStdout || close_main) { if (part == kChannelPartStdout || close_main) {
stream_may_close(&chan->stream.stdio.out); stream_may_close(&chan->stream.stdio.out);
} }
if (part == kChannelPartStderr) { if (part == kChannelPartStderr) {
*error = (const char *)e_invstream; *error = (const char *)e_invstream;
return false; return false;
} }
break; break;
case kChannelStreamStderr: case kChannelStreamStderr:
if (part != kChannelPartAll && part != kChannelPartStderr) { if (part != kChannelPartAll && part != kChannelPartStderr) {
*error = (const char *)e_invstream; *error = (const char *)e_invstream;
return false; 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);
} }
if (!chan->stream.err.closed) { channel_decref(chan);
chan->stream.err.closed = true; }
// Don't close on exit, in case late error messages break;
if (!exiting) {
fclose(stderr);
}
channel_decref(chan);
}
break;
case kChannelStreamInternal: case kChannelStreamInternal:
if (!close_main) { if (!close_main) {
*error = (const char *)e_invstream; *error = (const char *)e_invstream;
return false; return false;
} }
break; break;
default: default:
abort(); abort();
} }
return true; return true;
@@ -301,12 +301,10 @@ static void close_cb(Stream *stream, void *data)
/// < 0 if the job can't start /// < 0 if the job can't start
/// ///
/// @returns [allocated] channel /// @returns [allocated] channel
Channel *channel_job_start(char **argv, CallbackReader on_stdout, Channel *channel_job_start(char **argv, CallbackReader on_stdout, CallbackReader on_stderr,
CallbackReader on_stderr, Callback on_exit, Callback on_exit, bool pty, bool rpc, bool overlapped, bool detach,
bool pty, bool rpc, bool overlapped, bool detach, ChannelStdinMode stdin_mode, const char *cwd, uint16_t pty_width,
ChannelStdinMode stdin_mode, const char *cwd, uint16_t pty_height, dict_T *env, varnumber_T *status_out)
uint16_t pty_width, uint16_t pty_height,
dict_T *env, varnumber_T *status_out)
{ {
assert(cwd == NULL || os_isdir_executable(cwd)); 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, uint64_t channel_connect(bool tcp, const char *address, bool rpc, CallbackReader on_output,
bool rpc, CallbackReader on_output,
int timeout, const char **error) int timeout, const char **error)
{ {
Channel *channel; Channel *channel;
@@ -470,8 +467,7 @@ void channel_from_connection(SocketWatcher *watcher)
/// Creates an API channel from stdin/stdout. This is used when embedding /// Creates an API channel from stdin/stdout. This is used when embedding
/// Neovim /// Neovim
uint64_t channel_from_stdio(bool rpc, CallbackReader on_output, uint64_t channel_from_stdio(bool rpc, CallbackReader on_output, const char **error)
const char **error)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
if (!headless_mode && !embedded_mode) { if (!headless_mode && !embedded_mode) {
@@ -514,8 +510,7 @@ uint64_t channel_from_stdio(bool rpc, CallbackReader on_output,
} }
/// @param data will be consumed /// @param data will be consumed
size_t channel_send(uint64_t id, char *data, size_t len, size_t channel_send(uint64_t id, char *data, size_t len, bool data_owned, const char **error)
bool data_owned, const char **error)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
Channel *chan = find_channel(id); 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; return l;
} }
void on_channel_data(Stream *stream, RBuffer *buf, size_t count, void on_channel_data(Stream *stream, RBuffer *buf, size_t count, void *data, bool eof)
void *data, bool eof)
{ {
Channel *chan = data; Channel *chan = data;
on_channel_output(stream, chan, buf, count, eof, &chan->on_data); on_channel_output(stream, chan, buf, count, eof, &chan->on_data);
} }
void on_job_stderr(Stream *stream, RBuffer *buf, size_t count, void on_job_stderr(Stream *stream, RBuffer *buf, size_t count, void *data, bool eof)
void *data, bool eof)
{ {
Channel *chan = data; Channel *chan = data;
on_channel_output(stream, chan, buf, count, eof, &chan->on_stderr); on_channel_output(stream, chan, buf, count, eof, &chan->on_stderr);
} }
static void on_channel_output(Stream *stream, Channel *chan, RBuffer *buf, static void on_channel_output(Stream *stream, Channel *chan, RBuffer *buf, size_t count, bool eof,
size_t count, bool eof, CallbackReader *reader) CallbackReader *reader)
{ {
// stub variable, to keep reading consistent with the order of events, only // stub variable, to keep reading consistent with the order of events, only
// consider the count parameter. // consider the count parameter.
@@ -852,43 +845,43 @@ Dictionary channel_info(uint64_t id)
const char *stream_desc, *mode_desc; const char *stream_desc, *mode_desc;
switch (chan->streamtype) { switch (chan->streamtype) {
case kChannelStreamProc: { case kChannelStreamProc: {
stream_desc = "job"; stream_desc = "job";
if (chan->stream.proc.type == kProcessTypePty) { if (chan->stream.proc.type == kProcessTypePty) {
const char *name = pty_process_tty_name(&chan->stream.pty); const char *name = pty_process_tty_name(&chan->stream.pty);
PUT(info, "pty", STRING_OBJ(cstr_to_string(name))); 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++;
}
}
PUT(info, "argv", ARRAY_OBJ(argv));
break;
} }
case kChannelStreamStdio: char **p = chan->stream.proc.argv;
stream_desc = "stdio"; Array argv = ARRAY_DICT_INIT;
break; if (p != NULL) {
while (*p != NULL) {
ADD(argv, STRING_OBJ(cstr_to_string(*p)));
p++;
}
}
PUT(info, "argv", ARRAY_OBJ(argv));
break;
}
case kChannelStreamStderr: case kChannelStreamStdio:
stream_desc = "stderr"; stream_desc = "stdio";
break; break;
case kChannelStreamInternal: case kChannelStreamStderr:
PUT(info, "internal", BOOLEAN_OBJ(true)); stream_desc = "stderr";
FALLTHROUGH; break;
case kChannelStreamSocket: case kChannelStreamInternal:
stream_desc = "socket"; PUT(info, "internal", BOOLEAN_OBJ(true));
break; FALLTHROUGH;
default: case kChannelStreamSocket:
abort(); stream_desc = "socket";
break;
default:
abort();
} }
PUT(info, "stream", STRING_OBJ(cstr_to_string(stream_desc))); PUT(info, "stream", STRING_OBJ(cstr_to_string(stream_desc)));

View File

@@ -6,14 +6,15 @@
/// Code related to character sets. /// Code related to character sets.
#include <assert.h> #include <assert.h>
#include <inttypes.h>
#include <string.h> #include <string.h>
#include <wctype.h> #include <wctype.h>
#include <inttypes.h>
#include "nvim/vim.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/charset.h" #include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/func_attr.h" #include "nvim/func_attr.h"
#include "nvim/garray.h"
#include "nvim/indent.h" #include "nvim/indent.h"
#include "nvim/main.h" #include "nvim/main.h"
#include "nvim/mark.h" #include "nvim/mark.h"
@@ -21,15 +22,14 @@
#include "nvim/memline.h" #include "nvim/memline.h"
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/misc1.h" #include "nvim/misc1.h"
#include "nvim/garray.h"
#include "nvim/move.h" #include "nvim/move.h"
#include "nvim/option.h" #include "nvim/option.h"
#include "nvim/os_unix.h" #include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/plines.h" #include "nvim/plines.h"
#include "nvim/state.h" #include "nvim/state.h"
#include "nvim/strings.h" #include "nvim/strings.h"
#include "nvim/path.h" #include "nvim/vim.h"
#include "nvim/cursor.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "charset.c.generated.h" # 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 // b_chartab[] is an array with 256 bits, each bit representing one of the
// characters 0-255. // characters 0-255.
#define SET_CHARTAB(buf, c) \ #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) \ #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) \ #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 // Table used below, see init_chartab() for an explanation
static char_u g_chartab[256]; static char_u g_chartab[256];
@@ -212,7 +212,7 @@ int buf_init_chartab(buf_T *buf, int global)
if (i == 0) { if (i == 0) {
// (re)set ID flag // (re)set ID flag
if (tilde) { if (tilde) {
g_chartab[c] &= (uint8_t)~CT_ID_CHAR; g_chartab[c] &= (uint8_t) ~CT_ID_CHAR;
} else { } else {
g_chartab[c] |= CT_ID_CHAR; g_chartab[c] |= CT_ID_CHAR;
} }
@@ -224,7 +224,7 @@ int buf_init_chartab(buf_T *buf, int global)
if (tilde) { if (tilde) {
g_chartab[c] = (uint8_t)((g_chartab[c] & ~CT_CELL_MASK) g_chartab[c] = (uint8_t)((g_chartab[c] & ~CT_CELL_MASK)
+ ((dy_flags & DY_UHEX) ? 4 : 2)); + ((dy_flags & DY_UHEX) ? 4 : 2));
g_chartab[c] &= (uint8_t)~CT_PRINT_CHAR; g_chartab[c] &= (uint8_t) ~CT_PRINT_CHAR;
} else { } else {
g_chartab[c] = (uint8_t)((g_chartab[c] & ~CT_CELL_MASK) + 1); g_chartab[c] = (uint8_t)((g_chartab[c] & ~CT_CELL_MASK) + 1);
g_chartab[c] |= CT_PRINT_CHAR; g_chartab[c] |= CT_PRINT_CHAR;
@@ -233,7 +233,7 @@ int buf_init_chartab(buf_T *buf, int global)
} else if (i == 2) { } else if (i == 2) {
// (re)set fname flag // (re)set fname flag
if (tilde) { if (tilde) {
g_chartab[c] &= (uint8_t)~CT_FNAME_CHAR; g_chartab[c] &= (uint8_t) ~CT_FNAME_CHAR;
} else { } else {
g_chartab[c] |= CT_FNAME_CHAR; g_chartab[c] |= CT_FNAME_CHAR;
} }
@@ -417,7 +417,7 @@ char *transstr(const char *const s)
/// ///
/// When "buf" is NULL, return an allocated string. /// When "buf" is NULL, return an allocated string.
/// Otherwise, put the result in buf, limited by buflen, and return buf. /// 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 FUNC_ATTR_NONNULL_RET
{ {
garray_T ga; garray_T ga;
@@ -906,12 +906,11 @@ bool in_win_border(win_T *wp, colnr_T vcol)
/// @param start /// @param start
/// @param cursor /// @param cursor
/// @param end /// @param end
void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *end)
colnr_T *end)
{ {
colnr_T vcol; colnr_T vcol;
char_u *ptr; // points to current char 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 char_u *line; // start of the line
int incr; int incr;
int head; int head;
@@ -1059,8 +1058,7 @@ colnr_T getvcol_nolist(pos_T *posp)
/// @param start /// @param start
/// @param cursor /// @param cursor
/// @param end /// @param end
void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *end)
colnr_T *end)
{ {
colnr_T col; colnr_T col;
colnr_T coladd; colnr_T coladd;
@@ -1115,8 +1113,7 @@ void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor,
/// @param pos2 /// @param pos2
/// @param left /// @param left
/// @param right /// @param right
void getvcols(win_T *wp, pos_T *pos1, pos_T *pos2, colnr_T *left, void getvcols(win_T *wp, pos_T *pos1, pos_T *pos2, colnr_T *left, colnr_T *right)
colnr_T *right)
{ {
colnr_T from1; colnr_T from1;
colnr_T from2; colnr_T from2;
@@ -1212,7 +1209,7 @@ char_u *skipdigits(const char_u *q)
/// @param q pointer to string /// @param q pointer to string
/// ///
/// @return Pointer to the character after the skipped digits. /// @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_PURE
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
FUNC_ATTR_NONNULL_RET 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 /// @return Pointer to the character after the skipped digits and hex
/// characters. /// characters.
char_u* skiphex(char_u *q) char_u * skiphex(char_u *q)
{ {
char_u *p = q; char_u *p = q;
while (ascii_isxdigit(*p)) { while (ascii_isxdigit(*p)) {
@@ -1246,7 +1243,7 @@ char_u* skiphex(char_u *q)
/// @param q /// @param q
/// ///
/// @return Pointer to the digit or (NUL after the string). /// @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; char_u *p = q;
while (*p != NUL && !ascii_isdigit(*p)) { while (*p != NUL && !ascii_isdigit(*p)) {
@@ -1261,7 +1258,7 @@ char_u* skiptodigit(char_u *q)
/// @param q pointer to string /// @param q pointer to string
/// ///
/// @return Pointer to the binary character or (NUL after the 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_PURE
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
FUNC_ATTR_NONNULL_RET FUNC_ATTR_NONNULL_RET
@@ -1279,7 +1276,7 @@ const char* skiptobin(const char *q)
/// @param q /// @param q
/// ///
/// @return Pointer to the hex character or (NUL after the string). /// @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; char_u *p = q;
while (*p != NUL && !ascii_isxdigit(*p)) { while (*p != NUL && !ascii_isxdigit(*p)) {
@@ -1308,7 +1305,7 @@ char_u *skiptowhite(const char_u *p)
/// @param p /// @param p
/// ///
/// @return Pointer to the next whitespace character. /// @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) { while (*p != ' ' && *p != '\t' && *p != NUL) {
if (((*p == '\\') || (*p == Ctrl_V)) && (*(p + 1) != NUL)) { if (((*p == '\\') || (*p == Ctrl_V)) && (*(p + 1) != NUL)) {
++p; ++p;
@@ -1440,14 +1437,14 @@ bool vim_isblankline(char_u *lbuf)
/// @param strict If true, fail if the number has unexpected trailing /// @param strict If true, fail if the number has unexpected trailing
/// alpha-numeric chars: *len is set to 0 and nothing else is /// alpha-numeric chars: *len is set to 0 and nothing else is
/// returned. /// returned.
void vim_str2nr(const char_u *const start, int *const prep, int *const len, void vim_str2nr(const char_u *const start, int *const prep, int *const len, const int what,
const int what, varnumber_T *const nptr, varnumber_T *const nptr, uvarnumber_T *const unptr, const int maxlen,
uvarnumber_T *const unptr, const int maxlen, const bool strict) const bool strict)
FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_NONNULL_ARG(1)
{ {
const char *ptr = (const char *)start; const char *ptr = (const char *)start;
#define STRING_ENDED(ptr) \ #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 int pre = 0; // default is decimal
const bool negative = (ptr[0] == '-'); const bool negative = (ptr[0] == '-');
uvarnumber_T un = 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 // When forcing main consideration is skipping the prefix. Decimal numbers
// have no prefixes to skip. pre is not set. // have no prefixes to skip. pre is not set.
switch (what & ~(STR2NR_FORCE | STR2NR_QUOTE)) { switch (what & ~(STR2NR_FORCE | STR2NR_QUOTE)) {
case STR2NR_HEX: { case STR2NR_HEX:
if (!STRING_ENDED(ptr + 2) if (!STRING_ENDED(ptr + 2)
&& ptr[0] == '0' && ptr[0] == '0'
&& (ptr[1] == 'x' || ptr[1] == 'X') && (ptr[1] == 'x' || ptr[1] == 'X')
&& ascii_isxdigit(ptr[2])) { && ascii_isxdigit(ptr[2])) {
ptr += 2; ptr += 2;
}
goto vim_str2nr_hex;
} }
case STR2NR_BIN: { goto vim_str2nr_hex;
if (!STRING_ENDED(ptr + 2) case STR2NR_BIN:
&& ptr[0] == '0' if (!STRING_ENDED(ptr + 2)
&& (ptr[1] == 'b' || ptr[1] == 'B') && ptr[0] == '0'
&& ascii_isbdigit(ptr[2])) { && (ptr[1] == 'b' || ptr[1] == 'B')
ptr += 2; && ascii_isbdigit(ptr[2])) {
} ptr += 2;
goto vim_str2nr_bin;
} }
// Make STR2NR_OOCT work the same as STR2NR_OCT when forcing. goto vim_str2nr_bin;
case STR2NR_OCT: // Make STR2NR_OOCT work the same as STR2NR_OCT when forcing.
case STR2NR_OOCT: case STR2NR_OCT:
case STR2NR_OCT | STR2NR_OOCT: { case STR2NR_OOCT:
if (!STRING_ENDED(ptr + 2) case STR2NR_OCT | STR2NR_OOCT:
&& ptr[0] == '0' if (!STRING_ENDED(ptr + 2)
&& (ptr[1] == 'o' || ptr[1] == 'O') && ptr[0] == '0'
&& ascii_isodigit(ptr[2])) { && (ptr[1] == 'o' || ptr[1] == 'O')
ptr += 2; && ascii_isodigit(ptr[2])) {
} ptr += 2;
goto vim_str2nr_oct;
}
case 0: {
goto vim_str2nr_dec;
}
default: {
abort();
} }
goto vim_str2nr_oct;
case 0:
goto vim_str2nr_dec;
default:
abort();
} }
} else if ((what & (STR2NR_HEX | STR2NR_OCT | STR2NR_OOCT | STR2NR_BIN)) } else if ((what & (STR2NR_HEX | STR2NR_OCT | STR2NR_OOCT | STR2NR_BIN))
&& !STRING_ENDED(ptr + 1) && ptr[0] == '0' && ptr[1] != '8' && !STRING_ENDED(ptr + 1) && ptr[0] == '0' && ptr[1] != '8'

View File

@@ -3,13 +3,13 @@
// Context: snapshot of the entire editor state as one big object/map // 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/context.h"
#include "nvim/eval/encode.h" #include "nvim/eval/encode.h"
#include "nvim/ex_docmd.h" #include "nvim/ex_docmd.h"
#include "nvim/option.h" #include "nvim/option.h"
#include "nvim/shada.h" #include "nvim/shada.h"
#include "nvim/api/vim.h"
#include "nvim/api/private/helpers.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "context.c.generated.h" # include "context.c.generated.h"

View File

@@ -1,25 +1,25 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check // 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 // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <stdbool.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdbool.h>
#include "nvim/ascii.h"
#include "nvim/assert.h" #include "nvim/assert.h"
#include "nvim/change.h" #include "nvim/change.h"
#include "nvim/cursor.h"
#include "nvim/charset.h" #include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/extmark.h"
#include "nvim/fold.h" #include "nvim/fold.h"
#include "nvim/mark.h"
#include "nvim/memline.h" #include "nvim/memline.h"
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/misc1.h" #include "nvim/misc1.h"
#include "nvim/move.h" #include "nvim/move.h"
#include "nvim/plines.h" #include "nvim/plines.h"
#include "nvim/screen.h" #include "nvim/screen.h"
#include "nvim/extmark.h"
#include "nvim/state.h" #include "nvim/state.h"
#include "nvim/vim.h" #include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/mark.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "cursor.c.generated.h" # include "cursor.c.generated.h"
@@ -63,7 +63,7 @@ int coladvance_force(colnr_T wcol)
if (wcol == MAXCOL) { if (wcol == MAXCOL) {
curwin->w_valid &= ~VALID_VIRTCOL; curwin->w_valid &= ~VALID_VIRTCOL;
} else { } else {
/* Virtcol is valid */ // Virtcol is valid
curwin->w_valid |= VALID_VIRTCOL; curwin->w_valid |= VALID_VIRTCOL;
curwin->w_virtcol = wcol; curwin->w_virtcol = wcol;
} }
@@ -83,27 +83,25 @@ int coladvance(colnr_T wcol)
{ {
int rc = getvpos(&curwin->w_cursor, wcol); int rc = getvpos(&curwin->w_cursor, wcol);
if (wcol == MAXCOL || rc == FAIL) if (wcol == MAXCOL || rc == FAIL) {
curwin->w_valid &= ~VALID_VIRTCOL; curwin->w_valid &= ~VALID_VIRTCOL;
else if (*get_cursor_pos_ptr() != TAB) { } else if (*get_cursor_pos_ptr() != TAB) {
/* Virtcol is valid when not on a TAB */ // Virtcol is valid when not on a TAB
curwin->w_valid |= VALID_VIRTCOL; curwin->w_valid |= VALID_VIRTCOL;
curwin->w_virtcol = wcol; curwin->w_virtcol = wcol;
} }
return rc; return rc;
} }
static int coladvance2( static int coladvance2(pos_T *pos, bool addspaces, // change the text to achieve our goal?
pos_T *pos, bool finetune, // change char offset for the exact column
bool addspaces, // change the text to achieve our goal? colnr_T wcol_arg // column to move to (can be negative)
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; colnr_T wcol = wcol_arg;
int idx; int idx;
char_u *ptr; char_u *ptr;
char_u *line; char_u *line;
colnr_T col = 0; colnr_T col = 0;
int csize = 0; int csize = 0;
int one_more; int one_more;
@@ -121,8 +119,9 @@ static int coladvance2(
if ((addspaces || finetune) && !VIsual_active) { if ((addspaces || finetune) && !VIsual_active) {
curwin->w_curswant = linetabsize(line) + one_more; curwin->w_curswant = linetabsize(line) + one_more;
if (curwin->w_curswant > 0) if (curwin->w_curswant > 0) {
--curwin->w_curswant; --curwin->w_curswant;
}
} }
} else { } else {
int width = curwin->w_width_inner - win_col_off(curwin); int width = curwin->w_width_inner - win_col_off(curwin);
@@ -133,8 +132,9 @@ static int coladvance2(
&& wcol >= (colnr_T)width && wcol >= (colnr_T)width
&& width > 0) { && width > 0) {
csize = linetabsize(line); csize = linetabsize(line);
if (csize > 0) if (csize > 0) {
csize--; csize--;
}
if (wcol / width > (colnr_T)csize / width if (wcol / width > (colnr_T)csize / width
&& ((State & INSERT) == 0 || (int)wcol > csize + 1)) { && ((State & INSERT) == 0 || (int)wcol > csize + 1)) {
@@ -148,7 +148,7 @@ static int coladvance2(
ptr = line; ptr = line;
while (col <= wcol && *ptr != NUL) { 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); csize = win_lbr_chartabsize(curwin, line, ptr, col, &head);
MB_PTR_ADV(ptr); MB_PTR_ADV(ptr);
col += csize; col += csize;
@@ -162,7 +162,7 @@ static int coladvance2(
*/ */
if (col > wcol || (!virtual_active() && one_more == 0)) { if (col > wcol || (!virtual_active() && one_more == 0)) {
idx -= 1; idx -= 1;
/* Don't count the chars from 'showbreak'. */ // Don't count the chars from 'showbreak'.
csize -= head; csize -= head;
col -= csize; col -= csize;
} }
@@ -175,7 +175,7 @@ static int coladvance2(
* filled with spaces. */ * filled with spaces. */
if (line[idx] == NUL) { if (line[idx] == NUL) {
/* Append spaces */ // Append spaces
int correct = wcol - col; int correct = wcol - col;
size_t newline_size; size_t newline_size;
STRICT_ADD(idx, correct, &newline_size, size_t); STRICT_ADD(idx, correct, &newline_size, size_t);
@@ -188,13 +188,14 @@ static int coladvance2(
idx += correct; idx += correct;
col = wcol; col = wcol;
} else { } else {
/* Break a tab */ // Break a tab
int linelen = (int)STRLEN(line); int linelen = (int)STRLEN(line);
int correct = wcol - col - csize + 1; /* negative!! */ int correct = wcol - col - csize + 1; // negative!!
char_u *newline; char_u *newline;
if (-correct > csize) if (-correct > csize) {
return FAIL; return FAIL;
}
size_t n; size_t n;
STRICT_ADD(linelen - 1, csize, &n, size_t); STRICT_ADD(linelen - 1, csize, &n, size_t);
@@ -216,16 +217,17 @@ static int coladvance2(
} }
} }
if (idx < 0) if (idx < 0) {
pos->col = 0; pos->col = 0;
else } else {
pos->col = idx; pos->col = idx;
}
pos->coladd = 0; pos->coladd = 0;
if (finetune) { if (finetune) {
if (wcol == MAXCOL) { 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) { if (!one_more) {
colnr_T scol, ecol; colnr_T scol, ecol;
@@ -319,15 +321,15 @@ void check_pos(buf_T *buf, pos_T *pos)
colnr_T len; colnr_T len;
if (pos->lnum > buf->b_ml.ml_line_count) { 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) { if (pos->col > 0) {
line = ml_get_buf(buf, pos->lnum, false); line = ml_get_buf(buf, pos->lnum, false);
len = (colnr_T)STRLEN(line); len = (colnr_T)STRLEN(line);
if (pos->col > len) { if (pos->col > len) {
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 /* If there is a closed fold at the end of the file, put the cursor in
* its first line. Otherwise in the last line. */ * its first line. Otherwise in the last line. */
if (!hasFolding(curbuf->b_ml.ml_line_count, 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; 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; curwin->w_cursor.lnum = 1;
}
} }
/* /*
@@ -430,8 +434,9 @@ void adjust_cursor_col(void)
{ {
if (curwin->w_cursor.col > 0 if (curwin->w_cursor.col > 0
&& (!VIsual_active || *p_sel == 'o') && (!VIsual_active || *p_sel == 'o')
&& gchar_cursor() == NUL) && gchar_cursor() == NUL) {
--curwin->w_cursor.col; --curwin->w_cursor.col;
}
} }
/* /*
@@ -473,14 +478,15 @@ bool leftcol_changed(void)
coladvance(s - 1); coladvance(s - 1);
} else if (s < curwin->w_leftcol) { } else if (s < curwin->w_leftcol) {
retval = true; retval = true;
if (coladvance(e + 1) == FAIL) { /* there isn't another character */ if (coladvance(e + 1) == FAIL) { // there isn't another character
curwin->w_leftcol = s; /* adjust w_leftcol instead */ curwin->w_leftcol = s; // adjust w_leftcol instead
changed_cline_bef_curs(); changed_cline_bef_curs();
} }
} }
if (retval) if (retval) {
curwin->w_set_curswant = true; curwin->w_set_curswant = true;
}
redraw_later(curwin, NOT_VALID); redraw_later(curwin, NOT_VALID);
return retval; return retval;
} }

View File

@@ -3,15 +3,16 @@
#include <assert.h> #include <assert.h>
#include <stdint.h> #include <stdint.h>
#include "nvim/vim.h"
#include "nvim/api/private/helpers.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/charset.h"
#include "nvim/cursor_shape.h" #include "nvim/cursor_shape.h"
#include "nvim/ex_getln.h" #include "nvim/ex_getln.h"
#include "nvim/charset.h"
#include "nvim/strings.h" #include "nvim/strings.h"
#include "nvim/syntax.h" #include "nvim/syntax.h"
#include "nvim/api/private/helpers.h"
#include "nvim/ui.h" #include "nvim/ui.h"
#include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "cursor_shape.c.generated.h" # include "cursor_shape.c.generated.h"
@@ -56,10 +57,14 @@ Array mode_style_array(void)
if (cur->used_for & SHAPE_CURSOR) { if (cur->used_for & SHAPE_CURSOR) {
String shape_str; String shape_str;
switch (cur->shape) { switch (cur->shape) {
case SHAPE_BLOCK: shape_str = cstr_to_string("block"); break; case SHAPE_BLOCK:
case SHAPE_VER: shape_str = cstr_to_string("vertical"); break; shape_str = cstr_to_string("block"); break;
case SHAPE_HOR: shape_str = cstr_to_string("horizontal"); break; case SHAPE_VER:
default: shape_str = cstr_to_string("unknown"); 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, "cursor_shape", STRING_OBJ(shape_str));
PUT(dic, "cell_percentage", INTEGER_OBJ(cur->percentage)); 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. /// @returns error message for an illegal option, NULL otherwise.
char_u *parse_shape_opt(int what) char_u *parse_shape_opt(int what)
{ {
char_u *modep; char_u *modep;
char_u *colonp; char_u *colonp;
char_u *commap; char_u *commap;
char_u *slashp; char_u *slashp;
char_u *p = NULL; char_u *p = NULL;
char_u *endp; char_u *endp;
int idx = 0; // init for GCC int idx = 0; // init for GCC
int all_idx; int all_idx;
int len; int len;
@@ -142,14 +147,18 @@ char_u *parse_shape_opt(int what)
if (len == 1 && TOLOWER_ASC(modep[0]) == 'a') { if (len == 1 && TOLOWER_ASC(modep[0]) == 'a') {
all_idx = SHAPE_IDX_COUNT - 1; all_idx = SHAPE_IDX_COUNT - 1;
} else { } else {
for (idx = 0; idx < SHAPE_IDX_COUNT; ++idx) for (idx = 0; idx < SHAPE_IDX_COUNT; ++idx) {
if (STRNICMP(modep, shape_table[idx].name, len) == 0) if (STRNICMP(modep, shape_table[idx].name, len) == 0) {
break; break;
}
}
if (idx == SHAPE_IDX_COUNT 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"); 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; found_ve = true;
}
} }
modep += len + 1; modep += len + 1;
} }
@@ -158,7 +167,7 @@ char_u *parse_shape_opt(int what)
idx = all_idx--; idx = all_idx--;
} }
/* Parse the part after the colon */ // Parse the part after the colon
for (p = colonp + 1; *p && *p != ','; ) { for (p = colonp + 1; *p && *p != ','; ) {
{ {
/* /*
@@ -166,20 +175,22 @@ char_u *parse_shape_opt(int what)
*/ */
i = *p; i = *p;
len = 0; len = 0;
if (STRNICMP(p, "ver", 3) == 0) if (STRNICMP(p, "ver", 3) == 0) {
len = 3; len = 3;
else if (STRNICMP(p, "hor", 3) == 0) } else if (STRNICMP(p, "hor", 3) == 0) {
len = 3; len = 3;
else if (STRNICMP(p, "blinkwait", 9) == 0) } else if (STRNICMP(p, "blinkwait", 9) == 0) {
len = 9; len = 9;
else if (STRNICMP(p, "blinkon", 7) == 0) } else if (STRNICMP(p, "blinkon", 7) == 0) {
len = 7; len = 7;
else if (STRNICMP(p, "blinkoff", 8) == 0) } else if (STRNICMP(p, "blinkoff", 8) == 0) {
len = 8; len = 8;
}
if (len != 0) { if (len != 0) {
p += len; p += len;
if (!ascii_isdigit(*p)) if (!ascii_isdigit(*p)) {
return (char_u *)N_("E548: digit expected"); return (char_u *)N_("E548: digit expected");
}
int n = getdigits_int(&p, false, 0); int n = getdigits_int(&p, false, 0);
if (len == 3) { // "ver" or "hor" if (len == 3) { // "ver" or "hor"
if (n == 0) { if (n == 0) {
@@ -194,44 +205,49 @@ char_u *parse_shape_opt(int what)
shape_table[idx].percentage = n; shape_table[idx].percentage = n;
} }
} else if (round == 2) { } else if (round == 2) {
if (len == 9) if (len == 9) {
shape_table[idx].blinkwait = n; shape_table[idx].blinkwait = n;
else if (len == 7) } else if (len == 7) {
shape_table[idx].blinkon = n; shape_table[idx].blinkon = n;
else } else {
shape_table[idx].blinkoff = n; shape_table[idx].blinkoff = n;
}
} }
} else if (STRNICMP(p, "block", 5) == 0) { } else if (STRNICMP(p, "block", 5) == 0) {
if (round == 2) if (round == 2) {
shape_table[idx].shape = SHAPE_BLOCK; shape_table[idx].shape = SHAPE_BLOCK;
}
p += 5; p += 5;
} else { /* must be a highlight group name then */ } else { // must be a highlight group name then
endp = vim_strchr(p, '-'); endp = vim_strchr(p, '-');
if (commap == NULL) { /* last part */ if (commap == NULL) { // last part
if (endp == NULL) if (endp == NULL) {
endp = p + STRLEN(p); /* find end of part */ endp = p + STRLEN(p); // find end of part
}
} else if (endp > commap || endp == NULL) { } else if (endp > commap || endp == NULL) {
endp = commap; endp = commap;
} }
slashp = vim_strchr(p, '/'); slashp = vim_strchr(p, '/');
if (slashp != NULL && slashp < endp) { if (slashp != NULL && slashp < endp) {
/* "group/langmap_group" */ // "group/langmap_group"
i = syn_check_group(p, (int)(slashp - p)); i = syn_check_group(p, (int)(slashp - p));
p = slashp + 1; p = slashp + 1;
} }
if (round == 2) { if (round == 2) {
shape_table[idx].id = syn_check_group(p, shape_table[idx].id = syn_check_group(p,
(int)(endp - p)); (int)(endp - p));
shape_table[idx].id_lm = shape_table[idx].id; shape_table[idx].id_lm = shape_table[idx].id;
if (slashp != NULL && slashp < endp) if (slashp != NULL && slashp < endp) {
shape_table[idx].id = i; shape_table[idx].id = i;
}
} }
p = endp; p = endp;
} }
} /* if (what != SHAPE_MOUSE) */ } // if (what != SHAPE_MOUSE)
if (*p == '-') if (*p == '-') {
++p; ++p;
}
} }
} }
modep = 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) { if (!found_ve) {
{ {
shape_table[SHAPE_IDX_VE].shape = shape_table[SHAPE_IDX_V].shape; shape_table[SHAPE_IDX_VE].shape = shape_table[SHAPE_IDX_V].shape;

View File

@@ -4251,8 +4251,8 @@ static void f_glob(typval_T *argvars, typval_T *rettv, FunPtr fptr)
options += WILD_ICASE; options += WILD_ICASE;
} }
if (rettv->v_type == VAR_STRING) { if (rettv->v_type == VAR_STRING) {
rettv->vval.v_string = ExpandOne(&xpc, (char_u *)tv_get_string( rettv->vval.v_string = ExpandOne(&xpc, (char_u *)tv_get_string(&argvars[0]), NULL, options,
&argvars[0]), NULL, options, WILD_ALL); WILD_ALL);
} else { } else {
ExpandOne(&xpc, (char_u *)tv_get_string(&argvars[0]), NULL, options, ExpandOne(&xpc, (char_u *)tv_get_string(&argvars[0]), NULL, options,
WILD_ALL_KEEP); WILD_ALL_KEEP);
@@ -6564,8 +6564,8 @@ static void msgpackparse_unpack_list(const list_T *const list, list_T *const ret
goto end; goto end;
} }
size_t read_bytes; size_t read_bytes;
const int rlret = encode_read_from_list(&lrstate, msgpack_unpacker_buffer( const int rlret = encode_read_from_list(&lrstate, msgpack_unpacker_buffer(unpacker), IOSIZE,
unpacker), IOSIZE, &read_bytes); &read_bytes);
if (rlret == FAIL) { if (rlret == FAIL) {
EMSG2(_(e_invarg2), "List item is not a string"); EMSG2(_(e_invarg2), "List item is not a string");
goto end; 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]); const bool do_special = non_zero_arg(&argvars[1]);
rettv->vval.v_string = vim_strsave_shellescape((const char_u *)tv_get_string( 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; rettv->v_type = VAR_STRING;
} }

View File

@@ -1,33 +1,31 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check // 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 // 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 <lua.h>
#include <lualib.h> #include <lualib.h>
#include <lauxlib.h>
#include <assert.h>
#include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
#include "nvim/api/private/defs.h" #include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h" #include "nvim/api/private/helpers.h"
#include "nvim/assert.h"
#include "nvim/func_attr.h" #include "nvim/func_attr.h"
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/assert.h"
// FIXME: vim.h is not actually needed, but otherwise it states MAXPATHL is // FIXME: vim.h is not actually needed, but otherwise it states MAXPATHL is
// redefined // redefined
#include "nvim/vim.h" #include "nvim/ascii.h"
#include "nvim/globals.h" #include "nvim/eval/decode.h"
#include "nvim/message.h"
#include "nvim/eval/typval.h" #include "nvim/eval/typval.h"
#include "nvim/eval/userfunc.h" #include "nvim/eval/userfunc.h"
#include "nvim/ascii.h" #include "nvim/globals.h"
#include "nvim/macros.h"
#include "nvim/lib/kvec.h" #include "nvim/lib/kvec.h"
#include "nvim/eval/decode.h"
#include "nvim/lua/converter.h" #include "nvim/lua/converter.h"
#include "nvim/lua/executor.h" #include "nvim/lua/executor.h"
#include "nvim/macros.h"
#include "nvim/message.h"
#include "nvim/vim.h"
/// Determine, which keys lua table contains /// Determine, which keys lua table contains
typedef struct { typedef struct {
@@ -49,7 +47,7 @@ typedef struct {
#define VAL_IDX_VALUE false #define VAL_IDX_VALUE false
#define LUA_PUSH_STATIC_STRING(lstate, s) \ #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) 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); lua_pushnil(lstate);
while (lua_next(lstate, -2)) { while (lua_next(lstate, -2)) {
switch (lua_type(lstate, -2)) { switch (lua_type(lstate, -2)) {
case LUA_TSTRING: { case LUA_TSTRING: {
size_t len; size_t len;
const char *s = lua_tolstring(lstate, -2, &len); const char *s = lua_tolstring(lstate, -2, &len);
if (memchr(s, NUL, len) != NULL) { if (memchr(s, NUL, len) != NULL) {
ret.has_string_with_nul = true; ret.has_string_with_nul = true;
}
ret.string_keys_num++;
break;
} }
case LUA_TNUMBER: { ret.string_keys_num++;
const lua_Number n = lua_tonumber(lstate, -2); break;
if (n > (lua_Number)SIZE_MAX || n <= 0 }
|| ((lua_Number)((size_t)n)) != n) { case LUA_TNUMBER: {
other_keys_num++; const lua_Number n = lua_tonumber(lstate, -2);
} else { if (n > (lua_Number)SIZE_MAX || n <= 0
const size_t idx = (size_t)n; || ((lua_Number)((size_t)n)) != n) {
if (idx > ret.maxidx) { other_keys_num++;
ret.maxidx = idx; } else {
} const size_t idx = (size_t)n;
if (idx > ret.maxidx) {
ret.maxidx = idx;
} }
break;
} }
case LUA_TBOOLEAN: { break;
const bool b = lua_toboolean(lstate, -2); }
if (b == TYPE_IDX_VALUE) { case LUA_TBOOLEAN: {
if (lua_type(lstate, -1) == LUA_TNUMBER) { const bool b = lua_toboolean(lstate, -2);
lua_Number n = lua_tonumber(lstate, -1); if (b == TYPE_IDX_VALUE) {
if (n == (lua_Number)kObjectTypeFloat if (lua_type(lstate, -1) == LUA_TNUMBER) {
|| n == (lua_Number)kObjectTypeArray lua_Number n = lua_tonumber(lstate, -1);
|| n == (lua_Number)kObjectTypeDictionary) { if (n == (lua_Number)kObjectTypeFloat
ret.has_type_key = true; || n == (lua_Number)kObjectTypeArray
ret.type = (ObjectType)n; || n == (lua_Number)kObjectTypeDictionary) {
} else { ret.has_type_key = true;
other_keys_num++; ret.type = (ObjectType)n;
}
} else { } else {
other_keys_num++; other_keys_num++;
} }
} else { } else {
has_val_key = true; other_keys_num++;
val_type = lua_type(lstate, -1); }
if (val_type == LUA_TNUMBER) { } else {
ret.val = lua_tonumber(lstate, -1); 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++; tsize++;
lua_pop(lstate, 1); lua_pop(lstate, 1);
@@ -283,153 +280,143 @@ bool nlua_pop_typval(lua_State *lstate, typval_T *ret_tv)
.vval = { .v_number = 0 }, .vval = { .v_number = 0 },
}; };
switch (lua_type(lstate, -1)) { switch (lua_type(lstate, -1)) {
case LUA_TNIL: { case LUA_TNIL:
cur.tv->v_type = VAR_SPECIAL; cur.tv->v_type = VAR_SPECIAL;
cur.tv->vval.v_special = kSpecialVarNull; cur.tv->vval.v_special = kSpecialVarNull;
break; break;
} case LUA_TBOOLEAN:
case LUA_TBOOLEAN: { cur.tv->v_type = VAR_BOOL;
cur.tv->v_type = VAR_BOOL; cur.tv->vval.v_bool = (lua_toboolean(lstate, -1)
cur.tv->vval.v_bool = (lua_toboolean(lstate, -1)
? kBoolVarTrue ? kBoolVarTrue
: kBoolVarFalse); : 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: { break;
size_t len; }
const char *s = lua_tolstring(lstate, -1, &len); case LUA_TNUMBER: {
*cur.tv = decode_string(s, len, kNone, true, false); const lua_Number n = lua_tonumber(lstate, -1);
if (cur.tv->v_type == VAR_UNKNOWN) { if (n > (lua_Number)VARNUMBER_MAX || n < (lua_Number)VARNUMBER_MIN
ret = false; || ((lua_Number)((varnumber_T)n)) != n) {
} cur.tv->v_type = VAR_FLOAT;
break; 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: { break;
const lua_Number n = lua_tonumber(lstate, -1); }
if (n > (lua_Number)VARNUMBER_MAX || n < (lua_Number)VARNUMBER_MIN case LUA_TTABLE: {
|| ((lua_Number)((varnumber_T)n)) != n) { // Only need to track table refs if we have a metatable associated.
cur.tv->v_type = VAR_FLOAT; LuaRef table_ref = LUA_NOREF;
cur.tv->vval.v_float = (float_T)n; if (lua_getmetatable(lstate, -1)) {
} else {
cur.tv->v_type = VAR_NUMBER;
cur.tv->vval.v_number = (varnumber_T)n;
}
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);
}
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;
}
}
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;
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();
}
}
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); lua_pop(lstate, 1);
if (is_nil) { table_ref = nlua_ref(lstate, -1);
cur.tv->v_type = VAR_SPECIAL; }
cur.tv->vval.v_special = kSpecialVarNull;
} else { const LuaTableProps table_props = nlua_traverse_table(lstate);
EMSG(_("E5101: Cannot convert given lua type"));
ret = false; 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);
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; break;
} case kObjectTypeDictionary:
default: { if (table_props.string_keys_num == 0) {
EMSG(_("E5101: Cannot convert given lua type")); 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; ret = false;
break; break;
default:
abort();
} }
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;
}
default:
EMSG(_("E5101: Cannot convert given lua type"));
ret = false;
break;
} }
if (!cur.container) { if (!cur.container) {
lua_pop(lstate, 1); lua_pop(lstate, 1);
@@ -454,97 +441,97 @@ static bool typval_conv_special = false;
#define TYPVAL_ENCODE_ALLOW_SPECIALS true #define TYPVAL_ENCODE_ALLOW_SPECIALS true
#define TYPVAL_ENCODE_CONV_NIL(tv) \ #define TYPVAL_ENCODE_CONV_NIL(tv) \
do { \ do { \
if (typval_conv_special) { \ if (typval_conv_special) { \
lua_pushnil(lstate); \ lua_pushnil(lstate); \
} else { \ } else { \
nlua_pushref(lstate, nlua_nil_ref); \ nlua_pushref(lstate, nlua_nil_ref); \
} \ } \
} while (0) } while (0)
#define TYPVAL_ENCODE_CONV_BOOL(tv, num) \ #define TYPVAL_ENCODE_CONV_BOOL(tv, num) \
lua_pushboolean(lstate, (bool)(num)) lua_pushboolean(lstate, (bool)(num))
#define TYPVAL_ENCODE_CONV_NUMBER(tv, 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_UNSIGNED_NUMBER TYPVAL_ENCODE_CONV_NUMBER
#define TYPVAL_ENCODE_CONV_FLOAT(tv, flt) \ #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) \ #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_STR_STRING TYPVAL_ENCODE_CONV_STRING
#define TYPVAL_ENCODE_CONV_EXT_STRING(tv, str, len, type) \ #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) \ #define TYPVAL_ENCODE_CONV_BLOB(tv, blob, len) \
do { \ do { \
const blob_T *const blob_ = (blob); \ const blob_T *const blob_ = (blob); \
lua_pushlstring(lstate, \ lua_pushlstring(lstate, \
blob_ != NULL ? (const char *)blob_->bv_ga.ga_data : "", \ blob_ != NULL ? (const char *)blob_->bv_ga.ga_data : "", \
(size_t)(len)); \ (size_t)(len)); \
} while (0) } while (0)
#define TYPVAL_ENCODE_CONV_FUNC_START(tv, fun) \ #define TYPVAL_ENCODE_CONV_FUNC_START(tv, fun) \
do { \ do { \
TYPVAL_ENCODE_CONV_NIL(tv); \ TYPVAL_ENCODE_CONV_NIL(tv); \
goto typval_encode_stop_converting_one_item; \ goto typval_encode_stop_converting_one_item; \
} while (0) } while (0)
#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS(tv, len) #define TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS(tv, len)
#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF(tv, len) #define TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF(tv, len)
#define TYPVAL_ENCODE_CONV_FUNC_END(tv) #define TYPVAL_ENCODE_CONV_FUNC_END(tv)
#define TYPVAL_ENCODE_CONV_EMPTY_LIST(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) \ #define TYPVAL_ENCODE_CONV_EMPTY_DICT(tv, dict) \
do { \ do { \
if (typval_conv_special) { \ if (typval_conv_special) { \
nlua_create_typed_table(lstate, 0, 0, kObjectTypeDictionary); \ nlua_create_typed_table(lstate, 0, 0, kObjectTypeDictionary); \
} else { \ } else { \
lua_createtable(lstate, 0, 0); \ lua_createtable(lstate, 0, 0); \
nlua_pushref(lstate, nlua_empty_dict_ref); \ nlua_pushref(lstate, nlua_empty_dict_ref); \
lua_setmetatable(lstate, -2); \ lua_setmetatable(lstate, -2); \
} \ } \
} while (0) } while (0)
#define TYPVAL_ENCODE_CONV_LIST_START(tv, len) \ #define TYPVAL_ENCODE_CONV_LIST_START(tv, len) \
do { \ do { \
if (!lua_checkstack(lstate, lua_gettop(lstate) + 3)) { \ if (!lua_checkstack(lstate, lua_gettop(lstate) + 3)) { \
emsgf(_("E5102: Lua failed to grow stack to %i"), \ emsgf(_("E5102: Lua failed to grow stack to %i"), \
lua_gettop(lstate) + 3); \ lua_gettop(lstate) + 3); \
return false; \ return false; \
} \ } \
lua_createtable(lstate, (int)(len), 0); \ lua_createtable(lstate, (int)(len), 0); \
lua_pushnumber(lstate, 1); \ lua_pushnumber(lstate, 1); \
} while (0) } while (0)
#define TYPVAL_ENCODE_CONV_REAL_LIST_AFTER_START(tv, mpsv) #define TYPVAL_ENCODE_CONV_REAL_LIST_AFTER_START(tv, mpsv)
#define TYPVAL_ENCODE_CONV_LIST_BETWEEN_ITEMS(tv) \ #define TYPVAL_ENCODE_CONV_LIST_BETWEEN_ITEMS(tv) \
do { \ do { \
lua_Number idx = lua_tonumber(lstate, -2); \ lua_Number idx = lua_tonumber(lstate, -2); \
lua_rawset(lstate, -3); \ lua_rawset(lstate, -3); \
lua_pushnumber(lstate, idx + 1); \ lua_pushnumber(lstate, idx + 1); \
} while (0) } while (0)
#define TYPVAL_ENCODE_CONV_LIST_END(tv) \ #define TYPVAL_ENCODE_CONV_LIST_END(tv) \
lua_rawset(lstate, -3) lua_rawset(lstate, -3)
#define TYPVAL_ENCODE_CONV_DICT_START(tv, dict, len) \ #define TYPVAL_ENCODE_CONV_DICT_START(tv, dict, len) \
do { \ do { \
if (!lua_checkstack(lstate, lua_gettop(lstate) + 3)) { \ if (!lua_checkstack(lstate, lua_gettop(lstate) + 3)) { \
emsgf(_("E5102: Lua failed to grow stack to %i"), \ emsgf(_("E5102: Lua failed to grow stack to %i"), \
lua_gettop(lstate) + 3); \ lua_gettop(lstate) + 3); \
return false; \ return false; \
} \ } \
lua_createtable(lstate, 0, (int)(len)); \ lua_createtable(lstate, 0, (int)(len)); \
} while (0) } while (0)
#define TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK(label, kv_pair) #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_AFTER_KEY(tv, dict)
#define TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS(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) \ #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) \ #define TYPVAL_ENCODE_CONV_RECURSE(val, conv_type) \
do { \ do { \
for (size_t backref = kv_size(*mpstack); backref; backref--) { \ for (size_t backref = kv_size(*mpstack); backref; backref--) { \
const MPConvStackVal mpval = kv_A(*mpstack, backref - 1); \ const MPConvStackVal mpval = kv_A(*mpstack, backref - 1); \
if (mpval.type == conv_type) { \ if (mpval.type == conv_type) { \
if (conv_type == kMPConvDict \ if (conv_type == kMPConvDict \
? (void *)mpval.data.d.dict == (void *)(val) \ ? (void *)mpval.data.d.dict == (void *)(val) \
: (void *)mpval.data.l.list == (void *)(val)) { \ : (void *)mpval.data.l.list == (void *)(val)) { \
lua_pushvalue(lstate, \ lua_pushvalue(lstate, \
-((int)((kv_size(*mpstack) - backref + 1) * 2))); \ -((int)((kv_size(*mpstack) - backref + 1) * 2))); \
break; \ break; \
} \
} \ } \
} \ } \
} while (0) } \
} while (0)
#define TYPVAL_ENCODE_SCOPE static #define TYPVAL_ENCODE_SCOPE static
#define TYPVAL_ENCODE_NAME lua #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] narr Number of “array” entries to be populated later.
/// @param[in] nrec Number of “dictionary” entries to be populated later. /// @param[in] nrec Number of “dictionary” entries to be populated later.
/// @param[in] type Type of the table. /// @param[in] type Type of the table.
static inline void nlua_create_typed_table(lua_State *lstate, static inline void nlua_create_typed_table(lua_State *lstate, const size_t narr, const size_t nrec,
const size_t narr,
const size_t nrec,
const ObjectType type) const ObjectType type)
FUNC_ATTR_NONNULL_ALL 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 /// Convert given Dictionary to lua table
/// ///
/// Leaves converted table on top of the stack. /// Leaves converted table on top of the stack.
void nlua_push_Dictionary(lua_State *lstate, const Dictionary dict, void nlua_push_Dictionary(lua_State *lstate, const Dictionary dict, bool special)
bool special)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
if (dict.size == 0 && special) { 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) \ #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 \ FUNC_ATTR_NONNULL_ALL \
{ \ { \
lua_pushnumber(lstate, (lua_Number)(item)); \ lua_pushnumber(lstate, (lua_Number)(item)); \
} }
GENERATE_INDEX_FUNCTION(Buffer) GENERATE_INDEX_FUNCTION(Buffer)
@@ -786,23 +770,22 @@ void nlua_push_Object(lua_State *lstate, const Object obj, bool special)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
switch (obj.type) { switch (obj.type) {
case kObjectTypeNil: { case kObjectTypeNil:
if (special) { if (special) {
lua_pushnil(lstate); lua_pushnil(lstate);
} else { } else {
nlua_pushref(lstate, nlua_nil_ref); nlua_pushref(lstate, nlua_nil_ref);
}
break;
}
case kObjectTypeLuaRef: {
nlua_pushref(lstate, obj.data.luaref);
break;
} }
break;
case kObjectTypeLuaRef: {
nlua_pushref(lstate, obj.data.luaref);
break;
}
#define ADD_TYPE(type, data_key) \ #define ADD_TYPE(type, data_key) \
case kObjectType##type: { \ case kObjectType##type: { \
nlua_push_##type(lstate, obj.data.data_key, special); \ nlua_push_##type(lstate, obj.data.data_key, special); \
break; \ break; \
} }
ADD_TYPE(Boolean, boolean) ADD_TYPE(Boolean, boolean)
ADD_TYPE(Integer, integer) ADD_TYPE(Integer, integer)
ADD_TYPE(Float, floating) ADD_TYPE(Float, floating)
@@ -811,10 +794,10 @@ void nlua_push_Object(lua_State *lstate, const Object obj, bool special)
ADD_TYPE(Dictionary, dictionary) ADD_TYPE(Dictionary, dictionary)
#undef ADD_TYPE #undef ADD_TYPE
#define ADD_REMOTE_TYPE(type) \ #define ADD_REMOTE_TYPE(type) \
case kObjectType##type: { \ case kObjectType##type: { \
nlua_push_##type(lstate, (type)obj.data.integer, special); \ nlua_push_##type(lstate, (type)obj.data.integer, special); \
break; \ break; \
} }
ADD_REMOTE_TYPE(Buffer) ADD_REMOTE_TYPE(Buffer)
ADD_REMOTE_TYPE(Window) ADD_REMOTE_TYPE(Window)
ADD_REMOTE_TYPE(Tabpage) ADD_REMOTE_TYPE(Tabpage)
@@ -883,8 +866,7 @@ Boolean nlua_pop_Boolean(lua_State *lstate, Error *err)
/// @param[in] type Type to check. /// @param[in] type Type to check.
/// ///
/// @return @see nlua_traverse_table(). /// @return @see nlua_traverse_table().
static inline LuaTableProps nlua_check_type(lua_State *const lstate, static inline LuaTableProps nlua_check_type(lua_State *const lstate, Error *const err,
Error *const err,
const ObjectType type) const ObjectType type)
FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_WARN_UNUSED_RESULT 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 lstate Lua state.
/// @param[in] table_props nlua_traverse_table() output. /// @param[in] table_props nlua_traverse_table() output.
/// @param[out] err Location where error will be saved. /// @param[out] err Location where error will be saved.
static Array nlua_pop_Array_unchecked(lua_State *const lstate, static Array nlua_pop_Array_unchecked(lua_State *const lstate, const LuaTableProps table_props,
const LuaTableProps table_props,
Error *const err) Error *const err)
{ {
Array ret = { .size = table_props.maxidx, .items = NULL }; 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 lstate Lua interpreter state.
/// @param[in] table_props nlua_traverse_table() output. /// @param[in] table_props nlua_traverse_table() output.
/// @param[out] err Location where error will be saved. /// @param[out] err Location where error will be saved.
static Dictionary nlua_pop_Dictionary_unchecked(lua_State *lstate, static Dictionary nlua_pop_Dictionary_unchecked(lua_State *lstate, const LuaTableProps table_props,
const LuaTableProps table_props, bool ref, Error *err)
bool ref,
Error *err)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{ {
Dictionary ret = { .size = table_props.string_keys_num, .items = NULL }; 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); assert(!cur.container);
*cur.obj = NIL; *cur.obj = NIL;
switch (lua_type(lstate, -1)) { switch (lua_type(lstate, -1)) {
case LUA_TNIL: { case LUA_TNIL:
break; 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_TBOOLEAN: { break;
*cur.obj = BOOLEAN_OBJ(lua_toboolean(lstate, -1)); }
break; case LUA_TTABLE: {
} const LuaTableProps table_props = nlua_traverse_table(lstate);
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_TTABLE: {
const LuaTableProps table_props = nlua_traverse_table(lstate);
switch (table_props.type) { switch (table_props.type) {
case kObjectTypeArray: { case kObjectTypeArray:
*cur.obj = ARRAY_OBJ(((Array) { *cur.obj = ARRAY_OBJ(((Array) {
.items = NULL, .items = NULL,
.size = 0, .size = 0,
.capacity = 0, .capacity = 0,
})); }));
if (table_props.maxidx != 0) { if (table_props.maxidx != 0) {
cur.obj->data.array.items = cur.obj->data.array.items =
xcalloc(table_props.maxidx, xcalloc(table_props.maxidx,
sizeof(cur.obj->data.array.items[0])); sizeof(cur.obj->data.array.items[0]));
cur.obj->data.array.capacity = table_props.maxidx; cur.obj->data.array.capacity = table_props.maxidx;
cur.container = true; cur.container = true;
kvi_push(stack, cur); kvi_push(stack, cur);
} }
break; break;
} case kObjectTypeDictionary:
case kObjectTypeDictionary: { *cur.obj = DICTIONARY_OBJ(((Dictionary) {
*cur.obj = DICTIONARY_OBJ(((Dictionary) {
.items = NULL, .items = NULL,
.size = 0, .size = 0,
.capacity = 0, .capacity = 0,
})); }));
if (table_props.string_keys_num != 0) { if (table_props.string_keys_num != 0) {
cur.obj->data.dictionary.items = cur.obj->data.dictionary.items =
xcalloc(table_props.string_keys_num, xcalloc(table_props.string_keys_num,
sizeof(cur.obj->data.dictionary.items[0])); sizeof(cur.obj->data.dictionary.items[0]));
cur.obj->data.dictionary.capacity = table_props.string_keys_num; cur.obj->data.dictionary.capacity = table_props.string_keys_num;
cur.container = true; cur.container = true;
kvi_push(stack, cur); kvi_push(stack, cur);
lua_pushnil(lstate); 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();
}
} }
break; break;
} case kObjectTypeFloat:
*cur.obj = FLOAT_OBJ((Float)table_props.val);
case LUA_TFUNCTION: {
if (ref) {
*cur.obj = LUAREF_OBJ(nlua_ref(lstate, -1));
} else {
goto type_error;
}
break; break;
} case kObjectTypeNil:
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;
}
default: {
type_error:
api_set_error(err, kErrorTypeValidation, api_set_error(err, kErrorTypeValidation,
"Cannot convert given lua type"); "Cannot convert given lua table");
break; break;
default:
abort();
} }
break;
}
case LUA_TFUNCTION:
if (ref) {
*cur.obj = LUAREF_OBJ(nlua_ref(lstate, -1));
} else {
goto type_error;
}
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;
}
default:
type_error:
api_set_error(err, kErrorTypeValidation,
"Cannot convert given lua type");
break;
} }
if (!cur.container) { if (!cur.container) {
lua_pop(lstate, 1); lua_pop(lstate, 1);
@@ -1268,14 +1238,14 @@ LuaRef nlua_pop_LuaRef(lua_State *const lstate, Error *err)
} }
#define GENERATE_INDEX_FUNCTION(type) \ #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 \ FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT \
{ \ { \
type ret; \ type ret; \
ret = (type)lua_tonumber(lstate, -1); \ ret = (type)lua_tonumber(lstate, -1); \
lua_pop(lstate, 1); \ lua_pop(lstate, 1); \
return ret; \ return ret; \
} }
GENERATE_INDEX_FUNCTION(Buffer) GENERATE_INDEX_FUNCTION(Buffer)
GENERATE_INDEX_FUNCTION(Window) GENERATE_INDEX_FUNCTION(Window)

View File

@@ -1,48 +1,45 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check // 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 // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <lauxlib.h>
#include <lua.h> #include <lua.h>
#include <lualib.h> #include <lualib.h>
#include <lauxlib.h>
#include "nvim/assert.h" #include "luv/luv.h"
#include "nvim/version.h" #include "mpack/lmpack.h"
#include "nvim/misc1.h"
#include "nvim/getchar.h"
#include "nvim/garray.h"
#include "nvim/func_attr.h"
#include "nvim/api/private/defs.h" #include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h" #include "nvim/api/private/helpers.h"
#include "nvim/api/vim.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/ascii.h"
#include "nvim/assert.h"
#include "nvim/buffer_defs.h"
#include "nvim/change.h" #include "nvim/change.h"
#include "nvim/cursor.h"
#include "nvim/eval/userfunc.h" #include "nvim/eval/userfunc.h"
#include "nvim/event/time.h"
#include "nvim/event/loop.h" #include "nvim/event/loop.h"
#include "mpack/lmpack.h" #include "nvim/event/time.h"
#include "nvim/ex_cmds2.h"
#include "nvim/os/os.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/converter.h"
#include "nvim/lua/executor.h" #include "nvim/lua/executor.h"
#include "nvim/lua/treesitter.h" #include "nvim/lua/treesitter.h"
#include "nvim/lua/xdiff.h" #include "nvim/lua/xdiff.h"
#include "nvim/macros.h"
#include "luv/luv.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; static int in_fast_callback = 0;
@@ -55,8 +52,8 @@ typedef struct {
} LuaError; } LuaError;
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "lua/vim_module.generated.h"
# include "lua/executor.c.generated.h" # include "lua/executor.c.generated.h"
# include "lua/vim_module.generated.h"
#endif #endif
#define PUSH_ALL_TYPVALS(lstate, args, argcount, special) \ #define PUSH_ALL_TYPVALS(lstate, args, argcount, special) \
@@ -69,8 +66,8 @@ typedef struct {
} }
#if __has_feature(address_sanitizer) #if __has_feature(address_sanitizer)
static PMap(handle_T) nlua_ref_markers = MAP_INIT; static PMap(handle_T) nlua_ref_markers = MAP_INIT;
static bool nlua_track_refs = false; static bool nlua_track_refs = false;
# define NLUA_TRACK_REFS # define NLUA_TRACK_REFS
#endif #endif
@@ -216,8 +213,7 @@ static void nlua_luv_error_event(void **argv)
xfree(error); xfree(error);
} }
static int nlua_luv_cfpcall(lua_State *lstate, int nargs, int nresult, static int nlua_luv_cfpcall(lua_State *lstate, int nargs, int nresult, int flags)
int flags)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
int retval; int retval;
@@ -300,8 +296,7 @@ static void dummy_timer_close_cb(TimeWatcher *tw, void *data)
xfree(tw); xfree(tw);
} }
static bool nlua_wait_condition(lua_State *lstate, int *status, static bool nlua_wait_condition(lua_State *lstate, int *status, bool *callback_result)
bool *callback_result)
{ {
lua_pushvalue(lstate, 2); lua_pushvalue(lstate, 2);
*status = lua_pcall(lstate, 0, 1, 0); *status = lua_pcall(lstate, 0, 1, 0);
@@ -336,9 +331,8 @@ static int nlua_wait(lua_State *lstate)
} }
if (!is_function) { if (!is_function) {
lua_pushliteral( lua_pushliteral(lstate,
lstate, "vim.wait: if passed, condition must be a function");
"vim.wait: if passed, condition must be a function");
return lua_error(lstate); return lua_error(lstate);
} }
} }
@@ -365,23 +359,20 @@ static int nlua_wait(lua_State *lstate)
time_watcher_init(&main_loop, tw, NULL); time_watcher_init(&main_loop, tw, NULL);
tw->events = loop_events; tw->events = loop_events;
tw->blockable = true; tw->blockable = true;
time_watcher_start( time_watcher_start(tw,
tw, dummy_timer_due_cb,
dummy_timer_due_cb, (uint64_t)interval,
(uint64_t)interval, (uint64_t)interval);
(uint64_t)interval);
int pcall_status = 0; int pcall_status = 0;
bool callback_result = false; bool callback_result = false;
LOOP_PROCESS_EVENTS_UNTIL( LOOP_PROCESS_EVENTS_UNTIL(&main_loop,
&main_loop, loop_events,
loop_events, (int)timeout,
(int)timeout, is_function ? nlua_wait_condition(lstate,
is_function ? nlua_wait_condition( &pcall_status,
lstate, &callback_result) : false || got_int);
&pcall_status,
&callback_result) : false || got_int);
// Stop dummy timer // Stop dummy timer
time_watcher_stop(tw); time_watcher_stop(tw);
@@ -663,22 +654,19 @@ static void nlua_print_event(void **argv)
const size_t start = i; const size_t start = i;
while (i < len) { while (i < len) {
switch (str[i]) { switch (str[i]) {
case NUL: { case NUL:
str[i] = NL; str[i] = NL;
i++; i++;
continue; continue;
} case NL:
case NL: { // TODO(bfredl): use proper multiline msg? Probably should implement
// TODO(bfredl): use proper multiline msg? Probably should implement // print() in lua in terms of nvim_message(), when it is available.
// print() in lua in terms of nvim_message(), when it is available. str[i] = NUL;
str[i] = NUL; i++;
i++; break;
break; default:
} i++;
default: { continue;
i++;
continue;
}
} }
break; break;
} }
@@ -719,8 +707,7 @@ static int nlua_print(lua_State *const lstate)
size_t len; size_t len;
const char *const s = lua_tolstring(lstate, -1, &len); const char *const s = lua_tolstring(lstate, -1, &len);
if (s == NULL) { if (s == NULL) {
PRINT_ERROR( PRINT_ERROR("<Unknown error: lua_tolstring returned NULL for tostring result>");
"<Unknown error: lua_tolstring returned NULL for tostring result>");
} }
ga_concat_len(&msg_ga, s, len); ga_concat_len(&msg_ga, s, len);
if (curargidx < nargs) { if (curargidx < nargs) {
@@ -893,7 +880,7 @@ static int nlua_rpc(lua_State *lstate, bool request)
} else { } else {
if (!rpc_send_event(chan_id, name, args)) { if (!rpc_send_event(chan_id, name, args)) {
api_set_error(&err, kErrorTypeValidation, 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) { if (ref > 0) {
nlua_refcount++; nlua_refcount++;
#ifdef NLUA_TRACK_REFS #ifdef NLUA_TRACK_REFS
if (nlua_track_refs) { if (nlua_track_refs) {
// dummy allocation to make LeakSanitizer track our luarefs // dummy allocation to make LeakSanitizer track our luarefs
pmap_put(handle_T)(&nlua_ref_markers, ref, xmalloc(3)); pmap_put(handle_T)(&nlua_ref_markers, ref, xmalloc(3));
} }
#endif #endif
} }
return ref; return ref;
@@ -1108,8 +1095,7 @@ LuaRef api_new_luaref(LuaRef original_ref)
/// @param[out] ret_tv Location where result will be saved. /// @param[out] ret_tv Location where result will be saved.
/// ///
/// @return Result of the execution. /// @return Result of the execution.
void nlua_typval_eval(const String str, typval_T *const arg, void nlua_typval_eval(const String str, typval_T *const arg, typval_T *const ret_tv)
typval_T *const ret_tv)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
#define EVALHEADER "local _A=select(1,...) return (" #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, void nlua_typval_call(const char *str, size_t len, typval_T *const args, int argcount,
int argcount, typval_T *ret_tv) typval_T *ret_tv)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
#define CALLHEADER "return " #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, static void nlua_typval_exec(const char *lcmd, size_t lcmd_len, const char *name,
const char *name, typval_T *const args, typval_T *const args, int argcount, bool special, typval_T *ret_tv)
int argcount, bool special, typval_T *ret_tv)
{ {
if (check_secure()) { if (check_secure()) {
if (ret_tv) { 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, int nlua_source_using_linegetter(LineGetter fgetline, void *cookie, char *name)
void *cookie, char *name)
{ {
const linenr_T save_sourcing_lnum = sourcing_lnum; const linenr_T save_sourcing_lnum = sourcing_lnum;
const sctx_T save_current_sctx = current_sctx; 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] argcount Count of typval arguments
/// @param[in] argvars Typval Arguments /// @param[in] argvars Typval Arguments
/// @param[out] rettv The return value from the called function. /// @param[out] rettv The return value from the called function.
int typval_exec_lua_callable( int typval_exec_lua_callable(lua_State *lstate, LuaCallable lua_cb, int argcount, typval_T *argvars,
lua_State *lstate, typval_T *rettv)
LuaCallable lua_cb,
int argcount,
typval_T *argvars,
typval_T *rettv
)
{ {
LuaRef cb = lua_cb.func_ref; 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 /// if false, discard return value
/// @param err Error details, if any (if NULL, errors are echoed) /// @param err Error details, if any (if NULL, errors are echoed)
/// @return Return value of function, if retval was set. Otherwise NIL. /// @return Return value of function, if retval was set. Otherwise NIL.
Object nlua_call_ref(LuaRef ref, const char *name, Array args, Object nlua_call_ref(LuaRef ref, const char *name, Array args, bool retval, Error *err)
bool retval, Error *err)
{ {
lua_State *const lstate = global_lstate; lua_State *const lstate = global_lstate;
nlua_pushref(lstate, ref); 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"); lua_setfield(lstate, -2, "_ts_get_language_version");
} }
int nlua_expand_pat(expand_T *xp, int nlua_expand_pat(expand_T *xp, char_u *pat, int *num_results, char_u ***results)
char_u *pat,
int *num_results,
char_u ***results)
{ {
lua_State *const lstate = global_lstate; lua_State *const lstate = global_lstate;
int ret = OK; int ret = OK;
@@ -1521,9 +1496,8 @@ int nlua_expand_pat(expand_T *xp,
lua_pushlstring(lstate, (const char *)pat, STRLEN(pat)); lua_pushlstring(lstate, (const char *)pat, STRLEN(pat));
if (lua_pcall(lstate, 1, 2, 0) != 0) { if (lua_pcall(lstate, 1, 2, 0) != 0) {
nlua_error( nlua_error(lstate,
lstate, _("Error executing vim._expand_pat: %.*s"));
_("Error executing vim._expand_pat: %.*s"));
return FAIL; return FAIL;
} }
@@ -1554,10 +1528,9 @@ int nlua_expand_pat(expand_T *xp,
goto cleanup_array; goto cleanup_array;
} }
GA_APPEND( GA_APPEND(char_u *,
char_u *, &result_array,
&result_array, vim_strsave((char_u *)v.data.string.data));
vim_strsave((char_u *)v.data.string.data));
} }
xp->xp_pattern += prefix_len; 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 // Required functions for lua c functions as VimL callbacks
int nlua_CFunction_func_call( int nlua_CFunction_func_call(int argcount, typval_T *argvars, typval_T *rettv, void *state)
int argcount,
typval_T *argvars,
typval_T *rettv,
void *state)
{ {
lua_State *const lstate = global_lstate; lua_State *const lstate = global_lstate;
LuaCFunctionState *funcstate = (LuaCFunctionState *)state; LuaCFunctionState *funcstate = (LuaCFunctionState *)state;
return typval_exec_lua_callable(lstate, funcstate->lua_callable, return typval_exec_lua_callable(lstate, funcstate->lua_callable,
argcount, argvars, rettv); argcount, argvars, rettv);
} }
void nlua_CFunction_func_free(void *state) void nlua_CFunction_func_free(void *state)
{ {
lua_State *const lstate = global_lstate; lua_State *const lstate = global_lstate;
LuaCFunctionState *funcstate = (LuaCFunctionState *)state; LuaCFunctionState *funcstate = (LuaCFunctionState *)state;
nlua_unref(lstate, funcstate->lua_callable.func_ref); nlua_unref(lstate, funcstate->lua_callable.func_ref);
xfree(funcstate); xfree(funcstate);
} }
bool nlua_is_table_from_lua(typval_T *const arg) 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); lua_pushlstring(lstate, (const char *)buf, buf_len);
if (lua_pcall(lstate, 1, 0, 0)) { if (lua_pcall(lstate, 1, 0, 0)) {
nlua_error( nlua_error(lstate,
lstate, _("Error executing vim.on_key Lua callback: %.*s"));
_("Error executing vim.on_key Lua callback: %.*s"));
} }
// [ vim ] // [ vim ]

View File

@@ -5,22 +5,20 @@
// NB: this file mostly contains a generic lua interface for tree-sitter // 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 // trees and nodes, and could be broken out as a reusable lua package
#include <assert.h>
#include <inttypes.h>
#include <lauxlib.h>
#include <lua.h>
#include <lualib.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <inttypes.h>
#include <assert.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include "tree_sitter/api.h"
#include "nvim/lua/treesitter.h"
#include "nvim/api/private/helpers.h" #include "nvim/api/private/helpers.h"
#include "nvim/memline.h"
#include "nvim/buffer.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_PARSER "treesitter_parser"
#define TS_META_TREE "treesitter_tree" #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); uint32_t lang_version = ts_language_version(lang);
if (lang_version < TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION if (lang_version < TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION
|| lang_version > TREE_SITTER_LANGUAGE_VERSION) { || lang_version > TREE_SITTER_LANGUAGE_VERSION) {
return luaL_error( return luaL_error(L,
L, "ABI version mismatch for %s: supported between %d and %d, found %d",
"ABI version mismatch for %s: supported between %d and %d, found %d", path,
path, TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION,
TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION, TREE_SITTER_LANGUAGE_VERSION, lang_version);
TREE_SITTER_LANGUAGE_VERSION, lang_version);
} }
pmap_put(cstr_t)(&langs, xstrdup(lang_name), lang); pmap_put(cstr_t)(&langs, xstrdup(lang_name), lang);
@@ -285,8 +282,8 @@ static int parser_tostring(lua_State *L)
return 1; return 1;
} }
static const char *input_cb(void *payload, uint32_t byte_index, static const char *input_cb(void *payload, uint32_t byte_index, TSPoint position,
TSPoint position, uint32_t *bytes_read) uint32_t *bytes_read)
{ {
buf_T *bp = payload; buf_T *bp = payload;
#define BUFSIZE 256 #define BUFSIZE 256
@@ -318,9 +315,7 @@ static const char *input_cb(void *payload, uint32_t byte_index,
#undef BUFSIZE #undef BUFSIZE
} }
static void push_ranges(lua_State *L, static void push_ranges(lua_State *L, const TSRange *ranges, const unsigned int length)
const TSRange *ranges,
const unsigned int length)
{ {
lua_createtable(L, length, 0); lua_createtable(L, length, 0);
for (size_t i = 0; i < length; i++) { 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 // This switch is necessary because of the behavior of lua_isstring, that
// consider numbers as strings... // consider numbers as strings...
switch (lua_type(L, 3)) { switch (lua_type(L, 3)) {
case LUA_TSTRING: case LUA_TSTRING:
str = lua_tolstring(L, 3, &len); str = lua_tolstring(L, 3, &len);
new_tree = ts_parser_parse_string(*p, old_tree, str, len); new_tree = ts_parser_parse_string(*p, old_tree, str, len);
break; break;
case LUA_TNUMBER: case LUA_TNUMBER:
bufnr = lua_tointeger(L, 3); bufnr = lua_tointeger(L, 3);
buf = handle_get_buffer(bufnr); buf = handle_get_buffer(bufnr);
if (!buf) { if (!buf) {
return luaL_error(L, "invalid buffer handle: %d", bufnr); return luaL_error(L, "invalid buffer handle: %d", bufnr);
} }
input = (TSInput){ (void *)buf, input_cb, TSInputEncodingUTF8 }; input = (TSInput){ (void *)buf, input_cb, TSInputEncodingUTF8 };
new_tree = ts_parser_parse(*p, old_tree, input); new_tree = ts_parser_parse(*p, old_tree, input);
break; break;
default: default:
return luaL_error(L, "invalid argument to parser:parse()"); return luaL_error(L, "invalid argument to parser:parse()");
} }
// Sometimes parsing fails (timeout, or wrong parser ABI) // Sometimes parsing fails (timeout, or wrong parser ABI)
@@ -393,8 +388,7 @@ static int parser_parse(lua_State *L)
// the lua GC. // the lua GC.
// Old tree is still owned by the lua GC. // Old tree is still owned by the lua GC.
uint32_t n_ranges = 0; uint32_t n_ranges = 0;
TSRange *changed = old_tree ? ts_tree_get_changed_ranges( TSRange *changed = old_tree ? ts_tree_get_changed_ranges(old_tree, new_tree, &n_ranges) : NULL;
old_tree, new_tree, &n_ranges) : NULL;
push_tree(L, new_tree, false); // [tree] push_tree(L, new_tree, false); // [tree]
@@ -504,17 +498,15 @@ static void range_from_lua(lua_State *L, TSRange *range)
} }
return; return;
error: error:
luaL_error( luaL_error(L,
L, "Ranges can only be made from 6 element long tables or nodes.");
"Ranges can only be made from 6 element long tables or nodes.");
} }
static int parser_set_ranges(lua_State *L) static int parser_set_ranges(lua_State *L)
{ {
if (lua_gettop(L) < 2) { if (lua_gettop(L) < 2) {
return luaL_error( return luaL_error(L,
L, "not enough args to parser:set_included_ranges()");
"not enough args to parser:set_included_ranges()");
} }
TSParser **p = parser_check(L, 1); TSParser **p = parser_check(L, 1);
@@ -523,9 +515,8 @@ static int parser_set_ranges(lua_State *L)
} }
if (!lua_istable(L, 2)) { if (!lua_istable(L, 2)) {
return luaL_error( return luaL_error(L,
L, "argument for parser:set_included_ranges() should be a table.");
"argument for parser:set_included_ranges() should be a table.");
} }
size_t tbl_len = lua_objlen(L, 2); size_t tbl_len = lua_objlen(L, 2);
@@ -890,9 +881,9 @@ static int node_descendant_for_range(lua_State *L)
return 0; return 0;
} }
TSPoint start = { (uint32_t)lua_tointeger(L, 2), 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), 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); TSNode child = ts_node_descendant_for_point_range(node, start, end);
push_node(L, child, 1); push_node(L, child, 1);
@@ -906,9 +897,9 @@ static int node_named_descendant_for_range(lua_State *L)
return 0; return 0;
} }
TSPoint start = { (uint32_t)lua_tointeger(L, 2), 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), 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); TSNode child = ts_node_named_descendant_for_point_range(node, start, end);
push_node(L, child, 1); 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) static int node_next_child(lua_State *L)
{ {
TSTreeCursor *ud = luaL_checkudata( TSTreeCursor *ud = luaL_checkudata(L, lua_upvalueindex(1), TS_META_TREECURSOR);
L, lua_upvalueindex(1), TS_META_TREECURSOR);
if (!ud) { if (!ud) {
return 0; return 0;
} }
@@ -939,19 +929,18 @@ static int node_next_child(lua_State *L)
if (ts_tree_cursor_goto_next_sibling(ud)) { if (ts_tree_cursor_goto_next_sibling(ud)) {
push: push:
push_node( push_node(L,
L, ts_tree_cursor_current_node(ud),
ts_tree_cursor_current_node(ud), lua_upvalueindex(2)); // [node]
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) { if (field != NULL) {
lua_pushstring(L, ts_tree_cursor_current_field_name(ud)); lua_pushstring(L, ts_tree_cursor_current_field_name(ud));
} else { } else {
lua_pushnil(L); lua_pushnil(L);
} // [node, field_name_or_nil] } // [node, field_name_or_nil]
return 2; return 2;
} }
end: end:
@@ -1200,11 +1189,16 @@ int tslua_parse_query(lua_State *L)
static const char *query_err_string(TSQueryError err) { static const char *query_err_string(TSQueryError err) {
switch (err) { switch (err) {
case TSQueryErrorSyntax: return "invalid syntax"; case TSQueryErrorSyntax:
case TSQueryErrorNodeType: return "invalid node type"; return "invalid syntax";
case TSQueryErrorField: return "invalid field"; case TSQueryErrorNodeType:
case TSQueryErrorCapture: return "invalid capture"; return "invalid node type";
default: return "error"; case TSQueryErrorField:
return "invalid field";
case TSQueryErrorCapture:
return "invalid capture";
default:
return "error";
} }
} }

View File

@@ -1,18 +1,17 @@
#include <errno.h>
#include <lauxlib.h>
#include <lua.h> #include <lua.h>
#include <lualib.h> #include <lualib.h>
#include <lauxlib.h>
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "nvim/vim.h" #include "nvim/api/private/helpers.h"
#include "xdiff/xdiff.h"
#include "nvim/lua/xdiff.h"
#include "nvim/lua/converter.h" #include "nvim/lua/converter.h"
#include "nvim/lua/executor.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 { typedef enum {
kNluaXdiffModeUnified = 0, kNluaXdiffModeUnified = 0,
@@ -22,7 +21,7 @@ typedef enum {
typedef struct { typedef struct {
lua_State *lstate; lua_State *lstate;
Error *err; Error *err;
} hunkpriv_t; } hunkpriv_t;
#ifdef INCLUDE_GENERATED_DECLARATIONS #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 // hunk_func callback used when opts.hunk_lines = true
static int hunk_locations_cb(long start_a, long count_a, static int hunk_locations_cb(long start_a, long count_a, long start_b, long count_b, void *cb_data)
long start_b, long count_b, void *cb_data)
{ {
// Mimic extra offsets done by xdiff, see: // Mimic extra offsets done by xdiff, see:
// src/nvim/xdiff/xemit.c:284 // 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 // hunk_func callback used when opts.on_hunk is given
static int call_on_hunk_cb(long start_a, long count_a, static int call_on_hunk_cb(long start_a, long count_a, long start_b, long count_b, void *cb_data)
long start_b, long count_b, void *cb_data)
{ {
// Mimic extra offsets done by xdiff, see: // Mimic extra offsets done by xdiff, see:
// src/nvim/xdiff/xemit.c:284 // 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 // Helper function for validating option types
static bool check_xdiff_opt(ObjectType actType, ObjectType expType, static bool check_xdiff_opt(ObjectType actType, ObjectType expType, const char *name, Error *err)
const char *name, Error *err)
{ {
if (actType != expType) { if (actType != expType) {
const char * type_str = const char * type_str =
@@ -139,7 +135,7 @@ static bool check_xdiff_opt(ObjectType actType, ObjectType expType,
expType == kObjectTypeInteger ? "integer" : expType == kObjectTypeInteger ? "integer" :
expType == kObjectTypeBoolean ? "boolean" : expType == kObjectTypeBoolean ? "boolean" :
expType == kObjectTypeLuaRef ? "function" : expType == kObjectTypeLuaRef ? "function" :
"NA"; "NA";
api_set_error(err, kErrorTypeValidation, "%s is not a %s", name, api_set_error(err, kErrorTypeValidation, "%s is not a %s", name,
type_str); type_str);
@@ -149,9 +145,8 @@ static bool check_xdiff_opt(ObjectType actType, ObjectType expType,
return false; return false;
} }
static NluaXdiffMode process_xdl_diff_opts(lua_State *lstate, static NluaXdiffMode process_xdl_diff_opts(lua_State *lstate, xdemitconf_t *cfg, xpparam_t *params,
xdemitconf_t *cfg, Error *err)
xpparam_t *params, Error *err)
{ {
const DictionaryOf(LuaRef) opts = nlua_pop_Dictionary(lstate, true, 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; const char *name;
unsigned long value; unsigned long value;
} flags[] = { } flags[] = {
{ "ignore_whitespace" , XDF_IGNORE_WHITESPACE }, { "ignore_whitespace", XDF_IGNORE_WHITESPACE },
{ "ignore_whitespace_change" , XDF_IGNORE_WHITESPACE_CHANGE }, { "ignore_whitespace_change", XDF_IGNORE_WHITESPACE_CHANGE },
{ "ignore_whitespace_change_at_eol", XDF_IGNORE_WHITESPACE_AT_EOL }, { "ignore_whitespace_change_at_eol", XDF_IGNORE_WHITESPACE_AT_EOL },
{ "ignore_cr_at_eol" , XDF_IGNORE_CR_AT_EOL }, { "ignore_cr_at_eol", XDF_IGNORE_CR_AT_EOL },
{ "ignore_blank_lines" , XDF_IGNORE_BLANK_LINES }, { "ignore_blank_lines", XDF_IGNORE_BLANK_LINES },
{ "indent_heuristic" , XDF_INDENT_HEURISTIC }, { "indent_heuristic", XDF_INDENT_HEURISTIC },
{ NULL , 0 }, { NULL, 0 },
}; };
bool key_used = false; bool key_used = false;
for (size_t j = 0; flags[j].name; j++) { for (size_t j = 0; flags[j].name; j++) {
@@ -270,9 +265,9 @@ int nlua_xdl_diff(lua_State *lstate)
xpparam_t params; xpparam_t params;
xdemitcb_t ecb; xdemitcb_t ecb;
memset(&cfg , 0, sizeof(cfg)); memset(&cfg, 0, sizeof(cfg));
memset(&params, 0, sizeof(params)); memset(&params, 0, sizeof(params));
memset(&ecb , 0, sizeof(ecb)); memset(&ecb, 0, sizeof(ecb));
NluaXdiffMode mode = kNluaXdiffModeUnified; NluaXdiffMode mode = kNluaXdiffModeUnified;
@@ -291,21 +286,21 @@ int nlua_xdl_diff(lua_State *lstate)
luaL_Buffer buf; luaL_Buffer buf;
hunkpriv_t *priv = NULL; hunkpriv_t *priv = NULL;
switch (mode) { switch (mode) {
case kNluaXdiffModeUnified: case kNluaXdiffModeUnified:
luaL_buffinit(lstate, &buf); luaL_buffinit(lstate, &buf);
ecb.priv = &buf; ecb.priv = &buf;
ecb.out_line = write_string; ecb.out_line = write_string;
break; break;
case kNluaXdiffModeOnHunkCB: case kNluaXdiffModeOnHunkCB:
priv = xmalloc(sizeof(*priv)); priv = xmalloc(sizeof(*priv));
priv->lstate = lstate; priv->lstate = lstate;
priv->err = &err; priv->err = &err;
ecb.priv = priv; ecb.priv = priv;
break; break;
case kNluaXdiffModeLocations: case kNluaXdiffModeLocations:
lua_createtable(lstate, 0, 0); lua_createtable(lstate, 0, 0);
ecb.priv = lstate; ecb.priv = lstate;
break; break;
} }
if (xdl_diff(&ma, &mb, &params, &cfg, &ecb) == -1) { if (xdl_diff(&ma, &mb, &params, &cfg, &ecb) == -1) {