mirror of
https://github.com/neovim/neovim.git
synced 2025-09-16 00:08:19 +00:00
refactor: format with uncrustify #15722
This commit is contained in:
@@ -15,9 +15,9 @@
|
|||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "nvim/vim.h"
|
|
||||||
#include "nvim/ascii.h"
|
|
||||||
#include "nvim/arabic.h"
|
#include "nvim/arabic.h"
|
||||||
|
#include "nvim/ascii.h"
|
||||||
|
#include "nvim/vim.h"
|
||||||
|
|
||||||
// Arabic ISO-10646-1 character set definition
|
// Arabic ISO-10646-1 character set definition
|
||||||
|
|
||||||
@@ -394,43 +394,80 @@ static bool A_is_f(int cur_c)
|
|||||||
static int chg_c_a2s(int cur_c)
|
static int chg_c_a2s(int cur_c)
|
||||||
{
|
{
|
||||||
switch (cur_c) {
|
switch (cur_c) {
|
||||||
case a_HAMZA: return a_s_HAMZA;
|
case a_HAMZA:
|
||||||
case a_ALEF_MADDA: return a_s_ALEF_MADDA;
|
return a_s_HAMZA;
|
||||||
case a_ALEF_HAMZA_ABOVE: return a_s_ALEF_HAMZA_ABOVE;
|
case a_ALEF_MADDA:
|
||||||
case a_WAW_HAMZA: return a_s_WAW_HAMZA;
|
return a_s_ALEF_MADDA;
|
||||||
case a_ALEF_HAMZA_BELOW: return a_s_ALEF_HAMZA_BELOW;
|
case a_ALEF_HAMZA_ABOVE:
|
||||||
case a_YEH_HAMZA: return a_s_YEH_HAMZA;
|
return a_s_ALEF_HAMZA_ABOVE;
|
||||||
case a_ALEF: return a_s_ALEF;
|
case a_WAW_HAMZA:
|
||||||
case a_TEH_MARBUTA: return a_s_TEH_MARBUTA;
|
return a_s_WAW_HAMZA;
|
||||||
case a_DAL: return a_s_DAL;
|
case a_ALEF_HAMZA_BELOW:
|
||||||
case a_THAL: return a_s_THAL;
|
return a_s_ALEF_HAMZA_BELOW;
|
||||||
case a_REH: return a_s_REH;
|
case a_YEH_HAMZA:
|
||||||
case a_ZAIN: return a_s_ZAIN;
|
return a_s_YEH_HAMZA;
|
||||||
case a_TATWEEL: return cur_c; // exceptions
|
case a_ALEF:
|
||||||
case a_WAW: return a_s_WAW;
|
return a_s_ALEF;
|
||||||
case a_ALEF_MAKSURA: return a_s_ALEF_MAKSURA;
|
case a_TEH_MARBUTA:
|
||||||
case a_BEH: return a_s_BEH;
|
return a_s_TEH_MARBUTA;
|
||||||
case a_TEH: return a_s_TEH;
|
case a_DAL:
|
||||||
case a_THEH: return a_s_THEH;
|
return a_s_DAL;
|
||||||
case a_JEEM: return a_s_JEEM;
|
case a_THAL:
|
||||||
case a_HAH: return a_s_HAH;
|
return a_s_THAL;
|
||||||
case a_KHAH: return a_s_KHAH;
|
case a_REH:
|
||||||
case a_SEEN: return a_s_SEEN;
|
return a_s_REH;
|
||||||
case a_SHEEN: return a_s_SHEEN;
|
case a_ZAIN:
|
||||||
case a_SAD: return a_s_SAD;
|
return a_s_ZAIN;
|
||||||
case a_DAD: return a_s_DAD;
|
case a_TATWEEL:
|
||||||
case a_TAH: return a_s_TAH;
|
return cur_c; // exceptions
|
||||||
case a_ZAH: return a_s_ZAH;
|
case a_WAW:
|
||||||
case a_AIN: return a_s_AIN;
|
return a_s_WAW;
|
||||||
case a_GHAIN: return a_s_GHAIN;
|
case a_ALEF_MAKSURA:
|
||||||
case a_FEH: return a_s_FEH;
|
return a_s_ALEF_MAKSURA;
|
||||||
case a_QAF: return a_s_QAF;
|
case a_BEH:
|
||||||
case a_KAF: return a_s_KAF;
|
return a_s_BEH;
|
||||||
case a_LAM: return a_s_LAM;
|
case a_TEH:
|
||||||
case a_MEEM: return a_s_MEEM;
|
return a_s_TEH;
|
||||||
case a_NOON: return a_s_NOON;
|
case a_THEH:
|
||||||
case a_HEH: return a_s_HEH;
|
return a_s_THEH;
|
||||||
case a_YEH: return a_s_YEH;
|
case a_JEEM:
|
||||||
|
return a_s_JEEM;
|
||||||
|
case a_HAH:
|
||||||
|
return a_s_HAH;
|
||||||
|
case a_KHAH:
|
||||||
|
return a_s_KHAH;
|
||||||
|
case a_SEEN:
|
||||||
|
return a_s_SEEN;
|
||||||
|
case a_SHEEN:
|
||||||
|
return a_s_SHEEN;
|
||||||
|
case a_SAD:
|
||||||
|
return a_s_SAD;
|
||||||
|
case a_DAD:
|
||||||
|
return a_s_DAD;
|
||||||
|
case a_TAH:
|
||||||
|
return a_s_TAH;
|
||||||
|
case a_ZAH:
|
||||||
|
return a_s_ZAH;
|
||||||
|
case a_AIN:
|
||||||
|
return a_s_AIN;
|
||||||
|
case a_GHAIN:
|
||||||
|
return a_s_GHAIN;
|
||||||
|
case a_FEH:
|
||||||
|
return a_s_FEH;
|
||||||
|
case a_QAF:
|
||||||
|
return a_s_QAF;
|
||||||
|
case a_KAF:
|
||||||
|
return a_s_KAF;
|
||||||
|
case a_LAM:
|
||||||
|
return a_s_LAM;
|
||||||
|
case a_MEEM:
|
||||||
|
return a_s_MEEM;
|
||||||
|
case a_NOON:
|
||||||
|
return a_s_NOON;
|
||||||
|
case a_HEH:
|
||||||
|
return a_s_HEH;
|
||||||
|
case a_YEH:
|
||||||
|
return a_s_YEH;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -439,43 +476,80 @@ static int chg_c_a2s(int cur_c)
|
|||||||
static int chg_c_a2i(int cur_c)
|
static int chg_c_a2i(int cur_c)
|
||||||
{
|
{
|
||||||
switch (cur_c) {
|
switch (cur_c) {
|
||||||
case a_YEH_HAMZA: return a_i_YEH_HAMZA;
|
case a_YEH_HAMZA:
|
||||||
case a_HAMZA: return a_s_HAMZA; // exceptions
|
return a_i_YEH_HAMZA;
|
||||||
case a_ALEF_MADDA: return a_s_ALEF_MADDA; // exceptions
|
case a_HAMZA:
|
||||||
case a_ALEF_HAMZA_ABOVE: return a_s_ALEF_HAMZA_ABOVE; // exceptions
|
return a_s_HAMZA; // exceptions
|
||||||
case a_WAW_HAMZA: return a_s_WAW_HAMZA; // exceptions
|
case a_ALEF_MADDA:
|
||||||
case a_ALEF_HAMZA_BELOW: return a_s_ALEF_HAMZA_BELOW; // exceptions
|
return a_s_ALEF_MADDA; // exceptions
|
||||||
case a_ALEF: return a_s_ALEF; // exceptions
|
case a_ALEF_HAMZA_ABOVE:
|
||||||
case a_TEH_MARBUTA: return a_s_TEH_MARBUTA; // exceptions
|
return a_s_ALEF_HAMZA_ABOVE; // exceptions
|
||||||
case a_DAL: return a_s_DAL; // exceptions
|
case a_WAW_HAMZA:
|
||||||
case a_THAL: return a_s_THAL; // exceptions
|
return a_s_WAW_HAMZA; // exceptions
|
||||||
case a_REH: return a_s_REH; // exceptions
|
case a_ALEF_HAMZA_BELOW:
|
||||||
case a_ZAIN: return a_s_ZAIN; // exceptions
|
return a_s_ALEF_HAMZA_BELOW; // exceptions
|
||||||
case a_TATWEEL: return cur_c; // exceptions
|
case a_ALEF:
|
||||||
case a_WAW: return a_s_WAW; // exceptions
|
return a_s_ALEF; // exceptions
|
||||||
case a_ALEF_MAKSURA: return a_s_ALEF_MAKSURA; // exceptions
|
case a_TEH_MARBUTA:
|
||||||
case a_BEH: return a_i_BEH;
|
return a_s_TEH_MARBUTA; // exceptions
|
||||||
case a_TEH: return a_i_TEH;
|
case a_DAL:
|
||||||
case a_THEH: return a_i_THEH;
|
return a_s_DAL; // exceptions
|
||||||
case a_JEEM: return a_i_JEEM;
|
case a_THAL:
|
||||||
case a_HAH: return a_i_HAH;
|
return a_s_THAL; // exceptions
|
||||||
case a_KHAH: return a_i_KHAH;
|
case a_REH:
|
||||||
case a_SEEN: return a_i_SEEN;
|
return a_s_REH; // exceptions
|
||||||
case a_SHEEN: return a_i_SHEEN;
|
case a_ZAIN:
|
||||||
case a_SAD: return a_i_SAD;
|
return a_s_ZAIN; // exceptions
|
||||||
case a_DAD: return a_i_DAD;
|
case a_TATWEEL:
|
||||||
case a_TAH: return a_i_TAH;
|
return cur_c; // exceptions
|
||||||
case a_ZAH: return a_i_ZAH;
|
case a_WAW:
|
||||||
case a_AIN: return a_i_AIN;
|
return a_s_WAW; // exceptions
|
||||||
case a_GHAIN: return a_i_GHAIN;
|
case a_ALEF_MAKSURA:
|
||||||
case a_FEH: return a_i_FEH;
|
return a_s_ALEF_MAKSURA; // exceptions
|
||||||
case a_QAF: return a_i_QAF;
|
case a_BEH:
|
||||||
case a_KAF: return a_i_KAF;
|
return a_i_BEH;
|
||||||
case a_LAM: return a_i_LAM;
|
case a_TEH:
|
||||||
case a_MEEM: return a_i_MEEM;
|
return a_i_TEH;
|
||||||
case a_NOON: return a_i_NOON;
|
case a_THEH:
|
||||||
case a_HEH: return a_i_HEH;
|
return a_i_THEH;
|
||||||
case a_YEH: return a_i_YEH;
|
case a_JEEM:
|
||||||
|
return a_i_JEEM;
|
||||||
|
case a_HAH:
|
||||||
|
return a_i_HAH;
|
||||||
|
case a_KHAH:
|
||||||
|
return a_i_KHAH;
|
||||||
|
case a_SEEN:
|
||||||
|
return a_i_SEEN;
|
||||||
|
case a_SHEEN:
|
||||||
|
return a_i_SHEEN;
|
||||||
|
case a_SAD:
|
||||||
|
return a_i_SAD;
|
||||||
|
case a_DAD:
|
||||||
|
return a_i_DAD;
|
||||||
|
case a_TAH:
|
||||||
|
return a_i_TAH;
|
||||||
|
case a_ZAH:
|
||||||
|
return a_i_ZAH;
|
||||||
|
case a_AIN:
|
||||||
|
return a_i_AIN;
|
||||||
|
case a_GHAIN:
|
||||||
|
return a_i_GHAIN;
|
||||||
|
case a_FEH:
|
||||||
|
return a_i_FEH;
|
||||||
|
case a_QAF:
|
||||||
|
return a_i_QAF;
|
||||||
|
case a_KAF:
|
||||||
|
return a_i_KAF;
|
||||||
|
case a_LAM:
|
||||||
|
return a_i_LAM;
|
||||||
|
case a_MEEM:
|
||||||
|
return a_i_MEEM;
|
||||||
|
case a_NOON:
|
||||||
|
return a_i_NOON;
|
||||||
|
case a_HEH:
|
||||||
|
return a_i_HEH;
|
||||||
|
case a_YEH:
|
||||||
|
return a_i_YEH;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -484,43 +558,80 @@ static int chg_c_a2i(int cur_c)
|
|||||||
static int chg_c_a2m(int cur_c)
|
static int chg_c_a2m(int cur_c)
|
||||||
{
|
{
|
||||||
switch (cur_c) {
|
switch (cur_c) {
|
||||||
case a_HAMZA: return a_s_HAMZA; // exception
|
case a_HAMZA:
|
||||||
case a_ALEF_MADDA: return a_f_ALEF_MADDA; // exception
|
return a_s_HAMZA; // exception
|
||||||
case a_ALEF_HAMZA_ABOVE: return a_f_ALEF_HAMZA_ABOVE; // exception
|
case a_ALEF_MADDA:
|
||||||
case a_WAW_HAMZA: return a_f_WAW_HAMZA; // exception
|
return a_f_ALEF_MADDA; // exception
|
||||||
case a_ALEF_HAMZA_BELOW: return a_f_ALEF_HAMZA_BELOW; // exception
|
case a_ALEF_HAMZA_ABOVE:
|
||||||
case a_YEH_HAMZA: return a_m_YEH_HAMZA;
|
return a_f_ALEF_HAMZA_ABOVE; // exception
|
||||||
case a_ALEF: return a_f_ALEF; // exception
|
case a_WAW_HAMZA:
|
||||||
case a_BEH: return a_m_BEH;
|
return a_f_WAW_HAMZA; // exception
|
||||||
case a_TEH_MARBUTA: return a_f_TEH_MARBUTA; // exception
|
case a_ALEF_HAMZA_BELOW:
|
||||||
case a_TEH: return a_m_TEH;
|
return a_f_ALEF_HAMZA_BELOW; // exception
|
||||||
case a_THEH: return a_m_THEH;
|
case a_YEH_HAMZA:
|
||||||
case a_JEEM: return a_m_JEEM;
|
return a_m_YEH_HAMZA;
|
||||||
case a_HAH: return a_m_HAH;
|
case a_ALEF:
|
||||||
case a_KHAH: return a_m_KHAH;
|
return a_f_ALEF; // exception
|
||||||
case a_DAL: return a_f_DAL; // exception
|
case a_BEH:
|
||||||
case a_THAL: return a_f_THAL; // exception
|
return a_m_BEH;
|
||||||
case a_REH: return a_f_REH; // exception
|
case a_TEH_MARBUTA:
|
||||||
case a_ZAIN: return a_f_ZAIN; // exception
|
return a_f_TEH_MARBUTA; // exception
|
||||||
case a_SEEN: return a_m_SEEN;
|
case a_TEH:
|
||||||
case a_SHEEN: return a_m_SHEEN;
|
return a_m_TEH;
|
||||||
case a_SAD: return a_m_SAD;
|
case a_THEH:
|
||||||
case a_DAD: return a_m_DAD;
|
return a_m_THEH;
|
||||||
case a_TAH: return a_m_TAH;
|
case a_JEEM:
|
||||||
case a_ZAH: return a_m_ZAH;
|
return a_m_JEEM;
|
||||||
case a_AIN: return a_m_AIN;
|
case a_HAH:
|
||||||
case a_GHAIN: return a_m_GHAIN;
|
return a_m_HAH;
|
||||||
case a_TATWEEL: return cur_c; // exception
|
case a_KHAH:
|
||||||
case a_FEH: return a_m_FEH;
|
return a_m_KHAH;
|
||||||
case a_QAF: return a_m_QAF;
|
case a_DAL:
|
||||||
case a_KAF: return a_m_KAF;
|
return a_f_DAL; // exception
|
||||||
case a_LAM: return a_m_LAM;
|
case a_THAL:
|
||||||
case a_MEEM: return a_m_MEEM;
|
return a_f_THAL; // exception
|
||||||
case a_NOON: return a_m_NOON;
|
case a_REH:
|
||||||
case a_HEH: return a_m_HEH;
|
return a_f_REH; // exception
|
||||||
case a_WAW: return a_f_WAW; // exception
|
case a_ZAIN:
|
||||||
case a_ALEF_MAKSURA: return a_f_ALEF_MAKSURA; // exception
|
return a_f_ZAIN; // exception
|
||||||
case a_YEH: return a_m_YEH;
|
case a_SEEN:
|
||||||
|
return a_m_SEEN;
|
||||||
|
case a_SHEEN:
|
||||||
|
return a_m_SHEEN;
|
||||||
|
case a_SAD:
|
||||||
|
return a_m_SAD;
|
||||||
|
case a_DAD:
|
||||||
|
return a_m_DAD;
|
||||||
|
case a_TAH:
|
||||||
|
return a_m_TAH;
|
||||||
|
case a_ZAH:
|
||||||
|
return a_m_ZAH;
|
||||||
|
case a_AIN:
|
||||||
|
return a_m_AIN;
|
||||||
|
case a_GHAIN:
|
||||||
|
return a_m_GHAIN;
|
||||||
|
case a_TATWEEL:
|
||||||
|
return cur_c; // exception
|
||||||
|
case a_FEH:
|
||||||
|
return a_m_FEH;
|
||||||
|
case a_QAF:
|
||||||
|
return a_m_QAF;
|
||||||
|
case a_KAF:
|
||||||
|
return a_m_KAF;
|
||||||
|
case a_LAM:
|
||||||
|
return a_m_LAM;
|
||||||
|
case a_MEEM:
|
||||||
|
return a_m_MEEM;
|
||||||
|
case a_NOON:
|
||||||
|
return a_m_NOON;
|
||||||
|
case a_HEH:
|
||||||
|
return a_m_HEH;
|
||||||
|
case a_WAW:
|
||||||
|
return a_f_WAW; // exception
|
||||||
|
case a_ALEF_MAKSURA:
|
||||||
|
return a_f_ALEF_MAKSURA; // exception
|
||||||
|
case a_YEH:
|
||||||
|
return a_m_YEH;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -538,43 +649,80 @@ static int chg_c_a2f(int cur_c)
|
|||||||
// a_f_LAM_ALEF_HAMZA_BELOW;
|
// a_f_LAM_ALEF_HAMZA_BELOW;
|
||||||
|
|
||||||
switch (cur_c) {
|
switch (cur_c) {
|
||||||
case a_HAMZA: return a_s_HAMZA; // exception
|
case a_HAMZA:
|
||||||
case a_ALEF_MADDA: return a_f_ALEF_MADDA;
|
return a_s_HAMZA; // exception
|
||||||
case a_ALEF_HAMZA_ABOVE: return a_f_ALEF_HAMZA_ABOVE;
|
case a_ALEF_MADDA:
|
||||||
case a_WAW_HAMZA: return a_f_WAW_HAMZA;
|
return a_f_ALEF_MADDA;
|
||||||
case a_ALEF_HAMZA_BELOW: return a_f_ALEF_HAMZA_BELOW;
|
case a_ALEF_HAMZA_ABOVE:
|
||||||
case a_YEH_HAMZA: return a_f_YEH_HAMZA;
|
return a_f_ALEF_HAMZA_ABOVE;
|
||||||
case a_ALEF: return a_f_ALEF;
|
case a_WAW_HAMZA:
|
||||||
case a_BEH: return a_f_BEH;
|
return a_f_WAW_HAMZA;
|
||||||
case a_TEH_MARBUTA: return a_f_TEH_MARBUTA;
|
case a_ALEF_HAMZA_BELOW:
|
||||||
case a_TEH: return a_f_TEH;
|
return a_f_ALEF_HAMZA_BELOW;
|
||||||
case a_THEH: return a_f_THEH;
|
case a_YEH_HAMZA:
|
||||||
case a_JEEM: return a_f_JEEM;
|
return a_f_YEH_HAMZA;
|
||||||
case a_HAH: return a_f_HAH;
|
case a_ALEF:
|
||||||
case a_KHAH: return a_f_KHAH;
|
return a_f_ALEF;
|
||||||
case a_DAL: return a_f_DAL;
|
case a_BEH:
|
||||||
case a_THAL: return a_f_THAL;
|
return a_f_BEH;
|
||||||
case a_REH: return a_f_REH;
|
case a_TEH_MARBUTA:
|
||||||
case a_ZAIN: return a_f_ZAIN;
|
return a_f_TEH_MARBUTA;
|
||||||
case a_SEEN: return a_f_SEEN;
|
case a_TEH:
|
||||||
case a_SHEEN: return a_f_SHEEN;
|
return a_f_TEH;
|
||||||
case a_SAD: return a_f_SAD;
|
case a_THEH:
|
||||||
case a_DAD: return a_f_DAD;
|
return a_f_THEH;
|
||||||
case a_TAH: return a_f_TAH;
|
case a_JEEM:
|
||||||
case a_ZAH: return a_f_ZAH;
|
return a_f_JEEM;
|
||||||
case a_AIN: return a_f_AIN;
|
case a_HAH:
|
||||||
case a_GHAIN: return a_f_GHAIN;
|
return a_f_HAH;
|
||||||
case a_TATWEEL: return cur_c; // exception
|
case a_KHAH:
|
||||||
case a_FEH: return a_f_FEH;
|
return a_f_KHAH;
|
||||||
case a_QAF: return a_f_QAF;
|
case a_DAL:
|
||||||
case a_KAF: return a_f_KAF;
|
return a_f_DAL;
|
||||||
case a_LAM: return a_f_LAM;
|
case a_THAL:
|
||||||
case a_MEEM: return a_f_MEEM;
|
return a_f_THAL;
|
||||||
case a_NOON: return a_f_NOON;
|
case a_REH:
|
||||||
case a_HEH: return a_f_HEH;
|
return a_f_REH;
|
||||||
case a_WAW: return a_f_WAW;
|
case a_ZAIN:
|
||||||
case a_ALEF_MAKSURA: return a_f_ALEF_MAKSURA;
|
return a_f_ZAIN;
|
||||||
case a_YEH: return a_f_YEH;
|
case a_SEEN:
|
||||||
|
return a_f_SEEN;
|
||||||
|
case a_SHEEN:
|
||||||
|
return a_f_SHEEN;
|
||||||
|
case a_SAD:
|
||||||
|
return a_f_SAD;
|
||||||
|
case a_DAD:
|
||||||
|
return a_f_DAD;
|
||||||
|
case a_TAH:
|
||||||
|
return a_f_TAH;
|
||||||
|
case a_ZAH:
|
||||||
|
return a_f_ZAH;
|
||||||
|
case a_AIN:
|
||||||
|
return a_f_AIN;
|
||||||
|
case a_GHAIN:
|
||||||
|
return a_f_GHAIN;
|
||||||
|
case a_TATWEEL:
|
||||||
|
return cur_c; // exception
|
||||||
|
case a_FEH:
|
||||||
|
return a_f_FEH;
|
||||||
|
case a_QAF:
|
||||||
|
return a_f_QAF;
|
||||||
|
case a_KAF:
|
||||||
|
return a_f_KAF;
|
||||||
|
case a_LAM:
|
||||||
|
return a_f_LAM;
|
||||||
|
case a_MEEM:
|
||||||
|
return a_f_MEEM;
|
||||||
|
case a_NOON:
|
||||||
|
return a_f_NOON;
|
||||||
|
case a_HEH:
|
||||||
|
return a_f_HEH;
|
||||||
|
case a_WAW:
|
||||||
|
return a_f_WAW;
|
||||||
|
case a_ALEF_MAKSURA:
|
||||||
|
return a_f_ALEF_MAKSURA;
|
||||||
|
case a_YEH:
|
||||||
|
return a_f_YEH;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -586,29 +734,52 @@ static int chg_c_a2f(int cur_c)
|
|||||||
static int chg_c_i2m(int cur_c)
|
static int chg_c_i2m(int cur_c)
|
||||||
{
|
{
|
||||||
switch (cur_c) {
|
switch (cur_c) {
|
||||||
case a_i_YEH_HAMZA: return a_m_YEH_HAMZA;
|
case a_i_YEH_HAMZA:
|
||||||
case a_i_BEH: return a_m_BEH;
|
return a_m_YEH_HAMZA;
|
||||||
case a_i_TEH: return a_m_TEH;
|
case a_i_BEH:
|
||||||
case a_i_THEH: return a_m_THEH;
|
return a_m_BEH;
|
||||||
case a_i_JEEM: return a_m_JEEM;
|
case a_i_TEH:
|
||||||
case a_i_HAH: return a_m_HAH;
|
return a_m_TEH;
|
||||||
case a_i_KHAH: return a_m_KHAH;
|
case a_i_THEH:
|
||||||
case a_i_SEEN: return a_m_SEEN;
|
return a_m_THEH;
|
||||||
case a_i_SHEEN: return a_m_SHEEN;
|
case a_i_JEEM:
|
||||||
case a_i_SAD: return a_m_SAD;
|
return a_m_JEEM;
|
||||||
case a_i_DAD: return a_m_DAD;
|
case a_i_HAH:
|
||||||
case a_i_TAH: return a_m_TAH;
|
return a_m_HAH;
|
||||||
case a_i_ZAH: return a_m_ZAH;
|
case a_i_KHAH:
|
||||||
case a_i_AIN: return a_m_AIN;
|
return a_m_KHAH;
|
||||||
case a_i_GHAIN: return a_m_GHAIN;
|
case a_i_SEEN:
|
||||||
case a_i_FEH: return a_m_FEH;
|
return a_m_SEEN;
|
||||||
case a_i_QAF: return a_m_QAF;
|
case a_i_SHEEN:
|
||||||
case a_i_KAF: return a_m_KAF;
|
return a_m_SHEEN;
|
||||||
case a_i_LAM: return a_m_LAM;
|
case a_i_SAD:
|
||||||
case a_i_MEEM: return a_m_MEEM;
|
return a_m_SAD;
|
||||||
case a_i_NOON: return a_m_NOON;
|
case a_i_DAD:
|
||||||
case a_i_HEH: return a_m_HEH;
|
return a_m_DAD;
|
||||||
case a_i_YEH: return a_m_YEH;
|
case a_i_TAH:
|
||||||
|
return a_m_TAH;
|
||||||
|
case a_i_ZAH:
|
||||||
|
return a_m_ZAH;
|
||||||
|
case a_i_AIN:
|
||||||
|
return a_m_AIN;
|
||||||
|
case a_i_GHAIN:
|
||||||
|
return a_m_GHAIN;
|
||||||
|
case a_i_FEH:
|
||||||
|
return a_m_FEH;
|
||||||
|
case a_i_QAF:
|
||||||
|
return a_m_QAF;
|
||||||
|
case a_i_KAF:
|
||||||
|
return a_m_KAF;
|
||||||
|
case a_i_LAM:
|
||||||
|
return a_m_LAM;
|
||||||
|
case a_i_MEEM:
|
||||||
|
return a_m_MEEM;
|
||||||
|
case a_i_NOON:
|
||||||
|
return a_m_NOON;
|
||||||
|
case a_i_HEH:
|
||||||
|
return a_m_HEH;
|
||||||
|
case a_i_YEH:
|
||||||
|
return a_m_YEH;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -622,7 +793,8 @@ static int chg_c_f2m(int cur_c)
|
|||||||
// case a_f_ALEF_MADDA:
|
// case a_f_ALEF_MADDA:
|
||||||
// case a_f_ALEF_HAMZA_ABOVE:
|
// case a_f_ALEF_HAMZA_ABOVE:
|
||||||
// case a_f_ALEF_HAMZA_BELOW:
|
// case a_f_ALEF_HAMZA_BELOW:
|
||||||
case a_f_YEH_HAMZA: return a_m_YEH_HAMZA;
|
case a_f_YEH_HAMZA:
|
||||||
|
return a_m_YEH_HAMZA;
|
||||||
case a_f_WAW_HAMZA: // exceptions
|
case a_f_WAW_HAMZA: // exceptions
|
||||||
case a_f_ALEF:
|
case a_f_ALEF:
|
||||||
case a_f_TEH_MARBUTA:
|
case a_f_TEH_MARBUTA:
|
||||||
@@ -633,28 +805,50 @@ static int chg_c_f2m(int cur_c)
|
|||||||
case a_f_WAW:
|
case a_f_WAW:
|
||||||
case a_f_ALEF_MAKSURA:
|
case a_f_ALEF_MAKSURA:
|
||||||
return cur_c;
|
return cur_c;
|
||||||
case a_f_BEH: return a_m_BEH;
|
case a_f_BEH:
|
||||||
case a_f_TEH: return a_m_TEH;
|
return a_m_BEH;
|
||||||
case a_f_THEH: return a_m_THEH;
|
case a_f_TEH:
|
||||||
case a_f_JEEM: return a_m_JEEM;
|
return a_m_TEH;
|
||||||
case a_f_HAH: return a_m_HAH;
|
case a_f_THEH:
|
||||||
case a_f_KHAH: return a_m_KHAH;
|
return a_m_THEH;
|
||||||
case a_f_SEEN: return a_m_SEEN;
|
case a_f_JEEM:
|
||||||
case a_f_SHEEN: return a_m_SHEEN;
|
return a_m_JEEM;
|
||||||
case a_f_SAD: return a_m_SAD;
|
case a_f_HAH:
|
||||||
case a_f_DAD: return a_m_DAD;
|
return a_m_HAH;
|
||||||
case a_f_TAH: return a_m_TAH;
|
case a_f_KHAH:
|
||||||
case a_f_ZAH: return a_m_ZAH;
|
return a_m_KHAH;
|
||||||
case a_f_AIN: return a_m_AIN;
|
case a_f_SEEN:
|
||||||
case a_f_GHAIN: return a_m_GHAIN;
|
return a_m_SEEN;
|
||||||
case a_f_FEH: return a_m_FEH;
|
case a_f_SHEEN:
|
||||||
case a_f_QAF: return a_m_QAF;
|
return a_m_SHEEN;
|
||||||
case a_f_KAF: return a_m_KAF;
|
case a_f_SAD:
|
||||||
case a_f_LAM: return a_m_LAM;
|
return a_m_SAD;
|
||||||
case a_f_MEEM: return a_m_MEEM;
|
case a_f_DAD:
|
||||||
case a_f_NOON: return a_m_NOON;
|
return a_m_DAD;
|
||||||
case a_f_HEH: return a_m_HEH;
|
case a_f_TAH:
|
||||||
case a_f_YEH: return a_m_YEH;
|
return a_m_TAH;
|
||||||
|
case a_f_ZAH:
|
||||||
|
return a_m_ZAH;
|
||||||
|
case a_f_AIN:
|
||||||
|
return a_m_AIN;
|
||||||
|
case a_f_GHAIN:
|
||||||
|
return a_m_GHAIN;
|
||||||
|
case a_f_FEH:
|
||||||
|
return a_m_FEH;
|
||||||
|
case a_f_QAF:
|
||||||
|
return a_m_QAF;
|
||||||
|
case a_f_KAF:
|
||||||
|
return a_m_KAF;
|
||||||
|
case a_f_LAM:
|
||||||
|
return a_m_LAM;
|
||||||
|
case a_f_MEEM:
|
||||||
|
return a_m_MEEM;
|
||||||
|
case a_f_NOON:
|
||||||
|
return a_m_NOON;
|
||||||
|
case a_f_HEH:
|
||||||
|
return a_m_HEH;
|
||||||
|
case a_f_YEH:
|
||||||
|
return a_m_YEH;
|
||||||
// NOTE: these encodings are multi-positional, no ?
|
// NOTE: these encodings are multi-positional, no ?
|
||||||
// case a_f_LAM_ALEF_MADDA_ABOVE:
|
// case a_f_LAM_ALEF_MADDA_ABOVE:
|
||||||
// case a_f_LAM_ALEF_HAMZA_ABOVE:
|
// case a_f_LAM_ALEF_HAMZA_ABOVE:
|
||||||
@@ -668,10 +862,14 @@ static int chg_c_f2m(int cur_c)
|
|||||||
static int chg_c_laa2i(int hid_c)
|
static int chg_c_laa2i(int hid_c)
|
||||||
{
|
{
|
||||||
switch (hid_c) {
|
switch (hid_c) {
|
||||||
case a_ALEF_MADDA: return a_s_LAM_ALEF_MADDA_ABOVE;
|
case a_ALEF_MADDA:
|
||||||
case a_ALEF_HAMZA_ABOVE: return a_s_LAM_ALEF_HAMZA_ABOVE;
|
return a_s_LAM_ALEF_MADDA_ABOVE;
|
||||||
case a_ALEF_HAMZA_BELOW: return a_s_LAM_ALEF_HAMZA_BELOW;
|
case a_ALEF_HAMZA_ABOVE:
|
||||||
case a_ALEF: return a_s_LAM_ALEF;
|
return a_s_LAM_ALEF_HAMZA_ABOVE;
|
||||||
|
case a_ALEF_HAMZA_BELOW:
|
||||||
|
return a_s_LAM_ALEF_HAMZA_BELOW;
|
||||||
|
case a_ALEF:
|
||||||
|
return a_s_LAM_ALEF;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -680,10 +878,14 @@ static int chg_c_laa2i(int hid_c)
|
|||||||
static int chg_c_laa2f(int hid_c)
|
static int chg_c_laa2f(int hid_c)
|
||||||
{
|
{
|
||||||
switch (hid_c) {
|
switch (hid_c) {
|
||||||
case a_ALEF_MADDA: return a_f_LAM_ALEF_MADDA_ABOVE;
|
case a_ALEF_MADDA:
|
||||||
case a_ALEF_HAMZA_ABOVE: return a_f_LAM_ALEF_HAMZA_ABOVE;
|
return a_f_LAM_ALEF_MADDA_ABOVE;
|
||||||
case a_ALEF_HAMZA_BELOW: return a_f_LAM_ALEF_HAMZA_BELOW;
|
case a_ALEF_HAMZA_ABOVE:
|
||||||
case a_ALEF: return a_f_LAM_ALEF;
|
return a_f_LAM_ALEF_HAMZA_ABOVE;
|
||||||
|
case a_ALEF_HAMZA_BELOW:
|
||||||
|
return a_f_LAM_ALEF_HAMZA_BELOW;
|
||||||
|
case a_ALEF:
|
||||||
|
return a_f_LAM_ALEF;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -708,8 +910,7 @@ static int half_shape(int c)
|
|||||||
// in: "prev_c1" is the first composing char for the previous char
|
// in: "prev_c1" is the first composing char for the previous char
|
||||||
// (not shaped)
|
// (not shaped)
|
||||||
// in: "next_c" is the next character (not shaped).
|
// in: "next_c" is the next character (not shaped).
|
||||||
int arabic_shape(int c, int *ccp, int *c1p, int prev_c, int prev_c1,
|
int arabic_shape(int c, int *ccp, int *c1p, int prev_c, int prev_c1, int next_c)
|
||||||
int next_c)
|
|
||||||
{
|
{
|
||||||
// Deal only with Arabic character, pass back all others
|
// Deal only with Arabic character, pass back all others
|
||||||
if (!A_is_ok(c)) {
|
if (!A_is_ok(c)) {
|
||||||
|
@@ -1,16 +1,16 @@
|
|||||||
// This is an open source non-commercial project. Dear PVS-Studio, please check
|
// This is an open source non-commercial project. Dear PVS-Studio, please check
|
||||||
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||||
|
|
||||||
#include "nvim/os/os.h"
|
|
||||||
#include "nvim/fileio.h"
|
|
||||||
#include "nvim/vim.h"
|
|
||||||
#include "nvim/main.h"
|
|
||||||
#include "nvim/ui.h"
|
|
||||||
#include "nvim/aucmd.h"
|
#include "nvim/aucmd.h"
|
||||||
|
#include "nvim/buffer.h"
|
||||||
#include "nvim/eval.h"
|
#include "nvim/eval.h"
|
||||||
#include "nvim/ex_docmd.h"
|
#include "nvim/ex_docmd.h"
|
||||||
#include "nvim/ex_getln.h"
|
#include "nvim/ex_getln.h"
|
||||||
#include "nvim/buffer.h"
|
#include "nvim/fileio.h"
|
||||||
|
#include "nvim/main.h"
|
||||||
|
#include "nvim/os/os.h"
|
||||||
|
#include "nvim/ui.h"
|
||||||
|
#include "nvim/vim.h"
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "aucmd.c.generated.h"
|
# include "aucmd.c.generated.h"
|
||||||
|
@@ -3,10 +3,9 @@
|
|||||||
|
|
||||||
// autocmd.c: Autocommand related functions
|
// autocmd.c: Autocommand related functions
|
||||||
|
|
||||||
#include "nvim/autocmd.h"
|
|
||||||
|
|
||||||
#include "nvim/api/private/helpers.h"
|
#include "nvim/api/private/helpers.h"
|
||||||
#include "nvim/ascii.h"
|
#include "nvim/ascii.h"
|
||||||
|
#include "nvim/autocmd.h"
|
||||||
#include "nvim/buffer.h"
|
#include "nvim/buffer.h"
|
||||||
#include "nvim/charset.h"
|
#include "nvim/charset.h"
|
||||||
#include "nvim/cursor.h"
|
#include "nvim/cursor.h"
|
||||||
@@ -326,8 +325,7 @@ static void au_del_group(char_u *name)
|
|||||||
event = (event_T)((int)event + 1)) {
|
event = (event_T)((int)event + 1)) {
|
||||||
for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next) {
|
for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next) {
|
||||||
if (ap->group == i && ap->pat != NULL) {
|
if (ap->group == i && ap->pat != NULL) {
|
||||||
give_warning(
|
give_warning((char_u *)_("W19: Deleting augroup that is still in use"), true);
|
||||||
(char_u *)_("W19: Deleting augroup that is still in use"), true);
|
|
||||||
in_use = true;
|
in_use = true;
|
||||||
event = NUM_EVENTS;
|
event = NUM_EVENTS;
|
||||||
break;
|
break;
|
||||||
@@ -761,13 +759,8 @@ static int au_get_grouparg(char_u **argp)
|
|||||||
// If *cmd == NUL: show entries.
|
// If *cmd == NUL: show entries.
|
||||||
// If forceit == true: delete entries.
|
// If forceit == true: delete entries.
|
||||||
// If group is not AUGROUP_ALL: only use this group.
|
// If group is not AUGROUP_ALL: only use this group.
|
||||||
static int do_autocmd_event(event_T event,
|
static int do_autocmd_event(event_T event, char_u *pat, bool once, int nested, char_u *cmd,
|
||||||
char_u *pat,
|
int forceit, int group)
|
||||||
bool once,
|
|
||||||
int nested,
|
|
||||||
char_u *cmd,
|
|
||||||
int forceit,
|
|
||||||
int group)
|
|
||||||
{
|
{
|
||||||
AutoPat *ap;
|
AutoPat *ap;
|
||||||
AutoPat **prev_ap;
|
AutoPat **prev_ap;
|
||||||
@@ -847,8 +840,7 @@ static int do_autocmd_event(event_T event,
|
|||||||
|
|
||||||
if (is_buflocal) {
|
if (is_buflocal) {
|
||||||
// normalize pat into standard "<buffer>#N" form
|
// normalize pat into standard "<buffer>#N" form
|
||||||
snprintf(
|
snprintf((char *)buflocal_pat,
|
||||||
(char *)buflocal_pat,
|
|
||||||
BUFLOCAL_PAT_LEN,
|
BUFLOCAL_PAT_LEN,
|
||||||
"<buffer=%d>",
|
"<buffer=%d>",
|
||||||
buflocal_nr);
|
buflocal_nr);
|
||||||
@@ -889,7 +881,6 @@ static int do_autocmd_event(event_T event,
|
|||||||
} else if (*cmd == NUL) {
|
} else if (*cmd == NUL) {
|
||||||
// Show autocmd's for this autopat, or buflocals <buffer=X>
|
// Show autocmd's for this autopat, or buflocals <buffer=X>
|
||||||
show_autocmd(ap, event);
|
show_autocmd(ap, event);
|
||||||
|
|
||||||
} else if (ap->next == NULL) {
|
} else if (ap->next == NULL) {
|
||||||
// Add autocmd to this autopat, if it's the last one.
|
// Add autocmd to this autopat, if it's the last one.
|
||||||
break;
|
break;
|
||||||
@@ -967,8 +958,7 @@ static int do_autocmd_event(event_T event,
|
|||||||
|
|
||||||
// Implementation of ":doautocmd [group] event [fname]".
|
// Implementation of ":doautocmd [group] event [fname]".
|
||||||
// Return OK for success, FAIL for failure;
|
// Return OK for success, FAIL for failure;
|
||||||
int do_doautocmd(char_u *arg,
|
int do_doautocmd(char_u *arg, bool do_msg, // give message for no matching autocmds?
|
||||||
bool do_msg, // give message for no matching autocmds?
|
|
||||||
bool *did_something)
|
bool *did_something)
|
||||||
{
|
{
|
||||||
char_u *fname;
|
char_u *fname;
|
||||||
@@ -1268,11 +1258,7 @@ void aucmd_restbuf(aco_save_T *aco)
|
|||||||
/// @param buf Buffer for <abuf>
|
/// @param buf Buffer for <abuf>
|
||||||
///
|
///
|
||||||
/// @return true if some commands were executed.
|
/// @return true if some commands were executed.
|
||||||
bool apply_autocmds(event_T event,
|
bool apply_autocmds(event_T event, char_u *fname, char_u *fname_io, bool force, buf_T *buf)
|
||||||
char_u *fname,
|
|
||||||
char_u *fname_io,
|
|
||||||
bool force,
|
|
||||||
buf_T *buf)
|
|
||||||
{
|
{
|
||||||
return apply_autocmds_group(event, fname, fname_io, force, AUGROUP_ALL, buf,
|
return apply_autocmds_group(event, fname, fname_io, force, AUGROUP_ALL, buf,
|
||||||
NULL);
|
NULL);
|
||||||
@@ -1289,11 +1275,7 @@ bool apply_autocmds(event_T event,
|
|||||||
/// @param exarg Ex command arguments
|
/// @param exarg Ex command arguments
|
||||||
///
|
///
|
||||||
/// @return true if some commands were executed.
|
/// @return true if some commands were executed.
|
||||||
bool apply_autocmds_exarg(event_T event,
|
bool apply_autocmds_exarg(event_T event, char_u *fname, char_u *fname_io, bool force, buf_T *buf,
|
||||||
char_u *fname,
|
|
||||||
char_u *fname_io,
|
|
||||||
bool force,
|
|
||||||
buf_T *buf,
|
|
||||||
exarg_T *eap)
|
exarg_T *eap)
|
||||||
{
|
{
|
||||||
return apply_autocmds_group(event, fname, fname_io, force, AUGROUP_ALL, buf,
|
return apply_autocmds_group(event, fname, fname_io, force, AUGROUP_ALL, buf,
|
||||||
@@ -1313,11 +1295,7 @@ bool apply_autocmds_exarg(event_T event,
|
|||||||
/// @param[in,out] retval caller's retval
|
/// @param[in,out] retval caller's retval
|
||||||
///
|
///
|
||||||
/// @return true if some autocommands were executed
|
/// @return true if some autocommands were executed
|
||||||
bool apply_autocmds_retval(event_T event,
|
bool apply_autocmds_retval(event_T event, char_u *fname, char_u *fname_io, bool force, buf_T *buf,
|
||||||
char_u *fname,
|
|
||||||
char_u *fname_io,
|
|
||||||
bool force,
|
|
||||||
buf_T *buf,
|
|
||||||
int *retval)
|
int *retval)
|
||||||
{
|
{
|
||||||
if (should_abort(*retval)) {
|
if (should_abort(*retval)) {
|
||||||
@@ -1344,8 +1322,7 @@ bool has_event(event_T event) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
|
|||||||
/// the current mode.
|
/// the current mode.
|
||||||
bool has_cursorhold(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
|
bool has_cursorhold(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
|
||||||
{
|
{
|
||||||
return has_event(
|
return has_event((get_real_state() == NORMAL_BUSY ? EVENT_CURSORHOLD : EVENT_CURSORHOLDI));
|
||||||
(get_real_state() == NORMAL_BUSY ? EVENT_CURSORHOLD : EVENT_CURSORHOLDI));
|
|
||||||
// return first_autopat[] != NULL;
|
// return first_autopat[] != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1376,13 +1353,8 @@ bool trigger_cursorhold(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
|
|||||||
/// @param eap Ex command arguments
|
/// @param eap Ex command arguments
|
||||||
///
|
///
|
||||||
/// @return true if some commands were executed.
|
/// @return true if some commands were executed.
|
||||||
static bool apply_autocmds_group(event_T event,
|
static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, bool force,
|
||||||
char_u *fname,
|
int group, buf_T *buf, exarg_T *eap)
|
||||||
char_u *fname_io,
|
|
||||||
bool force,
|
|
||||||
int group,
|
|
||||||
buf_T *buf,
|
|
||||||
exarg_T *eap)
|
|
||||||
{
|
{
|
||||||
char_u *sfname = NULL; // short file name
|
char_u *sfname = NULL; // short file name
|
||||||
char_u *tail;
|
char_u *tail;
|
||||||
@@ -1769,8 +1741,7 @@ void auto_next_pat(AutoPatCmd *apc, int stop_at_last)
|
|||||||
&& (apc->group == AUGROUP_ALL || apc->group == ap->group)) {
|
&& (apc->group == AUGROUP_ALL || apc->group == ap->group)) {
|
||||||
// execution-condition
|
// execution-condition
|
||||||
if (ap->buflocal_nr == 0
|
if (ap->buflocal_nr == 0
|
||||||
? match_file_pat(
|
? match_file_pat(NULL,
|
||||||
NULL,
|
|
||||||
&ap->reg_prog,
|
&ap->reg_prog,
|
||||||
apc->fname,
|
apc->fname,
|
||||||
apc->sfname,
|
apc->sfname,
|
||||||
@@ -1885,9 +1856,7 @@ char_u *getnextac(int c, void *cookie, int indent, bool do_concat)
|
|||||||
/// @param event event that occurred.
|
/// @param event event that occurred.
|
||||||
/// @param sfname filename the event occurred in.
|
/// @param sfname filename the event occurred in.
|
||||||
/// @param buf buffer the file is open in
|
/// @param buf buffer the file is open in
|
||||||
bool has_autocmd(event_T event,
|
bool has_autocmd(event_T event, char_u *sfname, buf_T *buf) FUNC_ATTR_WARN_UNUSED_RESULT
|
||||||
char_u *sfname,
|
|
||||||
buf_T *buf) FUNC_ATTR_WARN_UNUSED_RESULT
|
|
||||||
{
|
{
|
||||||
AutoPat *ap;
|
AutoPat *ap;
|
||||||
char_u *fname;
|
char_u *fname;
|
||||||
@@ -1910,8 +1879,7 @@ bool has_autocmd(event_T event,
|
|||||||
for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next) {
|
for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next) {
|
||||||
if (ap->pat != NULL && ap->cmds != NULL
|
if (ap->pat != NULL && ap->cmds != NULL
|
||||||
&& (ap->buflocal_nr == 0
|
&& (ap->buflocal_nr == 0
|
||||||
? match_file_pat(
|
? match_file_pat(NULL,
|
||||||
NULL,
|
|
||||||
&ap->reg_prog,
|
&ap->reg_prog,
|
||||||
fname,
|
fname,
|
||||||
sfname,
|
sfname,
|
||||||
@@ -1948,10 +1916,7 @@ char_u *get_augroup_name(expand_T *xp, int idx)
|
|||||||
return (char_u *)AUGROUP_NAME(idx);
|
return (char_u *)AUGROUP_NAME(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
char_u *set_context_in_autocmd(
|
char_u *set_context_in_autocmd(expand_T *xp, char_u *arg, int doautocmd // true for :doauto*, false for :autocmd
|
||||||
expand_T *xp,
|
|
||||||
char_u *arg,
|
|
||||||
int doautocmd // true for :doauto*, false for :autocmd
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
char_u *p;
|
char_u *p;
|
||||||
|
@@ -19,32 +19,34 @@
|
|||||||
// The current implementation remembers all file names ever used.
|
// The current implementation remembers all file names ever used.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <inttypes.h>
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include "nvim/api/private/helpers.h"
|
#include "nvim/api/private/helpers.h"
|
||||||
#include "nvim/api/vim.h"
|
#include "nvim/api/vim.h"
|
||||||
#include "nvim/ascii.h"
|
#include "nvim/ascii.h"
|
||||||
#include "nvim/assert.h"
|
#include "nvim/assert.h"
|
||||||
#include "nvim/channel.h"
|
|
||||||
#include "nvim/vim.h"
|
|
||||||
#include "nvim/buffer.h"
|
#include "nvim/buffer.h"
|
||||||
|
#include "nvim/buffer_updates.h"
|
||||||
#include "nvim/change.h"
|
#include "nvim/change.h"
|
||||||
|
#include "nvim/channel.h"
|
||||||
#include "nvim/charset.h"
|
#include "nvim/charset.h"
|
||||||
#include "nvim/cursor.h"
|
#include "nvim/cursor.h"
|
||||||
#include "nvim/diff.h"
|
#include "nvim/diff.h"
|
||||||
#include "nvim/digraph.h"
|
#include "nvim/digraph.h"
|
||||||
#include "nvim/eval.h"
|
#include "nvim/eval.h"
|
||||||
#include "nvim/ex_cmds2.h"
|
|
||||||
#include "nvim/ex_cmds.h"
|
#include "nvim/ex_cmds.h"
|
||||||
|
#include "nvim/ex_cmds2.h"
|
||||||
#include "nvim/ex_docmd.h"
|
#include "nvim/ex_docmd.h"
|
||||||
#include "nvim/ex_eval.h"
|
#include "nvim/ex_eval.h"
|
||||||
#include "nvim/ex_getln.h"
|
#include "nvim/ex_getln.h"
|
||||||
#include "nvim/fileio.h"
|
#include "nvim/extmark.h"
|
||||||
#include "nvim/file_search.h"
|
#include "nvim/file_search.h"
|
||||||
|
#include "nvim/fileio.h"
|
||||||
#include "nvim/fold.h"
|
#include "nvim/fold.h"
|
||||||
|
#include "nvim/garray.h"
|
||||||
#include "nvim/getchar.h"
|
#include "nvim/getchar.h"
|
||||||
#include "nvim/hashtab.h"
|
#include "nvim/hashtab.h"
|
||||||
#include "nvim/highlight.h"
|
#include "nvim/highlight.h"
|
||||||
@@ -52,19 +54,21 @@
|
|||||||
#include "nvim/indent_c.h"
|
#include "nvim/indent_c.h"
|
||||||
#include "nvim/main.h"
|
#include "nvim/main.h"
|
||||||
#include "nvim/mark.h"
|
#include "nvim/mark.h"
|
||||||
#include "nvim/extmark.h"
|
|
||||||
#include "nvim/mbyte.h"
|
#include "nvim/mbyte.h"
|
||||||
#include "nvim/memory.h"
|
#include "nvim/memory.h"
|
||||||
#include "nvim/message.h"
|
#include "nvim/message.h"
|
||||||
#include "nvim/misc1.h"
|
#include "nvim/misc1.h"
|
||||||
#include "nvim/garray.h"
|
|
||||||
#include "nvim/move.h"
|
#include "nvim/move.h"
|
||||||
#include "nvim/option.h"
|
#include "nvim/option.h"
|
||||||
|
#include "nvim/os/input.h"
|
||||||
|
#include "nvim/os/os.h"
|
||||||
|
#include "nvim/os/time.h"
|
||||||
#include "nvim/os_unix.h"
|
#include "nvim/os_unix.h"
|
||||||
#include "nvim/path.h"
|
#include "nvim/path.h"
|
||||||
#include "nvim/quickfix.h"
|
#include "nvim/quickfix.h"
|
||||||
#include "nvim/regexp.h"
|
#include "nvim/regexp.h"
|
||||||
#include "nvim/screen.h"
|
#include "nvim/screen.h"
|
||||||
|
#include "nvim/shada.h"
|
||||||
#include "nvim/sign.h"
|
#include "nvim/sign.h"
|
||||||
#include "nvim/spell.h"
|
#include "nvim/spell.h"
|
||||||
#include "nvim/strings.h"
|
#include "nvim/strings.h"
|
||||||
@@ -72,12 +76,8 @@
|
|||||||
#include "nvim/ui.h"
|
#include "nvim/ui.h"
|
||||||
#include "nvim/undo.h"
|
#include "nvim/undo.h"
|
||||||
#include "nvim/version.h"
|
#include "nvim/version.h"
|
||||||
|
#include "nvim/vim.h"
|
||||||
#include "nvim/window.h"
|
#include "nvim/window.h"
|
||||||
#include "nvim/shada.h"
|
|
||||||
#include "nvim/os/os.h"
|
|
||||||
#include "nvim/os/time.h"
|
|
||||||
#include "nvim/os/input.h"
|
|
||||||
#include "nvim/buffer_updates.h"
|
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "buffer.c.generated.h"
|
# include "buffer.c.generated.h"
|
||||||
@@ -99,9 +99,7 @@ typedef enum {
|
|||||||
} BufFreeFlags;
|
} BufFreeFlags;
|
||||||
|
|
||||||
// Read data from buffer for retrying.
|
// Read data from buffer for retrying.
|
||||||
static int
|
static int read_buffer(int read_stdin, // read file from stdin, otherwise fifo
|
||||||
read_buffer(
|
|
||||||
int read_stdin, // read file from stdin, otherwise fifo
|
|
||||||
exarg_T *eap, // for forced 'ff' and 'fenc' or NULL
|
exarg_T *eap, // for forced 'ff' and 'fenc' or NULL
|
||||||
int flags) // extra flags for readfile()
|
int flags) // extra flags for readfile()
|
||||||
{
|
{
|
||||||
@@ -114,8 +112,7 @@ read_buffer(
|
|||||||
// 'fileencoding' was guessed wrong.
|
// 'fileencoding' was guessed wrong.
|
||||||
//
|
//
|
||||||
line_count = curbuf->b_ml.ml_line_count;
|
line_count = curbuf->b_ml.ml_line_count;
|
||||||
retval = readfile(
|
retval = readfile(read_stdin ? NULL : curbuf->b_ffname,
|
||||||
read_stdin ? NULL : curbuf->b_ffname,
|
|
||||||
read_stdin ? NULL : curbuf->b_fname,
|
read_stdin ? NULL : curbuf->b_fname,
|
||||||
(linenr_T)line_count, (linenr_T)0, (linenr_T)MAXLNUM, eap,
|
(linenr_T)line_count, (linenr_T)0, (linenr_T)MAXLNUM, eap,
|
||||||
flags | READ_BUFFER);
|
flags | READ_BUFFER);
|
||||||
@@ -152,8 +149,7 @@ read_buffer(
|
|||||||
// Open current buffer, that is: open the memfile and read the file into
|
// Open current buffer, that is: open the memfile and read the file into
|
||||||
// memory.
|
// memory.
|
||||||
// Return FAIL for failure, OK otherwise.
|
// Return FAIL for failure, OK otherwise.
|
||||||
int open_buffer(
|
int open_buffer(int read_stdin, // read file from stdin
|
||||||
int read_stdin, // read file from stdin
|
|
||||||
exarg_T *eap, // for forced 'ff' and 'fenc' or NULL
|
exarg_T *eap, // for forced 'ff' and 'fenc' or NULL
|
||||||
int flags // extra flags for readfile()
|
int flags // extra flags for readfile()
|
||||||
)
|
)
|
||||||
@@ -169,8 +165,9 @@ int open_buffer(
|
|||||||
* user may have reset the flag by hand.
|
* user may have reset the flag by hand.
|
||||||
*/
|
*/
|
||||||
if (readonlymode && curbuf->b_ffname != NULL
|
if (readonlymode && curbuf->b_ffname != NULL
|
||||||
&& (curbuf->b_flags & BF_NEVERLOADED))
|
&& (curbuf->b_flags & BF_NEVERLOADED)) {
|
||||||
curbuf->b_p_ro = true;
|
curbuf->b_p_ro = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (ml_open(curbuf) == FAIL) {
|
if (ml_open(curbuf) == FAIL) {
|
||||||
/*
|
/*
|
||||||
@@ -227,8 +224,7 @@ int open_buffer(
|
|||||||
|| (S_ISCHR(perm)
|
|| (S_ISCHR(perm)
|
||||||
&& is_dev_fd_file(curbuf->b_ffname))
|
&& is_dev_fd_file(curbuf->b_ffname))
|
||||||
# endif
|
# endif
|
||||||
)
|
)) {
|
||||||
) {
|
|
||||||
read_fifo = true;
|
read_fifo = true;
|
||||||
}
|
}
|
||||||
if (read_fifo) {
|
if (read_fifo) {
|
||||||
@@ -431,9 +427,10 @@ bool close_buffer(win_T *win, buf_T *buf, int action, bool abort_if_last)
|
|||||||
del_buf = true;
|
del_buf = true;
|
||||||
unload_buf = true;
|
unload_buf = true;
|
||||||
wipe_buf = true;
|
wipe_buf = true;
|
||||||
} else if (buf->b_p_bh[0] == 'u') // 'bufhidden' == "unload"
|
} else if (buf->b_p_bh[0] == 'u') { // 'bufhidden' == "unload"
|
||||||
unload_buf = true;
|
unload_buf = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (buf->terminal && (unload_buf || del_buf || wipe_buf)) {
|
if (buf->terminal && (unload_buf || del_buf || wipe_buf)) {
|
||||||
// terminal buffers can only be wiped
|
// terminal buffers can only be wiped
|
||||||
@@ -806,8 +803,8 @@ static void free_buffer_stuff(buf_T *buf, int free_flags)
|
|||||||
// Avoid losing b:changedtick when deleting buffer: clearing variables
|
// Avoid losing b:changedtick when deleting buffer: clearing variables
|
||||||
// implies using clear_tv() on b:changedtick and that sets changedtick to
|
// implies using clear_tv() on b:changedtick and that sets changedtick to
|
||||||
// zero.
|
// zero.
|
||||||
hashitem_T *const changedtick_hi = hash_find(
|
hashitem_T *const changedtick_hi = hash_find(&buf->b_vars->dv_hashtab,
|
||||||
&buf->b_vars->dv_hashtab, (const char_u *)"changedtick");
|
(const char_u *)"changedtick");
|
||||||
assert(changedtick_hi != NULL);
|
assert(changedtick_hi != NULL);
|
||||||
hash_remove(&buf->b_vars->dv_hashtab, changedtick_hi);
|
hash_remove(&buf->b_vars->dv_hashtab, changedtick_hi);
|
||||||
}
|
}
|
||||||
@@ -955,15 +952,10 @@ void handle_swap_exists(bufref_T *old_curbuf)
|
|||||||
*
|
*
|
||||||
* Returns error message or NULL
|
* Returns error message or NULL
|
||||||
*/
|
*/
|
||||||
char_u *
|
char_u *do_bufdel(int command, char_u *arg, // pointer to extra arguments
|
||||||
do_bufdel(
|
int addr_count, int start_bnr, // first buffer number in a range
|
||||||
int command,
|
|
||||||
char_u *arg, // pointer to extra arguments
|
|
||||||
int addr_count,
|
|
||||||
int start_bnr, // first buffer number in a range
|
|
||||||
int end_bnr, // buffer nr or last buffer nr in a range
|
int end_bnr, // buffer nr or last buffer nr in a range
|
||||||
int forceit
|
int forceit)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
int do_current = 0; // delete current buffer?
|
int do_current = 0; // delete current buffer?
|
||||||
int deleted = 0; // number of buffers deleted
|
int deleted = 0; // number of buffers deleted
|
||||||
@@ -1121,11 +1113,7 @@ static int empty_curbuf(int close_others, int forceit, int action)
|
|||||||
*
|
*
|
||||||
* Return FAIL or OK.
|
* Return FAIL or OK.
|
||||||
*/
|
*/
|
||||||
int
|
int do_buffer(int action, int start, int dir, // FORWARD or BACKWARD
|
||||||
do_buffer(
|
|
||||||
int action,
|
|
||||||
int start,
|
|
||||||
int dir, // FORWARD or BACKWARD
|
|
||||||
int count, // buffer number or number of buffers
|
int count, // buffer number or number of buffers
|
||||||
int forceit // true for :...!
|
int forceit // true for :...!
|
||||||
)
|
)
|
||||||
@@ -1136,9 +1124,12 @@ do_buffer(
|
|||||||
|| action == DOBUF_WIPE);
|
|| action == DOBUF_WIPE);
|
||||||
|
|
||||||
switch (start) {
|
switch (start) {
|
||||||
case DOBUF_FIRST: buf = firstbuf; break;
|
case DOBUF_FIRST:
|
||||||
case DOBUF_LAST: buf = lastbuf; break;
|
buf = firstbuf; break;
|
||||||
default: buf = curbuf; break;
|
case DOBUF_LAST:
|
||||||
|
buf = lastbuf; break;
|
||||||
|
default:
|
||||||
|
buf = curbuf; break;
|
||||||
}
|
}
|
||||||
if (start == DOBUF_MOD) { // find next modified buffer
|
if (start == DOBUF_MOD) { // find next modified buffer
|
||||||
while (count-- > 0) {
|
while (count-- > 0) {
|
||||||
@@ -1522,8 +1513,7 @@ void set_curbuf(buf_T *buf, int action)
|
|||||||
* If curwin->w_buffer is null, enter_buffer() will make it valid again */
|
* If curwin->w_buffer is null, enter_buffer() will make it valid again */
|
||||||
if ((buf_valid(buf) && buf != curbuf
|
if ((buf_valid(buf) && buf != curbuf
|
||||||
&& !aborting()
|
&& !aborting()
|
||||||
) || curwin->w_buffer == NULL
|
) || curwin->w_buffer == NULL) {
|
||||||
) {
|
|
||||||
enter_buffer(buf);
|
enter_buffer(buf);
|
||||||
if (old_tw != curbuf->b_p_tw) {
|
if (old_tw != curbuf->b_p_tw) {
|
||||||
check_colorcolumn(curwin);
|
check_colorcolumn(curwin);
|
||||||
@@ -1705,8 +1695,7 @@ static inline void buf_init_changedtick(buf_T *const buf)
|
|||||||
/// @param bufnr
|
/// @param bufnr
|
||||||
///
|
///
|
||||||
/// @return pointer to the buffer
|
/// @return pointer to the buffer
|
||||||
buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum,
|
buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum, int flags)
|
||||||
int flags)
|
|
||||||
{
|
{
|
||||||
char_u *ffname = ffname_arg;
|
char_u *ffname = ffname_arg;
|
||||||
char_u *sfname = sfname_arg;
|
char_u *sfname = sfname_arg;
|
||||||
@@ -2038,8 +2027,9 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
|
|||||||
fpos = buflist_findfpos(buf);
|
fpos = buflist_findfpos(buf);
|
||||||
lnum = fpos->lnum;
|
lnum = fpos->lnum;
|
||||||
col = fpos->col;
|
col = fpos->col;
|
||||||
} else
|
} else {
|
||||||
col = 0;
|
col = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (options & GETF_SWITCH) {
|
if (options & GETF_SWITCH) {
|
||||||
// If 'switchbuf' contains "useopen": jump to first window containing
|
// If 'switchbuf' contains "useopen": jump to first window containing
|
||||||
@@ -2149,8 +2139,7 @@ buf_T *buflist_findname(char_u *ffname)
|
|||||||
* getting it twice for the same file.
|
* getting it twice for the same file.
|
||||||
* Returns NULL if not found.
|
* Returns NULL if not found.
|
||||||
*/
|
*/
|
||||||
static buf_T *buflist_findname_file_id(char_u *ffname, FileID *file_id,
|
static buf_T *buflist_findname_file_id(char_u *ffname, FileID *file_id, bool file_id_valid)
|
||||||
bool file_id_valid)
|
|
||||||
{
|
{
|
||||||
// Start at the last buffer, expect to find a match sooner.
|
// Start at the last buffer, expect to find a match sooner.
|
||||||
FOR_ALL_BUFFERS_BACKWARDS(buf) {
|
FOR_ALL_BUFFERS_BACKWARDS(buf) {
|
||||||
@@ -2165,9 +2154,7 @@ static buf_T *buflist_findname_file_id(char_u *ffname, FileID *file_id,
|
|||||||
/// Find file in buffer list by a regexp pattern.
|
/// Find file in buffer list by a regexp pattern.
|
||||||
/// Return fnum of the found buffer.
|
/// Return fnum of the found buffer.
|
||||||
/// Return < 0 for error.
|
/// Return < 0 for error.
|
||||||
int buflist_findpat(
|
int buflist_findpat(const char_u *pattern, const char_u *pattern_end, // pointer to first char after pattern
|
||||||
const char_u *pattern,
|
|
||||||
const char_u *pattern_end, // pointer to first char after pattern
|
|
||||||
bool unlisted, // find unlisted buffers
|
bool unlisted, // find unlisted buffers
|
||||||
bool diffmode, // find diff-mode buffers only
|
bool diffmode, // find diff-mode buffers only
|
||||||
bool curtab_only // find buffers in current tab only
|
bool curtab_only // find buffers in current tab only
|
||||||
@@ -2288,8 +2275,7 @@ typedef struct {
|
|||||||
} bufmatch_T;
|
} bufmatch_T;
|
||||||
|
|
||||||
/// Compare functions for qsort() below, that compares b_last_used.
|
/// Compare functions for qsort() below, that compares b_last_used.
|
||||||
static int
|
static int buf_time_compare(const void *s1, const void *s2)
|
||||||
buf_time_compare(const void *s1, const void *s2)
|
|
||||||
{
|
{
|
||||||
buf_T *buf1 = *(buf_T **)s1;
|
buf_T *buf1 = *(buf_T **)s1;
|
||||||
buf_T *buf2 = *(buf_T **)s2;
|
buf_T *buf2 = *(buf_T **)s2;
|
||||||
@@ -2326,8 +2312,9 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options)
|
|||||||
patc = xmalloc(STRLEN(pat) + 11);
|
patc = xmalloc(STRLEN(pat) + 11);
|
||||||
STRCPY(patc, "\\(^\\|[\\/]\\)");
|
STRCPY(patc, "\\(^\\|[\\/]\\)");
|
||||||
STRCPY(patc + 11, pat + 1);
|
STRCPY(patc + 11, pat + 1);
|
||||||
} else
|
} else {
|
||||||
patc = pat;
|
patc = pat;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* attempt == 0: try match with '\<', match at start of word
|
* attempt == 0: try match with '\<', match at start of word
|
||||||
@@ -2485,11 +2472,7 @@ buf_T *buflist_findnr(int nr)
|
|||||||
* home_replace() is used to shorten the file name (used for marks).
|
* home_replace() is used to shorten the file name (used for marks).
|
||||||
* Returns a pointer to allocated memory, of NULL when failed.
|
* Returns a pointer to allocated memory, of NULL when failed.
|
||||||
*/
|
*/
|
||||||
char_u *
|
char_u *buflist_nr2name(int n, int fullname, int helptail // for help buffers return tail only
|
||||||
buflist_nr2name(
|
|
||||||
int n,
|
|
||||||
int fullname,
|
|
||||||
int helptail // for help buffers return tail only
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
buf_T *buf;
|
buf_T *buf;
|
||||||
@@ -2511,8 +2494,7 @@ buflist_nr2name(
|
|||||||
/// options are touched.
|
/// options are touched.
|
||||||
/// @param[in] col Column number to be set.
|
/// @param[in] col Column number to be set.
|
||||||
/// @param[in] copy_options If true save the local window option values.
|
/// @param[in] copy_options If true save the local window option values.
|
||||||
void buflist_setfpos(buf_T *const buf, win_T *const win,
|
void buflist_setfpos(buf_T *const buf, win_T *const win, linenr_T lnum, colnr_T col,
|
||||||
linenr_T lnum, colnr_T col,
|
|
||||||
bool copy_options)
|
bool copy_options)
|
||||||
FUNC_ATTR_NONNULL_ARG(1)
|
FUNC_ATTR_NONNULL_ARG(1)
|
||||||
{
|
{
|
||||||
@@ -2593,8 +2575,7 @@ static bool wininfo_other_tab_diff(wininfo_T *wip)
|
|||||||
// When "skip_diff_buffer" is true avoid windows with 'diff' set that is in
|
// When "skip_diff_buffer" is true avoid windows with 'diff' set that is in
|
||||||
// another tab page.
|
// another tab page.
|
||||||
// Returns NULL when there isn't any info.
|
// Returns NULL when there isn't any info.
|
||||||
static wininfo_T *find_wininfo(buf_T *buf, bool need_options,
|
static wininfo_T *find_wininfo(buf_T *buf, bool need_options, bool skip_diff_buffer)
|
||||||
bool skip_diff_buffer)
|
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
wininfo_T *wip;
|
wininfo_T *wip;
|
||||||
@@ -2654,8 +2635,9 @@ void get_winopts(buf_T *buf)
|
|||||||
curwin->w_fold_manual = wip->wi_fold_manual;
|
curwin->w_fold_manual = wip->wi_fold_manual;
|
||||||
curwin->w_foldinvalid = true;
|
curwin->w_foldinvalid = true;
|
||||||
cloneFoldGrowArray(&wip->wi_folds, &curwin->w_folds);
|
cloneFoldGrowArray(&wip->wi_folds, &curwin->w_folds);
|
||||||
} else
|
} else {
|
||||||
copy_winopt(&curwin->w_allbuf_opt, &curwin->w_onebuf_opt);
|
copy_winopt(&curwin->w_allbuf_opt, &curwin->w_onebuf_opt);
|
||||||
|
}
|
||||||
|
|
||||||
if (curwin->w_float_config.style == kWinStyleMinimal) {
|
if (curwin->w_float_config.style == kWinStyleMinimal) {
|
||||||
didset_window_options(curwin);
|
didset_window_options(curwin);
|
||||||
@@ -2761,8 +2743,7 @@ void buflist_list(exarg_T *eap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
msg_putchar('\n');
|
msg_putchar('\n');
|
||||||
len = vim_snprintf(
|
len = vim_snprintf((char *)IObuff, IOSIZE - 20, "%3d%c%c%c%c%c \"%s\"",
|
||||||
(char *)IObuff, IOSIZE - 20, "%3d%c%c%c%c%c \"%s\"",
|
|
||||||
buf->b_fnum,
|
buf->b_fnum,
|
||||||
buf->b_p_bl ? ' ' : 'u',
|
buf->b_p_bl ? ' ' : 'u',
|
||||||
buf == curbuf ? '%' : (curwin->w_alt_fnum == buf->b_fnum ? '#' : ' '),
|
buf == curbuf ? '%' : (curwin->w_alt_fnum == buf->b_fnum ? '#' : ' '),
|
||||||
@@ -2824,11 +2805,7 @@ int buflist_name_nr(int fnum, char_u **fname, linenr_T *lnum)
|
|||||||
// The file name with the full path is also remembered, for when :cd is used.
|
// The file name with the full path is also remembered, for when :cd is used.
|
||||||
// Returns FAIL for failure (file name already in use by other buffer)
|
// Returns FAIL for failure (file name already in use by other buffer)
|
||||||
// OK otherwise.
|
// OK otherwise.
|
||||||
int setfname(
|
int setfname(buf_T *buf, char_u *ffname_arg, char_u *sfname_arg, bool message // give message when buffer already exists
|
||||||
buf_T *buf,
|
|
||||||
char_u *ffname_arg,
|
|
||||||
char_u *sfname_arg,
|
|
||||||
bool message // give message when buffer already exists
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
char_u *ffname = ffname_arg;
|
char_u *ffname = ffname_arg;
|
||||||
@@ -2961,8 +2938,7 @@ buf_T *setaltfname(char_u *ffname, char_u *sfname, linenr_T lnum)
|
|||||||
* Get alternate file name for current window.
|
* Get alternate file name for current window.
|
||||||
* Return NULL if there isn't any, and give error message if requested.
|
* Return NULL if there isn't any, and give error message if requested.
|
||||||
*/
|
*/
|
||||||
char_u * getaltfname(
|
char_u * getaltfname(bool errmsg // give error message
|
||||||
bool errmsg // give error message
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
char_u *fname;
|
char_u *fname;
|
||||||
@@ -3038,8 +3014,7 @@ bool otherfile(char_u *ffname)
|
|||||||
/// @param ffname full path name to check
|
/// @param ffname full path name to check
|
||||||
/// @param file_id_p information about the file at "ffname".
|
/// @param file_id_p information about the file at "ffname".
|
||||||
/// @param file_id_valid whether a valid "file_id_p" was passed in.
|
/// @param file_id_valid whether a valid "file_id_p" was passed in.
|
||||||
static bool otherfile_buf(buf_T *buf, char_u *ffname, FileID *file_id_p,
|
static bool otherfile_buf(buf_T *buf, char_u *ffname, FileID *file_id_p, bool file_id_valid)
|
||||||
bool file_id_valid)
|
|
||||||
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
|
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
|
||||||
{
|
{
|
||||||
// no name is different
|
// no name is different
|
||||||
@@ -3106,12 +3081,8 @@ static bool buf_same_file_id(buf_T *buf, FileID *file_id)
|
|||||||
/*
|
/*
|
||||||
* Print info about the current buffer.
|
* Print info about the current buffer.
|
||||||
*/
|
*/
|
||||||
void
|
void fileinfo(int fullname, // when non-zero print full path
|
||||||
fileinfo(
|
int shorthelp, int dont_truncate)
|
||||||
int fullname, // when non-zero print full path
|
|
||||||
int shorthelp,
|
|
||||||
int dont_truncate
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
char_u *name;
|
char_u *name;
|
||||||
int n;
|
int n;
|
||||||
@@ -3124,8 +3095,9 @@ fileinfo(
|
|||||||
if (fullname > 1) { // 2 CTRL-G: include buffer number
|
if (fullname > 1) { // 2 CTRL-G: include buffer number
|
||||||
vim_snprintf((char *)buffer, IOSIZE, "buf %d: ", curbuf->b_fnum);
|
vim_snprintf((char *)buffer, IOSIZE, "buf %d: ", curbuf->b_fnum);
|
||||||
p = buffer + STRLEN(buffer);
|
p = buffer + STRLEN(buffer);
|
||||||
} else
|
} else {
|
||||||
p = buffer;
|
p = buffer;
|
||||||
|
}
|
||||||
|
|
||||||
*p++ = '"';
|
*p++ = '"';
|
||||||
if (buf_spname(curbuf) != NULL) {
|
if (buf_spname(curbuf) != NULL) {
|
||||||
@@ -3291,15 +3263,22 @@ void maketitle(void)
|
|||||||
switch (bufIsChanged(curbuf)
|
switch (bufIsChanged(curbuf)
|
||||||
| (curbuf->b_p_ro << 1)
|
| (curbuf->b_p_ro << 1)
|
||||||
| (!MODIFIABLE(curbuf) << 2)) {
|
| (!MODIFIABLE(curbuf) << 2)) {
|
||||||
case 0: break;
|
case 0:
|
||||||
case 1: buf_p = strappend(buf_p, " +"); break;
|
break;
|
||||||
case 2: buf_p = strappend(buf_p, " ="); break;
|
case 1:
|
||||||
case 3: buf_p = strappend(buf_p, " =+"); break;
|
buf_p = strappend(buf_p, " +"); break;
|
||||||
|
case 2:
|
||||||
|
buf_p = strappend(buf_p, " ="); break;
|
||||||
|
case 3:
|
||||||
|
buf_p = strappend(buf_p, " =+"); break;
|
||||||
case 4:
|
case 4:
|
||||||
case 6: buf_p = strappend(buf_p, " -"); break;
|
case 6:
|
||||||
|
buf_p = strappend(buf_p, " -"); break;
|
||||||
case 5:
|
case 5:
|
||||||
case 7: buf_p = strappend(buf_p, " -+"); break;
|
case 7:
|
||||||
default: abort();
|
buf_p = strappend(buf_p, " -+"); break;
|
||||||
|
default:
|
||||||
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curbuf->b_fname != NULL) {
|
if (curbuf->b_fname != NULL) {
|
||||||
@@ -3485,17 +3464,8 @@ typedef enum {
|
|||||||
/// @param tabtab Tab clicks definition (can be NULL).
|
/// @param tabtab Tab clicks definition (can be NULL).
|
||||||
///
|
///
|
||||||
/// @return The final width of the statusline
|
/// @return The final width of the statusline
|
||||||
int build_stl_str_hl(
|
int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use_sandbox,
|
||||||
win_T *wp,
|
char_u fillchar, int maxwidth, stl_hlrec_t **hltab, StlClickRecord **tabtab)
|
||||||
char_u *out,
|
|
||||||
size_t outlen,
|
|
||||||
char_u *fmt,
|
|
||||||
int use_sandbox,
|
|
||||||
char_u fillchar,
|
|
||||||
int maxwidth,
|
|
||||||
stl_hlrec_t **hltab,
|
|
||||||
StlClickRecord **tabtab
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
static size_t stl_items_len = 20; // Initial value, grows as needed.
|
static size_t stl_items_len = 20; // Initial value, grows as needed.
|
||||||
static stl_item_t *stl_items = NULL;
|
static stl_item_t *stl_items = NULL;
|
||||||
@@ -3608,8 +3578,9 @@ int build_stl_str_hl(
|
|||||||
// Copy the formatting verbatim until we reach the end of the string
|
// Copy the formatting verbatim until we reach the end of the string
|
||||||
// or find a formatting item (denoted by `%`)
|
// or find a formatting item (denoted by `%`)
|
||||||
// or run out of room in our output buffer.
|
// or run out of room in our output buffer.
|
||||||
while (*fmt_p != NUL && *fmt_p != '%' && out_p < out_end_p)
|
while (*fmt_p != NUL && *fmt_p != '%' && out_p < out_end_p) {
|
||||||
*out_p++ = *fmt_p++;
|
*out_p++ = *fmt_p++;
|
||||||
|
}
|
||||||
|
|
||||||
// If we have processed the entire format string or run out of
|
// If we have processed the entire format string or run out of
|
||||||
// room in our output buffer, exit the loop.
|
// room in our output buffer, exit the loop.
|
||||||
@@ -3759,8 +3730,9 @@ int build_stl_str_hl(
|
|||||||
// If the group is left-aligned, add characters to the right.
|
// If the group is left-aligned, add characters to the right.
|
||||||
if (min_group_width < 0) {
|
if (min_group_width < 0) {
|
||||||
min_group_width = 0 - min_group_width;
|
min_group_width = 0 - min_group_width;
|
||||||
while (group_len++ < min_group_width && out_p < out_end_p)
|
while (group_len++ < min_group_width && out_p < out_end_p) {
|
||||||
*out_p++ = fillchar;
|
*out_p++ = fillchar;
|
||||||
|
}
|
||||||
// If the group is right-aligned, shift everything to the right and
|
// If the group is right-aligned, shift everything to the right and
|
||||||
// prepend with filler characters.
|
// prepend with filler characters.
|
||||||
} else {
|
} else {
|
||||||
@@ -3935,7 +3907,6 @@ int build_stl_str_hl(
|
|||||||
case STL_FILEPATH:
|
case STL_FILEPATH:
|
||||||
case STL_FULLPATH:
|
case STL_FULLPATH:
|
||||||
case STL_FILENAME:
|
case STL_FILENAME:
|
||||||
{
|
|
||||||
// Set fillable to false so that ' ' in the filename will not
|
// Set fillable to false so that ' ' in the filename will not
|
||||||
// get replaced with the fillchar
|
// get replaced with the fillchar
|
||||||
fillable = false;
|
fillable = false;
|
||||||
@@ -3953,7 +3924,6 @@ int build_stl_str_hl(
|
|||||||
str = path_tail(NameBuff);
|
str = path_tail(NameBuff);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case STL_VIM_EXPR: // '{'
|
case STL_VIM_EXPR: // '{'
|
||||||
{
|
{
|
||||||
char_u *block_start = fmt_p - 1;
|
char_u *block_start = fmt_p - 1;
|
||||||
@@ -4077,8 +4047,7 @@ int build_stl_str_hl(
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case STL_VIRTCOL:
|
case STL_VIRTCOL:
|
||||||
case STL_VIRTCOL_ALT:
|
case STL_VIRTCOL_ALT: {
|
||||||
{
|
|
||||||
// In list mode virtcol needs to be recomputed
|
// In list mode virtcol needs to be recomputed
|
||||||
colnr_T virtcol = wp->w_virtcol;
|
colnr_T virtcol = wp->w_virtcol;
|
||||||
if (wp->w_p_list && wp->w_p_lcs_chars.tab1 == NUL) {
|
if (wp->w_p_list && wp->w_p_lcs_chars.tab1 == NUL) {
|
||||||
@@ -4090,8 +4059,9 @@ int build_stl_str_hl(
|
|||||||
// Don't display %V if it's the same as %c.
|
// Don't display %V if it's the same as %c.
|
||||||
if (opt == STL_VIRTCOL_ALT
|
if (opt == STL_VIRTCOL_ALT
|
||||||
&& (virtcol == (colnr_T)(!(State & INSERT) && empty_line
|
&& (virtcol == (colnr_T)(!(State & INSERT) && empty_line
|
||||||
? 0 : (int)wp->w_cursor.col + 1)))
|
? 0 : (int)wp->w_cursor.col + 1))) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
num = (long)virtcol;
|
num = (long)virtcol;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -4142,8 +4112,7 @@ int build_stl_str_hl(
|
|||||||
case STL_OFFSET_X:
|
case STL_OFFSET_X:
|
||||||
base = kNumBaseHexadecimal;
|
base = kNumBaseHexadecimal;
|
||||||
FALLTHROUGH;
|
FALLTHROUGH;
|
||||||
case STL_OFFSET:
|
case STL_OFFSET: {
|
||||||
{
|
|
||||||
long l = ml_find_line_or_offset(wp->w_buffer, wp->w_cursor.lnum, NULL,
|
long l = ml_find_line_or_offset(wp->w_buffer, wp->w_cursor.lnum, NULL,
|
||||||
false);
|
false);
|
||||||
num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) || l < 0 ?
|
num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) || l < 0 ?
|
||||||
@@ -4174,9 +4143,10 @@ int build_stl_str_hl(
|
|||||||
case STL_HELPFLAG:
|
case STL_HELPFLAG:
|
||||||
case STL_HELPFLAG_ALT:
|
case STL_HELPFLAG_ALT:
|
||||||
itemisflag = true;
|
itemisflag = true;
|
||||||
if (wp->w_buffer->b_help)
|
if (wp->w_buffer->b_help) {
|
||||||
str = (char_u *)((opt == STL_HELPFLAG_ALT) ? ",HLP"
|
str = (char_u *)((opt == STL_HELPFLAG_ALT) ? ",HLP"
|
||||||
: _("[Help]"));
|
: _("[Help]"));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STL_FILETYPE:
|
case STL_FILETYPE:
|
||||||
@@ -4192,7 +4162,6 @@ int build_stl_str_hl(
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case STL_FILETYPE_ALT:
|
case STL_FILETYPE_ALT:
|
||||||
{
|
|
||||||
itemisflag = true;
|
itemisflag = true;
|
||||||
// Copy the filetype if it is not null and the formatted string will fit
|
// Copy the filetype if it is not null and the formatted string will fit
|
||||||
// in the temporary buffer
|
// in the temporary buffer
|
||||||
@@ -4208,20 +4177,21 @@ int build_stl_str_hl(
|
|||||||
str = buf_tmp;
|
str = buf_tmp;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case STL_PREVIEWFLAG:
|
case STL_PREVIEWFLAG:
|
||||||
case STL_PREVIEWFLAG_ALT:
|
case STL_PREVIEWFLAG_ALT:
|
||||||
itemisflag = true;
|
itemisflag = true;
|
||||||
if (wp->w_p_pvw)
|
if (wp->w_p_pvw) {
|
||||||
str = (char_u *)((opt == STL_PREVIEWFLAG_ALT) ? ",PRV"
|
str = (char_u *)((opt == STL_PREVIEWFLAG_ALT) ? ",PRV"
|
||||||
: _("[Preview]"));
|
: _("[Preview]"));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STL_QUICKFIX:
|
case STL_QUICKFIX:
|
||||||
if (bt_quickfix(wp->w_buffer))
|
if (bt_quickfix(wp->w_buffer)) {
|
||||||
str = (char_u *)(wp->w_llist_ref
|
str = (char_u *)(wp->w_llist_ref
|
||||||
? _(msg_loclist)
|
? _(msg_loclist)
|
||||||
: _(msg_qflist));
|
: _(msg_qflist));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STL_MODIFIED:
|
case STL_MODIFIED:
|
||||||
@@ -4230,17 +4200,22 @@ int build_stl_str_hl(
|
|||||||
switch ((opt == STL_MODIFIED_ALT)
|
switch ((opt == STL_MODIFIED_ALT)
|
||||||
+ bufIsChanged(wp->w_buffer) * 2
|
+ bufIsChanged(wp->w_buffer) * 2
|
||||||
+ (!MODIFIABLE(wp->w_buffer)) * 4) {
|
+ (!MODIFIABLE(wp->w_buffer)) * 4) {
|
||||||
case 2: str = (char_u *)"[+]"; break;
|
case 2:
|
||||||
case 3: str = (char_u *)",+"; break;
|
str = (char_u *)"[+]"; break;
|
||||||
case 4: str = (char_u *)"[-]"; break;
|
case 3:
|
||||||
case 5: str = (char_u *)",-"; break;
|
str = (char_u *)",+"; break;
|
||||||
case 6: str = (char_u *)"[+-]"; break;
|
case 4:
|
||||||
case 7: str = (char_u *)",+-"; break;
|
str = (char_u *)"[-]"; break;
|
||||||
|
case 5:
|
||||||
|
str = (char_u *)",-"; break;
|
||||||
|
case 6:
|
||||||
|
str = (char_u *)"[+-]"; break;
|
||||||
|
case 7:
|
||||||
|
str = (char_u *)",+-"; break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STL_HIGHLIGHT:
|
case STL_HIGHLIGHT: {
|
||||||
{
|
|
||||||
// { The name of the highlight is surrounded by `#`
|
// { The name of the highlight is surrounded by `#`
|
||||||
char_u *t = fmt_p;
|
char_u *t = fmt_p;
|
||||||
while (*fmt_p != '#' && *fmt_p != NUL) {
|
while (*fmt_p != '#' && *fmt_p != NUL) {
|
||||||
@@ -4274,8 +4249,9 @@ int build_stl_str_hl(
|
|||||||
if (itemisflag) {
|
if (itemisflag) {
|
||||||
if ((t[0] && t[1])
|
if ((t[0] && t[1])
|
||||||
&& ((!prevchar_isitem && *t == ',')
|
&& ((!prevchar_isitem && *t == ',')
|
||||||
|| (prevchar_isflag && *t == ' ')))
|
|| (prevchar_isflag && *t == ' '))) {
|
||||||
t++;
|
t++;
|
||||||
|
}
|
||||||
prevchar_isflag = true;
|
prevchar_isflag = true;
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
@@ -4328,9 +4304,10 @@ int build_stl_str_hl(
|
|||||||
// Change a space by fillchar, unless fillchar is '-' and a
|
// Change a space by fillchar, unless fillchar is '-' and a
|
||||||
// digit follows.
|
// digit follows.
|
||||||
if (fillable && out_p[-1] == ' '
|
if (fillable && out_p[-1] == ' '
|
||||||
&& (!ascii_isdigit(*t) || fillchar != '-'))
|
&& (!ascii_isdigit(*t) || fillchar != '-')) {
|
||||||
out_p[-1] = fillchar;
|
out_p[-1] = fillchar;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// For left-aligned items, fill any remaining space with the fillchar
|
// For left-aligned items, fill any remaining space with the fillchar
|
||||||
@@ -4776,10 +4753,7 @@ char_u *alist_name(aentry_T *aep)
|
|||||||
/*
|
/*
|
||||||
* do_arg_all(): Open up to 'count' windows, one for each argument.
|
* do_arg_all(): Open up to 'count' windows, one for each argument.
|
||||||
*/
|
*/
|
||||||
void
|
void do_arg_all(int count, int forceit, // hide buffers in current windows
|
||||||
do_arg_all(
|
|
||||||
int count,
|
|
||||||
int forceit, // hide buffers in current windows
|
|
||||||
int keep_tabs // keep current tabs, for ":tab drop file"
|
int keep_tabs // keep current tabs, for ":tab drop file"
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -5097,8 +5071,8 @@ void ex_buffer_all(exarg_T *eap)
|
|||||||
: wp->w_width != Columns)
|
: wp->w_width != Columns)
|
||||||
|| (had_tab > 0 && wp != firstwin))
|
|| (had_tab > 0 && wp != firstwin))
|
||||||
&& !ONE_WINDOW
|
&& !ONE_WINDOW
|
||||||
&& !(wp->w_closing || wp->w_buffer->b_locked > 0)
|
&& !(wp->w_closing ||
|
||||||
) {
|
wp->w_buffer->b_locked > 0)) {
|
||||||
win_close(wp, false);
|
win_close(wp, false);
|
||||||
wpnext = firstwin; // just in case an autocommand does
|
wpnext = firstwin; // just in case an autocommand does
|
||||||
// something strange with windows
|
// something strange with windows
|
||||||
@@ -5189,9 +5163,10 @@ void ex_buffer_all(exarg_T *eap)
|
|||||||
* discarded by a new aborting error, interrupt, or uncaught
|
* discarded by a new aborting error, interrupt, or uncaught
|
||||||
* exception. */
|
* exception. */
|
||||||
leave_cleanup(&cs);
|
leave_cleanup(&cs);
|
||||||
} else
|
} else {
|
||||||
handle_swap_exists(NULL);
|
handle_swap_exists(NULL);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
os_breakcheck();
|
os_breakcheck();
|
||||||
if (got_int) {
|
if (got_int) {
|
||||||
@@ -5282,10 +5257,7 @@ void do_modelines(int flags)
|
|||||||
* chk_modeline() - check a single line for a mode string
|
* chk_modeline() - check a single line for a mode string
|
||||||
* Return FAIL if an error encountered.
|
* Return FAIL if an error encountered.
|
||||||
*/
|
*/
|
||||||
static int
|
static int chk_modeline(linenr_T lnum, int flags // Same as for do_modelines().
|
||||||
chk_modeline(
|
|
||||||
linenr_T lnum,
|
|
||||||
int flags // Same as for do_modelines().
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
char_u *s;
|
char_u *s;
|
||||||
@@ -5302,8 +5274,9 @@ chk_modeline(
|
|||||||
for (s = ml_get(lnum); *s != NUL; s++) {
|
for (s = ml_get(lnum); *s != NUL; s++) {
|
||||||
if (prev == -1 || ascii_isspace(prev)) {
|
if (prev == -1 || ascii_isspace(prev)) {
|
||||||
if ((prev != -1 && STRNCMP(s, "ex:", (size_t)3) == 0)
|
if ((prev != -1 && STRNCMP(s, "ex:", (size_t)3) == 0)
|
||||||
|| STRNCMP(s, "vi:", (size_t)3) == 0)
|
|| STRNCMP(s, "vi:", (size_t)3) == 0) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
// Accept both "vim" and "Vim".
|
// Accept both "vim" and "Vim".
|
||||||
if ((s[0] == 'v' || s[0] == 'V') && s[1] == 'i' && s[2] == 'm') {
|
if ((s[0] == 'v' || s[0] == 'V') && s[1] == 'i' && s[2] == 'm') {
|
||||||
if (s[3] == '<' || s[3] == '=' || s[3] == '>') {
|
if (s[3] == '<' || s[3] == '=' || s[3] == '>') {
|
||||||
@@ -5477,8 +5450,10 @@ bool buf_hide(const buf_T *const buf)
|
|||||||
switch (buf->b_p_bh[0]) {
|
switch (buf->b_p_bh[0]) {
|
||||||
case 'u': // "unload"
|
case 'u': // "unload"
|
||||||
case 'w': // "wipe"
|
case 'w': // "wipe"
|
||||||
case 'd': return false; // "delete"
|
case 'd':
|
||||||
case 'h': return true; // "hide"
|
return false; // "delete"
|
||||||
|
case 'h':
|
||||||
|
return true; // "hide"
|
||||||
}
|
}
|
||||||
return p_hid || cmdmod.hide;
|
return p_hid || cmdmod.hide;
|
||||||
}
|
}
|
||||||
@@ -5660,10 +5635,7 @@ bool buf_contents_changed(buf_T *buf)
|
|||||||
* this buffer. Call this to wipe out a temp buffer that does not contain any
|
* this buffer. Call this to wipe out a temp buffer that does not contain any
|
||||||
* marks.
|
* marks.
|
||||||
*/
|
*/
|
||||||
void
|
void wipe_buffer(buf_T *buf, bool aucmd // When true trigger autocommands.
|
||||||
wipe_buffer(
|
|
||||||
buf_T *buf,
|
|
||||||
bool aucmd // When true trigger autocommands.
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!aucmd) {
|
if (!aucmd) {
|
||||||
|
@@ -1,14 +1,14 @@
|
|||||||
// This is an open source non-commercial project. Dear PVS-Studio, please check
|
// This is an open source non-commercial project. Dear PVS-Studio, please check
|
||||||
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||||
|
|
||||||
#include "nvim/buffer_updates.h"
|
|
||||||
#include "nvim/extmark.h"
|
|
||||||
#include "nvim/memline.h"
|
|
||||||
#include "nvim/api/private/helpers.h"
|
#include "nvim/api/private/helpers.h"
|
||||||
#include "nvim/msgpack_rpc/channel.h"
|
|
||||||
#include "nvim/lua/executor.h"
|
|
||||||
#include "nvim/assert.h"
|
#include "nvim/assert.h"
|
||||||
#include "nvim/buffer.h"
|
#include "nvim/buffer.h"
|
||||||
|
#include "nvim/buffer_updates.h"
|
||||||
|
#include "nvim/extmark.h"
|
||||||
|
#include "nvim/lua/executor.h"
|
||||||
|
#include "nvim/memline.h"
|
||||||
|
#include "nvim/msgpack_rpc/channel.h"
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "buffer_updates.c.generated.h"
|
# include "buffer_updates.c.generated.h"
|
||||||
@@ -17,8 +17,7 @@
|
|||||||
// Register a channel. Return True if the channel was added, or already added.
|
// Register a channel. Return True if the channel was added, or already added.
|
||||||
// Return False if the channel couldn't be added because the buffer is
|
// Return False if the channel couldn't be added because the buffer is
|
||||||
// unloaded.
|
// unloaded.
|
||||||
bool buf_updates_register(buf_T *buf, uint64_t channel_id,
|
bool buf_updates_register(buf_T *buf, uint64_t channel_id, BufUpdateCallbacks cb, bool send_buffer)
|
||||||
BufUpdateCallbacks cb, bool send_buffer)
|
|
||||||
{
|
{
|
||||||
// must fail if the buffer isn't loaded
|
// must fail if the buffer isn't loaded
|
||||||
if (buf->b_ml.ml_mfp == NULL) {
|
if (buf->b_ml.ml_mfp == NULL) {
|
||||||
@@ -187,11 +186,8 @@ void buf_updates_unload(buf_T *buf, bool can_reload)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void buf_updates_send_changes(buf_T *buf,
|
void buf_updates_send_changes(buf_T *buf, linenr_T firstline, int64_t num_added,
|
||||||
linenr_T firstline,
|
int64_t num_removed, bool send_tick)
|
||||||
int64_t num_added,
|
|
||||||
int64_t num_removed,
|
|
||||||
bool send_tick)
|
|
||||||
{
|
{
|
||||||
size_t deleted_codepoints, deleted_codeunits;
|
size_t deleted_codepoints, deleted_codeunits;
|
||||||
size_t deleted_bytes = ml_flush_deleted_bytes(buf, &deleted_codepoints,
|
size_t deleted_bytes = ml_flush_deleted_bytes(buf, &deleted_codepoints,
|
||||||
@@ -302,11 +298,9 @@ void buf_updates_send_changes(buf_T *buf,
|
|||||||
kv_size(buf->update_callbacks) = j;
|
kv_size(buf->update_callbacks) = j;
|
||||||
}
|
}
|
||||||
|
|
||||||
void buf_updates_send_splice(
|
void buf_updates_send_splice(buf_T *buf, int start_row, colnr_T start_col, bcount_t start_byte,
|
||||||
buf_T *buf,
|
int old_row, colnr_T old_col, bcount_t old_byte, int new_row,
|
||||||
int start_row, colnr_T start_col, bcount_t start_byte,
|
colnr_T new_col, bcount_t new_byte)
|
||||||
int old_row, colnr_T old_col, bcount_t old_byte,
|
|
||||||
int new_row, colnr_T new_col, bcount_t new_byte)
|
|
||||||
{
|
{
|
||||||
if (!buf_updates_active(buf)
|
if (!buf_updates_active(buf)
|
||||||
|| (old_byte == 0 && new_byte == 0)) {
|
|| (old_byte == 0 && new_byte == 0)) {
|
||||||
|
@@ -12,12 +12,12 @@
|
|||||||
#include "nvim/diff.h"
|
#include "nvim/diff.h"
|
||||||
#include "nvim/edit.h"
|
#include "nvim/edit.h"
|
||||||
#include "nvim/eval.h"
|
#include "nvim/eval.h"
|
||||||
|
#include "nvim/extmark.h"
|
||||||
#include "nvim/fileio.h"
|
#include "nvim/fileio.h"
|
||||||
#include "nvim/fold.h"
|
#include "nvim/fold.h"
|
||||||
#include "nvim/indent.h"
|
#include "nvim/indent.h"
|
||||||
#include "nvim/indent_c.h"
|
#include "nvim/indent_c.h"
|
||||||
#include "nvim/mark.h"
|
#include "nvim/mark.h"
|
||||||
#include "nvim/extmark.h"
|
|
||||||
#include "nvim/memline.h"
|
#include "nvim/memline.h"
|
||||||
#include "nvim/misc1.h"
|
#include "nvim/misc1.h"
|
||||||
#include "nvim/move.h"
|
#include "nvim/move.h"
|
||||||
@@ -97,8 +97,7 @@ void changed(void)
|
|||||||
// Create a swap file if that is wanted.
|
// Create a swap file if that is wanted.
|
||||||
// Don't do this for "nofile" and "nowrite" buffer types.
|
// Don't do this for "nofile" and "nowrite" buffer types.
|
||||||
if (curbuf->b_may_swap
|
if (curbuf->b_may_swap
|
||||||
&& !bt_dontwrite(curbuf)
|
&& !bt_dontwrite(curbuf)) {
|
||||||
) {
|
|
||||||
bool save_need_wait_return = need_wait_return;
|
bool save_need_wait_return = need_wait_return;
|
||||||
|
|
||||||
need_wait_return = false;
|
need_wait_return = false;
|
||||||
@@ -140,8 +139,7 @@ void changed_internal(void)
|
|||||||
/// Common code for when a change was made.
|
/// Common code for when a change was made.
|
||||||
/// See changed_lines() for the arguments.
|
/// See changed_lines() for the arguments.
|
||||||
/// Careful: may trigger autocommands that reload the buffer.
|
/// Careful: may trigger autocommands that reload the buffer.
|
||||||
static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume,
|
static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra)
|
||||||
long xtra)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
pos_T *p;
|
pos_T *p;
|
||||||
@@ -463,9 +461,7 @@ void changed_lines_buf(buf_T *buf, linenr_T lnum, linenr_T lnume, long xtra)
|
|||||||
/// When only inserting lines, "lnum" and "lnume" are equal.
|
/// When only inserting lines, "lnum" and "lnume" are equal.
|
||||||
/// Takes care of calling changed() and updating b_mod_*.
|
/// Takes care of calling changed() and updating b_mod_*.
|
||||||
/// Careful: may trigger autocommands that reload the buffer.
|
/// Careful: may trigger autocommands that reload the buffer.
|
||||||
void
|
void changed_lines(linenr_T lnum, // first line with change
|
||||||
changed_lines(
|
|
||||||
linenr_T lnum, // first line with change
|
|
||||||
colnr_T col, // column in first line with change
|
colnr_T col, // column in first line with change
|
||||||
linenr_T lnume, // line below last changed line
|
linenr_T lnume, // line below last changed line
|
||||||
long xtra, // number of extra lines (negative when deleting)
|
long xtra, // number of extra lines (negative when deleting)
|
||||||
@@ -657,8 +653,7 @@ void ins_char_bytes(char_u *buf, size_t charlen)
|
|||||||
// show the match for right parens and braces.
|
// show the match for right parens and braces.
|
||||||
if (p_sm && (State & INSERT)
|
if (p_sm && (State & INSERT)
|
||||||
&& msg_silent == 0
|
&& msg_silent == 0
|
||||||
&& !ins_compl_active()
|
&& !ins_compl_active()) {
|
||||||
) {
|
|
||||||
showmatch(utf_ptr2char(buf));
|
showmatch(utf_ptr2char(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -791,8 +786,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine)
|
|||||||
// fixpos is true, we don't want to end up positioned at the NUL,
|
// fixpos is true, we don't want to end up positioned at the NUL,
|
||||||
// unless "restart_edit" is set or 'virtualedit' contains "onemore".
|
// unless "restart_edit" is set or 'virtualedit' contains "onemore".
|
||||||
if (col > 0 && fixpos && restart_edit == 0
|
if (col > 0 && fixpos && restart_edit == 0
|
||||||
&& (ve_flags & VE_ONEMORE) == 0
|
&& (ve_flags & VE_ONEMORE) == 0) {
|
||||||
) {
|
|
||||||
curwin->w_cursor.col--;
|
curwin->w_cursor.col--;
|
||||||
curwin->w_cursor.coladd = 0;
|
curwin->w_cursor.coladd = 0;
|
||||||
curwin->w_cursor.col -= utf_head_off(oldp, oldp + curwin->w_cursor.col);
|
curwin->w_cursor.col -= utf_head_off(oldp, oldp + curwin->w_cursor.col);
|
||||||
@@ -957,11 +951,8 @@ int copy_indent(int size, char_u *src)
|
|||||||
/// OPENLINE_COM_LIST
|
/// OPENLINE_COM_LIST
|
||||||
///
|
///
|
||||||
/// @return true on success, false on failure
|
/// @return true on success, false on failure
|
||||||
int open_line(
|
int open_line(int dir, // FORWARD or BACKWARD
|
||||||
int dir, // FORWARD or BACKWARD
|
int flags, int second_line_indent)
|
||||||
int flags,
|
|
||||||
int second_line_indent
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
char_u *next_line = NULL; // copy of the next line
|
char_u *next_line = NULL; // copy of the next line
|
||||||
char_u *p_extra = NULL; // what goes to next line
|
char_u *p_extra = NULL; // what goes to next line
|
||||||
@@ -1023,8 +1014,7 @@ int open_line(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((State & INSERT)
|
if ((State & INSERT)
|
||||||
&& !(State & VREPLACE_FLAG)
|
&& !(State & VREPLACE_FLAG)) {
|
||||||
) {
|
|
||||||
p_extra = saved_line + curwin->w_cursor.col;
|
p_extra = saved_line + curwin->w_cursor.col;
|
||||||
if (do_si) { // need first char after new line break
|
if (do_si) { // need first char after new line break
|
||||||
p = skipwhite(p_extra);
|
p = skipwhite(p_extra);
|
||||||
@@ -1049,8 +1039,7 @@ int open_line(
|
|||||||
// If 'autoindent' and/or 'smartindent' is set, try to figure out what
|
// If 'autoindent' and/or 'smartindent' is set, try to figure out what
|
||||||
// indent to use for the new line.
|
// indent to use for the new line.
|
||||||
if (curbuf->b_p_ai
|
if (curbuf->b_p_ai
|
||||||
|| do_si
|
|| do_si) {
|
||||||
) {
|
|
||||||
// count white space on current line
|
// count white space on current line
|
||||||
newindent = get_indent_str_vtab(saved_line,
|
newindent = get_indent_str_vtab(saved_line,
|
||||||
curbuf->b_p_ts,
|
curbuf->b_p_ts,
|
||||||
@@ -1476,8 +1465,7 @@ int open_line(
|
|||||||
|
|
||||||
// Recompute the indent, it may have changed.
|
// Recompute the indent, it may have changed.
|
||||||
if (curbuf->b_p_ai
|
if (curbuf->b_p_ai
|
||||||
|| do_si
|
|| do_si) {
|
||||||
) {
|
|
||||||
newindent = get_indent_str_vtab(leader,
|
newindent = get_indent_str_vtab(leader,
|
||||||
curbuf->b_p_ts,
|
curbuf->b_p_ts,
|
||||||
curbuf->b_p_vts_array, false);
|
curbuf->b_p_vts_array, false);
|
||||||
@@ -1521,8 +1509,7 @@ int open_line(
|
|||||||
// if a new indent will be set below, remove the indent that
|
// if a new indent will be set below, remove the indent that
|
||||||
// is in the comment leader
|
// is in the comment leader
|
||||||
if (newindent
|
if (newindent
|
||||||
|| did_si
|
|| did_si) {
|
||||||
) {
|
|
||||||
while (lead_len && ascii_iswhite(*leader)) {
|
while (lead_len && ascii_iswhite(*leader)) {
|
||||||
lead_len--;
|
lead_len--;
|
||||||
newcol--;
|
newcol--;
|
||||||
@@ -1641,8 +1628,7 @@ int open_line(
|
|||||||
|
|
||||||
inhibit_delete_count++;
|
inhibit_delete_count++;
|
||||||
if (newindent
|
if (newindent
|
||||||
|| did_si
|
|| did_si) {
|
||||||
) {
|
|
||||||
curwin->w_cursor.lnum++;
|
curwin->w_cursor.lnum++;
|
||||||
if (did_si) {
|
if (did_si) {
|
||||||
int sw = get_sw_value(curbuf);
|
int sw = get_sw_value(curbuf);
|
||||||
@@ -1706,8 +1692,7 @@ int open_line(
|
|||||||
// TODO(vigoux): maybe there is issues there with expandtabs ?
|
// TODO(vigoux): maybe there is issues there with expandtabs ?
|
||||||
int cols_spliced = 0;
|
int cols_spliced = 0;
|
||||||
if (new_len < curwin->w_cursor.col) {
|
if (new_len < curwin->w_cursor.col) {
|
||||||
extmark_splice_cols(
|
extmark_splice_cols(curbuf, (int)curwin->w_cursor.lnum - 1,
|
||||||
curbuf, (int)curwin->w_cursor.lnum - 1,
|
|
||||||
new_len, curwin->w_cursor.col - new_len, 0, kExtmarkUndo);
|
new_len, curwin->w_cursor.col - new_len, 0, kExtmarkUndo);
|
||||||
cols_spliced = curwin->w_cursor.col - new_len;
|
cols_spliced = curwin->w_cursor.col - new_len;
|
||||||
}
|
}
|
||||||
|
@@ -12,11 +12,11 @@
|
|||||||
#include "nvim/msgpack_rpc/server.h"
|
#include "nvim/msgpack_rpc/server.h"
|
||||||
#include "nvim/os/shell.h"
|
#include "nvim/os/shell.h"
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
# include "nvim/os/pty_conpty_win.h"
|
|
||||||
# include "nvim/os/os_win_console.h"
|
# include "nvim/os/os_win_console.h"
|
||||||
|
# include "nvim/os/pty_conpty_win.h"
|
||||||
#endif
|
#endif
|
||||||
#include "nvim/path.h"
|
|
||||||
#include "nvim/ascii.h"
|
#include "nvim/ascii.h"
|
||||||
|
#include "nvim/path.h"
|
||||||
|
|
||||||
static bool did_stdio = false;
|
static bool did_stdio = false;
|
||||||
|
|
||||||
@@ -301,12 +301,10 @@ static void close_cb(Stream *stream, void *data)
|
|||||||
/// < 0 if the job can't start
|
/// < 0 if the job can't start
|
||||||
///
|
///
|
||||||
/// @returns [allocated] channel
|
/// @returns [allocated] channel
|
||||||
Channel *channel_job_start(char **argv, CallbackReader on_stdout,
|
Channel *channel_job_start(char **argv, CallbackReader on_stdout, CallbackReader on_stderr,
|
||||||
CallbackReader on_stderr, Callback on_exit,
|
Callback on_exit, bool pty, bool rpc, bool overlapped, bool detach,
|
||||||
bool pty, bool rpc, bool overlapped, bool detach,
|
ChannelStdinMode stdin_mode, const char *cwd, uint16_t pty_width,
|
||||||
ChannelStdinMode stdin_mode, const char *cwd,
|
uint16_t pty_height, dict_T *env, varnumber_T *status_out)
|
||||||
uint16_t pty_width, uint16_t pty_height,
|
|
||||||
dict_T *env, varnumber_T *status_out)
|
|
||||||
{
|
{
|
||||||
assert(cwd == NULL || os_isdir_executable(cwd));
|
assert(cwd == NULL || os_isdir_executable(cwd));
|
||||||
|
|
||||||
@@ -409,8 +407,7 @@ Channel *channel_job_start(char **argv, CallbackReader on_stdout,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint64_t channel_connect(bool tcp, const char *address,
|
uint64_t channel_connect(bool tcp, const char *address, bool rpc, CallbackReader on_output,
|
||||||
bool rpc, CallbackReader on_output,
|
|
||||||
int timeout, const char **error)
|
int timeout, const char **error)
|
||||||
{
|
{
|
||||||
Channel *channel;
|
Channel *channel;
|
||||||
@@ -470,8 +467,7 @@ void channel_from_connection(SocketWatcher *watcher)
|
|||||||
|
|
||||||
/// Creates an API channel from stdin/stdout. This is used when embedding
|
/// Creates an API channel from stdin/stdout. This is used when embedding
|
||||||
/// Neovim
|
/// Neovim
|
||||||
uint64_t channel_from_stdio(bool rpc, CallbackReader on_output,
|
uint64_t channel_from_stdio(bool rpc, CallbackReader on_output, const char **error)
|
||||||
const char **error)
|
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
if (!headless_mode && !embedded_mode) {
|
if (!headless_mode && !embedded_mode) {
|
||||||
@@ -514,8 +510,7 @@ uint64_t channel_from_stdio(bool rpc, CallbackReader on_output,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @param data will be consumed
|
/// @param data will be consumed
|
||||||
size_t channel_send(uint64_t id, char *data, size_t len,
|
size_t channel_send(uint64_t id, char *data, size_t len, bool data_owned, const char **error)
|
||||||
bool data_owned, const char **error)
|
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
Channel *chan = find_channel(id);
|
Channel *chan = find_channel(id);
|
||||||
@@ -584,22 +579,20 @@ static inline list_T *buffer_to_tv_list(const char *const buf, const size_t len)
|
|||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_channel_data(Stream *stream, RBuffer *buf, size_t count,
|
void on_channel_data(Stream *stream, RBuffer *buf, size_t count, void *data, bool eof)
|
||||||
void *data, bool eof)
|
|
||||||
{
|
{
|
||||||
Channel *chan = data;
|
Channel *chan = data;
|
||||||
on_channel_output(stream, chan, buf, count, eof, &chan->on_data);
|
on_channel_output(stream, chan, buf, count, eof, &chan->on_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_job_stderr(Stream *stream, RBuffer *buf, size_t count,
|
void on_job_stderr(Stream *stream, RBuffer *buf, size_t count, void *data, bool eof)
|
||||||
void *data, bool eof)
|
|
||||||
{
|
{
|
||||||
Channel *chan = data;
|
Channel *chan = data;
|
||||||
on_channel_output(stream, chan, buf, count, eof, &chan->on_stderr);
|
on_channel_output(stream, chan, buf, count, eof, &chan->on_stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void on_channel_output(Stream *stream, Channel *chan, RBuffer *buf,
|
static void on_channel_output(Stream *stream, Channel *chan, RBuffer *buf, size_t count, bool eof,
|
||||||
size_t count, bool eof, CallbackReader *reader)
|
CallbackReader *reader)
|
||||||
{
|
{
|
||||||
// stub variable, to keep reading consistent with the order of events, only
|
// stub variable, to keep reading consistent with the order of events, only
|
||||||
// consider the count parameter.
|
// consider the count parameter.
|
||||||
|
@@ -6,14 +6,15 @@
|
|||||||
/// Code related to character sets.
|
/// Code related to character sets.
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <wctype.h>
|
#include <wctype.h>
|
||||||
#include <inttypes.h>
|
|
||||||
|
|
||||||
#include "nvim/vim.h"
|
|
||||||
#include "nvim/ascii.h"
|
#include "nvim/ascii.h"
|
||||||
#include "nvim/charset.h"
|
#include "nvim/charset.h"
|
||||||
|
#include "nvim/cursor.h"
|
||||||
#include "nvim/func_attr.h"
|
#include "nvim/func_attr.h"
|
||||||
|
#include "nvim/garray.h"
|
||||||
#include "nvim/indent.h"
|
#include "nvim/indent.h"
|
||||||
#include "nvim/main.h"
|
#include "nvim/main.h"
|
||||||
#include "nvim/mark.h"
|
#include "nvim/mark.h"
|
||||||
@@ -21,15 +22,14 @@
|
|||||||
#include "nvim/memline.h"
|
#include "nvim/memline.h"
|
||||||
#include "nvim/memory.h"
|
#include "nvim/memory.h"
|
||||||
#include "nvim/misc1.h"
|
#include "nvim/misc1.h"
|
||||||
#include "nvim/garray.h"
|
|
||||||
#include "nvim/move.h"
|
#include "nvim/move.h"
|
||||||
#include "nvim/option.h"
|
#include "nvim/option.h"
|
||||||
#include "nvim/os_unix.h"
|
#include "nvim/os_unix.h"
|
||||||
|
#include "nvim/path.h"
|
||||||
#include "nvim/plines.h"
|
#include "nvim/plines.h"
|
||||||
#include "nvim/state.h"
|
#include "nvim/state.h"
|
||||||
#include "nvim/strings.h"
|
#include "nvim/strings.h"
|
||||||
#include "nvim/path.h"
|
#include "nvim/vim.h"
|
||||||
#include "nvim/cursor.h"
|
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "charset.c.generated.h"
|
# include "charset.c.generated.h"
|
||||||
@@ -906,8 +906,7 @@ bool in_win_border(win_T *wp, colnr_T vcol)
|
|||||||
/// @param start
|
/// @param start
|
||||||
/// @param cursor
|
/// @param cursor
|
||||||
/// @param end
|
/// @param end
|
||||||
void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor,
|
void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *end)
|
||||||
colnr_T *end)
|
|
||||||
{
|
{
|
||||||
colnr_T vcol;
|
colnr_T vcol;
|
||||||
char_u *ptr; // points to current char
|
char_u *ptr; // points to current char
|
||||||
@@ -1059,8 +1058,7 @@ colnr_T getvcol_nolist(pos_T *posp)
|
|||||||
/// @param start
|
/// @param start
|
||||||
/// @param cursor
|
/// @param cursor
|
||||||
/// @param end
|
/// @param end
|
||||||
void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor,
|
void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *end)
|
||||||
colnr_T *end)
|
|
||||||
{
|
{
|
||||||
colnr_T col;
|
colnr_T col;
|
||||||
colnr_T coladd;
|
colnr_T coladd;
|
||||||
@@ -1115,8 +1113,7 @@ void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor,
|
|||||||
/// @param pos2
|
/// @param pos2
|
||||||
/// @param left
|
/// @param left
|
||||||
/// @param right
|
/// @param right
|
||||||
void getvcols(win_T *wp, pos_T *pos1, pos_T *pos2, colnr_T *left,
|
void getvcols(win_T *wp, pos_T *pos1, pos_T *pos2, colnr_T *left, colnr_T *right)
|
||||||
colnr_T *right)
|
|
||||||
{
|
{
|
||||||
colnr_T from1;
|
colnr_T from1;
|
||||||
colnr_T from2;
|
colnr_T from2;
|
||||||
@@ -1440,9 +1437,9 @@ bool vim_isblankline(char_u *lbuf)
|
|||||||
/// @param strict If true, fail if the number has unexpected trailing
|
/// @param strict If true, fail if the number has unexpected trailing
|
||||||
/// alpha-numeric chars: *len is set to 0 and nothing else is
|
/// alpha-numeric chars: *len is set to 0 and nothing else is
|
||||||
/// returned.
|
/// returned.
|
||||||
void vim_str2nr(const char_u *const start, int *const prep, int *const len,
|
void vim_str2nr(const char_u *const start, int *const prep, int *const len, const int what,
|
||||||
const int what, varnumber_T *const nptr,
|
varnumber_T *const nptr, uvarnumber_T *const unptr, const int maxlen,
|
||||||
uvarnumber_T *const unptr, const int maxlen, const bool strict)
|
const bool strict)
|
||||||
FUNC_ATTR_NONNULL_ARG(1)
|
FUNC_ATTR_NONNULL_ARG(1)
|
||||||
{
|
{
|
||||||
const char *ptr = (const char *)start;
|
const char *ptr = (const char *)start;
|
||||||
@@ -1464,7 +1461,7 @@ void vim_str2nr(const char_u *const start, int *const prep, int *const len,
|
|||||||
// When forcing main consideration is skipping the prefix. Decimal numbers
|
// When forcing main consideration is skipping the prefix. Decimal numbers
|
||||||
// have no prefixes to skip. pre is not set.
|
// have no prefixes to skip. pre is not set.
|
||||||
switch (what & ~(STR2NR_FORCE | STR2NR_QUOTE)) {
|
switch (what & ~(STR2NR_FORCE | STR2NR_QUOTE)) {
|
||||||
case STR2NR_HEX: {
|
case STR2NR_HEX:
|
||||||
if (!STRING_ENDED(ptr + 2)
|
if (!STRING_ENDED(ptr + 2)
|
||||||
&& ptr[0] == '0'
|
&& ptr[0] == '0'
|
||||||
&& (ptr[1] == 'x' || ptr[1] == 'X')
|
&& (ptr[1] == 'x' || ptr[1] == 'X')
|
||||||
@@ -1472,8 +1469,7 @@ void vim_str2nr(const char_u *const start, int *const prep, int *const len,
|
|||||||
ptr += 2;
|
ptr += 2;
|
||||||
}
|
}
|
||||||
goto vim_str2nr_hex;
|
goto vim_str2nr_hex;
|
||||||
}
|
case STR2NR_BIN:
|
||||||
case STR2NR_BIN: {
|
|
||||||
if (!STRING_ENDED(ptr + 2)
|
if (!STRING_ENDED(ptr + 2)
|
||||||
&& ptr[0] == '0'
|
&& ptr[0] == '0'
|
||||||
&& (ptr[1] == 'b' || ptr[1] == 'B')
|
&& (ptr[1] == 'b' || ptr[1] == 'B')
|
||||||
@@ -1481,11 +1477,10 @@ void vim_str2nr(const char_u *const start, int *const prep, int *const len,
|
|||||||
ptr += 2;
|
ptr += 2;
|
||||||
}
|
}
|
||||||
goto vim_str2nr_bin;
|
goto vim_str2nr_bin;
|
||||||
}
|
|
||||||
// Make STR2NR_OOCT work the same as STR2NR_OCT when forcing.
|
// Make STR2NR_OOCT work the same as STR2NR_OCT when forcing.
|
||||||
case STR2NR_OCT:
|
case STR2NR_OCT:
|
||||||
case STR2NR_OOCT:
|
case STR2NR_OOCT:
|
||||||
case STR2NR_OCT | STR2NR_OOCT: {
|
case STR2NR_OCT | STR2NR_OOCT:
|
||||||
if (!STRING_ENDED(ptr + 2)
|
if (!STRING_ENDED(ptr + 2)
|
||||||
&& ptr[0] == '0'
|
&& ptr[0] == '0'
|
||||||
&& (ptr[1] == 'o' || ptr[1] == 'O')
|
&& (ptr[1] == 'o' || ptr[1] == 'O')
|
||||||
@@ -1493,14 +1488,11 @@ void vim_str2nr(const char_u *const start, int *const prep, int *const len,
|
|||||||
ptr += 2;
|
ptr += 2;
|
||||||
}
|
}
|
||||||
goto vim_str2nr_oct;
|
goto vim_str2nr_oct;
|
||||||
}
|
case 0:
|
||||||
case 0: {
|
|
||||||
goto vim_str2nr_dec;
|
goto vim_str2nr_dec;
|
||||||
}
|
default:
|
||||||
default: {
|
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else if ((what & (STR2NR_HEX | STR2NR_OCT | STR2NR_OOCT | STR2NR_BIN))
|
} else if ((what & (STR2NR_HEX | STR2NR_OCT | STR2NR_OOCT | STR2NR_BIN))
|
||||||
&& !STRING_ENDED(ptr + 1) && ptr[0] == '0' && ptr[1] != '8'
|
&& !STRING_ENDED(ptr + 1) && ptr[0] == '0' && ptr[1] != '8'
|
||||||
&& ptr[1] != '9') {
|
&& ptr[1] != '9') {
|
||||||
|
@@ -3,13 +3,13 @@
|
|||||||
|
|
||||||
// Context: snapshot of the entire editor state as one big object/map
|
// Context: snapshot of the entire editor state as one big object/map
|
||||||
|
|
||||||
|
#include "nvim/api/private/helpers.h"
|
||||||
|
#include "nvim/api/vim.h"
|
||||||
#include "nvim/context.h"
|
#include "nvim/context.h"
|
||||||
#include "nvim/eval/encode.h"
|
#include "nvim/eval/encode.h"
|
||||||
#include "nvim/ex_docmd.h"
|
#include "nvim/ex_docmd.h"
|
||||||
#include "nvim/option.h"
|
#include "nvim/option.h"
|
||||||
#include "nvim/shada.h"
|
#include "nvim/shada.h"
|
||||||
#include "nvim/api/vim.h"
|
|
||||||
#include "nvim/api/private/helpers.h"
|
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "context.c.generated.h"
|
# include "context.c.generated.h"
|
||||||
|
@@ -1,25 +1,25 @@
|
|||||||
// This is an open source non-commercial project. Dear PVS-Studio, please check
|
// This is an open source non-commercial project. Dear PVS-Studio, please check
|
||||||
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "nvim/ascii.h"
|
||||||
#include "nvim/assert.h"
|
#include "nvim/assert.h"
|
||||||
#include "nvim/change.h"
|
#include "nvim/change.h"
|
||||||
#include "nvim/cursor.h"
|
|
||||||
#include "nvim/charset.h"
|
#include "nvim/charset.h"
|
||||||
|
#include "nvim/cursor.h"
|
||||||
|
#include "nvim/extmark.h"
|
||||||
#include "nvim/fold.h"
|
#include "nvim/fold.h"
|
||||||
|
#include "nvim/mark.h"
|
||||||
#include "nvim/memline.h"
|
#include "nvim/memline.h"
|
||||||
#include "nvim/memory.h"
|
#include "nvim/memory.h"
|
||||||
#include "nvim/misc1.h"
|
#include "nvim/misc1.h"
|
||||||
#include "nvim/move.h"
|
#include "nvim/move.h"
|
||||||
#include "nvim/plines.h"
|
#include "nvim/plines.h"
|
||||||
#include "nvim/screen.h"
|
#include "nvim/screen.h"
|
||||||
#include "nvim/extmark.h"
|
|
||||||
#include "nvim/state.h"
|
#include "nvim/state.h"
|
||||||
#include "nvim/vim.h"
|
#include "nvim/vim.h"
|
||||||
#include "nvim/ascii.h"
|
|
||||||
#include "nvim/mark.h"
|
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "cursor.c.generated.h"
|
# include "cursor.c.generated.h"
|
||||||
@@ -63,7 +63,7 @@ int coladvance_force(colnr_T wcol)
|
|||||||
if (wcol == MAXCOL) {
|
if (wcol == MAXCOL) {
|
||||||
curwin->w_valid &= ~VALID_VIRTCOL;
|
curwin->w_valid &= ~VALID_VIRTCOL;
|
||||||
} else {
|
} else {
|
||||||
/* Virtcol is valid */
|
// Virtcol is valid
|
||||||
curwin->w_valid |= VALID_VIRTCOL;
|
curwin->w_valid |= VALID_VIRTCOL;
|
||||||
curwin->w_virtcol = wcol;
|
curwin->w_virtcol = wcol;
|
||||||
}
|
}
|
||||||
@@ -83,19 +83,17 @@ int coladvance(colnr_T wcol)
|
|||||||
{
|
{
|
||||||
int rc = getvpos(&curwin->w_cursor, wcol);
|
int rc = getvpos(&curwin->w_cursor, wcol);
|
||||||
|
|
||||||
if (wcol == MAXCOL || rc == FAIL)
|
if (wcol == MAXCOL || rc == FAIL) {
|
||||||
curwin->w_valid &= ~VALID_VIRTCOL;
|
curwin->w_valid &= ~VALID_VIRTCOL;
|
||||||
else if (*get_cursor_pos_ptr() != TAB) {
|
} else if (*get_cursor_pos_ptr() != TAB) {
|
||||||
/* Virtcol is valid when not on a TAB */
|
// Virtcol is valid when not on a TAB
|
||||||
curwin->w_valid |= VALID_VIRTCOL;
|
curwin->w_valid |= VALID_VIRTCOL;
|
||||||
curwin->w_virtcol = wcol;
|
curwin->w_virtcol = wcol;
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int coladvance2(
|
static int coladvance2(pos_T *pos, bool addspaces, // change the text to achieve our goal?
|
||||||
pos_T *pos,
|
|
||||||
bool addspaces, // change the text to achieve our goal?
|
|
||||||
bool finetune, // change char offset for the exact column
|
bool finetune, // change char offset for the exact column
|
||||||
colnr_T wcol_arg // column to move to (can be negative)
|
colnr_T wcol_arg // column to move to (can be negative)
|
||||||
)
|
)
|
||||||
@@ -121,9 +119,10 @@ static int coladvance2(
|
|||||||
|
|
||||||
if ((addspaces || finetune) && !VIsual_active) {
|
if ((addspaces || finetune) && !VIsual_active) {
|
||||||
curwin->w_curswant = linetabsize(line) + one_more;
|
curwin->w_curswant = linetabsize(line) + one_more;
|
||||||
if (curwin->w_curswant > 0)
|
if (curwin->w_curswant > 0) {
|
||||||
--curwin->w_curswant;
|
--curwin->w_curswant;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
int width = curwin->w_width_inner - win_col_off(curwin);
|
int width = curwin->w_width_inner - win_col_off(curwin);
|
||||||
|
|
||||||
@@ -133,8 +132,9 @@ static int coladvance2(
|
|||||||
&& wcol >= (colnr_T)width
|
&& wcol >= (colnr_T)width
|
||||||
&& width > 0) {
|
&& width > 0) {
|
||||||
csize = linetabsize(line);
|
csize = linetabsize(line);
|
||||||
if (csize > 0)
|
if (csize > 0) {
|
||||||
csize--;
|
csize--;
|
||||||
|
}
|
||||||
|
|
||||||
if (wcol / width > (colnr_T)csize / width
|
if (wcol / width > (colnr_T)csize / width
|
||||||
&& ((State & INSERT) == 0 || (int)wcol > csize + 1)) {
|
&& ((State & INSERT) == 0 || (int)wcol > csize + 1)) {
|
||||||
@@ -148,7 +148,7 @@ static int coladvance2(
|
|||||||
|
|
||||||
ptr = line;
|
ptr = line;
|
||||||
while (col <= wcol && *ptr != NUL) {
|
while (col <= wcol && *ptr != NUL) {
|
||||||
/* Count a tab for what it's worth (if list mode not on) */
|
// Count a tab for what it's worth (if list mode not on)
|
||||||
csize = win_lbr_chartabsize(curwin, line, ptr, col, &head);
|
csize = win_lbr_chartabsize(curwin, line, ptr, col, &head);
|
||||||
MB_PTR_ADV(ptr);
|
MB_PTR_ADV(ptr);
|
||||||
col += csize;
|
col += csize;
|
||||||
@@ -162,7 +162,7 @@ static int coladvance2(
|
|||||||
*/
|
*/
|
||||||
if (col > wcol || (!virtual_active() && one_more == 0)) {
|
if (col > wcol || (!virtual_active() && one_more == 0)) {
|
||||||
idx -= 1;
|
idx -= 1;
|
||||||
/* Don't count the chars from 'showbreak'. */
|
// Don't count the chars from 'showbreak'.
|
||||||
csize -= head;
|
csize -= head;
|
||||||
col -= csize;
|
col -= csize;
|
||||||
}
|
}
|
||||||
@@ -175,7 +175,7 @@ static int coladvance2(
|
|||||||
* filled with spaces. */
|
* filled with spaces. */
|
||||||
|
|
||||||
if (line[idx] == NUL) {
|
if (line[idx] == NUL) {
|
||||||
/* Append spaces */
|
// Append spaces
|
||||||
int correct = wcol - col;
|
int correct = wcol - col;
|
||||||
size_t newline_size;
|
size_t newline_size;
|
||||||
STRICT_ADD(idx, correct, &newline_size, size_t);
|
STRICT_ADD(idx, correct, &newline_size, size_t);
|
||||||
@@ -188,13 +188,14 @@ static int coladvance2(
|
|||||||
idx += correct;
|
idx += correct;
|
||||||
col = wcol;
|
col = wcol;
|
||||||
} else {
|
} else {
|
||||||
/* Break a tab */
|
// Break a tab
|
||||||
int linelen = (int)STRLEN(line);
|
int linelen = (int)STRLEN(line);
|
||||||
int correct = wcol - col - csize + 1; /* negative!! */
|
int correct = wcol - col - csize + 1; // negative!!
|
||||||
char_u *newline;
|
char_u *newline;
|
||||||
|
|
||||||
if (-correct > csize)
|
if (-correct > csize) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
size_t n;
|
size_t n;
|
||||||
STRICT_ADD(linelen - 1, csize, &n, size_t);
|
STRICT_ADD(linelen - 1, csize, &n, size_t);
|
||||||
@@ -216,16 +217,17 @@ static int coladvance2(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idx < 0)
|
if (idx < 0) {
|
||||||
pos->col = 0;
|
pos->col = 0;
|
||||||
else
|
} else {
|
||||||
pos->col = idx;
|
pos->col = idx;
|
||||||
|
}
|
||||||
|
|
||||||
pos->coladd = 0;
|
pos->coladd = 0;
|
||||||
|
|
||||||
if (finetune) {
|
if (finetune) {
|
||||||
if (wcol == MAXCOL) {
|
if (wcol == MAXCOL) {
|
||||||
/* The width of the last character is used to set coladd. */
|
// The width of the last character is used to set coladd.
|
||||||
if (!one_more) {
|
if (!one_more) {
|
||||||
colnr_T scol, ecol;
|
colnr_T scol, ecol;
|
||||||
|
|
||||||
@@ -340,12 +342,14 @@ void check_cursor_lnum(void)
|
|||||||
/* If there is a closed fold at the end of the file, put the cursor in
|
/* If there is a closed fold at the end of the file, put the cursor in
|
||||||
* its first line. Otherwise in the last line. */
|
* its first line. Otherwise in the last line. */
|
||||||
if (!hasFolding(curbuf->b_ml.ml_line_count,
|
if (!hasFolding(curbuf->b_ml.ml_line_count,
|
||||||
&curwin->w_cursor.lnum, NULL))
|
&curwin->w_cursor.lnum, NULL)) {
|
||||||
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
||||||
}
|
}
|
||||||
if (curwin->w_cursor.lnum <= 0)
|
}
|
||||||
|
if (curwin->w_cursor.lnum <= 0) {
|
||||||
curwin->w_cursor.lnum = 1;
|
curwin->w_cursor.lnum = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make sure curwin->w_cursor.col is valid.
|
* Make sure curwin->w_cursor.col is valid.
|
||||||
@@ -430,9 +434,10 @@ void adjust_cursor_col(void)
|
|||||||
{
|
{
|
||||||
if (curwin->w_cursor.col > 0
|
if (curwin->w_cursor.col > 0
|
||||||
&& (!VIsual_active || *p_sel == 'o')
|
&& (!VIsual_active || *p_sel == 'o')
|
||||||
&& gchar_cursor() == NUL)
|
&& gchar_cursor() == NUL) {
|
||||||
--curwin->w_cursor.col;
|
--curwin->w_cursor.col;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* When curwin->w_leftcol has changed, adjust the cursor position.
|
* When curwin->w_leftcol has changed, adjust the cursor position.
|
||||||
@@ -473,14 +478,15 @@ bool leftcol_changed(void)
|
|||||||
coladvance(s - 1);
|
coladvance(s - 1);
|
||||||
} else if (s < curwin->w_leftcol) {
|
} else if (s < curwin->w_leftcol) {
|
||||||
retval = true;
|
retval = true;
|
||||||
if (coladvance(e + 1) == FAIL) { /* there isn't another character */
|
if (coladvance(e + 1) == FAIL) { // there isn't another character
|
||||||
curwin->w_leftcol = s; /* adjust w_leftcol instead */
|
curwin->w_leftcol = s; // adjust w_leftcol instead
|
||||||
changed_cline_bef_curs();
|
changed_cline_bef_curs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval)
|
if (retval) {
|
||||||
curwin->w_set_curswant = true;
|
curwin->w_set_curswant = true;
|
||||||
|
}
|
||||||
redraw_later(curwin, NOT_VALID);
|
redraw_later(curwin, NOT_VALID);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@@ -3,15 +3,16 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "nvim/vim.h"
|
|
||||||
|
#include "nvim/api/private/helpers.h"
|
||||||
#include "nvim/ascii.h"
|
#include "nvim/ascii.h"
|
||||||
|
#include "nvim/charset.h"
|
||||||
#include "nvim/cursor_shape.h"
|
#include "nvim/cursor_shape.h"
|
||||||
#include "nvim/ex_getln.h"
|
#include "nvim/ex_getln.h"
|
||||||
#include "nvim/charset.h"
|
|
||||||
#include "nvim/strings.h"
|
#include "nvim/strings.h"
|
||||||
#include "nvim/syntax.h"
|
#include "nvim/syntax.h"
|
||||||
#include "nvim/api/private/helpers.h"
|
|
||||||
#include "nvim/ui.h"
|
#include "nvim/ui.h"
|
||||||
|
#include "nvim/vim.h"
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "cursor_shape.c.generated.h"
|
# include "cursor_shape.c.generated.h"
|
||||||
@@ -56,10 +57,14 @@ Array mode_style_array(void)
|
|||||||
if (cur->used_for & SHAPE_CURSOR) {
|
if (cur->used_for & SHAPE_CURSOR) {
|
||||||
String shape_str;
|
String shape_str;
|
||||||
switch (cur->shape) {
|
switch (cur->shape) {
|
||||||
case SHAPE_BLOCK: shape_str = cstr_to_string("block"); break;
|
case SHAPE_BLOCK:
|
||||||
case SHAPE_VER: shape_str = cstr_to_string("vertical"); break;
|
shape_str = cstr_to_string("block"); break;
|
||||||
case SHAPE_HOR: shape_str = cstr_to_string("horizontal"); break;
|
case SHAPE_VER:
|
||||||
default: shape_str = cstr_to_string("unknown");
|
shape_str = cstr_to_string("vertical"); break;
|
||||||
|
case SHAPE_HOR:
|
||||||
|
shape_str = cstr_to_string("horizontal"); break;
|
||||||
|
default:
|
||||||
|
shape_str = cstr_to_string("unknown");
|
||||||
}
|
}
|
||||||
PUT(dic, "cursor_shape", STRING_OBJ(shape_str));
|
PUT(dic, "cursor_shape", STRING_OBJ(shape_str));
|
||||||
PUT(dic, "cell_percentage", INTEGER_OBJ(cur->percentage));
|
PUT(dic, "cell_percentage", INTEGER_OBJ(cur->percentage));
|
||||||
@@ -142,15 +147,19 @@ char_u *parse_shape_opt(int what)
|
|||||||
if (len == 1 && TOLOWER_ASC(modep[0]) == 'a') {
|
if (len == 1 && TOLOWER_ASC(modep[0]) == 'a') {
|
||||||
all_idx = SHAPE_IDX_COUNT - 1;
|
all_idx = SHAPE_IDX_COUNT - 1;
|
||||||
} else {
|
} else {
|
||||||
for (idx = 0; idx < SHAPE_IDX_COUNT; ++idx)
|
for (idx = 0; idx < SHAPE_IDX_COUNT; ++idx) {
|
||||||
if (STRNICMP(modep, shape_table[idx].name, len) == 0)
|
if (STRNICMP(modep, shape_table[idx].name, len) == 0) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (idx == SHAPE_IDX_COUNT
|
if (idx == SHAPE_IDX_COUNT
|
||||||
|| (shape_table[idx].used_for & what) == 0)
|
|| (shape_table[idx].used_for & what) == 0) {
|
||||||
return (char_u *)N_("E546: Illegal mode");
|
return (char_u *)N_("E546: Illegal mode");
|
||||||
if (len == 2 && modep[0] == 'v' && modep[1] == 'e')
|
}
|
||||||
|
if (len == 2 && modep[0] == 'v' && modep[1] == 'e') {
|
||||||
found_ve = true;
|
found_ve = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
modep += len + 1;
|
modep += len + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +167,7 @@ char_u *parse_shape_opt(int what)
|
|||||||
idx = all_idx--;
|
idx = all_idx--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse the part after the colon */
|
// Parse the part after the colon
|
||||||
for (p = colonp + 1; *p && *p != ','; ) {
|
for (p = colonp + 1; *p && *p != ','; ) {
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@@ -166,20 +175,22 @@ char_u *parse_shape_opt(int what)
|
|||||||
*/
|
*/
|
||||||
i = *p;
|
i = *p;
|
||||||
len = 0;
|
len = 0;
|
||||||
if (STRNICMP(p, "ver", 3) == 0)
|
if (STRNICMP(p, "ver", 3) == 0) {
|
||||||
len = 3;
|
len = 3;
|
||||||
else if (STRNICMP(p, "hor", 3) == 0)
|
} else if (STRNICMP(p, "hor", 3) == 0) {
|
||||||
len = 3;
|
len = 3;
|
||||||
else if (STRNICMP(p, "blinkwait", 9) == 0)
|
} else if (STRNICMP(p, "blinkwait", 9) == 0) {
|
||||||
len = 9;
|
len = 9;
|
||||||
else if (STRNICMP(p, "blinkon", 7) == 0)
|
} else if (STRNICMP(p, "blinkon", 7) == 0) {
|
||||||
len = 7;
|
len = 7;
|
||||||
else if (STRNICMP(p, "blinkoff", 8) == 0)
|
} else if (STRNICMP(p, "blinkoff", 8) == 0) {
|
||||||
len = 8;
|
len = 8;
|
||||||
|
}
|
||||||
if (len != 0) {
|
if (len != 0) {
|
||||||
p += len;
|
p += len;
|
||||||
if (!ascii_isdigit(*p))
|
if (!ascii_isdigit(*p)) {
|
||||||
return (char_u *)N_("E548: digit expected");
|
return (char_u *)N_("E548: digit expected");
|
||||||
|
}
|
||||||
int n = getdigits_int(&p, false, 0);
|
int n = getdigits_int(&p, false, 0);
|
||||||
if (len == 3) { // "ver" or "hor"
|
if (len == 3) { // "ver" or "hor"
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
@@ -194,28 +205,31 @@ char_u *parse_shape_opt(int what)
|
|||||||
shape_table[idx].percentage = n;
|
shape_table[idx].percentage = n;
|
||||||
}
|
}
|
||||||
} else if (round == 2) {
|
} else if (round == 2) {
|
||||||
if (len == 9)
|
if (len == 9) {
|
||||||
shape_table[idx].blinkwait = n;
|
shape_table[idx].blinkwait = n;
|
||||||
else if (len == 7)
|
} else if (len == 7) {
|
||||||
shape_table[idx].blinkon = n;
|
shape_table[idx].blinkon = n;
|
||||||
else
|
} else {
|
||||||
shape_table[idx].blinkoff = n;
|
shape_table[idx].blinkoff = n;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (STRNICMP(p, "block", 5) == 0) {
|
} else if (STRNICMP(p, "block", 5) == 0) {
|
||||||
if (round == 2)
|
if (round == 2) {
|
||||||
shape_table[idx].shape = SHAPE_BLOCK;
|
shape_table[idx].shape = SHAPE_BLOCK;
|
||||||
|
}
|
||||||
p += 5;
|
p += 5;
|
||||||
} else { /* must be a highlight group name then */
|
} else { // must be a highlight group name then
|
||||||
endp = vim_strchr(p, '-');
|
endp = vim_strchr(p, '-');
|
||||||
if (commap == NULL) { /* last part */
|
if (commap == NULL) { // last part
|
||||||
if (endp == NULL)
|
if (endp == NULL) {
|
||||||
endp = p + STRLEN(p); /* find end of part */
|
endp = p + STRLEN(p); // find end of part
|
||||||
|
}
|
||||||
} else if (endp > commap || endp == NULL) {
|
} else if (endp > commap || endp == NULL) {
|
||||||
endp = commap;
|
endp = commap;
|
||||||
}
|
}
|
||||||
slashp = vim_strchr(p, '/');
|
slashp = vim_strchr(p, '/');
|
||||||
if (slashp != NULL && slashp < endp) {
|
if (slashp != NULL && slashp < endp) {
|
||||||
/* "group/langmap_group" */
|
// "group/langmap_group"
|
||||||
i = syn_check_group(p, (int)(slashp - p));
|
i = syn_check_group(p, (int)(slashp - p));
|
||||||
p = slashp + 1;
|
p = slashp + 1;
|
||||||
}
|
}
|
||||||
@@ -223,17 +237,19 @@ char_u *parse_shape_opt(int what)
|
|||||||
shape_table[idx].id = syn_check_group(p,
|
shape_table[idx].id = syn_check_group(p,
|
||||||
(int)(endp - p));
|
(int)(endp - p));
|
||||||
shape_table[idx].id_lm = shape_table[idx].id;
|
shape_table[idx].id_lm = shape_table[idx].id;
|
||||||
if (slashp != NULL && slashp < endp)
|
if (slashp != NULL && slashp < endp) {
|
||||||
shape_table[idx].id = i;
|
shape_table[idx].id = i;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
p = endp;
|
p = endp;
|
||||||
}
|
}
|
||||||
} /* if (what != SHAPE_MOUSE) */
|
} // if (what != SHAPE_MOUSE)
|
||||||
|
|
||||||
if (*p == '-')
|
if (*p == '-') {
|
||||||
++p;
|
++p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
modep = p;
|
modep = p;
|
||||||
if (modep != NULL && *modep == ',') {
|
if (modep != NULL && *modep == ',') {
|
||||||
modep++;
|
modep++;
|
||||||
@@ -241,7 +257,7 @@ char_u *parse_shape_opt(int what)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the 's' flag is not given, use the 'v' cursor for 's' */
|
// If the 's' flag is not given, use the 'v' cursor for 's'
|
||||||
if (!found_ve) {
|
if (!found_ve) {
|
||||||
{
|
{
|
||||||
shape_table[SHAPE_IDX_VE].shape = shape_table[SHAPE_IDX_V].shape;
|
shape_table[SHAPE_IDX_VE].shape = shape_table[SHAPE_IDX_V].shape;
|
||||||
|
@@ -4251,8 +4251,8 @@ static void f_glob(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
options += WILD_ICASE;
|
options += WILD_ICASE;
|
||||||
}
|
}
|
||||||
if (rettv->v_type == VAR_STRING) {
|
if (rettv->v_type == VAR_STRING) {
|
||||||
rettv->vval.v_string = ExpandOne(&xpc, (char_u *)tv_get_string(
|
rettv->vval.v_string = ExpandOne(&xpc, (char_u *)tv_get_string(&argvars[0]), NULL, options,
|
||||||
&argvars[0]), NULL, options, WILD_ALL);
|
WILD_ALL);
|
||||||
} else {
|
} else {
|
||||||
ExpandOne(&xpc, (char_u *)tv_get_string(&argvars[0]), NULL, options,
|
ExpandOne(&xpc, (char_u *)tv_get_string(&argvars[0]), NULL, options,
|
||||||
WILD_ALL_KEEP);
|
WILD_ALL_KEEP);
|
||||||
@@ -6564,8 +6564,8 @@ static void msgpackparse_unpack_list(const list_T *const list, list_T *const ret
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
size_t read_bytes;
|
size_t read_bytes;
|
||||||
const int rlret = encode_read_from_list(&lrstate, msgpack_unpacker_buffer(
|
const int rlret = encode_read_from_list(&lrstate, msgpack_unpacker_buffer(unpacker), IOSIZE,
|
||||||
unpacker), IOSIZE, &read_bytes);
|
&read_bytes);
|
||||||
if (rlret == FAIL) {
|
if (rlret == FAIL) {
|
||||||
EMSG2(_(e_invarg2), "List item is not a string");
|
EMSG2(_(e_invarg2), "List item is not a string");
|
||||||
goto end;
|
goto end;
|
||||||
@@ -9275,7 +9275,8 @@ static void f_shellescape(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
const bool do_special = non_zero_arg(&argvars[1]);
|
const bool do_special = non_zero_arg(&argvars[1]);
|
||||||
|
|
||||||
rettv->vval.v_string = vim_strsave_shellescape((const char_u *)tv_get_string(
|
rettv->vval.v_string = vim_strsave_shellescape((const char_u *)tv_get_string(
|
||||||
&argvars[0]), do_special, do_special);
|
&argvars[0]), do_special,
|
||||||
|
do_special);
|
||||||
rettv->v_type = VAR_STRING;
|
rettv->v_type = VAR_STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,33 +1,31 @@
|
|||||||
// This is an open source non-commercial project. Dear PVS-Studio, please check
|
// This is an open source non-commercial project. Dear PVS-Studio, please check
|
||||||
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <lauxlib.h>
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
#include <lualib.h>
|
#include <lualib.h>
|
||||||
#include <lauxlib.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "nvim/api/private/defs.h"
|
#include "nvim/api/private/defs.h"
|
||||||
#include "nvim/api/private/helpers.h"
|
#include "nvim/api/private/helpers.h"
|
||||||
|
#include "nvim/assert.h"
|
||||||
#include "nvim/func_attr.h"
|
#include "nvim/func_attr.h"
|
||||||
#include "nvim/memory.h"
|
#include "nvim/memory.h"
|
||||||
#include "nvim/assert.h"
|
|
||||||
// FIXME: vim.h is not actually needed, but otherwise it states MAXPATHL is
|
// FIXME: vim.h is not actually needed, but otherwise it states MAXPATHL is
|
||||||
// redefined
|
// redefined
|
||||||
#include "nvim/vim.h"
|
#include "nvim/ascii.h"
|
||||||
#include "nvim/globals.h"
|
#include "nvim/eval/decode.h"
|
||||||
#include "nvim/message.h"
|
|
||||||
#include "nvim/eval/typval.h"
|
#include "nvim/eval/typval.h"
|
||||||
#include "nvim/eval/userfunc.h"
|
#include "nvim/eval/userfunc.h"
|
||||||
#include "nvim/ascii.h"
|
#include "nvim/globals.h"
|
||||||
#include "nvim/macros.h"
|
|
||||||
|
|
||||||
#include "nvim/lib/kvec.h"
|
#include "nvim/lib/kvec.h"
|
||||||
#include "nvim/eval/decode.h"
|
|
||||||
|
|
||||||
#include "nvim/lua/converter.h"
|
#include "nvim/lua/converter.h"
|
||||||
#include "nvim/lua/executor.h"
|
#include "nvim/lua/executor.h"
|
||||||
|
#include "nvim/macros.h"
|
||||||
|
#include "nvim/message.h"
|
||||||
|
#include "nvim/vim.h"
|
||||||
|
|
||||||
/// Determine, which keys lua table contains
|
/// Determine, which keys lua table contains
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -118,11 +116,10 @@ static LuaTableProps nlua_traverse_table(lua_State *const lstate)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default:
|
||||||
other_keys_num++;
|
other_keys_num++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
tsize++;
|
tsize++;
|
||||||
lua_pop(lstate, 1);
|
lua_pop(lstate, 1);
|
||||||
}
|
}
|
||||||
@@ -283,18 +280,16 @@ bool nlua_pop_typval(lua_State *lstate, typval_T *ret_tv)
|
|||||||
.vval = { .v_number = 0 },
|
.vval = { .v_number = 0 },
|
||||||
};
|
};
|
||||||
switch (lua_type(lstate, -1)) {
|
switch (lua_type(lstate, -1)) {
|
||||||
case LUA_TNIL: {
|
case LUA_TNIL:
|
||||||
cur.tv->v_type = VAR_SPECIAL;
|
cur.tv->v_type = VAR_SPECIAL;
|
||||||
cur.tv->vval.v_special = kSpecialVarNull;
|
cur.tv->vval.v_special = kSpecialVarNull;
|
||||||
break;
|
break;
|
||||||
}
|
case LUA_TBOOLEAN:
|
||||||
case LUA_TBOOLEAN: {
|
|
||||||
cur.tv->v_type = VAR_BOOL;
|
cur.tv->v_type = VAR_BOOL;
|
||||||
cur.tv->vval.v_bool = (lua_toboolean(lstate, -1)
|
cur.tv->vval.v_bool = (lua_toboolean(lstate, -1)
|
||||||
? kBoolVarTrue
|
? kBoolVarTrue
|
||||||
: kBoolVarFalse);
|
: kBoolVarFalse);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case LUA_TSTRING: {
|
case LUA_TSTRING: {
|
||||||
size_t len;
|
size_t len;
|
||||||
const char *s = lua_tolstring(lstate, -1, &len);
|
const char *s = lua_tolstring(lstate, -1, &len);
|
||||||
@@ -336,7 +331,7 @@ bool nlua_pop_typval(lua_State *lstate, typval_T *ret_tv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (table_props.type) {
|
switch (table_props.type) {
|
||||||
case kObjectTypeArray: {
|
case kObjectTypeArray:
|
||||||
cur.tv->v_type = VAR_LIST;
|
cur.tv->v_type = VAR_LIST;
|
||||||
cur.tv->vval.v_list = tv_list_alloc((ptrdiff_t)table_props.maxidx);
|
cur.tv->vval.v_list = tv_list_alloc((ptrdiff_t)table_props.maxidx);
|
||||||
cur.tv->vval.v_list->lua_table_ref = table_ref;
|
cur.tv->vval.v_list->lua_table_ref = table_ref;
|
||||||
@@ -347,8 +342,7 @@ bool nlua_pop_typval(lua_State *lstate, typval_T *ret_tv)
|
|||||||
kvi_push(stack, cur);
|
kvi_push(stack, cur);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
case kObjectTypeDictionary:
|
||||||
case kObjectTypeDictionary: {
|
|
||||||
if (table_props.string_keys_num == 0) {
|
if (table_props.string_keys_num == 0) {
|
||||||
cur.tv->v_type = VAR_DICT;
|
cur.tv->v_type = VAR_DICT;
|
||||||
cur.tv->vval.v_dict = tv_dict_alloc();
|
cur.tv->vval.v_dict = tv_dict_alloc();
|
||||||
@@ -357,8 +351,7 @@ bool nlua_pop_typval(lua_State *lstate, typval_T *ret_tv)
|
|||||||
} else {
|
} else {
|
||||||
cur.special = table_props.has_string_with_nul;
|
cur.special = table_props.has_string_with_nul;
|
||||||
if (table_props.has_string_with_nul) {
|
if (table_props.has_string_with_nul) {
|
||||||
decode_create_map_special_dict(
|
decode_create_map_special_dict(cur.tv, (ptrdiff_t)table_props.string_keys_num);
|
||||||
cur.tv, (ptrdiff_t)table_props.string_keys_num);
|
|
||||||
assert(cur.tv->v_type == VAR_DICT);
|
assert(cur.tv->v_type == VAR_DICT);
|
||||||
dictitem_T *const val_di = tv_dict_find(cur.tv->vval.v_dict,
|
dictitem_T *const val_di = tv_dict_find(cur.tv->vval.v_dict,
|
||||||
S_LEN("_VAL"));
|
S_LEN("_VAL"));
|
||||||
@@ -378,23 +371,19 @@ bool nlua_pop_typval(lua_State *lstate, typval_T *ret_tv)
|
|||||||
lua_pushnil(lstate);
|
lua_pushnil(lstate);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
case kObjectTypeFloat:
|
||||||
case kObjectTypeFloat: {
|
|
||||||
cur.tv->v_type = VAR_FLOAT;
|
cur.tv->v_type = VAR_FLOAT;
|
||||||
cur.tv->vval.v_float = (float_T)table_props.val;
|
cur.tv->vval.v_float = (float_T)table_props.val;
|
||||||
break;
|
break;
|
||||||
}
|
case kObjectTypeNil:
|
||||||
case kObjectTypeNil: {
|
|
||||||
EMSG(_("E5100: Cannot convert given lua table: table "
|
EMSG(_("E5100: Cannot convert given lua table: table "
|
||||||
"should either have a sequence of positive integer keys "
|
"should either have a sequence of positive integer keys "
|
||||||
"or contain only string keys"));
|
"or contain only string keys"));
|
||||||
ret = false;
|
ret = false;
|
||||||
break;
|
break;
|
||||||
}
|
default:
|
||||||
default: {
|
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
nlua_pop_typval_table_processing_end:
|
nlua_pop_typval_table_processing_end:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -402,8 +391,7 @@ nlua_pop_typval_table_processing_end:
|
|||||||
LuaCFunctionState *state = xmalloc(sizeof(LuaCFunctionState));
|
LuaCFunctionState *state = xmalloc(sizeof(LuaCFunctionState));
|
||||||
state->lua_callable.func_ref = nlua_ref(lstate, -1);
|
state->lua_callable.func_ref = nlua_ref(lstate, -1);
|
||||||
|
|
||||||
char_u *name = register_cfunc(
|
char_u *name = register_cfunc(&nlua_CFunction_func_call,
|
||||||
&nlua_CFunction_func_call,
|
|
||||||
&nlua_CFunction_func_free,
|
&nlua_CFunction_func_free,
|
||||||
state);
|
state);
|
||||||
|
|
||||||
@@ -425,12 +413,11 @@ nlua_pop_typval_table_processing_end:
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default:
|
||||||
EMSG(_("E5101: Cannot convert given lua type"));
|
EMSG(_("E5101: Cannot convert given lua type"));
|
||||||
ret = false;
|
ret = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (!cur.container) {
|
if (!cur.container) {
|
||||||
lua_pop(lstate, 1);
|
lua_pop(lstate, 1);
|
||||||
}
|
}
|
||||||
@@ -674,9 +661,7 @@ static inline void nlua_push_type(lua_State *lstate, ObjectType type)
|
|||||||
/// @param[in] narr Number of “array” entries to be populated later.
|
/// @param[in] narr Number of “array” entries to be populated later.
|
||||||
/// @param[in] nrec Number of “dictionary” entries to be populated later.
|
/// @param[in] nrec Number of “dictionary” entries to be populated later.
|
||||||
/// @param[in] type Type of the table.
|
/// @param[in] type Type of the table.
|
||||||
static inline void nlua_create_typed_table(lua_State *lstate,
|
static inline void nlua_create_typed_table(lua_State *lstate, const size_t narr, const size_t nrec,
|
||||||
const size_t narr,
|
|
||||||
const size_t nrec,
|
|
||||||
const ObjectType type)
|
const ObjectType type)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
@@ -733,8 +718,7 @@ void nlua_push_Boolean(lua_State *lstate, const Boolean b, bool special)
|
|||||||
/// Convert given Dictionary to lua table
|
/// Convert given Dictionary to lua table
|
||||||
///
|
///
|
||||||
/// Leaves converted table on top of the stack.
|
/// Leaves converted table on top of the stack.
|
||||||
void nlua_push_Dictionary(lua_State *lstate, const Dictionary dict,
|
void nlua_push_Dictionary(lua_State *lstate, const Dictionary dict, bool special)
|
||||||
bool special)
|
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
if (dict.size == 0 && special) {
|
if (dict.size == 0 && special) {
|
||||||
@@ -786,14 +770,13 @@ void nlua_push_Object(lua_State *lstate, const Object obj, bool special)
|
|||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
switch (obj.type) {
|
switch (obj.type) {
|
||||||
case kObjectTypeNil: {
|
case kObjectTypeNil:
|
||||||
if (special) {
|
if (special) {
|
||||||
lua_pushnil(lstate);
|
lua_pushnil(lstate);
|
||||||
} else {
|
} else {
|
||||||
nlua_pushref(lstate, nlua_nil_ref);
|
nlua_pushref(lstate, nlua_nil_ref);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case kObjectTypeLuaRef: {
|
case kObjectTypeLuaRef: {
|
||||||
nlua_pushref(lstate, obj.data.luaref);
|
nlua_pushref(lstate, obj.data.luaref);
|
||||||
break;
|
break;
|
||||||
@@ -883,8 +866,7 @@ Boolean nlua_pop_Boolean(lua_State *lstate, Error *err)
|
|||||||
/// @param[in] type Type to check.
|
/// @param[in] type Type to check.
|
||||||
///
|
///
|
||||||
/// @return @see nlua_traverse_table().
|
/// @return @see nlua_traverse_table().
|
||||||
static inline LuaTableProps nlua_check_type(lua_State *const lstate,
|
static inline LuaTableProps nlua_check_type(lua_State *const lstate, Error *const err,
|
||||||
Error *const err,
|
|
||||||
const ObjectType type)
|
const ObjectType type)
|
||||||
FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_WARN_UNUSED_RESULT
|
FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_WARN_UNUSED_RESULT
|
||||||
{
|
{
|
||||||
@@ -937,8 +919,7 @@ Float nlua_pop_Float(lua_State *lstate, Error *err)
|
|||||||
/// @param lstate Lua state.
|
/// @param lstate Lua state.
|
||||||
/// @param[in] table_props nlua_traverse_table() output.
|
/// @param[in] table_props nlua_traverse_table() output.
|
||||||
/// @param[out] err Location where error will be saved.
|
/// @param[out] err Location where error will be saved.
|
||||||
static Array nlua_pop_Array_unchecked(lua_State *const lstate,
|
static Array nlua_pop_Array_unchecked(lua_State *const lstate, const LuaTableProps table_props,
|
||||||
const LuaTableProps table_props,
|
|
||||||
Error *const err)
|
Error *const err)
|
||||||
{
|
{
|
||||||
Array ret = { .size = table_props.maxidx, .items = NULL };
|
Array ret = { .size = table_props.maxidx, .items = NULL };
|
||||||
@@ -990,10 +971,8 @@ Array nlua_pop_Array(lua_State *lstate, Error *err)
|
|||||||
/// @param lstate Lua interpreter state.
|
/// @param lstate Lua interpreter state.
|
||||||
/// @param[in] table_props nlua_traverse_table() output.
|
/// @param[in] table_props nlua_traverse_table() output.
|
||||||
/// @param[out] err Location where error will be saved.
|
/// @param[out] err Location where error will be saved.
|
||||||
static Dictionary nlua_pop_Dictionary_unchecked(lua_State *lstate,
|
static Dictionary nlua_pop_Dictionary_unchecked(lua_State *lstate, const LuaTableProps table_props,
|
||||||
const LuaTableProps table_props,
|
bool ref, Error *err)
|
||||||
bool ref,
|
|
||||||
Error *err)
|
|
||||||
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
|
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
|
||||||
{
|
{
|
||||||
Dictionary ret = { .size = table_props.string_keys_num, .items = NULL };
|
Dictionary ret = { .size = table_props.string_keys_num, .items = NULL };
|
||||||
@@ -1138,13 +1117,11 @@ Object nlua_pop_Object(lua_State *const lstate, bool ref, Error *const err)
|
|||||||
assert(!cur.container);
|
assert(!cur.container);
|
||||||
*cur.obj = NIL;
|
*cur.obj = NIL;
|
||||||
switch (lua_type(lstate, -1)) {
|
switch (lua_type(lstate, -1)) {
|
||||||
case LUA_TNIL: {
|
case LUA_TNIL:
|
||||||
break;
|
break;
|
||||||
}
|
case LUA_TBOOLEAN:
|
||||||
case LUA_TBOOLEAN: {
|
|
||||||
*cur.obj = BOOLEAN_OBJ(lua_toboolean(lstate, -1));
|
*cur.obj = BOOLEAN_OBJ(lua_toboolean(lstate, -1));
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case LUA_TSTRING: {
|
case LUA_TSTRING: {
|
||||||
size_t len;
|
size_t len;
|
||||||
const char *s = lua_tolstring(lstate, -1, &len);
|
const char *s = lua_tolstring(lstate, -1, &len);
|
||||||
@@ -1168,7 +1145,7 @@ Object nlua_pop_Object(lua_State *const lstate, bool ref, Error *const err)
|
|||||||
const LuaTableProps table_props = nlua_traverse_table(lstate);
|
const LuaTableProps table_props = nlua_traverse_table(lstate);
|
||||||
|
|
||||||
switch (table_props.type) {
|
switch (table_props.type) {
|
||||||
case kObjectTypeArray: {
|
case kObjectTypeArray:
|
||||||
*cur.obj = ARRAY_OBJ(((Array) {
|
*cur.obj = ARRAY_OBJ(((Array) {
|
||||||
.items = NULL,
|
.items = NULL,
|
||||||
.size = 0,
|
.size = 0,
|
||||||
@@ -1183,8 +1160,7 @@ Object nlua_pop_Object(lua_State *const lstate, bool ref, Error *const err)
|
|||||||
kvi_push(stack, cur);
|
kvi_push(stack, cur);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
case kObjectTypeDictionary:
|
||||||
case kObjectTypeDictionary: {
|
|
||||||
*cur.obj = DICTIONARY_OBJ(((Dictionary) {
|
*cur.obj = DICTIONARY_OBJ(((Dictionary) {
|
||||||
.items = NULL,
|
.items = NULL,
|
||||||
.size = 0,
|
.size = 0,
|
||||||
@@ -1200,31 +1176,26 @@ Object nlua_pop_Object(lua_State *const lstate, bool ref, Error *const err)
|
|||||||
lua_pushnil(lstate);
|
lua_pushnil(lstate);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
case kObjectTypeFloat:
|
||||||
case kObjectTypeFloat: {
|
|
||||||
*cur.obj = FLOAT_OBJ((Float)table_props.val);
|
*cur.obj = FLOAT_OBJ((Float)table_props.val);
|
||||||
break;
|
break;
|
||||||
}
|
case kObjectTypeNil:
|
||||||
case kObjectTypeNil: {
|
|
||||||
api_set_error(err, kErrorTypeValidation,
|
api_set_error(err, kErrorTypeValidation,
|
||||||
"Cannot convert given lua table");
|
"Cannot convert given lua table");
|
||||||
break;
|
break;
|
||||||
}
|
default:
|
||||||
default: {
|
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case LUA_TFUNCTION: {
|
case LUA_TFUNCTION:
|
||||||
if (ref) {
|
if (ref) {
|
||||||
*cur.obj = LUAREF_OBJ(nlua_ref(lstate, -1));
|
*cur.obj = LUAREF_OBJ(nlua_ref(lstate, -1));
|
||||||
} else {
|
} else {
|
||||||
goto type_error;
|
goto type_error;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case LUA_TUSERDATA: {
|
case LUA_TUSERDATA: {
|
||||||
nlua_pushref(lstate, nlua_nil_ref);
|
nlua_pushref(lstate, nlua_nil_ref);
|
||||||
@@ -1239,13 +1210,12 @@ Object nlua_pop_Object(lua_State *const lstate, bool ref, Error *const err)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default: {
|
default:
|
||||||
type_error:
|
type_error:
|
||||||
api_set_error(err, kErrorTypeValidation,
|
api_set_error(err, kErrorTypeValidation,
|
||||||
"Cannot convert given lua type");
|
"Cannot convert given lua type");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (!cur.container) {
|
if (!cur.container) {
|
||||||
lua_pop(lstate, 1);
|
lua_pop(lstate, 1);
|
||||||
}
|
}
|
||||||
|
@@ -1,48 +1,45 @@
|
|||||||
// This is an open source non-commercial project. Dear PVS-Studio, please check
|
// This is an open source non-commercial project. Dear PVS-Studio, please check
|
||||||
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||||
|
|
||||||
|
#include <lauxlib.h>
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
#include <lualib.h>
|
#include <lualib.h>
|
||||||
#include <lauxlib.h>
|
|
||||||
|
|
||||||
#include "nvim/assert.h"
|
#include "luv/luv.h"
|
||||||
#include "nvim/version.h"
|
#include "mpack/lmpack.h"
|
||||||
#include "nvim/misc1.h"
|
|
||||||
#include "nvim/getchar.h"
|
|
||||||
#include "nvim/garray.h"
|
|
||||||
#include "nvim/func_attr.h"
|
|
||||||
#include "nvim/api/private/defs.h"
|
#include "nvim/api/private/defs.h"
|
||||||
#include "nvim/api/private/helpers.h"
|
#include "nvim/api/private/helpers.h"
|
||||||
#include "nvim/api/vim.h"
|
#include "nvim/api/vim.h"
|
||||||
#include "nvim/msgpack_rpc/channel.h"
|
|
||||||
#include "nvim/vim.h"
|
|
||||||
#include "nvim/extmark.h"
|
|
||||||
#include "nvim/ex_getln.h"
|
|
||||||
#include "nvim/ex_cmds2.h"
|
|
||||||
#include "nvim/map.h"
|
|
||||||
#include "nvim/message.h"
|
|
||||||
#include "nvim/memline.h"
|
|
||||||
#include "nvim/buffer_defs.h"
|
|
||||||
#include "nvim/regexp.h"
|
|
||||||
#include "nvim/macros.h"
|
|
||||||
#include "nvim/screen.h"
|
|
||||||
#include "nvim/cursor.h"
|
|
||||||
#include "nvim/undo.h"
|
|
||||||
#include "nvim/ascii.h"
|
#include "nvim/ascii.h"
|
||||||
|
#include "nvim/assert.h"
|
||||||
|
#include "nvim/buffer_defs.h"
|
||||||
#include "nvim/change.h"
|
#include "nvim/change.h"
|
||||||
|
#include "nvim/cursor.h"
|
||||||
#include "nvim/eval/userfunc.h"
|
#include "nvim/eval/userfunc.h"
|
||||||
#include "nvim/event/time.h"
|
|
||||||
#include "nvim/event/loop.h"
|
#include "nvim/event/loop.h"
|
||||||
#include "mpack/lmpack.h"
|
#include "nvim/event/time.h"
|
||||||
|
#include "nvim/ex_cmds2.h"
|
||||||
#include "nvim/os/os.h"
|
#include "nvim/ex_getln.h"
|
||||||
|
#include "nvim/extmark.h"
|
||||||
|
#include "nvim/func_attr.h"
|
||||||
|
#include "nvim/garray.h"
|
||||||
|
#include "nvim/getchar.h"
|
||||||
#include "nvim/lua/converter.h"
|
#include "nvim/lua/converter.h"
|
||||||
#include "nvim/lua/executor.h"
|
#include "nvim/lua/executor.h"
|
||||||
#include "nvim/lua/treesitter.h"
|
#include "nvim/lua/treesitter.h"
|
||||||
#include "nvim/lua/xdiff.h"
|
#include "nvim/lua/xdiff.h"
|
||||||
|
#include "nvim/macros.h"
|
||||||
#include "luv/luv.h"
|
#include "nvim/map.h"
|
||||||
|
#include "nvim/memline.h"
|
||||||
|
#include "nvim/message.h"
|
||||||
|
#include "nvim/misc1.h"
|
||||||
|
#include "nvim/msgpack_rpc/channel.h"
|
||||||
|
#include "nvim/os/os.h"
|
||||||
|
#include "nvim/regexp.h"
|
||||||
|
#include "nvim/screen.h"
|
||||||
|
#include "nvim/undo.h"
|
||||||
|
#include "nvim/version.h"
|
||||||
|
#include "nvim/vim.h"
|
||||||
|
|
||||||
static int in_fast_callback = 0;
|
static int in_fast_callback = 0;
|
||||||
|
|
||||||
@@ -55,8 +52,8 @@ typedef struct {
|
|||||||
} LuaError;
|
} LuaError;
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "lua/vim_module.generated.h"
|
|
||||||
# include "lua/executor.c.generated.h"
|
# include "lua/executor.c.generated.h"
|
||||||
|
# include "lua/vim_module.generated.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define PUSH_ALL_TYPVALS(lstate, args, argcount, special) \
|
#define PUSH_ALL_TYPVALS(lstate, args, argcount, special) \
|
||||||
@@ -216,8 +213,7 @@ static void nlua_luv_error_event(void **argv)
|
|||||||
xfree(error);
|
xfree(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nlua_luv_cfpcall(lua_State *lstate, int nargs, int nresult,
|
static int nlua_luv_cfpcall(lua_State *lstate, int nargs, int nresult, int flags)
|
||||||
int flags)
|
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
@@ -300,8 +296,7 @@ static void dummy_timer_close_cb(TimeWatcher *tw, void *data)
|
|||||||
xfree(tw);
|
xfree(tw);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool nlua_wait_condition(lua_State *lstate, int *status,
|
static bool nlua_wait_condition(lua_State *lstate, int *status, bool *callback_result)
|
||||||
bool *callback_result)
|
|
||||||
{
|
{
|
||||||
lua_pushvalue(lstate, 2);
|
lua_pushvalue(lstate, 2);
|
||||||
*status = lua_pcall(lstate, 0, 1, 0);
|
*status = lua_pcall(lstate, 0, 1, 0);
|
||||||
@@ -336,8 +331,7 @@ static int nlua_wait(lua_State *lstate)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!is_function) {
|
if (!is_function) {
|
||||||
lua_pushliteral(
|
lua_pushliteral(lstate,
|
||||||
lstate,
|
|
||||||
"vim.wait: if passed, condition must be a function");
|
"vim.wait: if passed, condition must be a function");
|
||||||
return lua_error(lstate);
|
return lua_error(lstate);
|
||||||
}
|
}
|
||||||
@@ -365,8 +359,7 @@ static int nlua_wait(lua_State *lstate)
|
|||||||
time_watcher_init(&main_loop, tw, NULL);
|
time_watcher_init(&main_loop, tw, NULL);
|
||||||
tw->events = loop_events;
|
tw->events = loop_events;
|
||||||
tw->blockable = true;
|
tw->blockable = true;
|
||||||
time_watcher_start(
|
time_watcher_start(tw,
|
||||||
tw,
|
|
||||||
dummy_timer_due_cb,
|
dummy_timer_due_cb,
|
||||||
(uint64_t)interval,
|
(uint64_t)interval,
|
||||||
(uint64_t)interval);
|
(uint64_t)interval);
|
||||||
@@ -374,12 +367,10 @@ static int nlua_wait(lua_State *lstate)
|
|||||||
int pcall_status = 0;
|
int pcall_status = 0;
|
||||||
bool callback_result = false;
|
bool callback_result = false;
|
||||||
|
|
||||||
LOOP_PROCESS_EVENTS_UNTIL(
|
LOOP_PROCESS_EVENTS_UNTIL(&main_loop,
|
||||||
&main_loop,
|
|
||||||
loop_events,
|
loop_events,
|
||||||
(int)timeout,
|
(int)timeout,
|
||||||
is_function ? nlua_wait_condition(
|
is_function ? nlua_wait_condition(lstate,
|
||||||
lstate,
|
|
||||||
&pcall_status,
|
&pcall_status,
|
||||||
&callback_result) : false || got_int);
|
&callback_result) : false || got_int);
|
||||||
|
|
||||||
@@ -663,23 +654,20 @@ static void nlua_print_event(void **argv)
|
|||||||
const size_t start = i;
|
const size_t start = i;
|
||||||
while (i < len) {
|
while (i < len) {
|
||||||
switch (str[i]) {
|
switch (str[i]) {
|
||||||
case NUL: {
|
case NUL:
|
||||||
str[i] = NL;
|
str[i] = NL;
|
||||||
i++;
|
i++;
|
||||||
continue;
|
continue;
|
||||||
}
|
case NL:
|
||||||
case NL: {
|
|
||||||
// TODO(bfredl): use proper multiline msg? Probably should implement
|
// TODO(bfredl): use proper multiline msg? Probably should implement
|
||||||
// print() in lua in terms of nvim_message(), when it is available.
|
// print() in lua in terms of nvim_message(), when it is available.
|
||||||
str[i] = NUL;
|
str[i] = NUL;
|
||||||
i++;
|
i++;
|
||||||
break;
|
break;
|
||||||
}
|
default:
|
||||||
default: {
|
|
||||||
i++;
|
i++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
msg((char_u *)str + start);
|
msg((char_u *)str + start);
|
||||||
@@ -719,8 +707,7 @@ static int nlua_print(lua_State *const lstate)
|
|||||||
size_t len;
|
size_t len;
|
||||||
const char *const s = lua_tolstring(lstate, -1, &len);
|
const char *const s = lua_tolstring(lstate, -1, &len);
|
||||||
if (s == NULL) {
|
if (s == NULL) {
|
||||||
PRINT_ERROR(
|
PRINT_ERROR("<Unknown error: lua_tolstring returned NULL for tostring result>");
|
||||||
"<Unknown error: lua_tolstring returned NULL for tostring result>");
|
|
||||||
}
|
}
|
||||||
ga_concat_len(&msg_ga, s, len);
|
ga_concat_len(&msg_ga, s, len);
|
||||||
if (curargidx < nargs) {
|
if (curargidx < nargs) {
|
||||||
@@ -1108,8 +1095,7 @@ LuaRef api_new_luaref(LuaRef original_ref)
|
|||||||
/// @param[out] ret_tv Location where result will be saved.
|
/// @param[out] ret_tv Location where result will be saved.
|
||||||
///
|
///
|
||||||
/// @return Result of the execution.
|
/// @return Result of the execution.
|
||||||
void nlua_typval_eval(const String str, typval_T *const arg,
|
void nlua_typval_eval(const String str, typval_T *const arg, typval_T *const ret_tv)
|
||||||
typval_T *const ret_tv)
|
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
#define EVALHEADER "local _A=select(1,...) return ("
|
#define EVALHEADER "local _A=select(1,...) return ("
|
||||||
@@ -1131,8 +1117,8 @@ void nlua_typval_eval(const String str, typval_T *const arg,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void nlua_typval_call(const char *str, size_t len, typval_T *const args,
|
void nlua_typval_call(const char *str, size_t len, typval_T *const args, int argcount,
|
||||||
int argcount, typval_T *ret_tv)
|
typval_T *ret_tv)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
#define CALLHEADER "return "
|
#define CALLHEADER "return "
|
||||||
@@ -1158,9 +1144,8 @@ void nlua_typval_call(const char *str, size_t len, typval_T *const args,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void nlua_typval_exec(const char *lcmd, size_t lcmd_len,
|
static void nlua_typval_exec(const char *lcmd, size_t lcmd_len, const char *name,
|
||||||
const char *name, typval_T *const args,
|
typval_T *const args, int argcount, bool special, typval_T *ret_tv)
|
||||||
int argcount, bool special, typval_T *ret_tv)
|
|
||||||
{
|
{
|
||||||
if (check_secure()) {
|
if (check_secure()) {
|
||||||
if (ret_tv) {
|
if (ret_tv) {
|
||||||
@@ -1188,8 +1173,7 @@ static void nlua_typval_exec(const char *lcmd, size_t lcmd_len,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int nlua_source_using_linegetter(LineGetter fgetline,
|
int nlua_source_using_linegetter(LineGetter fgetline, void *cookie, char *name)
|
||||||
void *cookie, char *name)
|
|
||||||
{
|
{
|
||||||
const linenr_T save_sourcing_lnum = sourcing_lnum;
|
const linenr_T save_sourcing_lnum = sourcing_lnum;
|
||||||
const sctx_T save_current_sctx = current_sctx;
|
const sctx_T save_current_sctx = current_sctx;
|
||||||
@@ -1225,13 +1209,8 @@ int nlua_source_using_linegetter(LineGetter fgetline,
|
|||||||
/// @param[in] argcount Count of typval arguments
|
/// @param[in] argcount Count of typval arguments
|
||||||
/// @param[in] argvars Typval Arguments
|
/// @param[in] argvars Typval Arguments
|
||||||
/// @param[out] rettv The return value from the called function.
|
/// @param[out] rettv The return value from the called function.
|
||||||
int typval_exec_lua_callable(
|
int typval_exec_lua_callable(lua_State *lstate, LuaCallable lua_cb, int argcount, typval_T *argvars,
|
||||||
lua_State *lstate,
|
typval_T *rettv)
|
||||||
LuaCallable lua_cb,
|
|
||||||
int argcount,
|
|
||||||
typval_T *argvars,
|
|
||||||
typval_T *rettv
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
LuaRef cb = lua_cb.func_ref;
|
LuaRef cb = lua_cb.func_ref;
|
||||||
|
|
||||||
@@ -1294,8 +1273,7 @@ Object nlua_exec(const String str, const Array args, Error *err)
|
|||||||
/// if false, discard return value
|
/// if false, discard return value
|
||||||
/// @param err Error details, if any (if NULL, errors are echoed)
|
/// @param err Error details, if any (if NULL, errors are echoed)
|
||||||
/// @return Return value of function, if retval was set. Otherwise NIL.
|
/// @return Return value of function, if retval was set. Otherwise NIL.
|
||||||
Object nlua_call_ref(LuaRef ref, const char *name, Array args,
|
Object nlua_call_ref(LuaRef ref, const char *name, Array args, bool retval, Error *err)
|
||||||
bool retval, Error *err)
|
|
||||||
{
|
{
|
||||||
lua_State *const lstate = global_lstate;
|
lua_State *const lstate = global_lstate;
|
||||||
nlua_pushref(lstate, ref);
|
nlua_pushref(lstate, ref);
|
||||||
@@ -1502,10 +1480,7 @@ static void nlua_add_treesitter(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
|
|||||||
lua_setfield(lstate, -2, "_ts_get_language_version");
|
lua_setfield(lstate, -2, "_ts_get_language_version");
|
||||||
}
|
}
|
||||||
|
|
||||||
int nlua_expand_pat(expand_T *xp,
|
int nlua_expand_pat(expand_T *xp, char_u *pat, int *num_results, char_u ***results)
|
||||||
char_u *pat,
|
|
||||||
int *num_results,
|
|
||||||
char_u ***results)
|
|
||||||
{
|
{
|
||||||
lua_State *const lstate = global_lstate;
|
lua_State *const lstate = global_lstate;
|
||||||
int ret = OK;
|
int ret = OK;
|
||||||
@@ -1521,8 +1496,7 @@ int nlua_expand_pat(expand_T *xp,
|
|||||||
lua_pushlstring(lstate, (const char *)pat, STRLEN(pat));
|
lua_pushlstring(lstate, (const char *)pat, STRLEN(pat));
|
||||||
|
|
||||||
if (lua_pcall(lstate, 1, 2, 0) != 0) {
|
if (lua_pcall(lstate, 1, 2, 0) != 0) {
|
||||||
nlua_error(
|
nlua_error(lstate,
|
||||||
lstate,
|
|
||||||
_("Error executing vim._expand_pat: %.*s"));
|
_("Error executing vim._expand_pat: %.*s"));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@@ -1554,8 +1528,7 @@ int nlua_expand_pat(expand_T *xp,
|
|||||||
goto cleanup_array;
|
goto cleanup_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
GA_APPEND(
|
GA_APPEND(char_u *,
|
||||||
char_u *,
|
|
||||||
&result_array,
|
&result_array,
|
||||||
vim_strsave((char_u *)v.data.string.data));
|
vim_strsave((char_u *)v.data.string.data));
|
||||||
}
|
}
|
||||||
@@ -1711,11 +1684,7 @@ static int regex_match_line(lua_State *lstate)
|
|||||||
|
|
||||||
// Required functions for lua c functions as VimL callbacks
|
// Required functions for lua c functions as VimL callbacks
|
||||||
|
|
||||||
int nlua_CFunction_func_call(
|
int nlua_CFunction_func_call(int argcount, typval_T *argvars, typval_T *rettv, void *state)
|
||||||
int argcount,
|
|
||||||
typval_T *argvars,
|
|
||||||
typval_T *rettv,
|
|
||||||
void *state)
|
|
||||||
{
|
{
|
||||||
lua_State *const lstate = global_lstate;
|
lua_State *const lstate = global_lstate;
|
||||||
LuaCFunctionState *funcstate = (LuaCFunctionState *)state;
|
LuaCFunctionState *funcstate = (LuaCFunctionState *)state;
|
||||||
@@ -1813,8 +1782,7 @@ void nlua_execute_on_key(int c)
|
|||||||
lua_pushlstring(lstate, (const char *)buf, buf_len);
|
lua_pushlstring(lstate, (const char *)buf, buf_len);
|
||||||
|
|
||||||
if (lua_pcall(lstate, 1, 0, 0)) {
|
if (lua_pcall(lstate, 1, 0, 0)) {
|
||||||
nlua_error(
|
nlua_error(lstate,
|
||||||
lstate,
|
|
||||||
_("Error executing vim.on_key Lua callback: %.*s"));
|
_("Error executing vim.on_key Lua callback: %.*s"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,22 +5,20 @@
|
|||||||
// NB: this file mostly contains a generic lua interface for tree-sitter
|
// NB: this file mostly contains a generic lua interface for tree-sitter
|
||||||
// trees and nodes, and could be broken out as a reusable lua package
|
// trees and nodes, and could be broken out as a reusable lua package
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <lauxlib.h>
|
||||||
|
#include <lua.h>
|
||||||
|
#include <lualib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <inttypes.h>
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include <lua.h>
|
|
||||||
#include <lualib.h>
|
|
||||||
#include <lauxlib.h>
|
|
||||||
|
|
||||||
#include "tree_sitter/api.h"
|
|
||||||
|
|
||||||
#include "nvim/lua/treesitter.h"
|
|
||||||
#include "nvim/api/private/helpers.h"
|
#include "nvim/api/private/helpers.h"
|
||||||
#include "nvim/memline.h"
|
|
||||||
#include "nvim/buffer.h"
|
#include "nvim/buffer.h"
|
||||||
|
#include "nvim/lua/treesitter.h"
|
||||||
|
#include "nvim/memline.h"
|
||||||
|
#include "tree_sitter/api.h"
|
||||||
|
|
||||||
#define TS_META_PARSER "treesitter_parser"
|
#define TS_META_PARSER "treesitter_parser"
|
||||||
#define TS_META_TREE "treesitter_tree"
|
#define TS_META_TREE "treesitter_tree"
|
||||||
@@ -179,8 +177,7 @@ int tslua_add_language(lua_State *L)
|
|||||||
uint32_t lang_version = ts_language_version(lang);
|
uint32_t lang_version = ts_language_version(lang);
|
||||||
if (lang_version < TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION
|
if (lang_version < TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION
|
||||||
|| lang_version > TREE_SITTER_LANGUAGE_VERSION) {
|
|| lang_version > TREE_SITTER_LANGUAGE_VERSION) {
|
||||||
return luaL_error(
|
return luaL_error(L,
|
||||||
L,
|
|
||||||
"ABI version mismatch for %s: supported between %d and %d, found %d",
|
"ABI version mismatch for %s: supported between %d and %d, found %d",
|
||||||
path,
|
path,
|
||||||
TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION,
|
TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION,
|
||||||
@@ -285,8 +282,8 @@ static int parser_tostring(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *input_cb(void *payload, uint32_t byte_index,
|
static const char *input_cb(void *payload, uint32_t byte_index, TSPoint position,
|
||||||
TSPoint position, uint32_t *bytes_read)
|
uint32_t *bytes_read)
|
||||||
{
|
{
|
||||||
buf_T *bp = payload;
|
buf_T *bp = payload;
|
||||||
#define BUFSIZE 256
|
#define BUFSIZE 256
|
||||||
@@ -318,9 +315,7 @@ static const char *input_cb(void *payload, uint32_t byte_index,
|
|||||||
#undef BUFSIZE
|
#undef BUFSIZE
|
||||||
}
|
}
|
||||||
|
|
||||||
static void push_ranges(lua_State *L,
|
static void push_ranges(lua_State *L, const TSRange *ranges, const unsigned int length)
|
||||||
const TSRange *ranges,
|
|
||||||
const unsigned int length)
|
|
||||||
{
|
{
|
||||||
lua_createtable(L, length, 0);
|
lua_createtable(L, length, 0);
|
||||||
for (size_t i = 0; i < length; i++) {
|
for (size_t i = 0; i < length; i++) {
|
||||||
@@ -393,8 +388,7 @@ static int parser_parse(lua_State *L)
|
|||||||
// the lua GC.
|
// the lua GC.
|
||||||
// Old tree is still owned by the lua GC.
|
// Old tree is still owned by the lua GC.
|
||||||
uint32_t n_ranges = 0;
|
uint32_t n_ranges = 0;
|
||||||
TSRange *changed = old_tree ? ts_tree_get_changed_ranges(
|
TSRange *changed = old_tree ? ts_tree_get_changed_ranges(old_tree, new_tree, &n_ranges) : NULL;
|
||||||
old_tree, new_tree, &n_ranges) : NULL;
|
|
||||||
|
|
||||||
push_tree(L, new_tree, false); // [tree]
|
push_tree(L, new_tree, false); // [tree]
|
||||||
|
|
||||||
@@ -504,16 +498,14 @@ static void range_from_lua(lua_State *L, TSRange *range)
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
error:
|
error:
|
||||||
luaL_error(
|
luaL_error(L,
|
||||||
L,
|
|
||||||
"Ranges can only be made from 6 element long tables or nodes.");
|
"Ranges can only be made from 6 element long tables or nodes.");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parser_set_ranges(lua_State *L)
|
static int parser_set_ranges(lua_State *L)
|
||||||
{
|
{
|
||||||
if (lua_gettop(L) < 2) {
|
if (lua_gettop(L) < 2) {
|
||||||
return luaL_error(
|
return luaL_error(L,
|
||||||
L,
|
|
||||||
"not enough args to parser:set_included_ranges()");
|
"not enough args to parser:set_included_ranges()");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -523,8 +515,7 @@ static int parser_set_ranges(lua_State *L)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!lua_istable(L, 2)) {
|
if (!lua_istable(L, 2)) {
|
||||||
return luaL_error(
|
return luaL_error(L,
|
||||||
L,
|
|
||||||
"argument for parser:set_included_ranges() should be a table.");
|
"argument for parser:set_included_ranges() should be a table.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -917,8 +908,7 @@ static int node_named_descendant_for_range(lua_State *L)
|
|||||||
|
|
||||||
static int node_next_child(lua_State *L)
|
static int node_next_child(lua_State *L)
|
||||||
{
|
{
|
||||||
TSTreeCursor *ud = luaL_checkudata(
|
TSTreeCursor *ud = luaL_checkudata(L, lua_upvalueindex(1), TS_META_TREECURSOR);
|
||||||
L, lua_upvalueindex(1), TS_META_TREECURSOR);
|
|
||||||
if (!ud) {
|
if (!ud) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -939,8 +929,7 @@ static int node_next_child(lua_State *L)
|
|||||||
|
|
||||||
if (ts_tree_cursor_goto_next_sibling(ud)) {
|
if (ts_tree_cursor_goto_next_sibling(ud)) {
|
||||||
push:
|
push:
|
||||||
push_node(
|
push_node(L,
|
||||||
L,
|
|
||||||
ts_tree_cursor_current_node(ud),
|
ts_tree_cursor_current_node(ud),
|
||||||
lua_upvalueindex(2)); // [node]
|
lua_upvalueindex(2)); // [node]
|
||||||
|
|
||||||
@@ -1200,11 +1189,16 @@ int tslua_parse_query(lua_State *L)
|
|||||||
|
|
||||||
static const char *query_err_string(TSQueryError err) {
|
static const char *query_err_string(TSQueryError err) {
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case TSQueryErrorSyntax: return "invalid syntax";
|
case TSQueryErrorSyntax:
|
||||||
case TSQueryErrorNodeType: return "invalid node type";
|
return "invalid syntax";
|
||||||
case TSQueryErrorField: return "invalid field";
|
case TSQueryErrorNodeType:
|
||||||
case TSQueryErrorCapture: return "invalid capture";
|
return "invalid node type";
|
||||||
default: return "error";
|
case TSQueryErrorField:
|
||||||
|
return "invalid field";
|
||||||
|
case TSQueryErrorCapture:
|
||||||
|
return "invalid capture";
|
||||||
|
default:
|
||||||
|
return "error";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,18 +1,17 @@
|
|||||||
|
#include <errno.h>
|
||||||
|
#include <lauxlib.h>
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
#include <lualib.h>
|
#include <lualib.h>
|
||||||
#include <lauxlib.h>
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "nvim/vim.h"
|
#include "nvim/api/private/helpers.h"
|
||||||
#include "xdiff/xdiff.h"
|
|
||||||
#include "nvim/lua/xdiff.h"
|
|
||||||
#include "nvim/lua/converter.h"
|
#include "nvim/lua/converter.h"
|
||||||
#include "nvim/lua/executor.h"
|
#include "nvim/lua/executor.h"
|
||||||
#include "nvim/api/private/helpers.h"
|
#include "nvim/lua/xdiff.h"
|
||||||
|
#include "nvim/vim.h"
|
||||||
|
#include "xdiff/xdiff.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
kNluaXdiffModeUnified = 0,
|
kNluaXdiffModeUnified = 0,
|
||||||
@@ -48,8 +47,7 @@ static int write_string(void *priv, mmbuffer_t *mb, int nbuf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// hunk_func callback used when opts.hunk_lines = true
|
// hunk_func callback used when opts.hunk_lines = true
|
||||||
static int hunk_locations_cb(long start_a, long count_a,
|
static int hunk_locations_cb(long start_a, long count_a, long start_b, long count_b, void *cb_data)
|
||||||
long start_b, long count_b, void *cb_data)
|
|
||||||
{
|
{
|
||||||
// Mimic extra offsets done by xdiff, see:
|
// Mimic extra offsets done by xdiff, see:
|
||||||
// src/nvim/xdiff/xemit.c:284
|
// src/nvim/xdiff/xemit.c:284
|
||||||
@@ -79,8 +77,7 @@ static int hunk_locations_cb(long start_a, long count_a,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// hunk_func callback used when opts.on_hunk is given
|
// hunk_func callback used when opts.on_hunk is given
|
||||||
static int call_on_hunk_cb(long start_a, long count_a,
|
static int call_on_hunk_cb(long start_a, long count_a, long start_b, long count_b, void *cb_data)
|
||||||
long start_b, long count_b, void *cb_data)
|
|
||||||
{
|
{
|
||||||
// Mimic extra offsets done by xdiff, see:
|
// Mimic extra offsets done by xdiff, see:
|
||||||
// src/nvim/xdiff/xemit.c:284
|
// src/nvim/xdiff/xemit.c:284
|
||||||
@@ -130,8 +127,7 @@ static mmfile_t get_string_arg(lua_State *lstate, int idx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Helper function for validating option types
|
// Helper function for validating option types
|
||||||
static bool check_xdiff_opt(ObjectType actType, ObjectType expType,
|
static bool check_xdiff_opt(ObjectType actType, ObjectType expType, const char *name, Error *err)
|
||||||
const char *name, Error *err)
|
|
||||||
{
|
{
|
||||||
if (actType != expType) {
|
if (actType != expType) {
|
||||||
const char * type_str =
|
const char * type_str =
|
||||||
@@ -149,9 +145,8 @@ static bool check_xdiff_opt(ObjectType actType, ObjectType expType,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static NluaXdiffMode process_xdl_diff_opts(lua_State *lstate,
|
static NluaXdiffMode process_xdl_diff_opts(lua_State *lstate, xdemitconf_t *cfg, xpparam_t *params,
|
||||||
xdemitconf_t *cfg,
|
Error *err)
|
||||||
xpparam_t *params, Error *err)
|
|
||||||
{
|
{
|
||||||
const DictionaryOf(LuaRef) opts = nlua_pop_Dictionary(lstate, true, err);
|
const DictionaryOf(LuaRef) opts = nlua_pop_Dictionary(lstate, true, err);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user