annotate runtime/ftplugin/mp.vim @ 34134:8ae680be2a51

runtime(ftplugin): Use "*" browsefilter pattern to match "All Files" Commit: https://github.com/vim/vim/commit/93197fde0f1db09b1e495cf3eb14a8f42c318b80 Author: Doug Kearns <dougkearns@gmail.com> Date: Sun Jan 14 20:59:02 2024 +0100 runtime(ftplugin): Use "*" browsefilter pattern to match "All Files" Problem: The "*.*" browsefilter pattern only matches all files on Windows (Daryl Lee) Solution: Use "*" to filter on all platforms but keep "*.*" as the label text on Windows. (Fixes #12685, Doug Kearns) The *.* browsefilter pattern used to match "All Files" on Windows is a legacy of the DOS 8.3 filename wildcard matching algorithm. For reasons of backward compatibility this still works on Windows to match all files, even those without an extension. However, this pattern only matches filenames containing a dot on other platforms. This often makes files without an extension difficult to access from the file dialog, e.g., "Makefile" On Windows it is still standard practice to use "*.*" for the filter label so ftplugins should use "All Files (*.*)" on Windows and "All Files (*)" on other platforms. This matches Vim's default browsefilter values. This commit also normalises the browsefilter conditional test to check for the Win32 and GTK GUI features and an unset b:browsefilter. closes: #12759 Signed-off-by: Doug Kearns <dougkearns@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sun, 14 Jan 2024 21:15:03 +0100
parents 2acb87ee55fc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
1 vim9script
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
2
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
3 # Vim filetype plugin file
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
4 # Language: MetaPost
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
5 # Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com>
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
6 # Former Maintainers: Nikolai Weibull <now@bitwi.se>
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
7 # Latest Revision: 2022 Aug 12
34134
8ae680be2a51 runtime(ftplugin): Use "*" browsefilter pattern to match "All Files"
Christian Brabandt <cb@256bit.org>
parents: 29756
diff changeset
8 # 2024 Jan 14 by Vim Project (browsefilter)
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 7
diff changeset
9
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 7
diff changeset
10 if exists("b:did_ftplugin")
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 7
diff changeset
11 finish
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 7
diff changeset
12 endif
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
13
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
14 b:did_ftplugin = 1
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
15 b:undo_ftplugin = "setl com< cms< fo< sua< inc< def< ofu<"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
17 setlocal comments=:%
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
18 setlocal commentstring=%\ %s
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
19 setlocal formatoptions+=cjroql2
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
20 setlocal formatoptions-=t
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
21 setlocal omnifunc=syntaxcomplete#Complete
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
22 setlocal suffixesadd=.mp,.mpiv,.mpvi,.mpxl
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents: 1217
diff changeset
23
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
24 &l:include = '\<\%(input\|loadmodule\)\>' # loadmodule is from MetaFun
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
25 &l:define = '\<\%(let\|newinternal\|interim\|def\|vardef\)\>\|\<\%(primary\|secondary\|tertiary\)def\>\s*[^ .]\+'
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
26
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
27 g:omni_syntax_group_include_mp = 'mf\w\+,mp\w\+,metafun\w\+'
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
28 g:omni_syntax_group_exclude_mp = 'mfTodoComment'
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 7
diff changeset
29
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
30 var fignum: number
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
31
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
32 def FixBeginfigs()
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
33 fignum = 1
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
34 g/^\s*beginfig(\d*)\s*;\(\s*%.*\)\=$/s/^.\{-};/\='beginfig(' .. fignum .. ');'/ | ++fignum
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
35 enddef
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
36
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
37 command! -buffer -nargs=0 -bar FixBeginfigs FixBeginfigs()
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 7
diff changeset
38
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
39 if exists("g:loaded_matchit") && !exists("b:match_words")
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
40 b:match_ignorecase = 0
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
41 b:match_skip = 'synIDattr(synID(line("."), col("."), 1), "name") =~# "^mf\\%(Comment\\|String\\|\\)$\\|^mpTeXinsert$"'
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
42 b:match_words = '\<if\>:\<else\%[if]\>:\<fi\>,'
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
43 .. '\<for\%(\|suffixes\|ever\)\>:\<exit\%(if\|unless\)\>:\<endfor\>,'
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
44 .. '\<\%(\|var\|primary\|secondary\|tertiary\)def\>:\<enddef\>,'
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
45 .. '\<begin\(\a\+\)\>:end\1,'
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
46 .. '\<beginlogochar\>:\<endchar\>'
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
47 b:undo_ftplugin ..= "| unlet! b:match_ignorecase b:match_words b:match_skip"
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 7
diff changeset
48 endif
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents: 1217
diff changeset
49
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
50 if !get(g:, 'no_mp_maps', 0) && !get(g:, 'no_plugin_maps', 0)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
51 const mp_regex = {
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
52 'beginsection': '^\s*\%(\%(\|var\|primary\|secondary\|tertiary\)def\|begin\%(fig\|char\|logochar\|glyph\|graph\)\)\>',
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
53 'endsection': '^\s*\%(enddef\|end\%(fig\|char\|glyph\|graph\)\)\>',
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
54 'beginblock': '^\s*\%(begingroup\|if\|for\%(\|suffixes\|ever\)\)\>',
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
55 'endblock': '^\s*\%(endgroup\|fi\|endfor\)\>'}
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 1698
diff changeset
56
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
57 def MoveAround(count: number, what: string, flags: string)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
58 search(mp_regex[what], flags .. 's') # 's' sets previous context mark
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
59 var i = 2
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
60 while i <= count
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
61 search(mp_regex[what], flags)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
62 i += 1
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
63 endwhile
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
64 enddef
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 1698
diff changeset
65
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
66 # Macros to move around
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
67 nnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr>
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
68 vnoremap <silent><buffer> [[ <scriptcmd>MoveAround(v:count1, "beginsection", "bW")<cr>
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
69 nnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr>
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
70 vnoremap <silent><buffer> ]] <scriptcmd>MoveAround(v:count1, "beginsection", "W") <cr>
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
71 nnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr>
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
72 vnoremap <silent><buffer> [] <scriptcmd>MoveAround(v:count1, "endsection", "bW")<cr>
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
73 nnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr>
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
74 vnoremap <silent><buffer> ][ <scriptcmd>MoveAround(v:count1, "endsection", "W") <cr>
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
75 nnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr>
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
76 vnoremap <silent><buffer> [{ <scriptcmd>MoveAround(v:count1, "beginblock", "bW")<cr>
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
77 nnoremap <silent><buffer> ]} <scriptcmd>MoveAround(v:count1, "endblock", "W") <cr>
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
78 vnoremap <silent><buffer> ]} <scriptcmd>MoveAround(v:count1, "endblock", "W") <cr>
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 1698
diff changeset
79
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
80 for mapping in ["[[", "]]", "[]", "][", "[{", "]}"]
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
81 b:undo_ftplugin ..= printf(" | silent! execute 'nunmap <buffer> %s'", mapping)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
82 b:undo_ftplugin ..= printf(" | silent! execute 'vunmap <buffer> %s'", mapping)
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
83 endfor
10244
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 1698
diff changeset
84 endif
876fbdd84e52 commit https://github.com/vim/vim/commit/2ec618c9feac4573b154510236ad8121c77d0eca
Christian Brabandt <cb@256bit.org>
parents: 1698
diff changeset
85
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
86 if (has('gui_win32') || has('gui_gtk')) && !exists('b:browsefilter')
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
87 b:browsefilter = "MetaPost Source Files (*.mp)\t*.mp\n"
34134
8ae680be2a51 runtime(ftplugin): Use "*" browsefilter pattern to match "All Files"
Christian Brabandt <cb@256bit.org>
parents: 29756
diff changeset
88 if has("win32")
8ae680be2a51 runtime(ftplugin): Use "*" browsefilter pattern to match "All Files"
Christian Brabandt <cb@256bit.org>
parents: 29756
diff changeset
89 b:browsefilter ..= "All Files (*.*)\t*\n"
8ae680be2a51 runtime(ftplugin): Use "*" browsefilter pattern to match "All Files"
Christian Brabandt <cb@256bit.org>
parents: 29756
diff changeset
90 else
8ae680be2a51 runtime(ftplugin): Use "*" browsefilter pattern to match "All Files"
Christian Brabandt <cb@256bit.org>
parents: 29756
diff changeset
91 b:browsefilter ..= "All Files (*)\t*\n"
8ae680be2a51 runtime(ftplugin): Use "*" browsefilter pattern to match "All Files"
Christian Brabandt <cb@256bit.org>
parents: 29756
diff changeset
92 endif
29756
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
93 b:undo_ftplugin ..= ' | unlet! b:browsefilter'
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
94 endif
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
95
2acb87ee55fc Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 10261
diff changeset
96 # vim: sw=2 fdm=marker