aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2025-03-27 21:35:20 +0800
committerGitHub <noreply@github.com>2025-03-27 13:35:20 +0000
commitd01d4764804bd73ce213aab76a394c62c9f7d193 (patch)
treef1232fb6c860315974a5ee53bea6080d4add8ac8
parent703f4037c475ee504b71d393e152fb1ae44c7bb9 (diff)
downloadrneovim-d01d4764804bd73ce213aab76a394c62c9f7d193.tar.gz
rneovim-d01d4764804bd73ce213aab76a394c62c9f7d193.tar.bz2
rneovim-d01d4764804bd73ce213aab76a394c62c9f7d193.zip
refactor(eval): move diff functions to diff.c (#33085)
They were moved in Vim in patch 8.1.1989. This change is required to port patch 9.1.1243.
-rw-r--r--src/gen/gen_eval.lua1
-rw-r--r--src/nvim/diff.c58
-rw-r--r--src/nvim/eval/funcs.c58
3 files changed, 59 insertions, 58 deletions
diff --git a/src/gen/gen_eval.lua b/src/gen/gen_eval.lua
index 9d2f2f7523..2f2d09485b 100644
--- a/src/gen/gen_eval.lua
+++ b/src/gen/gen_eval.lua
@@ -16,6 +16,7 @@ hashpipe:write([[
#include "nvim/arglist.h"
#include "nvim/cmdexpand.h"
#include "nvim/cmdhist.h"
+#include "nvim/diff.h"
#include "nvim/digraph.h"
#include "nvim/eval.h"
#include "nvim/eval/buffer.h"
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index c9ca58c816..4c5b86adc4 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -29,6 +29,7 @@
#include "nvim/drawscreen.h"
#include "nvim/errors.h"
#include "nvim/eval.h"
+#include "nvim/eval/typval.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_cmds_defs.h"
#include "nvim/ex_docmd.h"
@@ -3488,3 +3489,60 @@ static int xdiff_out(int start_a, int count_a, int start_b, int count_b, void *p
}));
return 0;
}
+
+/// "diff_filler()" function
+void f_diff_filler(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
+{
+ rettv->vval.v_number = MAX(0, diff_check(curwin, tv_get_lnum(argvars)));
+}
+
+/// "diff_hlID()" function
+void f_diff_hlID(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
+{
+ linenr_T lnum = tv_get_lnum(argvars);
+ static linenr_T prev_lnum = 0;
+ static varnumber_T changedtick = 0;
+ static int fnum = 0;
+ static int change_start = 0;
+ static int change_end = 0;
+ static hlf_T hlID = (hlf_T)0;
+
+ if (lnum < 0) { // ignore type error in {lnum} arg
+ lnum = 0;
+ }
+ if (lnum != prev_lnum
+ || changedtick != buf_get_changedtick(curbuf)
+ || fnum != curbuf->b_fnum) {
+ // New line, buffer, change: need to get the values.
+ int linestatus = 0;
+ int filler_lines = diff_check_with_linestatus(curwin, lnum, &linestatus);
+ if (filler_lines < 0 || linestatus < 0) {
+ if (filler_lines == -1 || linestatus == -1) {
+ change_start = MAXCOL;
+ change_end = -1;
+ if (diff_find_change(curwin, lnum, &change_start, &change_end)) {
+ hlID = HLF_ADD; // added line
+ } else {
+ hlID = HLF_CHD; // changed line
+ }
+ } else {
+ hlID = HLF_ADD; // added line
+ }
+ } else {
+ hlID = (hlf_T)0;
+ }
+ prev_lnum = lnum;
+ changedtick = buf_get_changedtick(curbuf);
+ fnum = curbuf->b_fnum;
+ }
+
+ if (hlID == HLF_CHD || hlID == HLF_TXD) {
+ int col = (int)tv_get_number(&argvars[1]) - 1; // Ignore type error in {col}.
+ if (col >= change_start && col <= change_end) {
+ hlID = HLF_TXD; // Changed text.
+ } else {
+ hlID = HLF_CHD; // Changed line.
+ }
+ }
+ rettv->vval.v_number = hlID;
+}
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index edb77778a3..25252cdfde 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -34,7 +34,6 @@
#include "nvim/cmdexpand_defs.h"
#include "nvim/context.h"
#include "nvim/cursor.h"
-#include "nvim/diff.h"
#include "nvim/edit.h"
#include "nvim/errors.h"
#include "nvim/eval.h"
@@ -1300,63 +1299,6 @@ static void f_did_filetype(typval_T *argvars, typval_T *rettv, EvalFuncData fptr
rettv->vval.v_number = curbuf->b_did_filetype;
}
-/// "diff_filler()" function
-static void f_diff_filler(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
-{
- rettv->vval.v_number = MAX(0, diff_check(curwin, tv_get_lnum(argvars)));
-}
-
-/// "diff_hlID()" function
-static void f_diff_hlID(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
-{
- linenr_T lnum = tv_get_lnum(argvars);
- static linenr_T prev_lnum = 0;
- static varnumber_T changedtick = 0;
- static int fnum = 0;
- static int change_start = 0;
- static int change_end = 0;
- static hlf_T hlID = (hlf_T)0;
-
- if (lnum < 0) { // ignore type error in {lnum} arg
- lnum = 0;
- }
- if (lnum != prev_lnum
- || changedtick != buf_get_changedtick(curbuf)
- || fnum != curbuf->b_fnum) {
- // New line, buffer, change: need to get the values.
- int linestatus = 0;
- int filler_lines = diff_check_with_linestatus(curwin, lnum, &linestatus);
- if (filler_lines < 0 || linestatus < 0) {
- if (filler_lines == -1 || linestatus == -1) {
- change_start = MAXCOL;
- change_end = -1;
- if (diff_find_change(curwin, lnum, &change_start, &change_end)) {
- hlID = HLF_ADD; // added line
- } else {
- hlID = HLF_CHD; // changed line
- }
- } else {
- hlID = HLF_ADD; // added line
- }
- } else {
- hlID = (hlf_T)0;
- }
- prev_lnum = lnum;
- changedtick = buf_get_changedtick(curbuf);
- fnum = curbuf->b_fnum;
- }
-
- if (hlID == HLF_CHD || hlID == HLF_TXD) {
- int col = (int)tv_get_number(&argvars[1]) - 1; // Ignore type error in {col}.
- if (col >= change_start && col <= change_end) {
- hlID = HLF_TXD; // Changed text.
- } else {
- hlID = HLF_CHD; // Changed line.
- }
- }
- rettv->vval.v_number = hlID;
-}
-
/// "empty({expr})" function
static void f_empty(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{