diff options
-rw-r--r-- | runtime/autoload/hare.vim | 26 | ||||
-rw-r--r-- | runtime/compiler/hare.vim | 23 | ||||
-rw-r--r-- | runtime/doc/filetype.txt | 6 | ||||
-rw-r--r-- | runtime/doc/ft_hare.txt | 77 | ||||
-rw-r--r-- | runtime/doc/lsp.txt | 2 | ||||
-rw-r--r-- | runtime/ftplugin/deb822sources.vim | 4 | ||||
-rw-r--r-- | runtime/ftplugin/debcontrol.vim | 7 | ||||
-rw-r--r-- | runtime/ftplugin/debsources.vim | 4 | ||||
-rw-r--r-- | runtime/ftplugin/hare.vim | 56 | ||||
-rw-r--r-- | runtime/ftplugin/haredoc.vim | 44 | ||||
-rw-r--r-- | runtime/indent/hare.vim | 31 | ||||
-rw-r--r-- | runtime/lua/vim/filetype.lua | 2 | ||||
-rw-r--r-- | runtime/lua/vim/filetype/detect.lua | 24 | ||||
-rw-r--r-- | runtime/lua/vim/health.lua | 108 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/client.lua | 3 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/health.lua | 5 | ||||
-rw-r--r-- | runtime/lua/vim/provider/health.lua | 150 | ||||
-rw-r--r-- | runtime/lua/vim/snippet.lua | 2 | ||||
-rw-r--r-- | runtime/syntax/hare.vim | 188 | ||||
-rw-r--r-- | runtime/syntax/haredoc.vim | 32 | ||||
-rw-r--r-- | runtime/syntax/shared/debversions.vim | 9 | ||||
-rw-r--r-- | test/old/testdir/test_filetype.vim | 35 |
22 files changed, 569 insertions, 269 deletions
diff --git a/runtime/autoload/hare.vim b/runtime/autoload/hare.vim new file mode 100644 index 0000000000..c4581fccf9 --- /dev/null +++ b/runtime/autoload/hare.vim @@ -0,0 +1,26 @@ +" Vim autoload file. +" Language: Hare +" Maintainer: Amelia Clarke <selene@perilune.dev> +" Last Updated: 2024-05-10 +" Upstream: https://git.sr.ht/~sircmpwn/hare.vim + +" Attempt to find the directory for a given Hare module. +function hare#FindModule(str) + let path = substitute(trim(a:str, ':', 2), '::', '/', 'g') + let dir = finddir(path) + while !empty(path) && empty(dir) + let path = substitute(path, '/\?\h\w*$', '', '') + let dir = finddir(path) + endwhile + return dir +endfunction + +" Return the value of HAREPATH if it exists. Otherwise use a reasonable default. +function hare#GetPath() + if empty($HAREPATH) + return '/usr/src/hare/stdlib,/usr/src/hare/third-party' + endif + return substitute($HAREPATH, ':', ',', 'g') +endfunction + +" vim: et sts=2 sw=2 ts=8 diff --git a/runtime/compiler/hare.vim b/runtime/compiler/hare.vim index c98bbb9c63..33edb3a281 100644 --- a/runtime/compiler/hare.vim +++ b/runtime/compiler/hare.vim @@ -1,28 +1,29 @@ -" Vim compiler file -" Compiler: Hare Compiler -" Maintainer: Amelia Clarke <me@rsaihe.dev> -" Last Change: 2022-09-21 -" 2024 Apr 05 by The Vim Project (removed :CompilerSet definition) +" Vim compiler file. +" Compiler: Hare +" Maintainer: Amelia Clarke <selene@perilune.dev> +" Last Change: 2024-05-23 +" Upstream: https://git.sr.ht/~sircmpwn/hare.vim -if exists("g:current_compiler") +if exists('current_compiler') finish endif -let g:current_compiler = "hare" +let current_compiler = 'hare' let s:cpo_save = &cpo set cpo&vim -if filereadable("Makefile") || filereadable("makefile") +if filereadable('Makefile') || filereadable('makefile') CompilerSet makeprg=make else CompilerSet makeprg=hare\ build endif CompilerSet errorformat= - \Error\ %f:%l:%c:\ %m, - \Syntax\ error:\ %.%#\ at\ %f:%l:%c\\,\ %m, + \%f:%l:%c:\ syntax\ error:\ %m, + \%f:%l:%c:\ error:\ %m, \%-G%.%# let &cpo = s:cpo_save unlet s:cpo_save -" vim: tabstop=2 shiftwidth=2 expandtab + +" vim: et sts=2 sw=2 ts=8 diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt index 5eae78744c..eddf14014a 100644 --- a/runtime/doc/filetype.txt +++ b/runtime/doc/filetype.txt @@ -602,6 +602,12 @@ The mapping can be disabled with: > let g:no_gprof_maps = 1 +HARE *ft-hare* + +Since the text for this plugin is rather long it has been put in a separate +file: |ft_hare.txt|. + + JAVA *ft-java-plugin* Whenever the variable "g:ftplugin_java_source_path" is defined and its value diff --git a/runtime/doc/ft_hare.txt b/runtime/doc/ft_hare.txt new file mode 100644 index 0000000000..937c5e0961 --- /dev/null +++ b/runtime/doc/ft_hare.txt @@ -0,0 +1,77 @@ +*ft_hare.txt* Support for the Hare programming language + +============================================================================== +CONTENTS *hare* + +1. Introduction |hare-intro| +2. Filetype plugin |hare-plugin| +3. Settings |hare-settings| + +============================================================================== +INTRODUCTION *hare-intro* + +This plugin provides syntax highlighting, indentation, and other functionality +for the Hare programming language. Support is also provided for README files +inside Hare modules, but this must be enabled by setting |g:filetype_haredoc|. + +============================================================================== +FILETYPE PLUGIN *hare-plugin* + +This plugin automatically sets the value of 'path' to include the contents of +the HAREPATH environment variable, allowing commands such as |gf| to directly +open standard library or third-party modules. If HAREPATH is not set, it +defaults to the recommended paths for most Unix-like filesystems, namely +/usr/src/hare/stdlib and /usr/src/hare/third-party. + +============================================================================== +SETTINGS *hare-settings* + +This plugin provides a small number of variables that you can define in your +vimrc to configure its behavior. + + *g:filetype_haredoc* +This plugin is able to automatically detect Hare modules and set the "haredoc" +filetype for any README files. As the recursive directory search used as a +heuristic has a minor performance impact, this feature is disabled by default +and must be specifically opted into: > + let g:filetype_haredoc = 1 +< +See |g:haredoc_search_depth| for ways to tweak the searching behavior. + + *g:hare_recommended_style* +The following options are set by default, in accordance with the official Hare +style guide: > + setlocal noexpandtab + setlocal shiftwidth=0 + setlocal softtabstop=0 + setlocal tabstop=8 + setlocal textwidth=80 +< +To disable this behavior: > + let g:hare_recommended_style = 0 +< + *g:hare_space_error* +By default, trailing whitespace and tabs preceded by space characters are +highlighted as errors. This is automatically turned off when in insert mode. +To disable this highlighting completely: > + let g:hare_space_error = 0 +< + *g:haredoc_search_depth* +By default, when |g:filetype_haredoc| is enabled, only the current directory +and its immediate subdirectories are searched for Hare files. The maximum +search depth may be adjusted with: > + let g:haredoc_search_depth = 2 +< + Value Effect~ + 0 Only search the current directory. + 1 Search the current directory and immediate + subdirectories. + 2 Search the current directory and two levels of + subdirectories. + +The maximum search depth can be set to any integer, but using values higher +than 2 is not recommended, and will likely provide no tangible benefit in most +situations. + +============================================================================== + vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt index 50fffca497..a66b577b11 100644 --- a/runtime/doc/lsp.txt +++ b/runtime/doc/lsp.txt @@ -996,7 +996,7 @@ Lua module: vim.lsp.client *lsp-client* if the client supports workspace folders. It can be `null` if the client supports workspace folders but none are configured. - • {root_dir} (`string`) + • {root_dir} (`string?`) • {attached_buffers} (`table<integer,true>`) • {commands} (`table<string,fun(command: lsp.Command, ctx: table)>`) Table of command name to function which is diff --git a/runtime/ftplugin/deb822sources.vim b/runtime/ftplugin/deb822sources.vim index 4936f42bf9..31c81b1a5d 100644 --- a/runtime/ftplugin/deb822sources.vim +++ b/runtime/ftplugin/deb822sources.vim @@ -1,6 +1,6 @@ " Language: Debian sources.list " Maintainer: Debian Vim Maintainers <team+vim@tracker.debian.org> -" Last Change: 2024 Mar 20 +" Last Change: 2024 May 25 " License: Vim License " URL: https://salsa.debian.org/vim-team/vim-debian/blob/main/ftplugin/deb822sources.vim @@ -10,7 +10,7 @@ endif let b:did_ftplugin=1 setlocal comments=:# -setlocal commentstring=#%s +setlocal commentstring=#\ %s setlocal formatoptions-=t let b:undo_ftplugin = 'setlocal comments< commentstring< formatoptions<' diff --git a/runtime/ftplugin/debcontrol.vim b/runtime/ftplugin/debcontrol.vim index bb710e597c..5b8292ba6e 100644 --- a/runtime/ftplugin/debcontrol.vim +++ b/runtime/ftplugin/debcontrol.vim @@ -2,7 +2,7 @@ " Language: Debian control files " Maintainer: Debian Vim Maintainers " Former Maintainer: Pierre Habouzit <madcoder@debian.org> -" Last Change: 2023 Jan 16 +" Last Change: 2024 May 25 " URL: https://salsa.debian.org/vim-team/vim-debian/blob/main/ftplugin/debcontrol.vim " Do these settings once per buffer @@ -19,8 +19,11 @@ if exists('g:debcontrol_fold_enable') endif setlocal textwidth=0 +setlocal comments=:# +setlocal commentstring=#\ %s + " Clean unloading -let b:undo_ftplugin = 'setlocal tw< foldmethod< foldexpr< foldtext<' +let b:undo_ftplugin = 'setlocal tw< foldmethod< foldexpr< foldtext< comments< commentstring<' " }}}1 diff --git a/runtime/ftplugin/debsources.vim b/runtime/ftplugin/debsources.vim index cbb4fafd22..2c5ea3599f 100644 --- a/runtime/ftplugin/debsources.vim +++ b/runtime/ftplugin/debsources.vim @@ -1,6 +1,6 @@ " Language: Debian sources.list " Maintainer: Debian Vim Maintainers <team+vim@tracker.debian.org> -" Last Change: 2023 Aug 30 +" Last Change: 2024 May 25 " License: Vim License " URL: https://salsa.debian.org/vim-team/vim-debian/blob/main/ftplugin/debsources.vim @@ -10,7 +10,7 @@ endif let b:did_ftplugin=1 setlocal comments=:# -setlocal commentstring=#%s +setlocal commentstring=#\ %s setlocal formatoptions-=t let b:undo_ftplugin = 'setlocal comments< commentstring< formatoptions<' diff --git a/runtime/ftplugin/hare.vim b/runtime/ftplugin/hare.vim index 0200ba5913..422bb7b4e8 100644 --- a/runtime/ftplugin/hare.vim +++ b/runtime/ftplugin/hare.vim @@ -1,35 +1,59 @@ -" Vim filetype plugin -" Language: Hare -" Maintainer: Amelia Clarke <me@rsaihe.dev> -" Previous Maintainer: Drew DeVault <sir@cmpwn.com> -" Last Updated: 2022-09-28 -" 2023 Aug 28 by Vim Project (undo_ftplugin) +" Vim filetype plugin. +" Language: Hare +" Maintainer: Amelia Clarke <selene@perilune.dev> +" Last Updated: 2024-05-10 +" Upstream: https://git.sr.ht/~sircmpwn/hare.vim if exists('b:did_ftplugin') finish endif let b:did_ftplugin = 1 -" Formatting settings. -setlocal formatoptions-=t formatoptions+=croql/ +let s:cpo_save = &cpo +set cpo&vim + +" Set the default compiler. +compiler hare -" Miscellaneous. +" Formatting settings. setlocal comments=:// setlocal commentstring=//\ %s +setlocal formatlistpat=^\ \\?-\ +setlocal formatoptions+=croqnlj/ formatoptions-=t + +" Search for Hare modules. +setlocal include=^\\s*use\\> +setlocal includeexpr=hare#FindModule(v:fname) +setlocal isfname+=: setlocal suffixesadd=.ha -let b:undo_ftplugin = "setl cms< com< fo< sua<" +" Add HAREPATH to the default search paths. +setlocal path-=/usr/include,, +let &l:path .= ',' .. hare#GetPath() .. ',,' -" Hare recommended style. -if get(g:, "hare_recommended_style", 1) +let b:undo_ftplugin = 'setl cms< com< flp< fo< inc< inex< isf< pa< sua< mp<' + +" Follow the Hare style guide by default. +if get(g:, 'hare_recommended_style', 1) setlocal noexpandtab - setlocal shiftwidth=8 + setlocal shiftwidth=0 setlocal softtabstop=0 setlocal tabstop=8 setlocal textwidth=80 - let b:undo_ftplugin ..= " | setl et< sts< sw< ts< tw<" + let b:undo_ftplugin .= ' et< sts< sw< ts< tw<' endif -compiler hare +augroup hare.vim + autocmd! + + " Highlight whitespace errors by default. + if get(g:, 'hare_space_error', 1) + autocmd InsertEnter * hi link hareSpaceError NONE + autocmd InsertLeave * hi link hareSpaceError Error + endif +augroup END + +let &cpo = s:cpo_save +unlet s:cpo_save -" vim: et sw=2 sts=2 ts=8 +" vim: et sts=2 sw=2 ts=8 diff --git a/runtime/ftplugin/haredoc.vim b/runtime/ftplugin/haredoc.vim new file mode 100644 index 0000000000..69030b47ba --- /dev/null +++ b/runtime/ftplugin/haredoc.vim @@ -0,0 +1,44 @@ +" Vim filetype plugin. +" Language: Haredoc (Hare documentation format) +" Maintainer: Amelia Clarke <selene@perilune.dev> +" Last Updated: 2024-05-02 +" Upstream: https://git.sr.ht/~selene/hare.vim + +if exists('b:did_ftplugin') + finish +endif +let b:did_ftplugin = 1 + +let s:cpo_save = &cpo +set cpo&vim + +" Formatting settings. +setlocal comments=:\ +setlocal formatlistpat=^\ \\?-\ +setlocal formatoptions+=tnlj formatoptions-=c formatoptions-=q + +" Search for Hare modules. +setlocal includeexpr=hare#FindModule(v:fname) +setlocal isfname+=: +setlocal suffixesadd=.ha + +" Add HAREPATH to the default search paths. +setlocal path-=/usr/include,, +let &l:path .= ',' .. hare#GetPath() .. ',,' + +let b:undo_ftplugin = 'setl com< flp< fo< inex< isf< pa< sua<' + +" Follow the Hare style guide by default. +if get(g:, 'hare_recommended_style', 1) + setlocal noexpandtab + setlocal shiftwidth=0 + setlocal softtabstop=0 + setlocal tabstop=8 + setlocal textwidth=80 + let b:undo_ftplugin .= ' et< sts< sw< ts< tw<' +endif + +let &cpo = s:cpo_save +unlet s:cpo_save + +" vim: et sts=2 sw=2 ts=8 diff --git a/runtime/indent/hare.vim b/runtime/indent/hare.vim index 0a9d8dafd8..1b51d1e80a 100644 --- a/runtime/indent/hare.vim +++ b/runtime/indent/hare.vim @@ -1,19 +1,16 @@ " Vim indent file -" Language: Hare -" Maintainer: Amelia Clarke <me@rsaihe.dev> -" Last Change: 2022 Sep 22 -" 2023 Aug 28 by Vim Project (undo_indent) +" Language: Hare +" Maintainer: Amelia Clarke <selene@perilune.dev> +" Last Change: 2024-04-14 +" Upstream: https://git.sr.ht/~sircmpwn/hare.vim -if exists("b:did_indent") +if exists('b:did_indent') finish endif let b:did_indent = 1 -if !has("cindent") || !has("eval") - finish -endif - -setlocal cindent +let s:cpo_save = &cpo +set cpo&vim " L0 -> don't deindent labels " (s -> use one indent after a trailing ( @@ -41,7 +38,11 @@ setlocal cinwords=if,else,for,switch,match setlocal indentexpr=GetHareIndent() -let b:undo_indent = "setl cin< cino< cinw< inde< indk<" +let b:undo_indent = 'setl cino< cinw< inde< indk<' + +if exists('*GetHareIndent()') + finish +endif function! FloorCindent(lnum) return cindent(a:lnum) / shiftwidth() * shiftwidth() @@ -122,7 +123,8 @@ function! GetHareIndent() " Indent the body of a case. " If the previous line ended in a semicolon and the line before that was a " case, don't do any special indenting. - if prevline =~# '\v;\s*(//.*)?$' && prevprevline =~# '\v\=\>\s*(//.*)?$' && line !~# '\v^\s*}' + if prevline =~# '\v;\s*(//.*)?$' && prevprevline =~# '\v\=\>\s*(//.*)?$' + \ && line !~# '\v^\s*}' return indent(prevlnum) endif @@ -138,4 +140,7 @@ function! GetHareIndent() return l:indent endfunction -" vim: tabstop=2 shiftwidth=2 expandtab +let &cpo = s:cpo_save +unlet s:cpo_save + +" vim: et sw=2 sts=2 ts=8 diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index d1fdd0aa16..2ab6cc6059 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -1637,7 +1637,7 @@ local filename = { ['.xsdbcmdhistory'] = 'tcl', ['texmf.cnf'] = 'texmf', COPYING = 'text', - README = 'text', + README = detect_seq(detect.haredoc, 'text'), LICENSE = 'text', AUTHORS = 'text', tfrc = 'tf', diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua index ba86d8de5a..58d2666564 100644 --- a/runtime/lua/vim/filetype/detect.lua +++ b/runtime/lua/vim/filetype/detect.lua @@ -650,6 +650,30 @@ function M.header(_, bufnr) end end +--- Recursively search for Hare source files in a directory and any +--- subdirectories, up to a given depth. +--- @param dir string +--- @param depth number +--- @return boolean +local function is_hare_module(dir, depth) + depth = math.max(depth, 0) + for name, _ in vim.fs.dir(dir, { depth = depth + 1 }) do + if name:find('%.ha$') then + return true + end + end + return false +end + +--- @type vim.filetype.mapfn +function M.haredoc(path, _) + if vim.g.filetype_haredoc then + if is_hare_module(vim.fs.dirname(path), vim.g.haredoc_search_depth or 1) then + return 'haredoc' + end + end +end + --- @type vim.filetype.mapfn function M.html(_, bufnr) for _, line in ipairs(getlines(bufnr, 1, 10)) do diff --git a/runtime/lua/vim/health.lua b/runtime/lua/vim/health.lua index f40f04a064..afeba2ee9d 100644 --- a/runtime/lua/vim/health.lua +++ b/runtime/lua/vim/health.lua @@ -275,114 +275,6 @@ function M.error(msg, ...) collect_output(input) end -function M._provider_disabled(provider) - local loaded_var = 'loaded_' .. provider .. '_provider' - local v = vim.g[loaded_var] - if v == 0 then - M.info('Disabled (' .. loaded_var .. '=' .. v .. ').') - return true - end - return false -end - --- Handler for s:system() function. -local function system_handler(self, _, data, event) - if event == 'stderr' then - if self.add_stderr_to_output then - self.output = self.output .. table.concat(data, '') - else - self.stderr = self.stderr .. table.concat(data, '') - end - elseif event == 'stdout' then - self.output = self.output .. table.concat(data, '') - end -end - --- Attempts to construct a shell command from an args list. --- Only for display, to help users debug a failed command. -local function shellify(cmd) - if type(cmd) ~= 'table' then - return cmd - end - local escaped = {} - for i, v in ipairs(cmd) do - if v:match('[^A-Za-z_/.-]') then - escaped[i] = vim.fn.shellescape(v) - else - escaped[i] = v - end - end - return table.concat(escaped, ' ') -end - -function M._cmd_ok(cmd) - local out = vim.fn.system(cmd) - return vim.v.shell_error == 0, out -end - ---- Run a system command and timeout after 30 seconds. ---- ---- @param cmd table List of command arguments to execute ---- @param args? table Optional arguments: ---- - stdin (string): Data to write to the job's stdin ---- - stderr (boolean): Append stderr to stdout ---- - ignore_error (boolean): If true, ignore error output ---- - timeout (number): Number of seconds to wait before timing out (default 30) -function M._system(cmd, args) - args = args or {} - local stdin = args.stdin or '' - local stderr = vim.F.if_nil(args.stderr, false) - local ignore_error = vim.F.if_nil(args.ignore_error, false) - - local shell_error_code = 0 - local opts = { - add_stderr_to_output = stderr, - output = '', - stderr = '', - on_stdout = system_handler, - on_stderr = system_handler, - on_exit = function(_, data) - shell_error_code = data - end, - } - local jobid = vim.fn.jobstart(cmd, opts) - - if jobid < 1 then - local message = - string.format('Command error (job=%d): %s (in %s)', jobid, shellify(cmd), vim.uv.cwd()) - error(message) - return opts.output, 1 - end - - if stdin:find('^%s$') then - vim.fn.chansend(jobid, stdin) - end - - local res = vim.fn.jobwait({ jobid }, vim.F.if_nil(args.timeout, 30) * 1000) - if res[1] == -1 then - error('Command timed out: ' .. shellify(cmd)) - vim.fn.jobstop(jobid) - elseif shell_error_code ~= 0 and not ignore_error then - local emsg = string.format( - 'Command error (job=%d, exit code %d): %s (in %s)', - jobid, - shell_error_code, - shellify(cmd), - vim.uv.cwd() - ) - if opts.output:find('%S') then - emsg = string.format('%s\noutput: %s', emsg, opts.output) - end - if opts.stderr:find('%S') then - emsg = string.format('%s\nstderr: %s', emsg, opts.stderr) - end - error(emsg) - end - - -- return opts.output - return vim.trim(vim.fn.system(cmd)), shell_error_code -end - local path2name = function(path) if path:match('%.lua$') then -- Lua: transform "../lua/vim/lsp/health.lua" into "vim.lsp" diff --git a/runtime/lua/vim/lsp/client.lua b/runtime/lua/vim/lsp/client.lua index 4beb7fefda..58ea7d02b3 100644 --- a/runtime/lua/vim/lsp/client.lua +++ b/runtime/lua/vim/lsp/client.lua @@ -182,7 +182,7 @@ local validate = vim.validate --- It can be `null` if the client supports workspace folders but none are --- configured. --- @field workspace_folders lsp.WorkspaceFolder[]? ---- @field root_dir string +--- @field root_dir string? --- --- @field attached_buffers table<integer,true> --- @@ -470,7 +470,6 @@ function Client.create(config) _on_exit_cbs = ensure_list(config.on_exit), _on_attach_cbs = ensure_list(config.on_attach), _on_error_cb = config.on_error, - _root_dir = config.root_dir, _trace = get_trace(config.trace), --- Contains $/progress report messages. diff --git a/runtime/lua/vim/lsp/health.lua b/runtime/lua/vim/lsp/health.lua index b5dc710cc6..ffe595ab37 100644 --- a/runtime/lua/vim/lsp/health.lua +++ b/runtime/lua/vim/lsp/health.lua @@ -41,7 +41,10 @@ local function check_active_clients() end report_info(table.concat({ string.format('%s (id: %d)', client.name, client.id), - string.format(' Root directory: %s', vim.fn.fnamemodify(client.root_dir, ':~')), + string.format( + ' Root directory: %s', + client.root_dir and vim.fn.fnamemodify(client.root_dir, ':~') or nil + ), string.format(' Command: %s', cmd), string.format(' Settings: %s', vim.inspect(client.settings, { newline = '\n ' })), string.format( diff --git a/runtime/lua/vim/provider/health.lua b/runtime/lua/vim/provider/health.lua index 63e0da448a..d6932f651e 100644 --- a/runtime/lua/vim/provider/health.lua +++ b/runtime/lua/vim/provider/health.lua @@ -3,6 +3,112 @@ local iswin = vim.uv.os_uname().sysname == 'Windows_NT' local M = {} +local function cmd_ok(cmd) + local out = vim.fn.system(cmd) + return vim.v.shell_error == 0, out +end + +-- Attempts to construct a shell command from an args list. +-- Only for display, to help users debug a failed command. +local function shellify(cmd) + if type(cmd) ~= 'table' then + return cmd + end + local escaped = {} + for i, v in ipairs(cmd) do + if v:match('[^A-Za-z_/.-]') then + escaped[i] = vim.fn.shellescape(v) + else + escaped[i] = v + end + end + return table.concat(escaped, ' ') +end + +-- Handler for s:system() function. +local function system_handler(self, _, data, event) + if event == 'stderr' then + if self.add_stderr_to_output then + self.output = self.output .. table.concat(data, '') + else + self.stderr = self.stderr .. table.concat(data, '') + end + elseif event == 'stdout' then + self.output = self.output .. table.concat(data, '') + end +end + +--- @param cmd table List of command arguments to execute +--- @param args? table Optional arguments: +--- - stdin (string): Data to write to the job's stdin +--- - stderr (boolean): Append stderr to stdout +--- - ignore_error (boolean): If true, ignore error output +--- - timeout (number): Number of seconds to wait before timing out (default 30) +local function system(cmd, args) + args = args or {} + local stdin = args.stdin or '' + local stderr = vim.F.if_nil(args.stderr, false) + local ignore_error = vim.F.if_nil(args.ignore_error, false) + + local shell_error_code = 0 + local opts = { + add_stderr_to_output = stderr, + output = '', + stderr = '', + on_stdout = system_handler, + on_stderr = system_handler, + on_exit = function(_, data) + shell_error_code = data + end, + } + local jobid = vim.fn.jobstart(cmd, opts) + + if jobid < 1 then + local message = + string.format('Command error (job=%d): %s (in %s)', jobid, shellify(cmd), vim.uv.cwd()) + error(message) + return opts.output, 1 + end + + if stdin:find('^%s$') then + vim.fn.chansend(jobid, stdin) + end + + local res = vim.fn.jobwait({ jobid }, vim.F.if_nil(args.timeout, 30) * 1000) + if res[1] == -1 then + error('Command timed out: ' .. shellify(cmd)) + vim.fn.jobstop(jobid) + elseif shell_error_code ~= 0 and not ignore_error then + local emsg = string.format( + 'Command error (job=%d, exit code %d): %s (in %s)', + jobid, + shell_error_code, + shellify(cmd), + vim.uv.cwd() + ) + if opts.output:find('%S') then + emsg = string.format('%s\noutput: %s', emsg, opts.output) + end + if opts.stderr:find('%S') then + emsg = string.format('%s\nstderr: %s', emsg, opts.stderr) + end + error(emsg) + end + + -- return opts.output + return vim.trim(vim.fn.system(cmd)), shell_error_code +end + +local function provider_disabled(provider) + local loaded_var = 'loaded_' .. provider .. '_provider' + local v = vim.g[loaded_var] + if v == 0 then + health.info('Disabled (' .. loaded_var .. '=' .. v .. ').') + return true + end + return false +end + local function clipboard() health.start('Clipboard (optional)') @@ -10,7 +116,7 @@ local function clipboard() os.getenv('TMUX') and vim.fn.executable('tmux') == 1 and vim.fn.executable('pbpaste') == 1 - and not health._cmd_ok('pbpaste') + and not cmd_ok('pbpaste') then local tmux_version = string.match(vim.fn.system('tmux -V'), '%d+%.%d+') local advice = { @@ -40,7 +146,7 @@ end local function node() health.start('Node.js provider (optional)') - if health._provider_disabled('node') then + if provider_disabled('node') then return end @@ -60,7 +166,7 @@ local function node() end -- local node_v = vim.fn.split(system({'node', '-v'}), "\n")[1] or '' - local ok, node_v = health._cmd_ok({ 'node', '-v' }) + local ok, node_v = cmd_ok({ 'node', '-v' }) health.info('Node.js: ' .. node_v) if not ok or vim.version.lt(node_v, '6.0.0') then health.warn('Nvim node.js host does not support Node ' .. node_v) @@ -97,7 +203,7 @@ local function node() iswin and 'cmd /c ' .. manager .. ' info neovim --json' or manager .. ' info neovim --json' ) local latest_npm - ok, latest_npm = health._cmd_ok(vim.split(latest_npm_cmd, ' ')) + ok, latest_npm = cmd_ok(vim.split(latest_npm_cmd, ' ')) if not ok or latest_npm:find('^%s$') then health.error( 'Failed to run: ' .. latest_npm_cmd, @@ -115,7 +221,7 @@ local function node() local current_npm_cmd = { 'node', host, '--version' } local current_npm - ok, current_npm = health._cmd_ok(current_npm_cmd) + ok, current_npm = cmd_ok(current_npm_cmd) if not ok then health.error( 'Failed to run: ' .. table.concat(current_npm_cmd, ' '), @@ -143,7 +249,7 @@ end local function perl() health.start('Perl provider (optional)') - if health._provider_disabled('perl') then + if provider_disabled('perl') then return end @@ -162,7 +268,7 @@ local function perl() -- we cannot use cpanm that is on the path, as it may not be for the perl -- set with g:perl_host_prog - local ok = health._cmd_ok({ perl_exec, '-W', '-MApp::cpanminus', '-e', '' }) + local ok = cmd_ok({ perl_exec, '-W', '-MApp::cpanminus', '-e', '' }) if not ok then return { perl_exec, '"App::cpanminus" module is not installed' } end @@ -174,7 +280,7 @@ local function perl() 'my $app = App::cpanminus::script->new; $app->parse_options ("--info", "-q", "Neovim::Ext"); exit $app->doit', } local latest_cpan - ok, latest_cpan = health._cmd_ok(latest_cpan_cmd) + ok, latest_cpan = cmd_ok(latest_cpan_cmd) if not ok or latest_cpan:find('^%s*$') then health.error( 'Failed to run: ' .. table.concat(latest_cpan_cmd, ' '), @@ -205,7 +311,7 @@ local function perl() local current_cpan_cmd = { perl_exec, '-W', '-MNeovim::Ext', '-e', 'print $Neovim::Ext::VERSION' } local current_cpan - ok, current_cpan = health._cmd_ok(current_cpan_cmd) + ok, current_cpan = cmd_ok(current_cpan_cmd) if not ok then health.error( 'Failed to run: ' .. table.concat(current_cpan_cmd, ' '), @@ -292,7 +398,7 @@ end local function download(url) local has_curl = vim.fn.executable('curl') == 1 if has_curl and vim.fn.system({ 'curl', '-V' }):find('Protocols:.*https') then - local out, rc = health._system({ 'curl', '-sL', url }, { stderr = true, ignore_error = true }) + local out, rc = system({ 'curl', '-sL', url }, { stderr = true, ignore_error = true }) if rc ~= 0 then return 'curl error with ' .. url .. ': ' .. rc else @@ -305,7 +411,7 @@ local function download(url) from urllib2 import urlopen\n\ response = urlopen('" .. url .. "')\n\ print(response.read().decode('utf8'))\n" - local out, rc = health._system({ 'python', '-c', script }) + local out, rc = system({ 'python', '-c', script }) if out == '' and rc ~= 0 then return 'python urllib.request error: ' .. rc else @@ -362,7 +468,7 @@ end local function version_info(python) local pypi_version = latest_pypi_version() - local python_version, rc = health._system({ + local python_version, rc = system({ python, '-c', 'import sys; print(".".join(str(x) for x in sys.version_info[:3]))', @@ -373,7 +479,7 @@ local function version_info(python) end local nvim_path - nvim_path, rc = health._system({ + nvim_path, rc = system({ python, '-c', 'import sys; sys.path = [p for p in sys.path if p != ""]; import neovim; print(neovim.__file__)', @@ -398,7 +504,7 @@ local function version_info(python) -- Try to get neovim.VERSION (added in 0.1.11dev). local nvim_version - nvim_version, rc = health._system({ + nvim_version, rc = system({ python, '-c', 'from neovim import VERSION as v; print("{}.{}.{}{}".format(v.major, v.minor, v.patch, v.prerelease))', @@ -445,7 +551,7 @@ local function python() local host_prog_var = pyname .. '_host_prog' local python_multiple = {} - if health._provider_disabled(pyname) then + if provider_disabled(pyname) then return end @@ -487,7 +593,7 @@ local function python() end if pyenv ~= '' then - python_exe = health._system({ pyenv, 'which', pyname }, { stderr = true }) + python_exe = system({ pyenv, 'which', pyname }, { stderr = true }) if python_exe == '' then health.warn('pyenv could not find ' .. pyname .. '.') end @@ -710,9 +816,7 @@ local function python() health.info(msg) health.info( 'Python version: ' - .. health._system( - 'python -c "import platform, sys; sys.stdout.write(platform.python_version())"' - ) + .. system('python -c "import platform, sys; sys.stdout.write(platform.python_version())"') ) health.ok('$VIRTUAL_ENV provides :!python.') end @@ -721,7 +825,7 @@ end local function ruby() health.start('Ruby provider (optional)') - if health._provider_disabled('ruby') then + if provider_disabled('ruby') then return end @@ -732,7 +836,7 @@ local function ruby() ) return end - health.info('Ruby: ' .. health._system({ 'ruby', '-v' })) + health.info('Ruby: ' .. system({ 'ruby', '-v' })) local host, _ = vim.provider.ruby.detect() if (not host) or host:find('^%s*$') then @@ -748,7 +852,7 @@ local function ruby() health.info('Host: ' .. host) local latest_gem_cmd = (iswin and 'cmd /c gem list -ra "^^neovim$"' or 'gem list -ra ^neovim$') - local ok, latest_gem = health._cmd_ok(vim.split(latest_gem_cmd, ' ')) + local ok, latest_gem = cmd_ok(vim.split(latest_gem_cmd, ' ')) if not ok or latest_gem:find('^%s*$') then health.error( 'Failed to run: ' .. latest_gem_cmd, @@ -761,7 +865,7 @@ local function ruby() local current_gem_cmd = { host, '--version' } local current_gem - ok, current_gem = health._cmd_ok(current_gem_cmd) + ok, current_gem = cmd_ok(current_gem_cmd) if not ok then health.error( 'Failed to run: ' .. table.concat(current_gem_cmd, ' '), diff --git a/runtime/lua/vim/snippet.lua b/runtime/lua/vim/snippet.lua index 3d8f73f362..3fd2555046 100644 --- a/runtime/lua/vim/snippet.lua +++ b/runtime/lua/vim/snippet.lua @@ -315,7 +315,7 @@ local function select_tabstop(tabstop) move_cursor_to(range[1] + 1, range[2] + 1) feedkeys('v') move_cursor_to(range[3] + 1, range[4]) - feedkeys('o<c-g>') + feedkeys('o<c-g><c-r>_') end end diff --git a/runtime/syntax/hare.vim b/runtime/syntax/hare.vim index 07cf33fb11..4c7ae92486 100644 --- a/runtime/syntax/hare.vim +++ b/runtime/syntax/hare.vim @@ -1,119 +1,142 @@ -" PRELUDE {{{1 -" Vim syntax file -" Language: Hare -" Maintainer: Amelia Clarke <me@rsaihe.dev> -" Last Change: 2022-09-21 +" Vim syntax file. +" Language: Hare +" Maintainer: Amelia Clarke <selene@perilune.dev> +" Last Change: 2024-05-10 +" Upstream: https://git.sr.ht/~sircmpwn/hare.vim -if exists("b:current_syntax") +if exists('b:current_syntax') finish endif -let b:current_syntax = "hare" +syn include @haredoc syntax/haredoc.vim +let b:current_syntax = 'hare' -" SYNTAX {{{1 +" Syntax {{{1 syn case match +syn iskeyword @,48-57,@-@,_ -" KEYWORDS {{{2 -syn keyword hareConditional if else match switch +" Keywords {{{2 +syn keyword hareConditional else if match switch +syn keyword hareDefine def +syn keyword hareInclude use syn keyword hareKeyword break continue return yield +syn keyword hareKeyword case +syn keyword hareKeyword const let syn keyword hareKeyword defer +syn keyword hareKeyword export static syn keyword hareKeyword fn -syn keyword hareKeyword let -syn keyword hareLabel case syn keyword hareOperator as is syn keyword hareRepeat for -syn keyword hareStorageClass const def export nullable static -syn keyword hareStructure enum struct union syn keyword hareTypedef type -" C ABI. -syn keyword hareKeyword vastart vaarg vaend - -" BUILTINS {{{2 -syn keyword hareBuiltin abort +" Attributes. +syn keyword hareAttribute @fini @init @test +syn keyword hareAttribute @offset @packed +syn keyword hareAttribute @symbol +syn keyword hareAttribute @threadlocal + +" Builtins. +syn keyword hareBuiltin abort assert +syn keyword hareBuiltin align len offset syn keyword hareBuiltin alloc free syn keyword hareBuiltin append delete insert -syn keyword hareBuiltin assert -syn keyword hareBuiltin len offset +syn keyword hareBuiltin vaarg vaend vastart -" TYPES {{{2 +" Types {{{2 syn keyword hareType bool -syn keyword hareType char str +syn keyword hareType done syn keyword hareType f32 f64 -syn keyword hareType u8 u16 u32 u64 i8 i16 i32 i64 -syn keyword hareType uint int -syn keyword hareType rune +syn keyword hareType i8 i16 i32 i64 int +syn keyword hareType never +syn keyword hareType opaque +syn keyword hareType rune str +syn keyword hareType u8 u16 u32 u64 uint syn keyword hareType uintptr +syn keyword hareType valist syn keyword hareType void -" C ABI. -syn keyword hareType valist +" Other types. +syn keyword hareStorageClass nullable +syn keyword hareStructure enum struct union -" LITERALS {{{2 -syn keyword hareBoolean true false -syn keyword hareNull null - -" Number literals. -syn match hareNumber "\v(\.@1<!|\.\.)\zs<\d+([Ee][+-]?\d+)?(z|[iu](8|16|32|64)?)?>" display -syn match hareNumber "\v(\.@1<!|\.\.)\zs<0b[01]+(z|[iu](8|16|32|64)?)?>" display -syn match hareNumber "\v(\.@1<!|\.\.)\zs<0o\o+(z|[iu](8|16|32|64)?)?>" display -syn match hareNumber "\v(\.@1<!|\.\.)\zs<0x\x+(z|[iu](8|16|32|64)?)?>" display - -" Floating-point number literals. -syn match hareFloat "\v<\d+\.\d+([Ee][+-]?\d+)?(f32|f64)?>" display -syn match hareFloat "\v<\d+([Ee][+-]?\d+)?(f32|f64)>" display - -" String and rune literals. -syn match hareEscape "\\[\\'"0abfnrtv]" contained display -syn match hareEscape "\v\\(x\x{2}|u\x{4}|U\x{8})" contained display -syn match hareFormat "\v\{\d*(\%\d*|(:[ 0+-]?\d*(\.\d+)?[Xbox]?))?}" contained display -syn match hareFormat "\({{\|}}\)" contained display -syn region hareRune start="'" end="'\|$" skip="\\'" contains=hareEscape display extend -syn region hareString start=+"+ end=+"\|$+ skip=+\\"+ contains=hareEscape,hareFormat display extend -syn region hareString start="`" end="`\|$" contains=hareFormat display - -" MISCELLANEOUS {{{2 -syn keyword hareTodo FIXME TODO XXX contained +" Literals {{{2 +syn keyword hareBoolean false true +syn keyword hareConstant null -" Attributes. -syn match hareAttribute "@[a-z]*" +" Integer literals. +syn match hareNumber '\v<%(0|[1-9]%(_?\d)*)%([Ee]\+?\d+)?%([iu]%(8|16|32|64)?|z)?>' display +syn match hareNumber '\v<0b[01]%(_?[01])*%([iu]%(8|16|32|64)?|z)?>' display +syn match hareNumber '\v<0o\o%(_?\o)*%([iu]%(8|16|32|64)?|z)?>' display +syn match hareNumber '\v<0x\x%(_?\x)*%([iu]%(8|16|32|64)?|z)?>' display -" Blocks. -syn region hareBlock start="{" end="}" fold transparent +" Floating-point literals. +syn match hareFloat '\v<%(0|[1-9]%(_?\d)*)\.\d%(_?\d)*%([Ee][+-]?\d+)?%(f32|f64)?>' display +syn match hareFloat '\v<%(0|[1-9]%(_?\d)*)%([Ee][+-]?\d+)?%(f32|f64)>' display +syn match hareFloat '\v<0x\x%(_?\x)*%(\.\x%(_?\x)*)?[Pp][+-]?\d+%(f32|f64)?>' display + +" Rune and string literals. +syn region hareRune start="'" skip="\\'" end="'" contains=hareEscape +syn region hareString start='"' skip='\\"' end='"' contains=hareEscape,hareFormat +syn region hareString start='`' end='`' contains=hareFormat + +" Escape sequences. +syn match hareEscape '\\[0abfnrtv\\'"]' contained +syn match hareEscape '\v\\%(x\x{2}|u\x{4}|U\x{8})' contained display + +" Format sequences. +syn match hareFormat '\v\{\d*%(:%(\.?\d+|[ +\-=Xbefgox]|F[.2ESUs]|_%(.|\\%([0abfnrtv\\'"]|x\x{2}|u\x{4}|U\x{8})))*)?}' contained contains=hareEscape display +syn match hareFormat '{\d*%\d*}' contained display +syn match hareFormat '{{\|}}' contained display + +" Miscellaneous {{{2 " Comments. -syn region hareComment start="//" end="$" contains=hareCommentDoc,hareTodo,@Spell display keepend -syn region hareCommentDoc start="\[\[" end="]]\|\ze\_s" contained display +syn region hareComment start='//' end='$' contains=hareTodo,@haredoc,@Spell display +syn keyword hareTodo FIXME TODO XXX contained + +" Identifiers. +syn match hareDelimiter '::' display +syn match hareName '\<\h\w*\>' nextgroup=@harePostfix skipempty skipwhite transparent -" The size keyword can be either a builtin or a type. -syn match hareBuiltin "\v<size>\ze(\_s*//.*\_$)*\_s*\(" contains=hareComment -syn match hareType "\v<size>((\_s*//.*\_$)*\_s*\()@!" contains=hareComment +" Labels. +syn match hareLabel ':\h\w*\>' display -" Trailing whitespace. -syn match hareSpaceError "\v\s+$" display excludenl -syn match hareSpaceError "\v\zs +\ze\t" display +" Match `size` as a type unless it is followed by an open paren. +syn match hareType '\<size\>' display +syn match hareBuiltin '\<size\ze(' display -" Use statement. -syn region hareUse start="\v^\s*\zsuse>" end=";" contains=hareComment display +" Postfix expressions. +syn cluster harePostfix contains=hareErrorTest,hareField,hareIndex,hareParens +syn match hareErrorTest '!=\@!' contained nextgroup=@harePostfix skipempty skipwhite +syn match hareErrorTest '?' nextgroup=@harePostfix skipempty skipwhite +syn match hareField '\.\w*\>'hs=s+1 contained contains=hareNumber nextgroup=@harePostfix skipempty skipwhite +syn region hareIndex start='\[' end=']' contained nextgroup=@harePostfix skipempty skipwhite transparent +syn region hareParens start='(' end=')' nextgroup=@harePostfix skipempty skipwhite transparent -syn match hareErrorAssertion "\v(^([^/]|//@!)*\)\_s*)@<=!\=@!" -syn match hareQuestionMark "?" +" Whitespace errors. +syn match hareSpaceError '^ \+\ze\t' display +syn match hareSpaceError excludenl '\s\+$' containedin=ALL display -" DEFAULT HIGHLIGHTING {{{1 -hi def link hareAttribute Keyword +" Folding {{{3 +syn region hareBlock start='{' end='}' fold transparent + +" Default highlighting {{{1 +hi def link hareAttribute PreProc hi def link hareBoolean Boolean -hi def link hareBuiltin Function +hi def link hareBuiltin Operator hi def link hareComment Comment -hi def link hareCommentDoc SpecialComment hi def link hareConditional Conditional +hi def link hareConstant Constant +hi def link hareDefine Define +hi def link hareDelimiter Delimiter +hi def link hareErrorTest Special hi def link hareEscape SpecialChar hi def link hareFloat Float hi def link hareFormat SpecialChar +hi def link hareInclude Include hi def link hareKeyword Keyword -hi def link hareLabel Label -hi def link hareNull Constant +hi def link hareLabel Special hi def link hareNumber Number hi def link hareOperator Operator -hi def link hareQuestionMark Special hi def link hareRepeat Repeat hi def link hareRune Character hi def link hareStorageClass StorageClass @@ -122,12 +145,13 @@ hi def link hareStructure Structure hi def link hareTodo Todo hi def link hareType Type hi def link hareTypedef Typedef -hi def link hareUse PreProc -hi def link hareSpaceError Error -autocmd InsertEnter * hi link hareSpaceError NONE -autocmd InsertLeave * hi link hareSpaceError Error +" Highlight embedded haredoc references. +hi! def link haredocRefValid SpecialComment -hi def hareErrorAssertion ctermfg=red cterm=bold guifg=red gui=bold +" Highlight whitespace errors by default. +if get(g:, 'hare_space_error', 1) + hi def link hareSpaceError Error +endif -" vim: tabstop=8 shiftwidth=2 expandtab +" vim: et sts=2 sw=2 ts=8 diff --git a/runtime/syntax/haredoc.vim b/runtime/syntax/haredoc.vim new file mode 100644 index 0000000000..09c99c1d56 --- /dev/null +++ b/runtime/syntax/haredoc.vim @@ -0,0 +1,32 @@ +" Vim syntax file. +" Language: Haredoc (Hare documentation format) +" Maintainer: Amelia Clarke <selene@perilune.dev> +" Last Change: 2024-05-10 +" Upstream: https://git.sr.ht/~selene/hare.vim + +if exists('b:current_syntax') + finish +endif +let b:current_syntax = 'haredoc' + +" Syntax {{{1 +syn case match +syn iskeyword @,48-57,_ + +" Code samples. +syn region haredocCodeSample excludenl start='\t\zs' end='$' contains=@NoSpell display + +" References to other declarations and modules. +syn region haredocRef start='\[\[' end=']]' contains=haredocRefValid,@NoSpell display keepend oneline +syn match haredocRefValid '\v\[\[\h\w*%(::\h\w*)*%(::)?]]' contained contains=@NoSpell display + +" Miscellaneous. +syn keyword haredocTodo FIXME TODO XXX + +" Default highlighting {{{1 +hi def link haredocCodeSample Comment +hi def link haredocRef Error +hi def link haredocRefValid Special +hi def link haredocTodo Todo + +" vim: et sts=2 sw=2 ts=8 diff --git a/runtime/syntax/shared/debversions.vim b/runtime/syntax/shared/debversions.vim index e18eca96b1..56f18b969a 100644 --- a/runtime/syntax/shared/debversions.vim +++ b/runtime/syntax/shared/debversions.vim @@ -1,7 +1,7 @@ " Vim syntax file " Language: Debian version information " Maintainer: Debian Vim Maintainers -" Last Change: 2024 Apr 27 +" Last Change: 2024 May 25 " URL: https://salsa.debian.org/vim-team/vim-debian/blob/main/syntax/shared/debversions.vim let s:cpo = &cpo @@ -11,7 +11,7 @@ let g:debSharedSupportedVersions = [ \ 'oldstable', 'stable', 'testing', 'unstable', 'experimental', 'sid', 'rc-buggy', \ 'bullseye', 'bookworm', 'trixie', 'forky', \ - \ 'trusty', 'xenial', 'bionic', 'focal', 'jammy', 'mantic', 'noble', 'oracular', + \ 'focal', 'jammy', 'mantic', 'noble', 'oracular', \ 'devel' \ ] let g:debSharedUnsupportedVersions = [ @@ -22,8 +22,9 @@ let g:debSharedUnsupportedVersions = [ \ 'warty', 'hoary', 'breezy', 'dapper', 'edgy', 'feisty', \ 'gutsy', 'hardy', 'intrepid', 'jaunty', 'karmic', 'lucid', \ 'maverick', 'natty', 'oneiric', 'precise', 'quantal', 'raring', 'saucy', - \ 'utopic', 'vivid', 'wily', 'yakkety', 'zesty', 'artful', 'cosmic', - \ 'disco', 'eoan', 'hirsute', 'impish', 'kinetic', 'lunar', 'groovy' + \ 'trusty', 'utopic', 'vivid', 'wily', 'xenial', 'yakkety', 'zesty', + \ 'artful', 'bionic', 'cosmic', 'disco', 'eoan', 'hirsute', + \ 'impish', 'kinetic', 'lunar', 'groovy' \ ] let &cpo=s:cpo diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim index 34fe93fd55..16125559cf 100644 --- a/test/old/testdir/test_filetype.vim +++ b/test/old/testdir/test_filetype.vim @@ -1511,6 +1511,41 @@ func Test_git_file() filetype off endfunc +func Test_haredoc_file() + filetype on + call assert_true(mkdir('foo/bar', 'pR')) + + call writefile([], 'README', 'D') + split README + call assert_notequal('haredoc', &filetype) + bwipe! + + let g:filetype_haredoc = 1 + split README + call assert_notequal('haredoc', &filetype) + bwipe! + + call writefile([], 'foo/quux.ha') + split README + call assert_equal('haredoc', &filetype) + bwipe! + call delete('foo/quux.ha') + + call writefile([], 'foo/bar/baz.ha', 'D') + split README + call assert_notequal('haredoc', &filetype) + bwipe! + + let g:haredoc_search_depth = 2 + split README + call assert_equal('haredoc', &filetype) + bwipe! + unlet g:filetype_haredoc + unlet g:haredoc_search_depth + + filetype off +endfunc + func Test_hook_file() filetype on |