mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
'viewoptions': add "curdir" flag #7447
The flag enables the current local directory set by ":lcd" to be saved to views which is the current default behaviour. The option can be removed to disable this behaviour. closes #7435 vim-patch:8.0.1289
This commit is contained in:
parent
f185c739bc
commit
a6de144c3e
@ -6453,7 +6453,7 @@ A jump table for the options with a short description can be found at |Q_op|.
|
|||||||
security reasons.
|
security reasons.
|
||||||
|
|
||||||
*'viewoptions'* *'vop'*
|
*'viewoptions'* *'vop'*
|
||||||
'viewoptions' 'vop' string (default: "folds,options,cursor")
|
'viewoptions' 'vop' string (default: "folds,options,cursor,curdir")
|
||||||
global
|
global
|
||||||
{not available when compiled without the |+mksession|
|
{not available when compiled without the |+mksession|
|
||||||
feature}
|
feature}
|
||||||
@ -6461,6 +6461,7 @@ A jump table for the options with a short description can be found at |Q_op|.
|
|||||||
list of words. Each word enables saving and restoring something:
|
list of words. Each word enables saving and restoring something:
|
||||||
word save and restore ~
|
word save and restore ~
|
||||||
cursor cursor position in file and in window
|
cursor cursor position in file and in window
|
||||||
|
curdir local current directory, if set with |:lcd|
|
||||||
folds manually created folds, opened/closed folds and local
|
folds manually created folds, opened/closed folds and local
|
||||||
fold options
|
fold options
|
||||||
options options and mappings local to a window or buffer (not
|
options options and mappings local to a window or buffer (not
|
||||||
|
@ -885,7 +885,7 @@ The output of ":mkview" contains these items:
|
|||||||
5. The scroll position and the cursor position in the file. Doesn't work very
|
5. The scroll position and the cursor position in the file. Doesn't work very
|
||||||
well when there are closed folds.
|
well when there are closed folds.
|
||||||
6. The local current directory, if it is different from the global current
|
6. The local current directory, if it is different from the global current
|
||||||
directory.
|
directory and 'viewoptions' contains "curdir".
|
||||||
|
|
||||||
Note that Views and Sessions are not perfect:
|
Note that Views and Sessions are not perfect:
|
||||||
- They don't restore everything. For example, defined functions, autocommands
|
- They don't restore everything. For example, defined functions, autocommands
|
||||||
|
@ -9356,15 +9356,18 @@ put_view (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
//
|
||||||
* Local directory.
|
// Local directory, if the current flag is not view options or the "curdir"
|
||||||
*/
|
// option is included.
|
||||||
if (wp->w_localdir != NULL) {
|
//
|
||||||
|
if (wp->w_localdir != NULL
|
||||||
|
&& (flagp != &vop_flags || (*flagp & SSOP_CURDIR))) {
|
||||||
if (fputs("lcd ", fd) < 0
|
if (fputs("lcd ", fd) < 0
|
||||||
|| ses_put_fname(fd, wp->w_localdir, flagp) == FAIL
|
|| ses_put_fname(fd, wp->w_localdir, flagp) == FAIL
|
||||||
|| put_eol(fd) == FAIL)
|
|| put_eol(fd) == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
did_lcd = TRUE;
|
}
|
||||||
|
did_lcd = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
|
@ -539,7 +539,7 @@ static char *(p_ssop_values[]) = {"buffers", "winpos", "resize", "winsize",
|
|||||||
"localoptions", "options", "help", "blank",
|
"localoptions", "options", "help", "blank",
|
||||||
"globals", "slash", "unix",
|
"globals", "slash", "unix",
|
||||||
"sesdir", "curdir", "folds", "cursor",
|
"sesdir", "curdir", "folds", "cursor",
|
||||||
"tabpages", NULL};
|
"tabpages", NULL };
|
||||||
# endif
|
# endif
|
||||||
# define SSOP_BUFFERS 0x001
|
# define SSOP_BUFFERS 0x001
|
||||||
# define SSOP_WINPOS 0x002
|
# define SSOP_WINPOS 0x002
|
||||||
@ -557,16 +557,17 @@ static char *(p_ssop_values[]) = {"buffers", "winpos", "resize", "winsize",
|
|||||||
# define SSOP_FOLDS 0x2000
|
# define SSOP_FOLDS 0x2000
|
||||||
# define SSOP_CURSOR 0x4000
|
# define SSOP_CURSOR 0x4000
|
||||||
# define SSOP_TABPAGES 0x8000
|
# define SSOP_TABPAGES 0x8000
|
||||||
EXTERN char_u *p_sh; /* 'shell' */
|
|
||||||
EXTERN char_u *p_shcf; /* 'shellcmdflag' */
|
EXTERN char_u *p_sh; // 'shell'
|
||||||
EXTERN char_u *p_sp; /* 'shellpipe' */
|
EXTERN char_u *p_shcf; // 'shellcmdflag'
|
||||||
EXTERN char_u *p_shq; /* 'shellquote' */
|
EXTERN char_u *p_sp; // 'shellpipe'
|
||||||
EXTERN char_u *p_sxq; /* 'shellxquote' */
|
EXTERN char_u *p_shq; // 'shellquote'
|
||||||
EXTERN char_u *p_sxe; /* 'shellxescape' */
|
EXTERN char_u *p_sxq; // 'shellxquote'
|
||||||
EXTERN char_u *p_srr; /* 'shellredir' */
|
EXTERN char_u *p_sxe; // 'shellxescape'
|
||||||
EXTERN int p_stmp; /* 'shelltemp' */
|
EXTERN char_u *p_srr; // 'shellredir'
|
||||||
|
EXTERN int p_stmp; // 'shelltemp'
|
||||||
#ifdef BACKSLASH_IN_FILENAME
|
#ifdef BACKSLASH_IN_FILENAME
|
||||||
EXTERN int p_ssl; /* 'shellslash' */
|
EXTERN int p_ssl; // 'shellslash'
|
||||||
#endif
|
#endif
|
||||||
EXTERN char_u *p_stl; // 'statusline'
|
EXTERN char_u *p_stl; // 'statusline'
|
||||||
EXTERN int p_sr; // 'shiftround'
|
EXTERN int p_sr; // 'shiftround'
|
||||||
|
@ -2610,7 +2610,7 @@ return {
|
|||||||
deny_duplicates=true,
|
deny_duplicates=true,
|
||||||
vi_def=true,
|
vi_def=true,
|
||||||
varname='p_vop',
|
varname='p_vop',
|
||||||
defaults={if_true={vi="folds,options,cursor"}}
|
defaults={if_true={vi="folds,options,cursor,curdir"}}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
full_name='viminfo', abbreviation='vi',
|
full_name='viminfo', abbreviation='vi',
|
||||||
|
67
test/functional/ex_cmds/mkview_spec.lua
Normal file
67
test/functional/ex_cmds/mkview_spec.lua
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
local lfs = require('lfs')
|
||||||
|
local helpers = require('test.functional.helpers')(after_each)
|
||||||
|
|
||||||
|
local clear = helpers.clear
|
||||||
|
local command = helpers.command
|
||||||
|
local get_pathsep = helpers.get_pathsep
|
||||||
|
local eq = helpers.eq
|
||||||
|
local funcs = helpers.funcs
|
||||||
|
local rmdir = helpers.rmdir
|
||||||
|
|
||||||
|
local file_prefix = 'Xtest-functional-ex_cmds-mkview_spec'
|
||||||
|
|
||||||
|
describe(':mkview', function()
|
||||||
|
local tmp_file_base = file_prefix .. '-tmpfile'
|
||||||
|
local local_dir = file_prefix .. '.d'
|
||||||
|
local view_dir = file_prefix .. '.view.d'
|
||||||
|
|
||||||
|
before_each(function()
|
||||||
|
clear()
|
||||||
|
lfs.mkdir(view_dir)
|
||||||
|
lfs.mkdir(local_dir)
|
||||||
|
end)
|
||||||
|
|
||||||
|
after_each(function()
|
||||||
|
-- Remove any views created in the view directory
|
||||||
|
rmdir(view_dir)
|
||||||
|
lfs.rmdir(local_dir)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('viewoption curdir restores local current directory', function()
|
||||||
|
local cwd_dir = funcs.getcwd()
|
||||||
|
local set_view_dir_command = 'set viewdir=' .. cwd_dir ..
|
||||||
|
get_pathsep() .. view_dir
|
||||||
|
|
||||||
|
-- By default the local current directory should save
|
||||||
|
command(set_view_dir_command)
|
||||||
|
command('edit ' .. tmp_file_base .. '1')
|
||||||
|
command('lcd ' .. local_dir)
|
||||||
|
command('mkview')
|
||||||
|
|
||||||
|
-- Create a new instance of Nvim to remove the 'lcd'
|
||||||
|
clear()
|
||||||
|
|
||||||
|
-- Disable saving the local current directory for the second view
|
||||||
|
command(set_view_dir_command)
|
||||||
|
command('set viewoptions-=curdir')
|
||||||
|
command('edit ' .. tmp_file_base .. '2')
|
||||||
|
command('lcd ' .. local_dir)
|
||||||
|
command('mkview')
|
||||||
|
|
||||||
|
-- Create a new instance of Nvim to test saved 'lcd' option
|
||||||
|
clear()
|
||||||
|
command(set_view_dir_command)
|
||||||
|
|
||||||
|
-- Load the view without a saved local current directory
|
||||||
|
command('edit ' .. tmp_file_base .. '2')
|
||||||
|
command('loadview')
|
||||||
|
-- The view's current directory should not have changed
|
||||||
|
eq(cwd_dir, funcs.getcwd())
|
||||||
|
-- Load the view with a saved local current directory
|
||||||
|
command('edit ' .. tmp_file_base .. '1')
|
||||||
|
command('loadview')
|
||||||
|
-- The view's local directory should have been saved
|
||||||
|
eq(cwd_dir .. get_pathsep() .. local_dir, funcs.getcwd())
|
||||||
|
end)
|
||||||
|
|
||||||
|
end)
|
Loading…
Reference in New Issue
Block a user