When modelinescrict is enabled (which is the default), explicitly setting nomodeline in a file's modeline does not take effect. Vim continues to parse and apply other options from the modeline, contradicting the documented behavior.
I believe that setting nomodeline in a modeline should disable further processing of that modeline (i.e., ignore all other settings within it). This should be respected regardless of whether modelinescrict is enabled.
9.2.0421
MS-Windows 11
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
Related: #20028 which I also think is worth adding support.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
@chrisbra, please add modeline to modelinestrict.
This is mainly to disable it in certain files where it might be incorrectly matched. I think this is very reasonable and won't cause any security issues.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
I don't understand the use case. Setting nomodeline in a modeline is too late when reading the current file. By that time the modeline is already being processed. That means setting nomodeline will only be affective when loading this particular file the next time. That sounds wrong.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
I think this particular patch would allow to disable modelines in a modeline. But I am not sure of the use case yet and as such I am a bit hesitant to include it.
@@ -1590,7 +1589,12 @@ is_modeline_whitelisted(char *name) * if it can be changed. */ static int -validate_opt_idx(int opt_idx, int opt_flags, long_u flags, char **errmsg) +validate_opt_idx( + int opt_idx, + int opt_flags, + long_u flags, + char **errmsg, + set_prefix_T prefix) { // Skip all options that are not window-local (used when showing // an already loaded buffer in a window). @@ -1618,9 +1622,14 @@ validate_opt_idx(int opt_idx, int opt_flags, long_u flags, char **errmsg) } // When 'modelinestrict' is on, only whitelisted options may be // set from a modeline. Silently skip others. - if (p_mlstr && opt_idx >= 0 - && !is_modeline_whitelisted(options[opt_idx].fullname)) - return FAIL; + if (p_mlstr && opt_idx >= 0) + { + // Allow disabling modelines + if (options[opt_idx].var == (char_u *)&p_ml && prefix == PREFIX_NO) + return OK; + else if (!is_modeline_whitelisted(options[opt_idx].fullname)) + return FAIL; + } #ifdef FEAT_DIFF // In diff mode some options are overruled. This avoids that // 'foldmethod' becomes "marker" instead of "diff" and that @@ -2865,7 +2874,7 @@ do_set_option( } // Make sure the option value can be changed. - if (validate_opt_idx(opt_idx, opt_flags, flags, &errmsg) == FAIL) + if (validate_opt_idx(opt_idx, opt_flags, flags, &errmsg, prefix) == FAIL) goto skip; int cp_val = p_cp;
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
I think add it to whitelist is fine, cause when it is off it can’t be open by modeline again.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()