mirror of
https://github.com/neovim/neovim.git
synced 2026-08-27 09:31:47 +00:00
feat(jumplist): allow opting out of removing unloaded buffers (#30419)
Problem: Cannot opt out of removing unloaded buffers from the jumplist. Solution: Only enable that with "clean" flag in 'jumpoptions'.
This commit is contained in:
@@ -1395,8 +1395,10 @@ int do_buffer(int action, int start, int dir, int count, int forceit)
|
||||
|
||||
// If the buffer to be deleted is not the current one, delete it here.
|
||||
if (buf != curbuf) {
|
||||
// Remove the buffer to be deleted from the jump list.
|
||||
buf_remove_from_jumplist(buf);
|
||||
if (jop_flags & JOP_CLEAN) {
|
||||
// Remove the buffer to be deleted from the jump list.
|
||||
buf_remove_from_jumplist(buf);
|
||||
}
|
||||
|
||||
close_windows(buf, false);
|
||||
|
||||
@@ -1419,28 +1421,37 @@ int do_buffer(int action, int start, int dir, int count, int forceit)
|
||||
if (au_new_curbuf.br_buf != NULL && bufref_valid(&au_new_curbuf)) {
|
||||
buf = au_new_curbuf.br_buf;
|
||||
} else if (curwin->w_jumplistlen > 0) {
|
||||
// Remove the current buffer from the jump list.
|
||||
buf_remove_from_jumplist(curbuf);
|
||||
if (jop_flags & JOP_CLEAN) {
|
||||
// Remove the current buffer from the jump list.
|
||||
buf_remove_from_jumplist(curbuf);
|
||||
}
|
||||
|
||||
// It's possible that we removed all jump list entries, in that case we need to try another
|
||||
// approach
|
||||
if (curwin->w_jumplistlen > 0) {
|
||||
// If the index is the same as the length, the current position was not yet added to the jump
|
||||
// list. So we can safely go back to the last entry and search from there.
|
||||
if (curwin->w_jumplistidx == curwin->w_jumplistlen) {
|
||||
curwin->w_jumplistidx = curwin->w_jumplistlen - 1;
|
||||
}
|
||||
|
||||
int jumpidx = curwin->w_jumplistidx;
|
||||
|
||||
if (jop_flags & JOP_CLEAN) {
|
||||
// If the index is the same as the length, the current position was not yet added to the
|
||||
// jump list. So we can safely go back to the last entry and search from there.
|
||||
if (jumpidx == curwin->w_jumplistlen) {
|
||||
jumpidx = curwin->w_jumplistidx = curwin->w_jumplistlen - 1;
|
||||
}
|
||||
} else {
|
||||
jumpidx--;
|
||||
if (jumpidx < 0) {
|
||||
jumpidx = curwin->w_jumplistlen - 1;
|
||||
}
|
||||
}
|
||||
|
||||
forward = jumpidx;
|
||||
do {
|
||||
while ((jop_flags & JOP_CLEAN) || jumpidx != curwin->w_jumplistidx) {
|
||||
buf = buflist_findnr(curwin->w_jumplist[jumpidx].fmark.fnum);
|
||||
|
||||
if (buf != NULL) {
|
||||
// Skip unlisted bufs. Also skip a quickfix
|
||||
// Skip current and unlisted bufs. Also skip a quickfix
|
||||
// buffer, it might be deleted soon.
|
||||
if (!buf->b_p_bl || bt_quickfix(buf)) {
|
||||
if (buf == curbuf || !buf->b_p_bl || bt_quickfix(buf)) {
|
||||
buf = NULL;
|
||||
} else if (buf->b_ml.ml_mfp == NULL) {
|
||||
// skip unloaded buf, but may keep it for later
|
||||
@@ -1451,8 +1462,10 @@ int do_buffer(int action, int start, int dir, int count, int forceit)
|
||||
}
|
||||
}
|
||||
if (buf != NULL) { // found a valid buffer: stop searching
|
||||
curwin->w_jumplistidx = jumpidx;
|
||||
update_jumplist = false;
|
||||
if (jop_flags & JOP_CLEAN) {
|
||||
curwin->w_jumplistidx = jumpidx;
|
||||
update_jumplist = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// advance to older entry in jump list
|
||||
@@ -1465,7 +1478,7 @@ int do_buffer(int action, int start, int dir, int count, int forceit)
|
||||
if (jumpidx == forward) { // List exhausted for sure
|
||||
break;
|
||||
}
|
||||
} while (jumpidx != curwin->w_jumplistidx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3726,7 +3739,7 @@ void ex_buffer_all(exarg_T *eap)
|
||||
|
||||
// Open the buffer in this window.
|
||||
swap_exists_action = SEA_DIALOG;
|
||||
set_curbuf(buf, DOBUF_GOTO, false);
|
||||
set_curbuf(buf, DOBUF_GOTO, !(jop_flags & JOP_CLEAN));
|
||||
if (!bufref_valid(&bufref)) {
|
||||
// Autocommands deleted the buffer.
|
||||
swap_exists_action = SEA_NONE;
|
||||
|
||||
@@ -527,6 +527,7 @@ EXTERN char *p_jop; ///< 'jumpooptions'
|
||||
EXTERN unsigned jop_flags;
|
||||
#define JOP_STACK 0x01
|
||||
#define JOP_VIEW 0x02
|
||||
#define JOP_CLEAN 0x04
|
||||
EXTERN char *p_keymap; ///< 'keymap'
|
||||
EXTERN char *p_kp; ///< 'keywordprg'
|
||||
EXTERN char *p_km; ///< 'keymodel'
|
||||
|
||||
@@ -4484,7 +4484,7 @@ return {
|
||||
{
|
||||
abbreviation = 'jop',
|
||||
cb = 'did_set_jumpoptions',
|
||||
defaults = { if_true = '' },
|
||||
defaults = { if_true = 'clean' },
|
||||
deny_duplicates = true,
|
||||
desc = [=[
|
||||
List of words that change the behavior of the |jumplist|.
|
||||
@@ -4497,6 +4497,9 @@ return {
|
||||
view When moving through the jumplist, |changelist|,
|
||||
|alternate-file| or using |mark-motions| try to
|
||||
restore the |mark-view| in which the action occurred.
|
||||
|
||||
clean Remove unloaded buffers from the jumplist.
|
||||
EXPERIMENTAL: this flag may change in the future.
|
||||
]=],
|
||||
expand_cb = 'expand_set_jumpoptions',
|
||||
full_name = 'jumpoptions',
|
||||
|
||||
@@ -136,7 +136,7 @@ static char *(p_fdc_values[]) = { "auto", "auto:1", "auto:2", "auto:3", "auto:4"
|
||||
"5", "6", "7", "8", "9", NULL };
|
||||
static char *(p_spo_values[]) = { "camel", "noplainbuffer", NULL };
|
||||
static char *(p_icm_values[]) = { "nosplit", "split", NULL };
|
||||
static char *(p_jop_values[]) = { "stack", "view", NULL };
|
||||
static char *(p_jop_values[]) = { "stack", "view", "clean", NULL };
|
||||
static char *(p_tpf_values[]) = { "BS", "HT", "FF", "ESC", "DEL", "C0", "C1", NULL };
|
||||
static char *(p_rdb_values[]) = { "compositor", "nothrottle", "invalid", "nodelta", "line",
|
||||
"flush", NULL };
|
||||
|
||||
Reference in New Issue
Block a user