mksession: always unix slashes "/" for filepaths

This commit is contained in:
Justin M. Keyes 2020-01-26 14:26:01 -08:00
parent c4f4719ced
commit 1c3ca4f18f
6 changed files with 19 additions and 26 deletions

View File

@ -173,6 +173,9 @@ if (-not $NoTests) {
# Functional tests # Functional tests
# The $LastExitCode from MSBuild can't be trusted # The $LastExitCode from MSBuild can't be trusted
$failed = $false $failed = $false
# Run only this test file:
# $env:TEST_FILE = "test\functional\foo.lua"
cmake --build . --config $cmakeBuildType --target functionaltest -- $cmakeGeneratorArgs 2>&1 | cmake --build . --config $cmakeBuildType --target functionaltest -- $cmakeGeneratorArgs 2>&1 |
foreach { $failed = $failed -or foreach { $failed = $failed -or
$_ -match 'functional tests failed with error'; $_ } $_ -match 'functional tests failed with error'; $_ }

View File

@ -339,21 +339,6 @@ window, move the cursor to the filename and press "O". Double clicking with
the mouse will also do this. the mouse will also do this.
UNIX AND MS-WINDOWS
Some people have to do work on MS-Windows systems one day and on Unix another
day. If you are one of them, consider adding "slash" and "unix" to
'sessionoptions'. The session files will then be written in a format that can
be used on both systems. This is the command to put in your |init.vim| file:
>
:set sessionoptions+=unix,slash
Vim will use the Unix format then, because the MS-Windows Vim can read and
write Unix files, but Unix Vim can't read MS-Windows format session files.
Similarly, MS-Windows Vim understands file names with / to separate names, but
Unix Vim doesn't understand \.
SESSIONS AND SHADA SESSIONS AND SHADA
Sessions store many things, but not the position of marks, contents of Sessions store many things, but not the position of marks, contents of

View File

@ -8089,6 +8089,10 @@ static void close_redir(void)
do { if (FAIL == put_line(fd, (s))) { return FAIL; } } while (0) do { if (FAIL == put_line(fd, (s))) { return FAIL; } } while (0)
/// ":mkexrc", ":mkvimrc", ":mkview", ":mksession". /// ":mkexrc", ":mkvimrc", ":mkview", ":mksession".
///
/// Legacy 'sessionoptions' flags SSOP_UNIX, SSOP_SLASH are always enabled.
/// - SSOP_UNIX: line-endings are always LF
/// - SSOP_SLASH: filenames are always written with "/" slash
static void ex_mkrc(exarg_T *eap) static void ex_mkrc(exarg_T *eap)
{ {
FILE *fd; FILE *fd;
@ -9112,6 +9116,8 @@ char_u *expand_sfile(char_u *arg)
/// Writes commands for restoring the current buffers, for :mksession. /// Writes commands for restoring the current buffers, for :mksession.
/// ///
/// Legacy 'sessionoptions' flags SSOP_UNIX, SSOP_SLASH are always enabled.
///
/// @param dirnow Current directory name /// @param dirnow Current directory name
/// @param fd File descriptor to write to /// @param fd File descriptor to write to
/// ///
@ -9840,12 +9846,10 @@ static char *ses_escape_fname(char *name, unsigned *flagp)
char *p; char *p;
char *sname = (char *)home_replace_save(NULL, (char_u *)name); char *sname = (char *)home_replace_save(NULL, (char_u *)name);
if (*flagp & SSOP_SLASH) { // Always SSOP_SLASH: change all backslashes to forward slashes.
// change all backslashes to forward slashes for (p = sname; *p != NUL; MB_PTR_ADV(p)) {
for (p = sname; *p != NUL; MB_PTR_ADV(p)) { if (*p == '\\') {
if (*p == '\\') { *p = '/';
*p = '/';
}
} }
} }

View File

@ -577,8 +577,8 @@ static char *(p_ssop_values[]) = {
# define SSOP_HELP 0x040 # define SSOP_HELP 0x040
# define SSOP_BLANK 0x080 # define SSOP_BLANK 0x080
# define SSOP_GLOBALS 0x100 # define SSOP_GLOBALS 0x100
# define SSOP_SLASH 0x200 # define SSOP_SLASH 0x200 // Deprecated, always set.
# define SSOP_UNIX 0x400 // Deprecated, not used. # define SSOP_UNIX 0x400 // Deprecated, always set.
# define SSOP_SESDIR 0x800 # define SSOP_SESDIR 0x800
# define SSOP_CURDIR 0x1000 # define SSOP_CURDIR 0x1000
# define SSOP_FOLDS 0x2000 # define SSOP_FOLDS 0x2000

View File

@ -96,7 +96,8 @@ describe(':mksession', function()
it('restores CWD for :terminal buffers #11288', function() it('restores CWD for :terminal buffers #11288', function()
local cwd_dir = funcs.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '') local cwd_dir = funcs.fnamemodify('.', ':p:~'):gsub([[[\/]*$]], '')
local session_path = cwd_dir..get_pathsep()..session_file cwd_dir = cwd_dir:gsub([[\]], '/') -- :mksession always uses unix slashes.
local session_path = cwd_dir..'/'..session_file
command('cd '..tab_dir) command('cd '..tab_dir)
command('terminal echo $PWD') command('terminal echo $PWD')
@ -108,7 +109,7 @@ describe(':mksession', function()
clear() clear()
command('silent source '..session_path) command('silent source '..session_path)
local expected_cwd = cwd_dir..get_pathsep()..tab_dir local expected_cwd = cwd_dir..'/'..tab_dir
matches('^term://'..pesc(expected_cwd)..'//%d+:', funcs.expand('%')) matches('^term://'..pesc(expected_cwd)..'//%d+:', funcs.expand('%'))
command('qall!') command('qall!')
end) end)

View File

@ -794,7 +794,7 @@ function module.alter_slashes(obj)
end end
return ret return ret
else else
assert(false, 'Could only alter slashes for tables of strings and strings') assert(false, 'expected string or table of strings, got '..type(obj))
end end
end end