Skip to content

Sessions do not preserve script version for option holding expressions#20696

Open
illia-bobyr wants to merge 1 commit into
vim:masterfrom
illia-bobyr:pr/session-preserve-option-script-version
Open

Sessions do not preserve script version for option holding expressions#20696
illia-bobyr wants to merge 1 commit into
vim:masterfrom
illia-bobyr:pr/session-preserve-option-script-version

Conversation

@illia-bobyr

Copy link
Copy Markdown
Contributor
Problem:  Sessions do not preserve script version for option holding
          expressions
Solution: Remember script version for string options, and add a
          ":legacy" prefix for ":set"/":setlocal" calls when necessary

Since patch 9.2.0579 (":mksession, :mkview and :mkvimrc emit legacy Vim script") session files are marked as Vim9 script. A few options have Vim expressions as their values. When inserted their values literally into a Vim9 script, these expressions are now evaluated as Vim9 expressions. But the original value might have been set by a legacy script.

In order to be backward compatible and not break most of the existing file type plugin scripts, we need to consider the script version of the option value. If an option was set in a legacy script, or via "legacy set"/"legacy setlocal", we need to restore it using the "legacy" prefix as well.

Options are not marked as expression options, vs string options, vs bool options. We only know if an option is a bool, number or a string option. It seems safe to set bool and number options using Vim9 semantics. But for string options we do not know if an option value is a Vim expression. And so, if it was set by a legacy script we just use a conservative approach and prefix the "set" or "setlocal" command with "legacy" for all string options set in a legacy context.

Problem:  Sessions do not preserve script version for option holding
          expressions
Solution: Remember script version for string options, and add a
          ":legacy" prefix for ":set"/":setlocal" calls when necessary

Since patch 9.2.0579 (":mksession, :mkview and :mkvimrc emit legacy Vim
script") session files are marked as Vim9 script.  A few options have
Vim expressions as their values.  When inserted their values literally
into a Vim9 script, these expressions are now evaluated as Vim9
expressions.  But the original value might have been set by a legacy
script.

In order to be backward compatible and not break most of the existing
file type plugin scripts, we need to consider the script version of the
option value.  If an option was set in a legacy script, or via "legacy
set"/"legacy setlocal", we need to restore it using the "legacy" prefix
as well.

Options are not marked as expression options, vs string options, vs bool
options.  We only know if an option is a bool, number or a string
option.  It seems safe to set bool and number options using Vim9
semantics.  But for string options we do not know if an option value is
a Vim expression.  And so, if it was set by a legacy script we just
use a conservative approach and prefix the "set" or "setlocal" command
with "legacy" for all string options set in a legacy context.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant