refactor(defaults): do not use C specific default values for options (#22500)

The options 'path', 'include', and 'define' all use C-specific default
values. This may have made sense a long time ago when Vim was mostly
used just for writing C, but this is no longer the case, and we have
ample support for filetype specific configuration. Make the default
values of these options empty and move the C-specific values into a
filetype plugin where they belong.

Co-authored-by: zeertzjq <zeertzjq@outlook.com>
This commit is contained in:
Gregory Anders 2023-06-06 11:26:29 -05:00 committed by GitHub
parent 4382d2ed56
commit fcfe535e98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 15 deletions

View File

@ -1396,8 +1396,8 @@ A jump table for the options with a short description can be found at |Q_op|.
'commentstring' 'cms' string (default "")
local to buffer
A template for a comment. The "%s" in the value is replaced with the
comment text. Currently only used to add markers for folding, see
|fold-marker|.
comment text. For example, C uses "/*%s*/". Currently only used to
add markers for folding, see |fold-marker|.
*'complete'* *'cpt'* *E535*
'complete' 'cpt' string (default: ".,w,b,u,t")
@ -1861,7 +1861,7 @@ A jump table for the options with a short description can be found at |Q_op|.
'indentexpr'.
*'define'* *'def'*
'define' 'def' string (default "^\s*#\s*define")
'define' 'def' string (default "")
global or local to buffer |global-local|
Pattern to be used to find a macro definition. It is a search
pattern, just like for the "/" command. This option is used for the
@ -1870,8 +1870,7 @@ A jump table for the options with a short description can be found at |Q_op|.
{match with 'define'}{non-ID chars}{defined name}{non-ID char}
See |option-backslash| about inserting backslashes to include a space
or backslash.
The default value is for C programs. For C++ this value would be
useful, to include const type declarations: >
For C++ this value would be useful, to include const type declarations: >
^\(#\s*define\|[a-z]*\s*const\s*[a-z]*\)
< You can also use "\ze" just before the name and continue the pattern
to check what is following. E.g. for Javascript, if a function is
@ -3309,12 +3308,11 @@ A jump table for the options with a short description can be found at |Q_op|.
|Command-line-mode| is done.
*'include'* *'inc'*
'include' 'inc' string (default "^\s*#\s*include")
'include' 'inc' string (default "")
global or local to buffer |global-local|
Pattern to be used to find an include command. It is a search
pattern, just like for the "/" command (See |pattern|). The default
value is for C programs. This option is used for the commands "[i",
"]I", "[d", etc.
pattern, just like for the "/" command (See |pattern|). This option
is used for the commands "[i", "]I", "[d", etc.
Normally the 'isfname' option is used to recognize the file name that
comes after the matched pattern. But if "\zs" appears in the pattern
then the text matched from "\zs" to the end, or until "\ze" if it
@ -4489,8 +4487,7 @@ A jump table for the options with a short description can be found at |Q_op|.
Only normal file name characters can be used, "/\*?[|<>" are illegal.
*'path'* *'pa'* *E343* *E345* *E347* *E854*
'path' 'pa' string (default on Unix: ".,/usr/include,,"
other systems: ".,,")
'path' 'pa' string (default: ".,,")
global or local to buffer |global-local|
This is a list of directories which will be searched when using the
|gf|, [f, ]f, ^Wf, |:find|, |:sfind|, |:tabfind| and other commands,

View File

@ -37,6 +37,7 @@ Defaults *nvim-defaults*
- 'commentstring' defaults to ""
- 'compatible' is always disabled
- 'complete' excludes "i"
- 'define' defaults to "". The C ftplugin sets it to "^\\s*#\\s*define"
- 'directory' defaults to ~/.local/state/nvim/swap// (|xdg|), auto-created
- 'display' defaults to "lastline"
- 'encoding' is UTF-8 (cf. 'fileencoding' for file-content encoding)
@ -46,6 +47,7 @@ Defaults *nvim-defaults*
- 'hidden' is enabled
- 'history' defaults to 10000 (the maximum)
- 'hlsearch' is enabled
- 'include' defaults to "". The C ftplugin sets it to "^\\s*#\\s*include"
- 'incsearch' is enabled
- 'joinspaces' is disabled
- 'langnoremap' is enabled
@ -55,6 +57,7 @@ Defaults *nvim-defaults*
- 'mouse' defaults to "nvi"
- 'mousemodel' defaults to "popup_setpos"
- 'nrformats' defaults to "bin,hex"
- 'path' defaults to ".,,". The C ftplugin adds "/usr/include" if it exists.
- 'ruler' is enabled
- 'sessionoptions' includes "unix,slash", excludes "options"
- 'shortmess' includes "CF", excludes "S"

View File

@ -1 +1,14 @@
-- These are the default option values in Vim, but not in Nvim, so must be set explicitly.
vim.bo.commentstring = '/*%s*/'
vim.bo.define = '^\\s*#\\s*define'
vim.bo.include = '^\\s*#\\s*include'
if vim.fn.isdirectory('/usr/include') == 1 then
vim.cmd([[
setlocal path^=/usr/include
setlocal path-=.
setlocal path^=.
]])
end
vim.b.undo_ftplugin = vim.b.undo_ftplugin .. '|setl path<'

View File

@ -570,7 +570,7 @@ return {
alloced=true,
redraw={'curswant'},
varname='p_def',
defaults={if_true="^\\s*#\\s*define"}
defaults={if_true=""}
},
{
full_name='delcombine', abbreviation='deco',
@ -1227,7 +1227,7 @@ return {
type='string', scope={'global', 'buffer'},
alloced=true,
varname='p_inc',
defaults={if_true="^\\s*#\\s*include"}
defaults={if_true=""}
},
{
full_name='includeexpr', abbreviation='inex',
@ -1815,7 +1815,7 @@ return {
deny_duplicates=true,
expand=true,
varname='p_path',
defaults={if_true=".,/usr/include,,"}
defaults={if_true=".,,"}
},
{
full_name='preserveindent', abbreviation='pi',

View File

@ -706,7 +706,7 @@ describe('api/buf', function()
nvim('set_option_value', 'define', 'test', {buf = 0})
eq('test', nvim('get_option_value', 'define', {buf = 0}))
-- Doesn't change the global value
eq([[^\s*#\s*define]], nvim('get_option_value', 'define', {scope='global'}))
eq("", nvim('get_option_value', 'define', {scope='global'}))
end)
it('returns values for unset local options', function()

View File

@ -3,12 +3,14 @@ if exists('s:did_load')
set backspace=
set commentstring=/*%s*/
set complete=.,w,b,u,t,i
set define=^\\s*#\\s*define
set directory&
set directory^=.
set display=
set fillchars=vert:\|,foldsep:\|,fold:-
set formatoptions=tcq
set fsync
set include=^\\s*#\\s*include
set laststatus=1
set listchars=eol:$
set joinspaces