Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitef2c332

Browse files
committed
feat(marks): marks keep "view" info and restore it on jump
** RefactorPreviously most functions used to "get" a mark returned a position,changed the line number and sometimes changed even the current buffer.Now functions return a {x}fmark_T making calling context aware whetherthe mark is in another buffer without arcane casting. A new function isprovided for switching to the mark buffer and returning a flag styleEnum to convey what happen in the movement. If the cursor changed, line,columns, if it changed buffer, etc.The function to get named mark was split into multiple functions.- mark_get() -> fmark_T- mark_get_global() -> xfmark_T- mark_get_local() -> fmark_T - mark_get_motion() -> fmark_T - mark_get_visual() -> fmark_TFunctions that manage the changelist and jumplist were also modified toreturn mark types.- get_jumplist -> fmark_T- get_changelist -> fmark_TThe refactor is also seen mainly on normal.c, where all the markmovement has been siphoned through one function nv_gomark, while theother functions handle getting the mark and setting their movementflags. To handle whether context marks should be left, etc.** Mark ViewWhile doing the refactor the concept of a mark view was alsoimplemented:The view of a mark currently implemented as the number of lines betweenthe mark position on creation and the window topline. This allows formoving not only back to the position of a mark but having the windowlook similar to when the mark was defined. This is done by carrying andextra element in the fmark_T struct, which can be extended later to alsorestore horizontal shift.*** User space features1. There's a new option, jumpoptions+=view enables the mark view restoringautomatically when using the jumplist, changelist, alternate-file andmark motions. <C-O> <C-I> g; g, <C-^> '[mark] `[mark]** Limitations- The view information is not saved in shada.- Calls to get_mark should copy the value in the pointer since we are using pos_to_mark() to wrap and provide a homogeneous interfaces. This was also a limitation in the previous state of things.
1 parent35c9fe9 commitef2c332

File tree

26 files changed

+1088
-328
lines changed

26 files changed

+1088
-328
lines changed

‎runtime/doc/motion.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,11 @@ Jumping to a mark can be done in two ways:
735735
2. With ' (single quote): The cursor is positioned on the first non-blank
736736
character in the line of the specified location and
737737
the motion is linewise.
738+
*mark-view*
739+
3. Apart from the above if'jumpoptions' cotains "view", they will also try to
740+
restore the mark view. This is the number of lines between the cursor position
741+
and the window topline (first buffer line displayed in the window) when it was
742+
set.
738743

739744
*m**mark**Mark*
740745
m{a-zA-Z}Set mark{a-zA-Z} at cursor position (does not move

‎runtime/doc/options.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3530,6 +3530,10 @@ A jump table for the options with a short description can be found at |Q_op|.
35303530
jumplist and then jumping to a location.
35313531
|jumplist-stack|
35323532

3533+
view When moving through the jumplist,|changelist|,
3534+
|alternate-file| or using|mark-motions| try to
3535+
restore the|mark-view| in which the action occurred.
3536+
35333537
*'joinspaces'**'js'**'nojoinspaces'**'nojs'*
35343538
'joinspaces''js'boolean(default off)
35353539
global

‎runtime/doc/vim_diff.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ Normal commands:
383383
Options:
384384
'ttimeout','ttimeoutlen' behavior was simplified
385385
|jumpoptions| "stack" behavior
386+
|jumpoptions| "view" behavior which makes navigation less confusing, and
387+
also applies to|mark-motions|.
386388
'shortmess' the "F" flag does not affect output from autocommands
387389

388390
Shell:

‎src/nvim/api/buffer.c‎

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,17 +1155,17 @@ Boolean nvim_buf_del_mark(Buffer buffer, String name, Error *err)
11551155
returnres;
11561156
}
11571157

1158-
pos_T*pos=getmark_buf(buf,*name.data, false);
1158+
fmark_T*fm=mark_get(buf,curwin,NULL,kMarkAllNoResolve,*name.data);
11591159

1160-
//pos point toNULL when there's no mark with name
1161-
if (pos==NULL) {
1160+
//fm isNULL when there's no mark with the given name
1161+
if (fm==NULL) {
11621162
api_set_error(err,kErrorTypeValidation,"Invalid mark name: '%c'",
11631163
*name.data);
11641164
returnres;
11651165
}
11661166

1167-
//pos->lnum is 0 when the mark is not valid in the buffer, or is not set.
1168-
if (pos->lnum!=0) {
1167+
//mark.lnum is 0 when the mark is not valid in the buffer, or is not set.
1168+
if (fm->mark.lnum!=0&&fm->fnum==buf->handle) {
11691169
// since the mark belongs to the buffer delete it.
11701170
res=set_mark(buf,name,0,0,err);
11711171
}
@@ -1238,26 +1238,25 @@ ArrayOf(Integer, 2) nvim_buf_get_mark(Buffer buffer, String name, Error *err)
12381238
returnrv;
12391239
}
12401240

1241-
pos_T*posp;
1241+
fmark_T*fm;
1242+
pos_Tpos;
12421243
charmark=*name.data;
12431244

1244-
try_start();
1245-
bufref_Tsave_buf;
1246-
switch_buffer(&save_buf,buf);
1247-
posp=getmark(mark, false);
1248-
restore_buffer(&save_buf);
1249-
1250-
if (try_end(err)) {
1251-
returnrv;
1252-
}
1253-
1254-
if (posp==NULL) {
1245+
fm=mark_get(buf,curwin,NULL,kMarkAllNoResolve,mark);
1246+
if (fm==NULL) {
12551247
api_set_error(err,kErrorTypeValidation,"Invalid mark name");
12561248
returnrv;
12571249
}
1250+
// (0, 0) uppercase/file mark set in another buffer.
1251+
if (fm->fnum!=buf->handle) {
1252+
pos.lnum=0;
1253+
pos.col=0;
1254+
}else {
1255+
pos=fm->mark;
1256+
}
12581257

1259-
ADD(rv,INTEGER_OBJ(posp->lnum));
1260-
ADD(rv,INTEGER_OBJ(posp->col));
1258+
ADD(rv,INTEGER_OBJ(pos.lnum));
1259+
ADD(rv,INTEGER_OBJ(pos.col));
12611260

12621261
returnrv;
12631262
}

‎src/nvim/api/private/helpers.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ bool set_mark(buf_T *buf, String name, Integer line, Integer col, Error *err)
10821082
}
10831083
assert(INT32_MIN <=line&&line <=INT32_MAX);
10841084
pos_Tpos= { (linenr_T)line, (int)col, (int)col };
1085-
res=setmark_pos(*name.data,&pos,buf->handle);
1085+
res=setmark_pos(*name.data,&pos,buf->handle,NULL);
10861086
if (!res) {
10871087
if (deleting) {
10881088
api_set_error(err,kErrorTypeException,

‎src/nvim/api/vim.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,20 +2025,20 @@ Array nvim_get_mark(String name, Dictionary opts, Error *err)
20252025
returnrv;
20262026
}
20272027

2028-
xfmark_Tmark=get_global_mark(*name.data);
2029-
pos_Tpos=mark.fmark.mark;
2028+
xfmark_T*mark=mark_get_global(false,*name.data);// false avoids loading the mark buffer
2029+
pos_Tpos=mark->fmark.mark;
20302030
boolallocated= false;
20312031
intbufnr;
20322032
char*filename;
20332033

20342034
// Marks are from an open buffer it fnum is non zero
2035-
if (mark.fmark.fnum!=0) {
2036-
bufnr=mark.fmark.fnum;
2035+
if (mark->fmark.fnum!=0) {
2036+
bufnr=mark->fmark.fnum;
20372037
filename= (char*)buflist_nr2name(bufnr, true, true);
20382038
allocated= true;
20392039
// Marks comes from shada
20402040
}else {
2041-
filename=mark.fname;
2041+
filename=mark->fname;
20422042
bufnr=0;
20432043
}
20442044

‎src/nvim/buffer.c‎

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include"nvim/indent_c.h"
5555
#include"nvim/main.h"
5656
#include"nvim/mark.h"
57+
#include"nvim/mark_defs.h"
5758
#include"nvim/mbyte.h"
5859
#include"nvim/memory.h"
5960
#include"nvim/message.h"
@@ -1791,7 +1792,8 @@ buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum, int fl
17911792
buf_copy_options(buf,BCO_ALWAYS);
17921793
}
17931794

1794-
buf->b_wininfo->wi_fpos.lnum=lnum;
1795+
buf->b_wininfo->wi_mark= (fmark_T)INIT_FMARK;
1796+
buf->b_wininfo->wi_mark.mark.lnum=lnum;
17951797
buf->b_wininfo->wi_win=curwin;
17961798

17971799
hash_init(&buf->b_s.b_keywtab);
@@ -1939,7 +1941,7 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
19391941
{
19401942
buf_T*buf;
19411943
win_T*wp=NULL;
1942-
pos_T*fpos;
1944+
fmark_T*fm=NULL;
19431945
colnr_Tcol;
19441946

19451947
buf=buflist_findnr(n);
@@ -1965,11 +1967,13 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
19651967
returnFAIL;
19661968
}
19671969

1970+
boolrestore_view= false;
19681971
// altfpos may be changed by getfile(), get it now
19691972
if (lnum==0) {
1970-
fpos=buflist_findfpos(buf);
1971-
lnum=fpos->lnum;
1972-
col=fpos->col;
1973+
fm=buflist_findfmark(buf);
1974+
lnum=fm->mark.lnum;
1975+
col=fm->mark.col;
1976+
restore_view= true;
19731977
}else {
19741978
col=0;
19751979
}
@@ -2013,6 +2017,9 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
20132017
curwin->w_cursor.coladd=0;
20142018
curwin->w_set_curswant= true;
20152019
}
2020+
if (jop_flags&JOP_VIEW&&restore_view) {
2021+
mark_view_restore(fm);
2022+
}
20162023
returnOK;
20172024
}
20182025
RedrawingDisabled--;
@@ -2024,7 +2031,7 @@ void buflist_getfpos(void)
20242031
{
20252032
pos_T*fpos;
20262033

2027-
fpos=buflist_findfpos(curbuf);
2034+
fpos=&buflist_findfmark(curbuf)->mark;
20282035

20292036
curwin->w_cursor.lnum=fpos->lnum;
20302037
check_cursor_lnum();
@@ -2464,8 +2471,11 @@ void buflist_setfpos(buf_T *const buf, win_T *const win, linenr_T lnum, colnr_T
24642471
}
24652472
}
24662473
if (lnum!=0) {
2467-
wip->wi_fpos.lnum=lnum;
2468-
wip->wi_fpos.col=col;
2474+
wip->wi_mark.mark.lnum=lnum;
2475+
wip->wi_mark.mark.col=col;
2476+
if (win!=NULL) {
2477+
wip->wi_mark.view=mark_view_make(win->w_topline,wip->wi_mark.mark);
2478+
}
24692479
}
24702480
if (copy_options&&win!=NULL) {
24712481
// Save the window-specific option values.
@@ -2583,24 +2593,23 @@ void get_winopts(buf_T *buf)
25832593
didset_window_options(curwin);
25842594
}
25852595

2586-
/// Find the position (lnum and col) for the buffer 'buf' for the current
2587-
/// window.
2596+
/// Find the mark for the buffer 'buf' for the current window.
25882597
///
25892598
/// @return a pointer to no_position if no position is found.
2590-
pos_T*buflist_findfpos(buf_T*buf)
2599+
fmark_T*buflist_findfmark(buf_T*buf)
25912600
FUNC_ATTR_PURE
25922601
{
2593-
staticpos_Tno_position= {1,0,0 };
2602+
staticfmark_Tno_position= {{1,0,0 },0,0, {0 },NULL };
25942603

25952604
wininfo_T*constwip=find_wininfo(buf, false, false);
2596-
return (wip==NULL) ?&no_position :&(wip->wi_fpos);
2605+
return (wip==NULL) ?&no_position :&(wip->wi_mark);
25972606
}
25982607

25992608
/// Find the lnum for the buffer 'buf' for the current window.
26002609
linenr_Tbuflist_findlnum(buf_T*buf)
26012610
FUNC_ATTR_PURE
26022611
{
2603-
returnbuflist_findfpos(buf)->lnum;
2612+
returnbuflist_findfmark(buf)->mark.lnum;
26042613
}
26052614

26062615
/// List all known file names (for :files and :buffers command).

‎src/nvim/buffer_defs.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ typedef struct {
283283
structwininfo_S {
284284
wininfo_T*wi_next;// next entry or NULL for last entry
285285
wininfo_T*wi_prev;// previous entry or NULL for first entry
286-
win_T*wi_win;// pointer to window that did setwi_fpos
287-
pos_Twi_fpos;// last cursorposition in the file
286+
win_T*wi_win;// pointer to window that did setwi_mark
287+
fmark_Twi_mark;// last cursormark in the file
288288
boolwi_optset;// true when wi_opt has useful values
289289
winopt_Twi_opt;// local window options
290290
boolwi_fold_manual;// copy of w_fold_manual

‎src/nvim/change.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,13 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, linenr_T
149149

150150
// set the '. mark
151151
if ((cmdmod.cmod_flags&CMOD_KEEPJUMPS)==0) {
152-
RESET_FMARK(&curbuf->b_last_change, ((pos_T) {lnum,col,0 }),0);
152+
fmarkv_Tview=INIT_FMARKV;
153+
// Set the markview only if lnum is visible, as changes might be done
154+
// outside of the current window view.
155+
if (lnum >=curwin->w_topline&&lnum <=curwin->w_botline) {
156+
view=mark_view_make(curwin->w_topline,curwin->w_cursor);
157+
}
158+
RESET_FMARK(&curbuf->b_last_change, ((pos_T) {lnum,col,0 }),curbuf->handle,view);
153159

154160
// Create a new entry if a new undo-able change was started or we
155161
// don't have an entry yet.

‎src/nvim/edit.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7957,7 +7957,8 @@ static bool ins_esc(long *count, int cmdchar, bool nomove)
79577957

79587958
// Remember the last Insert position in the '^ mark.
79597959
if ((cmdmod.cmod_flags&CMOD_KEEPJUMPS)==0) {
7960-
RESET_FMARK(&curbuf->b_last_insert,curwin->w_cursor,curbuf->b_fnum);
7960+
fmarkv_Tview=mark_view_make(curwin->w_topline,curwin->w_cursor);
7961+
RESET_FMARK(&curbuf->b_last_insert,curwin->w_cursor,curbuf->b_fnum,view);
79617962
}
79627963

79637964
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp