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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 1806 additions and 1754 deletions

View File

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

View File

@ -1,16 +1,16 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "nvim/os/os.h"
#include "nvim/fileio.h"
#include "nvim/vim.h"
#include "nvim/main.h"
#include "nvim/ui.h"
#include "nvim/aucmd.h"
#include "nvim/buffer.h"
#include "nvim/eval.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/buffer.h"
#include "nvim/fileio.h"
#include "nvim/main.h"
#include "nvim/os/os.h"
#include "nvim/ui.h"
#include "nvim/vim.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "aucmd.c.generated.h"

View File

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

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
// 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/msgpack_rpc/channel.h"
#include "nvim/lua/executor.h"
#include "nvim/assert.h"
#include "nvim/buffer.h"
#include "nvim/buffer_updates.h"
#include "nvim/extmark.h"
#include "nvim/lua/executor.h"
#include "nvim/memline.h"
#include "nvim/msgpack_rpc/channel.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "buffer_updates.c.generated.h"
@ -17,8 +17,7 @@
// Register a channel. Return True if the channel was added, or already added.
// Return False if the channel couldn't be added because the buffer is
// unloaded.
bool buf_updates_register(buf_T *buf, uint64_t channel_id,
BufUpdateCallbacks cb, bool send_buffer)
bool buf_updates_register(buf_T *buf, uint64_t channel_id, BufUpdateCallbacks cb, bool send_buffer)
{
// must fail if the buffer isn't loaded
if (buf->b_ml.ml_mfp == NULL) {
@ -86,16 +85,16 @@ bool buf_updates_register(buf_T *buf, uint64_t channel_id,
bool buf_updates_active(buf_T *buf)
{
return kv_size(buf->update_channels) || kv_size(buf->update_callbacks);
return kv_size(buf->update_channels) || kv_size(buf->update_callbacks);
}
void buf_updates_send_end(buf_T *buf, uint64_t channelid)
{
Array args = ARRAY_DICT_INIT;
args.size = 1;
args.items = xcalloc(args.size, sizeof(Object));
args.items[0] = BUFFER_OBJ(buf->handle);
rpc_send_event(channelid, "nvim_buf_detach_event", args);
Array args = ARRAY_DICT_INIT;
args.size = 1;
args.items = xcalloc(args.size, sizeof(Object));
args.items[0] = BUFFER_OBJ(buf->handle);
rpc_send_event(channelid, "nvim_buf_detach_event", args);
}
void buf_updates_unregister(buf_T *buf, uint64_t channelid)
@ -187,11 +186,8 @@ void buf_updates_unload(buf_T *buf, bool can_reload)
}
void buf_updates_send_changes(buf_T *buf,
linenr_T firstline,
int64_t num_added,
int64_t num_removed,
bool send_tick)
void buf_updates_send_changes(buf_T *buf, linenr_T firstline, int64_t num_added,
int64_t num_removed, bool send_tick)
{
size_t deleted_codepoints, deleted_codeunits;
size_t deleted_bytes = ml_flush_deleted_bytes(buf, &deleted_codepoints,
@ -228,11 +224,11 @@ void buf_updates_send_changes(buf_T *buf,
// linedata of lines being swapped in
Array linedata = ARRAY_DICT_INIT;
if (num_added > 0) {
STATIC_ASSERT(SIZE_MAX >= MAXLNUM, "size_t smaller than MAXLNUM");
linedata.size = (size_t)num_added;
linedata.items = xcalloc((size_t)num_added, sizeof(Object));
buf_collect_lines(buf, (size_t)num_added, firstline, true, &linedata,
NULL);
STATIC_ASSERT(SIZE_MAX >= MAXLNUM, "size_t smaller than MAXLNUM");
linedata.size = (size_t)num_added;
linedata.items = xcalloc((size_t)num_added, sizeof(Object));
buf_collect_lines(buf, (size_t)num_added, firstline, true, &linedata,
NULL);
}
args.items[4] = ARRAY_OBJ(linedata);
args.items[5] = BOOLEAN_OBJ(false);
@ -248,7 +244,7 @@ void buf_updates_send_changes(buf_T *buf,
// change notifications are so frequent that many dead channels will be
// cleared up quickly.
if (badchannelid != 0) {
ELOG("Disabling buffer updates for dead channel %"PRIu64, badchannelid);
ELOG("Disabling buffer updates for dead channel %" PRIu64, badchannelid);
buf_updates_unregister(buf, badchannelid);
}
@ -302,11 +298,9 @@ void buf_updates_send_changes(buf_T *buf,
kv_size(buf->update_callbacks) = j;
}
void buf_updates_send_splice(
buf_T *buf,
int start_row, colnr_T start_col, bcount_t start_byte,
int old_row, colnr_T old_col, bcount_t old_byte,
int new_row, colnr_T new_col, bcount_t new_byte)
void buf_updates_send_splice(buf_T *buf, int start_row, colnr_T start_col, bcount_t start_byte,
int old_row, colnr_T old_col, bcount_t old_byte, int new_row,
colnr_T new_col, bcount_t new_byte)
{
if (!buf_updates_active(buf)
|| (old_byte == 0 && new_byte == 0)) {
@ -392,18 +386,18 @@ void buf_updates_changedtick(buf_T *buf)
void buf_updates_changedtick_single(buf_T *buf, uint64_t channel_id)
{
Array args = ARRAY_DICT_INIT;
args.size = 2;
args.items = xcalloc(args.size, sizeof(Object));
Array args = ARRAY_DICT_INIT;
args.size = 2;
args.items = xcalloc(args.size, sizeof(Object));
// the first argument is always the buffer handle
args.items[0] = BUFFER_OBJ(buf->handle);
// the first argument is always the buffer handle
args.items[0] = BUFFER_OBJ(buf->handle);
// next argument is b:changedtick
args.items[1] = INTEGER_OBJ(buf_get_changedtick(buf));
// next argument is b:changedtick
args.items[1] = INTEGER_OBJ(buf_get_changedtick(buf));
// don't try and clean up dead channels here
rpc_send_event(channel_id, "nvim_buf_changedtick_event", args);
// don't try and clean up dead channels here
rpc_send_event(channel_id, "nvim_buf_changedtick_event", args);
}
void buffer_update_callbacks_free(BufUpdateCallbacks cb)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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