diff options
57 files changed, 2083 insertions, 1678 deletions
diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 4dbd193dab..a9de7557e4 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -26,23 +26,14 @@ foreach(DF ${DOCFILES}) list(APPEND BUILDDOCFILES ${GENERATED_RUNTIME_DIR}/doc/${F}) endforeach() -add_custom_command(OUTPUT copy_docfiles - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${PROJECT_SOURCE_DIR}/runtime/doc ${GENERATED_RUNTIME_DIR}/doc -) - add_custom_target(helptags + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${PROJECT_SOURCE_DIR}/runtime/doc ${GENERATED_RUNTIME_DIR}/doc COMMAND "${PROJECT_BINARY_DIR}/bin/nvim" - -u NONE - -i NONE - -e - --headless - -c "helptags ++t ." - -c quit + -u NONE -i NONE -e --headless -c "helptags ++t doc" -c quit DEPENDS - copy_docfiles nvim - WORKING_DIRECTORY "${GENERATED_RUNTIME_DIR}/doc" + WORKING_DIRECTORY "${GENERATED_RUNTIME_DIR}" ) add_custom_command(OUTPUT ${GENERATED_HELP_TAGS} diff --git a/runtime/autoload/health.vim b/runtime/autoload/health.vim new file mode 100644 index 0000000000..dc362577a6 --- /dev/null +++ b/runtime/autoload/health.vim @@ -0,0 +1,433 @@ +function! s:trim(s) abort + return substitute(a:s, '^\_s*\|\_s*$', '', 'g') +endfunction + + +" Simple version comparison. +function! s:version_cmp(a, b) abort + let a = split(a:a, '\.') + let b = split(a:b, '\.') + + for i in range(len(a)) + if a[i] > b[i] + return 1 + elseif a[i] < b[i] + return -1 + endif + endfor + + return 0 +endfunction + + +" Fetch the contents of a URL. +function! s:download(url) abort + let content = '' + if executable('curl') + let content = system('curl -sL "'.a:url.'"') + endif + + if empty(content) && executable('python') + let script = " + \try:\n + \ from urllib.request import urlopen\n + \except ImportError:\n + \ from urllib2 import urlopen\n + \\n + \try:\n + \ response = urlopen('".a:url."')\n + \ print(response.read().decode('utf8'))\n + \except Exception:\n + \ pass\n + \" + let content = system('python -c "'.script.'" 2>/dev/null') + endif + + return content +endfunction + + +" Get the latest Neovim Python client version from PyPI. The result is +" cached. +function! s:latest_pypi_version() + if exists('s:pypi_version') + return s:pypi_version + endif + + let s:pypi_version = 'unknown' + let pypi_info = s:download('https://pypi.python.org/pypi/neovim/json') + if !empty(pypi_info) + let pypi_data = json_decode(pypi_info) + let s:pypi_version = get(get(pypi_data, 'info', {}), 'version', 'unknown') + return s:pypi_version + endif +endfunction + + +" Get version information using the specified interpreter. The interpreter is +" used directly in case breaking changes were introduced since the last time +" Neovim's Python client was updated. +function! s:version_info(python) abort + let pypi_version = s:latest_pypi_version() + let python_version = s:trim(system( + \ printf('"%s" -c "import sys; print(''.''.join(str(x) ' + \ . 'for x in sys.version_info[:3]))"', a:python))) + if empty(python_version) + let python_version = 'unknown' + endif + + let nvim_path = s:trim(system(printf('"%s" -c "import sys, neovim;' + \ . 'print(neovim.__file__)" 2>/dev/null', a:python))) + if empty(nvim_path) + return [python_version, 'not found', pypi_version, 'unknown'] + endif + + let nvim_version = 'unknown' + let base = fnamemodify(nvim_path, ':h') + for meta in glob(base.'-*/METADATA', 1, 1) + glob(base.'-*/PKG-INFO', 1, 1) + for meta_line in readfile(meta) + if meta_line =~# '^Version:' + let nvim_version = matchstr(meta_line, '^Version: \zs\S\+') + endif + endfor + endfor + + let version_status = 'unknown' + if nvim_version != 'unknown' && pypi_version != 'unknown' + if s:version_cmp(nvim_version, pypi_version) == -1 + let version_status = 'outdated' + else + let version_status = 'up to date' + endif + endif + + return [python_version, nvim_version, pypi_version, version_status] +endfunction + + +" Check the Python interpreter's usability. +function! s:check_bin(bin, notes) abort + if !filereadable(a:bin) + call add(a:notes, printf('Error: "%s" was not found.', a:bin)) + return 0 + elseif executable(a:bin) != 1 + call add(a:notes, printf('Error: "%s" is not executable.', a:bin)) + return 0 + endif + return 1 +endfunction + + +" Text wrapping that returns a list of lines +function! s:textwrap(text, width) abort + let pattern = '.*\%(\s\+\|\_$\)\zs\%<'.a:width.'c' + return map(split(a:text, pattern), 's:trim(v:val)') +endfunction + + +" Echo wrapped notes +function! s:echo_notes(notes) abort + if empty(a:notes) + return + endif + + echo ' Messages:' + for msg in a:notes + if msg =~# "\n" + let msg_lines = [] + for msgl in filter(split(msg, "\n"), 'v:val !~# ''^\s*$''') + call extend(msg_lines, s:textwrap(msgl, 74)) + endfor + else + let msg_lines = s:textwrap(msg, 74) + endif + + if !len(msg_lines) + continue + endif + echo ' *' msg_lines[0] + if len(msg_lines) > 1 + echo join(map(msg_lines[1:], '" ".v:val'), "\n") + endif + endfor +endfunction + + +" Load the remote plugin manifest file and check for unregistered plugins +function! s:diagnose_manifest() abort + echo 'Checking: Remote Plugins' + let existing_rplugins = {} + + for item in remote#host#PluginsForHost('python') + let existing_rplugins[item.path] = 'python' + endfor + + for item in remote#host#PluginsForHost('python3') + let existing_rplugins[item.path] = 'python3' + endfor + + let require_update = 0 + let notes = [] + + for path in map(split(&rtp, ','), 'resolve(v:val)') + let python_glob = glob(path.'/rplugin/python*', 1, 1) + if empty(python_glob) + continue + endif + + let python_dir = python_glob[0] + let python_version = fnamemodify(python_dir, ':t') + + for script in glob(python_dir.'/*.py', 1, 1) + \ + glob(python_dir.'/*/__init__.py', 1, 1) + let contents = join(readfile(script)) + if contents =~# '\<\%(from\|import\)\s\+neovim\>' + if script =~# '/__init__\.py$' + let script = fnamemodify(script, ':h') + endif + + if !has_key(existing_rplugins, script) + let msg = printf('"%s" is not registered.', fnamemodify(path, ':t')) + if python_version == 'pythonx' + if !has('python2') && !has('python3') + let msg .= ' (python2 and python3 not available)' + endif + elseif !has(python_version) + let msg .= printf(' (%s not available)', python_version) + else + let require_update = 1 + endif + + call add(notes, msg) + endif + + break + endif + endfor + endfor + + echo ' Status: ' + if require_update + echon 'Out of date' + call add(notes, 'Run :UpdateRemotePlugins') + else + echon 'Up to date' + endif + + call s:echo_notes(notes) +endfunction + + +function! s:diagnose_python(version) abort + let python_bin_name = 'python'.(a:version == 2 ? '' : '3') + let pyenv = resolve(exepath('pyenv')) + let pyenv_root = exists('$PYENV_ROOT') ? resolve($PYENV_ROOT) : '' + let venv = exists('$VIRTUAL_ENV') ? resolve($VIRTUAL_ENV) : '' + let host_prog_var = python_bin_name.'_host_prog' + let host_skip_var = python_bin_name.'_host_skip_check' + let python_bin = '' + let python_multiple = [] + let notes = [] + + if exists('g:'.host_prog_var) + call add(notes, printf('Using: g:%s = "%s"', host_prog_var, get(g:, host_prog_var))) + endif + + let [python_bin_name, pythonx_errs] = provider#pythonx#Detect(a:version) + if empty(python_bin_name) + call add(notes, 'Warning: No Python interpreter was found with the neovim ' + \ . 'module. Using the first available for diagnostics.') + if !empty(pythonx_errs) + call add(notes, pythonx_errs) + endif + let old_skip = get(g:, host_skip_var, 0) + let g:[host_skip_var] = 1 + let [python_bin_name, pythonx_errs] = provider#pythonx#Detect(a:version) + let g:[host_skip_var] = old_skip + endif + + if !empty(python_bin_name) + if exists('g:'.host_prog_var) + let python_bin = exepath(python_bin_name) + endif + let python_bin_name = fnamemodify(python_bin_name, ':t') + endif + + if !empty(pythonx_errs) + call add(notes, pythonx_errs) + endif + + if !empty(python_bin_name) && empty(python_bin) && empty(pythonx_errs) + if !exists('g:'.host_prog_var) + call add(notes, printf('Warning: "g:%s" is not set. Searching for ' + \ . '%s in the environment.', host_prog_var, python_bin_name)) + endif + + if !empty(pyenv) + if empty(pyenv_root) + call add(notes, 'Warning: pyenv was found, but $PYENV_ROOT ' + \ . 'is not set. Did you follow the final install ' + \ . 'instructions?') + else + call add(notes, printf('Notice: pyenv found: "%s"', pyenv)) + endif + + let python_bin = s:trim(system( + \ printf('"%s" which %s 2>/dev/null', pyenv, python_bin_name))) + + if empty(python_bin) + call add(notes, printf('Warning: pyenv couldn''t find %s.', python_bin_name)) + endif + endif + + if empty(python_bin) + let python_bin = exepath(python_bin_name) + + if exists('$PATH') + for path in split($PATH, ':') + let path_bin = path.'/'.python_bin_name + if path_bin != python_bin && index(python_multiple, path_bin) == -1 + \ && executable(path_bin) + call add(python_multiple, path_bin) + endif + endfor + + if len(python_multiple) + " This is worth noting since the user may install something + " that changes $PATH, like homebrew. + call add(notes, printf('Suggestion: There are multiple %s executables found. ' + \ . 'Set "g:%s" to avoid surprises.', python_bin_name, host_prog_var)) + endif + + if python_bin =~# '\<shims\>' + call add(notes, printf('Warning: "%s" appears to be a pyenv shim. ' + \ . 'This could mean that a) the "pyenv" executable is not in ' + \ . '$PATH, b) your pyenv installation is broken. ' + \ . 'You should set "g:%s" to avoid surprises.', + \ python_bin, host_prog_var)) + endif + endif + endif + endif + + if !empty(python_bin) + if !empty(pyenv) && !exists('g:'.host_prog_var) && !empty(pyenv_root) + \ && resolve(python_bin) !~# '^'.pyenv_root.'/' + call add(notes, printf('Suggestion: Create a virtualenv specifically ' + \ . 'for Neovim using pyenv and use "g:%s". This will avoid ' + \ . 'the need to install Neovim''s Python client in each ' + \ . 'version/virtualenv.', host_prog_var)) + endif + + if !empty(venv) && exists('g:'.host_prog_var) + if !empty(pyenv_root) + let venv_root = pyenv_root + else + let venv_root = fnamemodify(venv, ':h') + endif + + if resolve(python_bin) !~# '^'.venv_root.'/' + call add(notes, printf('Suggestion: Create a virtualenv specifically ' + \ . 'for Neovim and use "g:%s". This will avoid ' + \ . 'the need to install Neovim''s Python client in each ' + \ . 'virtualenv.', host_prog_var)) + endif + endif + endif + + if empty(python_bin) && !empty(python_bin_name) + " An error message should have already printed. + call add(notes, printf('Error: "%s" was not found.', python_bin_name)) + elseif !empty(python_bin) && !s:check_bin(python_bin, notes) + let python_bin = '' + endif + + " Check if $VIRTUAL_ENV is active + let virtualenv_inactive = 0 + + if exists('$VIRTUAL_ENV') + if !empty(pyenv) + let pyenv_prefix = resolve(s:trim(system(printf('"%s" prefix', pyenv)))) + if $VIRTUAL_ENV != pyenv_prefix + let virtualenv_inactive = 1 + endif + elseif !empty(python_bin_name) && exepath(python_bin_name) !~# '^'.$VIRTUAL_ENV.'/' + let virtualenv_inactive = 1 + endif + endif + + if virtualenv_inactive + call add(notes, 'Warning: $VIRTUAL_ENV exists but appears to be ' + \ . 'inactive. This could lead to unexpected results. If you are ' + \ . 'using Zsh, see: http://vi.stackexchange.com/a/7654/5229') + endif + + " Diagnostic output + echo 'Checking: Python' a:version + echo ' Executable:' (empty(python_bin) ? 'Not found' : python_bin) + if len(python_multiple) + for path_bin in python_multiple + echo ' (other):' path_bin + endfor + endif + + if !empty(python_bin) + let [pyversion, current, latest, status] = s:version_info(python_bin) + if a:version != str2nr(pyversion) + call add(notes, 'Warning: Got an unexpected version of Python. ' + \ . 'This could lead to confusing error messages. Please ' + \ . 'consider this before reporting bugs to plugin developers.') + endif + if a:version == 3 && str2float(pyversion) < 3.3 + call add(notes, 'Warning: Python 3.3+ is recommended.') + endif + + echo ' Python Version:' pyversion + echo printf(' %s-neovim Version: %s', python_bin_name, current) + + if current == 'not found' + call add(notes, 'Error: Neovim Python client is not installed.') + endif + + if latest == 'unknown' + call add(notes, 'Warning: Unable to fetch latest Neovim Python client version.') + endif + + if status == 'outdated' + echon ' (latest: '.latest.')' + else + echon ' ('.status.')' + endif + endif + + call s:echo_notes(notes) +endfunction + + +function! health#check(bang) abort + redir => report + try + silent call s:diagnose_python(2) + silent echo '' + silent call s:diagnose_python(3) + silent echo '' + silent call s:diagnose_manifest() + silent echo '' + finally + redir END + endtry + + if a:bang + new + setlocal bufhidden=wipe + call setline(1, split(report, "\n")) + setlocal nomodified + else + echo report + echo "\nTip: Use " + echohl Identifier + echon ":CheckHealth!" + echohl None + echon " to open this in a new buffer." + endif +endfunction diff --git a/runtime/autoload/provider/clipboard.vim b/runtime/autoload/provider/clipboard.vim index 2272519dfd..77bc8c781d 100644 --- a/runtime/autoload/provider/clipboard.vim +++ b/runtime/autoload/provider/clipboard.vim @@ -58,7 +58,7 @@ elseif executable('doitclient') let s:copy['*'] = s:copy['+'] let s:paste['*'] = s:paste['+'] else - echom 'clipboard: No clipboard tool available. See :help nvim-clipboard' + echom 'clipboard: No clipboard tool available. See :help clipboard' finish endif diff --git a/runtime/autoload/provider/python.vim b/runtime/autoload/provider/python.vim index cb9d5c5296..b99a046375 100644 --- a/runtime/autoload/provider/python.vim +++ b/runtime/autoload/provider/python.vim @@ -1,5 +1,5 @@ " The Python provider uses a Python host to emulate an environment for running -" python-vim plugins. See ":help nvim-provider" for more information. +" python-vim plugins. See ":help provider". " " Associating the plugin with the Python host is the first step because plugins " will be passed as command-line arguments diff --git a/runtime/autoload/provider/python3.vim b/runtime/autoload/provider/python3.vim index f4a751e7a2..4f47a03a9b 100644 --- a/runtime/autoload/provider/python3.vim +++ b/runtime/autoload/provider/python3.vim @@ -1,5 +1,5 @@ " The Python3 provider uses a Python3 host to emulate an environment for running -" python3 plugins. See ":help nvim-provider" for more information. +" python3 plugins. See ":help provider". " " Associating the plugin with the Python3 host is the first step because " plugins will be passed as command-line arguments diff --git a/runtime/autoload/provider/pythonx.vim b/runtime/autoload/provider/pythonx.vim index c3256e8308..0ebf00112f 100644 --- a/runtime/autoload/provider/pythonx.vim +++ b/runtime/autoload/provider/pythonx.vim @@ -106,7 +106,7 @@ function! s:check_interpreter(prog, major_ver, skip) abort if v:shell_error == 2 return [0, prog_path . ' does not have the neovim module installed. ' - \ . 'See ":help nvim-python".'] + \ . 'See ":help provider-python".'] elseif v:shell_error == 127 " This can happen with pyenv's shims. return [0, prog_path . ' does not exist: ' . prog_ver] diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt index ca79465e0d..bdeca367b1 100644 --- a/runtime/doc/api.txt +++ b/runtime/doc/api.txt @@ -1,31 +1,32 @@ -*api.txt* For Nvim. {Nvim} +*api.txt* {Nvim} NVIM REFERENCE MANUAL by Thiago de Arruda -The C API of Nvim *nvim-api* -1. Introduction |nvim-api-intro| -2. API Types |nvim-api-types| -3. API metadata |nvim-api-metadata| -4. Buffer highlighting |nvim-api-highlights| +C API for Nvim *API* *api* + +1. Introduction |api-intro| +2. API Types |api-types| +3. API metadata |api-metadata| +4. Buffer highlighting |api-highlights| ============================================================================== -1. Introduction *nvim-api-intro* +1. Introduction *api-intro* -Nvim defines a C API as the primary way for external code to interact with -the NVim core. In the present version of Nvim the API is primarily used by -external processes to interact with Nvim using the msgpack-rpc protocol, see -|msgpack-rpc|. The API will also be used from vimscript to access new Nvim core -features, but this is not implemented yet. Later on, Nvim might be embeddable -in C applications as libnvim, and the application will then control the -embedded instance by calling the C API directly. +Nvim exposes a public API for external code to interact with the Nvim core. In +the present version of Nvim the API is primarily used by external processes to +interact with Nvim using the msgpack-rpc protocol, see |msgpack-rpc|. The API +will also be used from vimscript to access new Nvim core features, but this is +not implemented yet. Later on, Nvim might be embeddable in C applications as +libnvim, and the application will then control the embedded instance by +calling the C API directly. ============================================================================== -2. API Types *nvim-api-types* +2. API Types *api-types* Nvim's C API uses custom types for all functions. Some are just typedefs -around C99 standard types, and some are Nvim defined data structures. +around C99 standard types, and some are Nvim-defined data structures. Boolean -> bool Integer (signed 64-bit integer) -> int64_t @@ -46,7 +47,7 @@ Window -> enum value kObjectTypeWindow Tabpage -> enum value kObjectTypeTabpage ============================================================================== -3. API metadata *nvim-api-metadata* +3. API metadata *api-metadata* Nvim exposes metadata about the API as a Dictionary with the following keys: @@ -54,11 +55,11 @@ functions calling signature of the API functions types The custom handle types defined by Nvim error_types The possible kinds of errors an API function can exit with. -This metadata is mostly useful for external programs accessing the api over -msgpack-api, see |msgpack-rpc-api|. +This metadata is mostly useful for external programs accessing the API via +RPC, see |rpc-api|. ============================================================================== -4. Buffer highlighting *nvim-api-highlights* +4. Buffer highlighting *api-highlights* Nvim allows plugins to add position-based highlights to buffers. This is similar to |matchaddpos()| but with some key differences. The added highlights diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index 25ae94f784..6641732679 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -912,8 +912,7 @@ TermClose When a terminal buffer ends. {Nvim} *TermOpen* TermOpen When a terminal buffer is starting. This can be used to configure the terminal emulator by - setting buffer variables. - See |nvim-terminal-emulator| for details. + setting buffer variables. |terminal-emulator| *TermResponse* TermResponse After the response to |t_RV| is received from the terminal. The value of |v:termresponse| diff --git a/runtime/doc/change.txt b/runtime/doc/change.txt index c3f1b69da7..4565cdf63e 100644 --- a/runtime/doc/change.txt +++ b/runtime/doc/change.txt @@ -1250,7 +1250,7 @@ register. Use these registers for storing and retrieving the selected text for the GUI. See |quotestar| and |quoteplus|. When the clipboard is not available or not working, the unnamed register is used instead. For Unix systems and Mac OS X, -see |nvim-clipboard|. +see |primary-selection|. 9. Black hole register "_ *quote_* When writing to this register, nothing happens. This can be used to delete diff --git a/runtime/doc/develop.txt b/runtime/doc/develop.txt index 8881845fdd..1b77d87aac 100644 --- a/runtime/doc/develop.txt +++ b/runtime/doc/develop.txt @@ -1,23 +1,19 @@ -*develop.txt* For Vim version 7.4. Last change: 2016 Jan 31 +*develop.txt* - VIM REFERENCE MANUAL by Bram Moolenaar + NVIM REFERENCE MANUAL -Development of Vim. *development* - -This text is important for those who want to be involved in further developing -Vim. +Development of Nvim. *development* 1. Design goals |design-goals| 2. Design decisions |design-decisions| -See the file "src/nvim/README.md" for a high-level overview of the source -code. +Nvim is open source software. Everybody is encouraged to contribute. + https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md -Vim is open source software. Everybody is encouraged to contribute to help -improving Vim. For sending patches a context diff "diff -c" is preferred. -Also see http://vim.wikia.com/wiki/How_to_make_and_submit_a_patch. +See src/nvim/README.md for a high-level overview of the source code: + https://github.com/neovim/neovim/blob/master/src/nvim/README.md ============================================================================== 1. Design goals *design-goals* @@ -28,7 +24,7 @@ Note that quite a few items are contradicting. This is intentional. A balance must be found between them. -VIM IS... IMPROVED *design-improved* +NVIM IS... IMPROVED *design-improved* The IMproved bits of Vim should make it a better Vi, without becoming a completely different editor. Extensions are done with a "Vi spirit". @@ -49,7 +45,7 @@ completely different editor. Extensions are done with a "Vi spirit". implement and (3) someone actually implementing it. -VIM IS... MULTI PLATFORM *design-multi-platform* +NVIM IS... MULTI PLATFORM *design-multi-platform* Vim tries to help as many users on as many platforms as possible. - Support many kinds of terminals. The minimal demands are cursor positioning @@ -68,7 +64,7 @@ Vim tries to help as many users on as many platforms as possible. contradicts the previous item, these two must be balanced.] -VIM IS... WELL DOCUMENTED *design-documented* +NVIM IS... WELL DOCUMENTED *design-documented* - A feature that isn't documented is a useless feature. A patch for a new feature must include the documentation. @@ -76,9 +72,14 @@ VIM IS... WELL DOCUMENTED *design-documented* recommended. - Don't make the text unnecessarily long. Less documentation means that an item is easier to find. +- Do not prefix doc-tags with "nvim-". Use |vim_diff.txt| to document + differences from Vim. The {Nvim} annotation is also available + to mark a specific feature. No other distinction is necessary. +- If a feature is removed, delete its doc entry and move its tag to + |vim_diff.txt|. -VIM IS... HIGH SPEED AND SMALL IN SIZE *design-speed-size* +NVIM IS... HIGH SPEED AND SMALL IN SIZE *design-speed-size* Using Vim must not be a big attack on system resources. Keep it small and fast. @@ -89,13 +90,11 @@ fast. possible. Useful commands may take longer. - Don't forget that some people use Vim over a slow connection. Minimize the communication overhead. -- Items that add considerably to the size and are not used by many people - should be a feature that can be disabled. - Vim is a component among other components. Don't turn it into a massive application, but have it work well together with other programs. -VIM IS... MAINTAINABLE *design-maintain* +NVIM IS... MAINTAINABLE *design-maintain* - The source code should not become a mess. It should be reliable code. - Use comments in a useful way! Quoting the function name and argument names @@ -106,7 +105,7 @@ VIM IS... MAINTAINABLE *design-maintain* knowledge spread to other parts of the code. -VIM IS... FLEXIBLE *design-flexible* +NVIM IS... FLEXIBLE *design-flexible* Vim should make it easy for users to work in their preferred styles rather than coercing its users into particular patterns of work. This can be for @@ -117,27 +116,15 @@ be used to adjust Vim to the desire of the user and its environment. NVIM IS... NOT *design-not* -Nvim is not an Operating System; instead it should be composed with other -tools, or hosted as a component. Marvim once said: "Unlike Emacs, Nvim does -not attempt to include everything but the kitchen sink, but some people use it -for plumbing." +Nvim is not an operating system; instead it should be composed with other +tools or hosted as a component. Marvim once said: "Unlike Emacs, Nvim does not +include the kitchen sink... but you can use it for plumbing." ============================================================================== 2. Design decisions *design-decisions* -Folding - -Several forms of folding should be possible for the same buffer. For example, -have one window that shows the text with function bodies folded, another -window that shows a function body. - -Folding is a way to display the text. It should not change the text itself. -Therefore the folding has been implemented as a filter between the text stored -in a buffer (buffer lines) and the text displayed in a window (logical lines). - - -Naming the window +Window The word "window" is commonly used for several things: A window on the screen, the xterm window, a window inside Vim to view a buffer. @@ -153,110 +140,52 @@ window View on a buffer. There can be several windows in Vim, fit in the shell. -Spell checking *develop-spell* - -When spell checking was going to be added to Vim a survey was done over the -available spell checking libraries and programs. Unfortunately, the result -was that none of them provided sufficient capabilities to be used as the spell -checking engine in Vim, for various reasons: - -- Missing support for multi-byte encodings. At least UTF-8 must be supported, - so that more than one language can be used in the same file. - Doing on-the-fly conversion is not always possible (would require iconv - support). -- For the programs and libraries: Using them as-is would require installing - them separately from Vim. That's mostly not impossible, but a drawback. -- Performance: A few tests showed that it's possible to check spelling on the - fly (while redrawing), just like syntax highlighting. But the mechanisms - used by other code are much slower. Myspell uses a hashtable, for example. - The affix compression that most spell checkers use makes it slower too. -- For using an external program like aspell a communication mechanism would - have to be setup. That's complicated to do in a portable way (Unix-only - would be relatively simple, but that's not good enough). And performance - will become a problem (lots of process switching involved). -- Missing support for words with non-word characters, such as "Etten-Leur" and - "et al.", would require marking the pieces of them OK, lowering the - reliability. -- Missing support for regions or dialects. Makes it difficult to accept - all English words and highlight non-Canadian words differently. -- Missing support for rare words. Many words are correct but hardly ever used - and could be a misspelled often-used word. -- For making suggestions the speed is less important and requiring to install - another program or library would be acceptable. But the word lists probably - differ, the suggestions may be wrong words. - - -Spelling suggestions *develop-spell-suggestions* - -For making suggestions there are two basic mechanisms: -1. Try changing the bad word a little bit and check for a match with a good - word. Or go through the list of good words, change them a little bit and - check for a match with the bad word. The changes are deleting a character, - inserting a character, swapping two characters, etc. -2. Perform soundfolding on both the bad word and the good words and then find - matches, possibly with a few changes like with the first mechanism. - -The first is good for finding typing mistakes. After experimenting with -hashtables and looking at solutions from other spell checkers the conclusion -was that a trie (a kind of tree structure) is ideal for this. Both for -reducing memory use and being able to try sensible changes. For example, when -inserting a character only characters that lead to good words need to be -tried. Other mechanisms (with hashtables) need to try all possible letters at -every position in the word. Also, a hashtable has the requirement that word -boundaries are identified separately, while a trie does not require this. -That makes the mechanism a lot simpler. - -Soundfolding is useful when someone knows how the words sounds but doesn't -know how it is spelled. For example, the word "dictionary" might be written -as "daktonerie". The number of changes that the first method would need to -try is very big, it's hard to find the good word that way. After soundfolding -the words become "tktnr" and "tkxnry", these differ by only two letters. - -To find words by their soundfolded equivalent (soundalike word) we need a list -of all soundfolded words. A few experiments have been done to find out what -the best method is. Alternatives: -1. Do the sound folding on the fly when looking for suggestions. This means - walking through the trie of good words, soundfolding each word and - checking how different it is from the bad word. This is very efficient for - memory use, but takes a long time. On a fast PC it takes a couple of - seconds for English, which can be acceptable for interactive use. But for - some languages it takes more than ten seconds (e.g., German, Catalan), - which is unacceptable slow. For batch processing (automatic corrections) - it's too slow for all languages. -2. Use a trie for the soundfolded words, so that searching can be done just - like how it works without soundfolding. This requires remembering a list - of good words for each soundfolded word. This makes finding matches very - fast but requires quite a lot of memory, in the order of 1 to 10 Mbyte. - For some languages more than the original word list. -3. Like the second alternative, but reduce the amount of memory by using affix - compression and store only the soundfolded basic word. This is what Aspell - does. Disadvantage is that affixes need to be stripped from the bad word - before soundfolding it, which means that mistakes at the start and/or end - of the word will cause the mechanism to fail. Also, this becomes slow when - the bad word is quite different from the good word. - -The choice made is to use the second mechanism and use a separate file. This -way a user with sufficient memory can get very good suggestions while a user -who is short of memory or just wants the spell checking and no suggestions -doesn't use so much memory. - - -Word frequency - -For sorting suggestions it helps to know which words are common. In theory we -could store a word frequency with the word in the dictionary. However, this -requires storing a count per word. That degrades word tree compression a lot. -And maintaining the word frequency for all languages will be a heavy task. -Also, it would be nice to prefer words that are already in the text. This way -the words that appear in the specific text are preferred for suggestions. - -What has been implemented is to count words that have been seen during -displaying. A hashtable is used to quickly find the word count. The count is -initialized from words listed in COMMON items in the affix file, so that it -also works when starting a new file. - -This isn't ideal, because the longer Vim is running the higher the counts -become. But in practice it is a noticeable improvement over not using the word -count. +Providers *dev-provider* + +A goal of Nvim is to allow extension of the editor without special knowledge +in the core. But some Vim components are too tightly coupled; in those cases +a "provider" hook is exposed. + +Consider two examples of integration with external systems that are +implemented in Vim and are now decoupled from Nvim core as providers: + +1. In the Vim source code, clipboard logic accounts for more than 1k lines of + C source code (ui.c), to perform two tasks that are now accomplished with + shell commands such as xclip or pbcopy/pbpaste. + +2. Python scripting support: Vim has three files dedicated to embedding the + Python interpreter: if_python.c, if_python3.c and if_py_both.h. Together + these files sum about 9.5k lines of C source code. In contrast, Nvim Python + scripting is performed by an external host process implemented in ~2k lines + of Python. + +Ideally we could implement Python and clipboard integration in pure vimscript +and without touching the C code. But this is infeasible without compromising +backwards compatibility with Vim; that's where providers help. + +The provider framework helps call vimscript from C. It is composed of two +functions in eval.c: + +- eval_call_provider(name, method, arguments): calls provider#(name)#Call + with the method and arguments. +- eval_has_provider(name): Checks if a provider is implemented. Returns true + if the provider#(name)#Call function is implemented. Called by |has()| + (vimscript) to check if features are available. + +The provider#(name)#Call function implements integration with an external +system, because shell commands and |RPC| clients are easier to work with in +vimscript. + +For example, the Python provider is implemented by the +autoload/provider/python.vim script; the provider#python#Call function is only +defined if a valid external Python host is found. That works well with the +`has('python')` expression (normally used by Python plugins) because if the +Python host isn't installed then the plugin will "think" it is running in +a Vim compiled without the |+python| feature. + + +RPC API +API client +remote plugin vim:tw=78:ts=8:ft=help:norl: diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 869fcf0078..193153e8a3 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1653,9 +1653,9 @@ v:scrollstart String describing the script or function that caused the hit-enter prompt. *v:servername* *servername-variable* + *$NVIM_LISTEN_ADDRESS* v:servername Default {Nvim} server address. Equivalent to - |$NVIM_LISTEN_ADDRESS| on startup, but may differ if the - latter is modified or unset. |serverstop()| + |$NVIM_LISTEN_ADDRESS| on startup. |serverstop()| Read-only. @@ -1783,6 +1783,7 @@ abs({expr}) Float or Number absolute value of {expr} acos({expr}) Float arc cosine of {expr} add({list}, {item}) List append {item} to |List| {list} and({expr}, {expr}) Number bitwise AND +api_info() Dict api metadata append({lnum}, {string}) Number append {string} below line {lnum} append({lnum}, {list}) Number append lines {list} below line {lnum} argc() Number number of files in the argument list @@ -1812,6 +1813,7 @@ byteidx({expr}, {nr}) Number byte index of {nr}'th char in {expr} byteidxcomp({expr}, {nr}) Number byte index of {nr}'th char in {expr} call({func}, {arglist} [, {dict}]) any call {func} with arguments {arglist} +capture({command}) String capture output of {command} ceil({expr}) Float round {expr} up changenr() Number current change number char2nr({expr}[, {utf8}]) Number ASCII/UTF8 value of first char in {expr} @@ -1890,7 +1892,7 @@ getcmdpos() Number return cursor position in command-line getcmdtype() String return current command-line type getcmdwintype() String return current command-line window type getcurpos() List position of the cursor -getcwd([{scope}]) String the current working directory +getcwd([{winnr} [, {tabnr}]]) String the current working directory getfontname([{name}]) String name of font being used getfperm({fname}) String file permissions of file {fname} getfsize({fname}) Number size in bytes of file {fname} @@ -1921,7 +1923,8 @@ globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]]) String do glob({expr}) for all dirs in {path} has({feature}) Number TRUE if feature {feature} supported has_key({dict}, {key}) Number TRUE if {dict} has entry {key} -haslocaldir() Number TRUE if current window executed |:lcd| +haslocaldir([{winnr} [, {tabnr}]]) + Number TRUE if current window executed |:lcd| hasmapto({what} [, {mode} [, {abbr}]]) Number TRUE if mapping to {what} exists histadd({history}, {item}) String add an item to a history @@ -2030,11 +2033,11 @@ resolve({filename}) String get filename a shortcut points to reverse({list}) List reverse {list} in-place round({expr}) Float round off {expr} rpcnotify({channel}, {event}[, {args}...]) - Sends a |msgpack-rpc| notification to {channel} + Sends an |RPC| notification to {channel} rpcrequest({channel}, {method}[, {args}...]) - Sends a |msgpack-rpc| request to {channel} -rpcstart({prog}[, {argv}]) Spawns {prog} and opens a |msgpack-rpc| channel -rpcstop({channel}) Closes a |msgpack-rpc| {channel} + Sends an |RPC| request to {channel} +rpcstart({prog}[, {argv}]) Spawns {prog} and opens an |RPC| channel +rpcstop({channel}) Closes an |RPC| {channel} screenattr({row}, {col}) Number attribute at screen position screenchar({row}, {col}) Number character at screen position screencol() Number current cursor column @@ -2195,6 +2198,10 @@ and({expr}, {expr}) *and()* :let flag = and(bits, 0x80) +api_info() *api_info()* + Returns Dictionary of |api-metadata|. + + append({lnum}, {expr}) *append()* When {expr} is a |List|: Append each item of the |List| as a text line below line {lnum} in the current buffer. @@ -2490,6 +2497,23 @@ call({func}, {arglist} [, {dict}]) *call()* *E699* {dict} is for functions with the "dict" attribute. It will be used to set the local variable "self". |Dictionary-function| +capture({command}) *capture()* + Capture output of {command}. + If {command} is a |String|, returns {command} output. + If {command} is a |List|, returns concatenated outputs. + Examples: > + echo capture('echon "foo"') +< foo > + echo capture(['echon "foo"', 'echon "bar"']) +< foobar + This function is not available in the |sandbox|. + Note: {command}s run as if prepended with |:silent| (output is + captured, but not displayed). If multiple capture() calls are + nested, the outer capture() will not catch the command output + of the inner capture(); the inner capture will not cancel the + outer. + Note: Text attributes (highlights) are not captured. + ceil({expr}) *ceil()* Return the smallest integral value greater than or equal to {expr} as a |Float| (round up). @@ -3598,17 +3622,17 @@ getcurpos() Get the position of the cursor. This is like getpos('.'), but MoveTheCursorAround call setpos('.', save_cursor) < -getcwd([{window}[, {tab}]]) *getcwd()* +getcwd([{winnr}[, {tabnr}]]) *getcwd()* With no arguments the result is a String, which is the name of - the current effective working directory. With {window} or - {tab} the working directory of that scope is returned. + the current effective working directory. With {winnr} or + {tabnr} the working directory of that scope is returned. Tabs and windows are identified by their respective numbers, 0 means current tab or window. Missing argument implies 0. Thus the following are equivalent: > getcwd() getcwd(0) getcwd(0, 0) -< If {window} is -1 it is ignored, only the tab is resolved. +< If {winnr} is -1 it is ignored, only the tab is resolved. getfsize({fname}) *getfsize()* @@ -3947,7 +3971,7 @@ has_key({dict}, {key}) *has_key()* The result is a Number, which is 1 if |Dictionary| {dict} has an entry with key {key}. Zero otherwise. -haslocaldir([{window}[, {tab}]]) *haslocaldir()* +haslocaldir([{winnr}[, {tabnr}]]) *haslocaldir()* The result is a Number, which is 1 when the specified tabpage or window has a local path set via |:lcd| or |:tcd|, and 0 otherwise. @@ -3958,7 +3982,7 @@ haslocaldir([{window}[, {tab}]]) *haslocaldir()* haslocaldir() haslocaldir(0) haslocaldir(0, 0) -< If {window} is -1 it is ignored, only the tab is resolved. +< If {winnr} is -1 it is ignored, only the tab is resolved. hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()* The result is a Number, which is 1 if there is a mapping that @@ -5525,31 +5549,31 @@ round({expr}) *round()* < -5.0 rpcnotify({channel}, {event}[, {args}...]) {Nvim} *rpcnotify()* - Sends {event} to {channel} via |msgpack-rpc| and returns - immediately. If {channel} is 0, the event is broadcast to all - channels. Example: > + Sends {event} to {channel} via |RPC| and returns immediately. + If {channel} is 0, the event is broadcast to all channels. + Example: > :au VimLeave call rpcnotify(0, "leaving") rpcrequest({channel}, {method}[, {args}...]) {Nvim} *rpcrequest()* Sends a request to {channel} to invoke {method} via - |msgpack-rpc| and blocks until a response is received. + |RPC| and blocks until a response is received. Example: > :let result = rpcrequest(rpc_chan, "func", 1, 2, 3) rpcstart({prog}[, {argv}]) {Nvim} *rpcstart()* Spawns {prog} as a job (optionally passing the list {argv}), - and opens a |msgpack-rpc| channel with the spawned process's - stdin/stdout. It returns: - - The channel id on success, which is used by |rpcrequest()|, + and opens an |RPC| channel with the spawned process's + stdin/stdout. Returns: + - channel id on success, which is used by |rpcrequest()|, |rpcnotify()| and |rpcstop()| - - 0 on failure. + - 0 on failure Example: > :let rpc_chan = rpcstart('prog', ['arg1', 'arg2']) rpcstop({channel}) {Nvim} *rpcstop()* - Closes a |msgpack-rpc| {channel}, possibly created via + Closes an |RPC| {channel}, possibly created via |rpcstart()|. Also closes channels created by connections to - |$NVIM_LISTEN_ADDRESS|. + |v:servername|. screenattr(row, col) *screenattr()* Like screenchar(), but return the attribute. This is a rather @@ -6840,7 +6864,7 @@ termopen({cmd}[, {opts}]) {Nvim} *termopen()* and `$TERM` is set to "xterm-256color". Returns the same values as |jobstart()|. - See |nvim-terminal-emulator| for more information. + See |terminal-emulator| for more information. tan({expr}) *tan()* Return the tangent of {expr}, measured in radians, as a |Float| diff --git a/runtime/doc/gui.txt b/runtime/doc/gui.txt index 8d97678af2..e2fb501ac5 100644 --- a/runtime/doc/gui.txt +++ b/runtime/doc/gui.txt @@ -395,9 +395,9 @@ You may make selections with the mouse (see |gui-mouse-select|), or by using Vim's Visual mode (see |v|). If 'a' is present in 'guioptions', then whenever a selection is started (Visual or Select mode), or when the selection is changed, Vim becomes the owner of the windowing system's primary selection -(on MS-Windows the |gui-clipboard| is used). +(on MS-Windows the |clipboard| is used). - *clipboard* + *primary-selection* There is a special register for storing this selection, it is the "* register. Nothing is put in here unless the information about what text is selected is about to change (e.g. with a left mouse click somewhere), or when diff --git a/runtime/doc/gui_w32.txt b/runtime/doc/gui_w32.txt deleted file mode 100644 index 228be9eab2..0000000000 --- a/runtime/doc/gui_w32.txt +++ /dev/null @@ -1,437 +0,0 @@ -*gui_w32.txt* For Vim version 7.4. Last change: 2014 Dec 20 - - - VIM REFERENCE MANUAL by Bram Moolenaar - - -Vim's Win32 Graphical User Interface *gui-w32* *win32-gui* - -1. Starting the GUI |gui-w32-start| -2. Vim as default editor |vim-default-editor| -3. Using the clipboard |gui-clipboard| -4. Shell Commands |gui-shell-win32| -5. Special colors |win32-colors| -6. Windows dialogs & browsers |gui-w32-dialogs| -7. Command line arguments |gui-w32-cmdargs| -8. Various |gui-w32-various| - -Other relevant documentation: -|gui.txt| For generic items of the GUI. -|os_win32.txt| For Win32 specific items. - -============================================================================== -1. Starting the GUI *gui-w32-start* - -The Win32 GUI version of Vim will always start the GUI, no matter how you -start it or what it's called. - -The GUI will always run in the Windows subsystem. Mostly shells automatically -return with a command prompt after starting gvim. If not, you should use the -"start" command: > - start gvim [options] file .. - -Note: All fonts (bold, italic) must be of the same size!!! If you don't do -this, text will disappear or mess up the display. Vim does not check the font -sizes. It's the size in screen pixels that must be the same. Note that some -fonts that have the same point size don't have the same pixel size! -Additionally, the positioning of the fonts must be the same (ascent and -descent). - -The Win32 GUI has an extra menu item: "Edit/Select Font". It brings up the -standard Windows font selector. - -Setting the menu height doesn't work for the Win32 GUI. - - *gui-win32-maximized* -If you want Vim to start with a maximized window, add this command to your -vimrc or gvimrc file: > - au GUIEnter * simalt ~x -< -============================================================================== -2. Vim as default editor *vim-default-editor* - -To set Vim as the default editor for a file type: -1. Start a Windows Explorer -2. Choose View/Options -> File Types -3. Select the path to gvim for every file type that you want to use it for. - (you can also use three spaces in the file type field, for files without an - extension). - In the "open" action, use: > - gvim "%1" -< The quotes are required for using file names with embedded spaces. - You can also use this: > - gvim "%L" -< This should avoid short (8.3 character) file names in some situations. But - I'm not sure if this works everywhere. - -When you open a file in Vim by double clicking it, Vim changes to that -file's directory. - -If you want Vim to start full-screen, use this for the Open action: > - gvim -c "simalt ~x" "%1" - -Another method, which also works when you put Vim in another directory (e.g., -when you have got a new version): -1. select a file you want to use Vim with -2. <Shift-F10> -3. select "Open With..." menu entry -4. click "Other..." -5. browse to the (new) location of Vim and click "Open" -6. make "Always Use this program..." checked -7. <OK> - - *send-to-menu* *sendto* -You can also install Vim in the "Send To" menu: -1. Start a Windows Explorer -2. Navigate to your sendto directory: - Windows NT: %windir%\profiles\%user%\sendto (e.g. - "c:\winnt\profiles\mattha\sendto"). -3. Right-click in the file pane and select New->Shortcut -4. Follow the shortcut wizard, using the full path to VIM/GVIM. - -When you 'send a file to Vim', Vim changes to that file's directory. Note, -however, that any long directory names will appear in their short (MS-DOS) -form. This is a limitation of the Windows "Send To" mechanism. - - *notepad* -You could replace notepad.exe with gvim.exe, but that has a few side effects. -Some programs rely on notepad arguments, which are not recognized by Vim. For -example "notepad -p" is used by some applications to print a file. It's -better to leave notepad where it is and use another way to start Vim. - - *win32-popup-menu* -A more drastic approach is to install an "Edit with Vim" entry in the popup -menu for the right mouse button. With this you can edit any file with Vim. - -This can co-exist with the file associations mentioned above. The difference -is that the file associations will make starting Vim the default action. With -the "Edit with Vim" menu entry you can keep the existing file association for -double clicking on the file, and edit the file with Vim when you want. For -example, you can associate "*.mak" with your make program. You can execute -the makefile by double clicking it and use the "Edit with Vim" entry to edit -the makefile. - -You can select any files and right-click to see a menu option called "Edit -with gvim". Choosing this menu option will invoke gvim with the file you have -selected. If you select multiple files, you will find two gvim-related menu -options: -"Edit with multiple gvims" -- one gvim for each file in the selection -"Edit with single gvim" -- one gvim for all the files in the selection -And if there already is a gvim running: -"Edit with existing gvim" -- edit the file with the running gvim - -The "edit with existing Vim" entries can be disabled by adding an entry in the -registry under HKLM\Software\Vim\Gvim, named DisableEditWithExisting, and with -any value. - *install-registry* -You can add the "Edit with Vim" menu entry in an easy way by using the -"install.exe" program. It will add several registry entries for you. - -You can also do this by hand. This is complicated! Use the install.exe if -you can. - -1. Start the registry editor with "regedit". -2. Add these keys: - key value name value ~ - HKEY_CLASSES_ROOT\CLSID\{51EEE242-AD87-11d3-9C1E-0090278BBD99} - {default} Vim Shell Extension - HKEY_CLASSES_ROOT\CLSID\{51EEE242-AD87-11d3-9C1E-0090278BBD99}\InProcServer32 - {default} {path}\gvimext.dll - ThreadingModel Apartment - HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\gvim - {default} {51EEE242-AD87-11d3-9C1E-0090278BBD99} - HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved - {51EEE242-AD87-11d3-9C1E-0090278BBD99} - Vim Shell Extension - HKEY_LOCAL_MACHINE\Software\Vim\Gvim - path {path}\gvim.exe - HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\vim 5.6 - DisplayName Vim 5.6: Edit with Vim popup menu entry - UninstallString {path}\uninstal.exe - - Replace {path} with the path that leads to the executable. - Don't type {default}, this is the value for the key itself. - -To remove "Edit with Vim" from the popup menu, just remove the registry -entries mentioned above. The "uninstal.exe" program can do this for you. You -can also use the entry in the Windows standard "Add/Remove Programs" list. - -If you notice that this entry overrules other file type associations, set -those associations again by hand (using Windows Explorer, see above). This -only seems to happen on some Windows NT versions (Windows bug?). Procedure: -1. Find the name of the file type. This can be done by starting the registry - editor, and searching for the extension in \\HKEY_CLASSES_ROOT -2. In a Windows Explorer, use View/Options/File Types. Search for the file - type in the list and click "Edit". In the actions list, you can select on - to be used as the default (normally the "open" action) and click on the - "Set Default" button. - - -Vim in the "Open With..." context menu *win32-open-with-menu* - -If you use the Vim install program you have the choice to add Vim to the "Open -With..." menu. This means you can use Vim to edit many files. Not every file -(for unclear reasons...), thus the "Edit with Vim" menu entry is still useful. - -One reason to add this is to be able to edit HTML files directly from Internet -Explorer. To enable this use the "Tools" menu, "Internet Options..." entry. -In the dialog select the "Programs" tab and select Vim in the "HTML editor" -choice. If it's not there than installing didn't work properly. - -Doing this manually can be done with this script: - ----------------------------------------------------------- -REGEDIT4 - -[HKEY_CLASSES_ROOT\Applications\gvim.exe] - -[HKEY_CLASSES_ROOT\Applications\gvim.exe\shell] - -[HKEY_CLASSES_ROOT\Applications\gvim.exe\shell\edit] - -[HKEY_CLASSES_ROOT\Applications\gvim.exe\shell\edit\command] -@="c:\\vim\\vim62\\gvim.exe \"%1\"" - -[HKEY_CLASSES_ROOT\.htm\OpenWithList\gvim.exe] - -[HKEY_CLASSES_ROOT\*\OpenWithList\gvim.exe] - ----------------------------------------------------------- - -Change the "c:\\vim\\vim62" bit to where gvim.exe is actually located. - -To uninstall this run the Vim uninstall program or manually delete the -registry entries with "regedit". - -============================================================================== -3. Using the clipboard *gui-clipboard* - -Windows has a clipboard, where you can copy text to, and paste text from. Vim -supports this in several ways. For other systems see |gui-selections|. - -The "* register reflects the contents of the clipboard. |quotestar| - -When the "unnamed" string is included in the 'clipboard' option, the unnamed -register is the same. Thus you can yank to and paste from the clipboard -without prepending "* to commands. - -The 'a' flag in 'guioptions' is not included by default. This means that text -is only put on the clipboard when an operation is performed on it. Just -Visually selecting text doesn't put it on the clipboard. When the 'a' flag is -included, the text is copied to the clipboard even when it is not operated -upon. - - *mswin.vim* -To use the standard MS-Windows way of CTRL-X, CTRL-C and CTRL-V, use the -$VIMRUNTIME/mswin.vim script. You could add this line to your _vimrc file: > - source $VIMRUNTIME/mswin.vim - -Since CTRL-C is used to copy the text to the clipboard, it can't be used to -cancel an operation. Use CTRL-Break for that. - -CTRL-Z is used for undo. This means you can't suspend Vim with this key, use -|:suspend| instead (if it's supported at all). - - *CTRL-V-alternative* *CTRL-Q* -Since CTRL-V is used to paste, you can't use it to start a blockwise Visual -selection. You can use CTRL-Q instead. You can also use CTRL-Q in Insert -mode and Command-line mode to get the old meaning of CTRL-V. But CTRL-Q -doesn't work for terminals when it's used for control flow. - -NOTE: The clipboard support still has a number of bugs. - -============================================================================== -4. Shell Commands *gui-shell-win32* - -Vim uses another window for external commands, to make it possible to run any -command. The external command gets its own environment for running, just like -it was started from a DOS prompt. - - *win32-vimrun* -Executing an external command is done indirectly by the "vimrun" command. The -"vimrun.exe" must be in the path for this to work. Or it must be in the same -directory as the Vim executable. If "vimrun" cannot be found, the command is -executed directly, but then the DOS window closes immediately after the -external command has finished. -WARNING: If you close this window with the "X" button, and confirm the -question if you really want to kill the application, Vim may be killed too! -(This does not apply to commands run asynchronously with ":!start".) - - *win32-!start* -Normally, Vim waits for a command to complete before continuing (this makes -sense for most shell commands which produce output for Vim to use). If you -want Vim to start a program and return immediately, you can use the following -syntax on W95 & NT: > - :!start [/min] {command} -The optional "/min" causes the window to be minimized. - -============================================================================== -5. Special colors *win32-colors* - -On Win32, the normal DOS colors can be used. See |dos-colors|. - -Additionally the system configured colors can also be used. These are known -by the names Sys_XXX, where XXX is the appropriate system color name, from the -following list (see the Win32 documentation for full descriptions). Case is -ignored. - -Sys_3DDKShadow Sys_3DFace Sys_BTNFace -Sys_3DHilight Sys_3DHighlight Sys_BTNHilight -Sys_BTNHighlight Sys_3DLight Sys_3DShadow -Sys_BTNShadow Sys_ActiveBorder Sys_ActiveCaption -Sys_AppWorkspace Sys_Background Sys_Desktop -Sys_BTNText Sys_CaptionText Sys_GrayText -Sys_Highlight Sys_HighlightText Sys_InactiveBorder -Sys_InactiveCaption Sys_InactiveCaptionText Sys_InfoBK -Sys_InfoText Sys_Menu Sys_MenuText -Sys_ScrollBar Sys_Window Sys_WindowFrame -Sys_WindowText - -Probably the most useful values are - Sys_Window Normal window background - Sys_WindowText Normal window text - Sys_Highlight Highlighted background - Sys_HighlightText Highlighted text - -These extra colors are also available: -Gray, Grey, LightYellow, SeaGreen, Orange, Purple, SlateBlue, Violet, - - *rgb.txt* -Additionally, colors defined by a "rgb.txt" file can be used. This file is -well known from X11. A few lines from it: > - - 255 218 185 peach puff - 205 133 63 peru - 255 181 197 pink - -This shows the layout of the file: First the R, G and B value as a decimal -number, followed by the name of the color. The four fields are separated by -spaces. - -You can get an rgb.txt file from any X11 distribution. It is located in a -directory like "/usr/X11R6/lib/X11/". For Vim it must be located in the -$VIMRUNTIME directory. Thus the file can be found with "$VIMRUNTIME/rgb.txt". - -============================================================================== - *gui-w32-dialogs* *dialog* -6. Windows dialogs & browsers - -The Win32 GUI can use familiar Windows components for some operations, as well -as the traditional interface shared with the console version. - - -6.1 Dialogs - -The dialogs displayed by the "confirm" family (i.e. the 'confirm' option, -|:confirm| command and |confirm()| function) are GUI-based rather than the -console-based ones used by other versions. The 'c' flag in 'guioptions' -changes this. - - -6.2 File Browsers - -When prepending ":browse" before file editing commands, a file requester is -used to allow you to select an existing file. See |:browse|. - -============================================================================== -7. Command line arguments *gui-w32-cmdargs* - -Analysis of a command line into parameters is not standardised in MS Windows. -Gvim has to provide logic to analyse a command line. This logic is likely to -be different from the default logic provided by a compilation system used to -build vim. The differences relate to unusual double quote (") usage. -The arguments "C:\My Music\freude.txt" and "+/Sch\"iller" are handled in the -same way. The argument "+/Sch""iller" may be handled different by gvim and -vim, depending what it was compiled with. - -The rules are: - a) A parameter is a sequence of graphic characters. - b) Parameters are separated by white space. - c) A parameter can be enclosed in double quotes to include white space. - d) A sequence of zero or more backslashes (\) and a double quote (") - is special. The effective number of backslashes is halved, rounded - down. An even number of backslashes reverses the acceptability of - spaces and tabs, an odd number of backslashes produces a literal - double quote. - -So: - " is a special double quote - \" is a literal double quote - \\" is a literal backslash and a special double quote - \\\" is a literal backslash and a literal double quote - \\\\" is 2 literal backslashes and a special double quote - \\\\\" is 2 literal backslashes and a literal double quote - etc. - -Example: > - gvim "C:\My Music\freude" +"set ignorecase" +/"\"foo\\" +\"bar\\\" - -opens "C:\My Music\freude" and executes the line mode commands: > - set ignorecase; /"foo\ and /bar\" - -============================================================================== -8. Various *gui-w32-various* - - *gui-w32-printing* -The "File/Print" menu prints the text with syntax highlighting, see -|:hardcopy|. If you just want to print the raw text and have a default -printer installed this should also work: > - :w >>prn - -Vim supports a number of standard MS Windows features. Some of these are -detailed elsewhere: see |'mouse'|, |win32-hidden-menus|. - - *drag-n-drop-win32* -You can drag and drop one or more files into the Vim window, where they will -be opened as normal. See |drag-n-drop|. - - *:simalt* *:sim* -:sim[alt] {key} simulate pressing {key} while holding Alt pressed. - {only for Win32 versions} - -Normally, Vim takes control of all Alt-<Key> combinations, to increase the -number of possible mappings. This clashes with the standard use of Alt as the -key for accessing menus. -The quick way of getting standard behavior is to set the 'winaltkeys' option -to "yes". This however prevents you from mapping Alt keys at all. -Another way is to set 'winaltkeys' to "menu". Menu shortcut keys are then -handled by windows, other ALT keys can be mapped. This doesn't allow a -dependency on the current state though. -To get round this, the :simalt command allows Vim (when 'winaltkeys' is not -"yes") to fake a Windows-style Alt keypress. You can use this to map Alt key -combinations (or anything else for that matter) to produce standard Windows -actions. Here are some examples: > - - :map <M-f> :simalt f<CR> -This makes Alt-F pop down the 'File' menu (with the stock Menu.vim) by -simulating the keystrokes Alt, F. > - :map <M-Space> :simalt ~<CR> -This maps Alt-Space to pop down the system menu for the Vim window. Note that -~ is used by simalt to represent the <Space> character. > - :map <C-n> :simalt ~n<CR> -Maps Control-N to produce the keys Alt-Space followed by N. This minimizes the -Vim window via the system menu. - -Note that the key changes depending on the language you are using. - - *intellimouse-wheel-problems* -When using the Intellimouse mouse wheel causes Vim to stop accepting input, go -to: - ControlPanel - Mouse - Wheel - UniversalScrolling - Exceptions - -And add gvim to the list of applications. This problem only appears to happen -with the Intellimouse driver 2.2 and when "Universal Scrolling" is turned on. - - -XPM support *w32-xpm-support* - -Gvim can be build on MS-Windows with support for XPM files. |+xpm_w32| -See the Make_mvc.mak file for instructions, search for XPM. - -To try out if XPM support works do this: > - :help - :exe 'sign define vimxpm icon=' . $VIMRUNTIME . '\\vim16x16.xpm' - :exe 'sign place 1 line=1 name=vimxpm file=' . expand('%:p') -< - - vim:tw=78:sw=4:ts=8:ft=help:norl: diff --git a/runtime/doc/if_pyth.txt b/runtime/doc/if_pyth.txt index f6bd365299..8946dd2e5a 100644 --- a/runtime/doc/if_pyth.txt +++ b/runtime/doc/if_pyth.txt @@ -16,7 +16,7 @@ The Python Interface to Vim *python* *Python* 8. pyeval(), py3eval() Vim functions |python-pyeval| 9. Python 3 |python3| -See |nvim-python| for more information. {Nvim} +See |provider-python| for more information. {Nvim} ============================================================================== 1. Commands *python-commands* diff --git a/runtime/doc/msgpack_rpc.txt b/runtime/doc/msgpack_rpc.txt index bafb9dfc2c..cfd9084cfc 100644 --- a/runtime/doc/msgpack_rpc.txt +++ b/runtime/doc/msgpack_rpc.txt @@ -1,97 +1,89 @@ -*msgpack_rpc.txt* For Nvim. {Nvim} +*msgpack_rpc.txt* {Nvim} NVIM REFERENCE MANUAL by Thiago de Arruda -The Msgpack-RPC Interface to Nvim *msgpack-rpc* +RPC API for Nvim *RPC* *rpc* *msgpack-rpc* -1. Introduction |msgpack-rpc-intro| -2. API mapping |msgpack-rpc-api| -3. Connecting |msgpack-rpc-connecting| -4. Clients |msgpack-rpc-clients| -5. Types |msgpack-rpc-types| -6. Wrapping methods |msgpack-rpc-wrap-methods| -7. Vimscript functions |msgpack-rpc-vim-functions| +1. Introduction |rpc-intro| +2. API mapping |rpc-api| +3. Connecting |rpc-connecting| +4. Clients |rpc-api-client| +5. Types |rpc-types| +6. Vimscript functions |rpc-vim-functions| ============================================================================== -1. Introduction *msgpack-rpc-intro* +1. Introduction *rpc-intro* -The primary way to control a running Nvim instance is through -MessagePack-RPC, a messaging protocol that uses the MessagePack serialization -format: https://github.com/msgpack/msgpack/blob/7498cf3/spec.md. -From now on, we refer to the protocol as msgpack-rpc. +The primary way to control Nvim programmatically is the RPC API, which speaks +MessagePack-RPC ("msgpack-rpc"), a messaging protocol that uses the +MessagePack serialization format: + https://github.com/msgpack/msgpack/blob/0b8f5ac/spec.md -At this point, only plugins use msgpack-rpc, but eventually even user -interaction will happen through it, since user interfaces will be separate -programs that control a headless Nvim instance. +All kinds of Nvim "clients" use the RPC API: user interfaces (GUIs), remote +plugins, scripts like "nvr" (https://github.com/mhinz/neovim-remote), and even +`nvim` itself can control other `nvim` instances. By connecting to the RPC API +programs can: -By connecting to the msgpack-rpc interface, programs can: + - Call any API function + - Listen for events + - Receive remote calls from Nvim -- Call any Nvim API function -- Listen for Nvim events -- Receive remote calls from Nvim - -Nvim's msgpack-rpc interface is like a more powerful version of Vim's -`clientserver` feature. +The RPC API is like a more powerful version of Vim's `clientserver` feature. ============================================================================== -2. API mapping *msgpack-rpc-api* + 2. API mapping *rpc-api* -The Nvim C API, see |nvim-api|, is automatically exposed to the msgpack-rpc -interface by the build system, which parses headers at src/nvim/api from the -project root. A dispatch function is generated, which matches msgpack-rpc method -names with non-static API functions, converting/validating arguments and return -values back to msgpack. +The Nvim C |API| is automatically exposed to the RPC API by the build system, +which parses headers at src/nvim/api/*. A dispatch function is generated which +matches RPC API method names with public API functions, converting/validating +arguments and return values back to msgpack. -Client libraries will normally provide wrappers that hide msgpack-rpc details -from programmers. The wrappers can be automatically generated by reading -bundled API metadata from a compiled Nvim instance. +Client libraries (|api-client|s) normally provide wrappers that hide +msgpack-rpc details from application developers. The wrappers can be +automatically generated by reading bundled API metadata from a compiled Nvim +instance. -There are two ways to obtain API metadata: +There are three ways to obtain API metadata: -1. By connecting to a running Nvim instance and calling `vim_get_api_info` - via msgpack-rpc. This is best for clients written in dynamically-typed - languages, which can define functions at runtime. + 1. Connect to a running Nvim instance and call `vim_get_api_info` via + msgpack-rpc. This is best for clients written in dynamic languages which + can define functions at runtime. -2. By starting Nvim with the `--api-info` command-line option, which makes Nvim - dump a blob of msgpack metadata to standard output and exit. This is best - for clients written in statically-typed languages, which require a separate - compilation step. + 2. Start Nvim with the |--api-info| option. Useful for clients written in + statically-compiled languages. -Here's a simple way to get human-readable description of the API (requires -Python and the `pyyaml`/`msgpack-python` pip packages): -> - nvim --api-info | python -c 'import msgpack, sys, yaml; print yaml.dump(msgpack.unpackb(sys.stdin.read()))' > api.yaml + 3. Use the |api_info()| vimscript function. + +To get a human-readable list of API functions: > + :new|put =map(api_info().functions, 'v:val.name') +< +To get a formatted dump of the API using python (requires the `pyyaml` and +`msgpack-python` packages): > + nvim --api-info | python -c 'import msgpack, sys, yaml; print yaml.dump(msgpack.unpackb(sys.stdin.read()))' < ============================================================================== -3. Connecting *msgpack-rpc-connecting* +3. Connecting *rpc-connecting* -There are four ways to open msgpack-rpc streams to Nvim: +There are several ways to open a msgpack-rpc stream to an Nvim server: -1. Through Nvim's stdin/stdout when it's started with the `--embed` option. - This is how other programs can embed Nvim. + 1. Through stdin/stdout when `nvim` is started with `--embed`. This is how + applications can embed Nvim. -2. Through the stdin/stdout of a program spawned by the |rpcstart()| function. + 2. Through stdin/stdout of some other process spawned by |rpcstart()|. - *$NVIM_LISTEN_ADDRESS* -3. Through the socket automatically created with each instance. To get the - socket location for a running Nvim instance (which is random by default), - see the |$NVIM_LISTEN_ADDRESS| environment variable: -> - :echo $NVIM_LISTEN_ADDRESS -< - See also |v:servername|. + 3. Through the socket automatically created with each instance. The socket + location is stored in |v:servername|. -4. Through a TCP/IP socket. To make Nvim listen on a TCP/IP socket, set the - |$NVIM_LISTEN_ADDRESS| environment variable in a shell before starting Nvim: -> + 4. Through a TCP/IP socket. To make Nvim listen on a TCP/IP socket, set the + |$NVIM_LISTEN_ADDRESS| environment variable before starting Nvim: > NVIM_LISTEN_ADDRESS=127.0.0.1:6666 nvim < -Connecting to the socket is the easiest way a programmer can test the API, which -can be done through any msgpack-rpc client library or fully-featured Nvim client -(which we'll see in the next section). Here's a Ruby script that prints 'hello -world!' in the current Nvim instance: +Connecting to the socket is the easiest way a programmer can test the API, +which can be done through any msgpack-rpc client library or full-featured +|api-client|. Here's a Ruby script that prints 'hello world!' in the current +Nvim instance: > #!/usr/bin/env ruby # Requires msgpack-rpc: gem install msgpack-rpc @@ -118,72 +110,103 @@ functions can be called interactively: >>> nvim = attach('socket', path='[address]') >>> nvim.command('echo "hello world!"') < -One can also spawn and connect to an embedded Nvim instance via |rpcstart()| +You can also embed an Nvim instance via |rpcstart()| > let vim = rpcstart('nvim', ['--embed']) echo rpcrequest(vim, 'vim_eval', '"Hello " . "world!"') call rpcstop(vim) < ============================================================================== -4. Implementing new clients *msgpack-rpc-clients* - -Nvim is still in alpha, so there's no in-depth documentation explaining how to -properly implement a client library yet. The Python client (the pip package -"neovim") will always be up-to-date with the latest API changes, so its source -code is the best documentation currently available. There are some guidelines -however: - -- Separate the transport layer from the rest of the library. See - |msgpack-rpc-connecting| for details on how clients can connect to Nvim. -- Use a MessagePack library that implements at least version 5 of the - MessagePack spec, which supports the `bin` and `ext` types used by Nvim. -- Read API metadata in order to create client-side wrappers for all - msgpack-rpc methods. -- Use a single-threaded event loop library/pattern. -- Use a fiber/coroutine library for the language being used for implementing a - client. These greatly simplify concurrency and allow the library to expose a - blocking API on top of a non-blocking event loop without the complexity that - comes with preemptive multitasking. -- Don't assume anything about the order that responses to msgpack-rpc requests - will arrive. -- Clients should expect msgpack-rpc requests, which need to be handled - immediately because Nvim is blocked while waiting for the client response. -- Clients should expect to receive msgpack-rpc notifications, but these don't - need to be handled immediately because they won't block Nvim (although they - should probably be handled immediately anyway). - -Most of the complexity could be handled by a msgpack-rpc library that supports -server to client requests and notifications, but it's not clear if this is part -of the msgpack-rpc spec. At least the Ruby msgpack-rpc library does not seem -to support it: - +4. Implementing API clients *rpc-api-client* *api-client* + +All external UIs and remote plugins (as opposed to regular Vim plugins) are +"clients" in general; but we call something an "API client" if its purpose is +to abstract or wrap the RPC API for the convenience of other applications +(just like a REST client or SDK such as boto3 for AWS: you can speak AWS REST +using an HTTP client like curl, but boto3 wraps that in a convenient python +interface). For example, the lua-client is an API client: + https://github.com/neovim/lua-client + +The Python client (pip package "neovim") is the reference implementation of an +API client. It is always up-to-date with the Nvim API, so its source code and +test suite are an authoritative reference. + https://github.com/neovim/python-client + +API client implementation guidelines ~ + + - Separate the transport layer from the rest of the library. See + |rpc-connecting| for details on how clients can connect to Nvim. + - Use a MessagePack library that implements at least version 5 of the + MessagePack spec, which supports the `bin` and `ext` types used by Nvim. + - Read API metadata in order to create client-side wrappers for all + msgpack-rpc methods. + - Use a single-threaded event loop library/pattern. + - Use a fiber/coroutine library for the language being used for implementing + a client. These greatly simplify concurrency and allow the library to + expose a blocking API on top of a non-blocking event loop without the + complexity that comes with preemptive multitasking. + - Don't assume anything about the order that responses to msgpack-rpc + requests will arrive. + - Clients should expect msgpack-rpc requests, which need to be handled + immediately because Nvim is blocked while waiting for the client response. + - Clients should expect to receive msgpack-rpc notifications, but these + don't need to be handled immediately because they won't block Nvim + (although they should probably be handled immediately anyway). + +Note: Most of the complexity could be handled by a msgpack-rpc library that +supports server to client requests and notifications, but it's not clear if +this is part of the msgpack-rpc spec. At least the Ruby msgpack-rpc library +does not seem to support it: https://github.com/msgpack-rpc/msgpack-rpc-ruby/blob/master/lib/msgpack/rpc/transport/tcp.rb#L150-L158 +API metadata object ~ + +API clients exist to hide msgpack-rpc details. The API metadata object +contains information that makes this task easier (see also |rpc-types|): + + - The "functions" key contains a list of metadata objects for individual + functions. + - Each function metadata object has |rpc-types| information about the return + value and parameters. These can be used for generating strongly-typed APIs + in static languages. + - Container types may be decorated with type/size constraints, e.g. + ArrayOf(Buffer) or ArrayOf(Integer, 2). This can be useful to generate + even more strongly-typed APIs. + - Methods that operate on instances of Nvim special types (msgpack EXT) are + prefixed with the type name in lower case, e.g. `buffer_get_line` + represents the `get_line` method of a Buffer instance. + - Global methods are prefixed with `vim`, e.g. `vim_get_buffers`. + +So for an object-oriented language, an API client contains the classes +representing Nvim special types, and the methods of each class could be +defined by inspecting the method name prefix. There could also be a singleton +Vim class with methods mapped to functions prefixed with `vim_`. + ============================================================================== -5. Types *msgpack-rpc-types* +5. Types *rpc-types* -Nvim's C API uses custom types for all functions, se |nvim-api-types|. -For the purpose of mapping to msgpack, he types can be split into two groups: +The Nvim C API uses custom types for all functions. |api-types| +For the purpose of mapping to msgpack, the types can be split into two groups: -- Basic types that map natively to msgpack (and probably have a default - representation in msgpack-supported programming languages) -- Special Nvim types that map to msgpack EXT with custom type codes. + - Basic types that map natively to msgpack (and probably have a default + representation in msgpack-supported programming languages) + - Special Nvim types that map to msgpack EXT with custom type codes. -Basic type mapping: +Basic types ~ -Nil -> msgpack nil -Boolean -> msgpack boolean -Integer (signed 64-bit integer) -> msgpack integer -Float (IEEE 754 double precision) -> msgpack float -String -> msgpack string -Array -> msgpack array -Dictionary -> msgpack map + Nil -> msgpack nil + Boolean -> msgpack boolean + Integer (signed 64-bit integer) -> msgpack integer + Float (IEEE 754 double precision) -> msgpack float + String -> msgpack string + Array -> msgpack array + Dictionary -> msgpack map -Special Nvim types that use msgpack EXT: +Special types (msgpack EXT) ~ -Buffer -> enum value kObjectTypeBuffer -Window -> enum value kObjectTypeWindow -Tabpage -> enum value kObjectTypeTabpage + Buffer -> enum value kObjectTypeBuffer + Window -> enum value kObjectTypeWindow + Tabpage -> enum value kObjectTypeTabpage An API method expecting one of these types may be passed an integer instead, although they are not interchangeable. For example, a Buffer may be passed as @@ -191,7 +214,7 @@ an integer, but not a Window or Tabpage. The most reliable way of determining the type codes for the special Nvim types is to inspect the `types` key of metadata dictionary returned by the -`vim_get_api_info` method at runtime. Here's an example JSON representation of +`vim_get_api_info` method at runtime. Here's a sample JSON representation of the `types` object: > "types": { @@ -206,55 +229,27 @@ the `types` object: } } < -Even for statically compiled clients, it's a good practice to avoid hardcoding -the type codes, because a client may be built against one Nvim version but connect -to another with different type codes. +Even for statically compiled clients it is good practice to avoid hardcoding +the type codes, because a client may be built against one Nvim version but +connect to another with different type codes. ============================================================================== -6. Wrapping methods *msgpack-rpc-wrap-methods* - -As mentioned before, clients should provide an API that hides msgpack-rpc -details from programmers, and the API metadata object contains information -that makes this task easier: - -- The "functions" key contains a list of metadata objects for individual - functions. -- Each function metadata object has type information about the return value - and parameters. These can be used for generating strongly-typed APIs in - static languages. -- Container types may be decorated with type/size constraints, e.g. - ArrayOf(Buffer) or ArrayOf(Integer, 2). This can be useful to generate even - more strongly-typed APIs. -- Methods that operate instances of Nvim's types are prefixed with the type - name in lower case, e.g. `buffer_get_line` represents the `get_line` method - of a Buffer instance. -- Global methods are prefixed with `vim`, e.g. `vim_get_buffers`. - -So, for an object-oriented language, a client library would have the classes -that represent Nvim's types, and the methods of each class could be defined -by inspecting the method name prefix. There could also be a singleton Vim -class with methods mapped to functions prefixed with `vim_` - -============================================================================== -7. Vimscript functions *msgpack-rpc-vim-functions* - -Four msgpack-rpc functions are available in Vimscript: - -1. |rpcstart()|: Similarly to |jobstart()|, this will spawn a co-process with - its standard handles connected to Nvim. The difference is that it's not - possible to process raw data to or from the process's stdin, stdout, or - stderr. This is because the job's stdin and stdout are used as a single - msgpack channel that is processed directly by Nvim. - -2. |rpcstop()|: Same as |jobstop()|, but operates on handles returned by - |rpcstart()|. - -3. |rpcrequest()|: Sends a msgpack-rpc request to the process. - -4. |rpcnotify()|: Sends a msgpack-rpc notification to the process. - -The last two functions may also be used with channels created from -connections to |$NVIM_LISTEN_ADDRESS|. +6. Vimscript functions *rpc-vim-functions* + +RPC functions are available in Vimscript: + + 1. |rpcstart()|: Similarly to |jobstart()|, this will spawn a co-process + with its standard handles connected to Nvim. The difference is that it's + not possible to process raw data to or from the process's stdin, stdout, + or stderr. This is because the job's stdin and stdout are used as + a single msgpack channel that is processed directly by Nvim. + 2. |rpcstop()|: Same as |jobstop()|, but operates on handles returned by + |rpcstart()|. + 3. |rpcrequest()|: Sends a msgpack-rpc request to the process. + 4. |rpcnotify()|: Sends a msgpack-rpc notification to the process. + +|rpcrequest()| and |rpcnotify()| can also be used with channels connected to +a nvim server. |v:servername| ============================================================================== vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/runtime/doc/nvim.txt b/runtime/doc/nvim.txt index a7c512d1dc..904fb3c16c 100644 --- a/runtime/doc/nvim.txt +++ b/runtime/doc/nvim.txt @@ -1,24 +1,56 @@ -*nvim.txt* For Nvim. {Nvim} +*nvim.txt* {Nvim} - NVIM REFERENCE MANUAL *nvim* + NVIM REFERENCE MANUAL -Introduction to Nvim *nvim-intro* +Nvim *nvim* *nvim-intro* -This is an introduction for Vim users who are just getting started with Nvim. -It is not meant for Vim beginners. For a basic introduction to Vim, -see |help.txt|. +If you are new to Vim (and Nvim) see |help.txt| or type ":Tutor". +If you already use Vim (but not Nvim) see |nvim-from-vim| for a quickstart. -1. Transitioning from Vim |nvim-from-vim| -2. Differences from Vim |vim-differences| -3. Msgpack-RPC |msgpack-rpc| -4. Job control |job-control| -5. Python plugins |nvim-python| -6. Clipboard integration |nvim-clipboard| -7. Remote plugins |remote-plugin| -8. Provider infrastructure |nvim-provider| -9. Integrated terminal emulator |nvim-terminal-emulator| +Nvim is emphatically a fork of Vim, not a clone: compatibility with Vim is +maintained where possible. See |vim_diff.txt| for the complete reference of +differences from Vim. + +============================================================================== +Transitioning from Vim *nvim-from-vim* + +To start the transition, link your previous configuration so Nvim can use it: +> + mkdir -p ${XDG_CONFIG_HOME:=$HOME/.config} + ln -s ~/.vim $XDG_CONFIG_HOME/nvim + ln -s ~/.vimrc $XDG_CONFIG_HOME/nvim/init.vim +< +See |provider-python| and |provider-clipboard| for additional software you +might need to use some features. + +Your Vim configuration might not be entirely compatible with Nvim. For a +full list of differences between Vim and Nvim see |vim-differences|. + +The |'ttymouse'| option, for example, was removed from Nvim (mouse support +should work without it). If you use the same |vimrc| for Vim and Nvim, +consider guarding |'ttymouse'| in your configuration like so: +> + if !has('nvim') + set ttymouse=xterm2 + endif +< +Conversely, if you have Nvim specific configuration items, you could do +this: +> + if has('nvim') + tnoremap <Esc> <C-\><C-n> + endif +< +For a more granular approach use |exists()|: +> + if exists(':tnoremap') + tnoremap <Esc> <C-\><C-n> + endif +< +Now you should be able to explore Nvim more comfortably. Check |nvim-features| +for more information. ============================================================================== vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/runtime/doc/nvim_clipboard.txt b/runtime/doc/nvim_clipboard.txt deleted file mode 100644 index 078382c7a7..0000000000 --- a/runtime/doc/nvim_clipboard.txt +++ /dev/null @@ -1,63 +0,0 @@ -*nvim_clipboard.txt* For Nvim. {Nvim} - - - NVIM REFERENCE MANUAL by Thiago de Arruda - - -Clipboard integration for Nvim *nvim-clipboard* - -1. Intro |nvim-clipboard-intro| -2. X11 selection mechanism |nvim-clipboard-x11| - -============================================================================== -1. Intro *nvim-clipboard-intro* - -Nvim has no direct connection to the system clipboard. Instead, it is -accessible through the |nvim-provider| infrastructure, which transparently -uses shell commands for communicating with the clipboard. - -Clipboard access is implicitly enabled if any of the following clipboard tools -is found in your `$PATH`. - -- xclip -- xsel (newer alternative to xclip) -- pbcopy/pbpaste (only for Mac OS X) -- lemonade (useful for SSH machine) - https://github.com/pocke/lemonade -- doitclient (another option for SSH setups from the maintainer of PuTTY) - http://www.chiark.greenend.org.uk/~sgtatham/doit/ - -The presence of a suitable clipboard tool implicitly enables the '+' and '*' -registers. - -If you want to ALWAYS use the clipboard for ALL operations (as opposed -to interacting with the '+' and/or '*' registers explicitly), set the -following option: -> - set clipboard+=unnamedplus -< -See 'clipboard' for details and more options. - -============================================================================== -2. X11 selection mechanism *nvim-clipboard-x11* *x11-selection* - -The clipboard providers for X11 store text in what is known as "selections". -Selections are "owned" by an application, so when the application is closed, -the selection text is lost. - -The contents of selections are held by the originating application (e.g., upon -a copy), and only passed on to another application when that other application -asks for them (e.g., upon a paste). - - *quoteplus* *quote+* - -There are three documented X11 selections: `PRIMARY`, `SECONDARY`, and `CLIPBOARD`. -`CLIPBOARD` is typically used in X11 applications for copy/paste operations -(`Ctrl-c`/`v`), while `PRIMARY` is used for the last selected text, which is -generally inserted with the middle mouse button. - -Nvim's X11 clipboard providers only utilize the `PRIMARY` and `CLIPBOARD` -selections, used for the '*' and '+' registers, respectively. - -============================================================================== - vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/runtime/doc/nvim_from_vim.txt b/runtime/doc/nvim_from_vim.txt deleted file mode 100644 index 299eeb05f5..0000000000 --- a/runtime/doc/nvim_from_vim.txt +++ /dev/null @@ -1,50 +0,0 @@ -*nvim_from_vim.txt* For Nvim. {Nvim} - - - NVIM REFERENCE MANUAL - - -Transitioning from Vim *nvim-from-vim* - -Nvim is emphatically a fork of Vim, so compatibility to Vim should be pretty -good. - -To start the transition, link your previous configuration so Nvim can use -it: -> - mkdir -p ${XDG_CONFIG_HOME:=$HOME/.config} - ln -s ~/.vim $XDG_CONFIG_HOME/nvim - ln -s ~/.vimrc $XDG_CONFIG_HOME/nvim/init.vim -< -See |nvim-intro|, especially |nvim-python| and |nvim-clipboard|, for -additional software you might need to install to use all of Nvim's features. - -Your Vim configuration might not be entirely compatible with Nvim. For a -full list of differences between Vim and Nvim, see |vim-differences|. - -The |'ttymouse'| option, for example, was removed from Nvim (mouse support -should work without it). If you use the same |vimrc| for Vim and Nvim, -consider guarding |'ttymouse'| in your configuration like so: -> - if !has('nvim') - set ttymouse=xterm2 - endif -< -Conversely, if you have Nvim specific configuration items, you could do -this: -> - if has('nvim') - tnoremap <Esc> <C-\><C-n> - endif -< -For a more granular approach, use |exists()|: -> - if exists(':tnoremap') - tnoremap <Esc> <C-\><C-n> - endif -< -Now you should be able to explore Nvim more comfortably. Check |nvim| for more -information. - -============================================================================== - vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/runtime/doc/nvim_provider.txt b/runtime/doc/nvim_provider.txt deleted file mode 100644 index 91cd5fbfc7..0000000000 --- a/runtime/doc/nvim_provider.txt +++ /dev/null @@ -1,76 +0,0 @@ -*nvim_provider.txt* For Nvim. {Nvim} - - - NVIM REFERENCE MANUAL by Thiago de Arruda - - -Nvim provider infrastructure *nvim-provider* - -First of all, this document is meant to be read by developers interested in -contributing to the refactoring effort. If you are a normal user or plugin -developer looking to learn about Nvim |msgpack-rpc| infrastructure for -implementing plugins in other programming languages, see |remote-plugin|. -For instructions on how to enable Python plugins, see |nvim-python|. For -clipboard, see |nvim-clipboard|. - -Instead of doing everything by itself, Nvim aims to simplify its own -maintenance by delegating as much work as possible to external systems. But -some Vim components are too tightly coupled and in some cases the refactoring -work necessary to swap in-house implementations by code that integrates to -other systems is too great. Nvim provider infrastructure is a facility that -aims to make this task simpler. - -To understand why the provider infrastructure is useful, let us consider two -examples of integration with external systems that are implemented in Vim and -are now decoupled from Nvim core as providers: - -The first example is clipboard integration: in the original Vim source code, -clipboard functions account for more than 1k lines of C source code (and that -is just on ui.c), all to perform two tasks that are now accomplished with -simple shell commands such as xclip or pbcopy/pbpaste. - -The other example is Python scripting support: Vim has three files dedicated to -embedding the Python interpreter: if_python.c, if_python3.c and if_py_both.h. -Together these files sum about 9.5k lines of C source code. On Nvim, Python -scripting is performed by an external host process that is running 2k sloc -Python program. - -In a perfect world, we would implement Python and clipboard integration in -pure vimscript and without touching the C code. Unfortunately we can't achieve -these goals without severely compromising backwards compatibility with Vim. -That's where providers come to the rescue. - -In essence, this infrastructure is a simple framework that simplifies the task -of calling vimscript from C code, making it simpler to rewrite C functions that -interact with external systems in pure vimscript. It is composed of two -functions in eval.c: - -- eval_call_provider(name, method, arguments): Call a provider(name) method - with arguments -- eval_has_provider(name): Checks if a provider is implemented - -What these functions do is simple: - -- eval_call_provider will call the provider#(name)#Call function passing in - the method and arguments. -- eval_has_provider will return true if the provider#(name)#Call function is - implemented, and is called by the "has" vimscript function to check if - features are available. - -The basic idea is that the provider#(name)#Call function should implement -integration with an external system, because calling shell commands and -|msgpack-rpc| clients (Nvim only) is easier to do in vimscript. - -Now, back to the Python example. Instead of modifying vimscript to allow for -the definition of lowercase functions and commands (for the |:python|, -|:pyfile|, and |:pydo| commands, and the |pyeval()| function), which would -break backwards compatibility with Vim, we implemented the -autoload/provider/python.vim script and the provider#python#Call function -that is only defined if an external Python host is started successfully. - -That works well with the `has('python')` expression (normally used by Python -plugins) because if the Python host isn't installed then the plugin will -"think" it is running in a Vim compiled without |+python| feature. - -============================================================================== - vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/runtime/doc/nvim_python.txt b/runtime/doc/nvim_python.txt deleted file mode 100644 index a2fc968db4..0000000000 --- a/runtime/doc/nvim_python.txt +++ /dev/null @@ -1,95 +0,0 @@ -*nvim_python.txt* For Nvim. {Nvim} - - - NVIM REFERENCE MANUAL by Thiago de Arruda - - -Python plugins and scripting in Nvim *nvim-python* - -1. Introduction |nvim-python-intro| -2. Quickstart |nvim-python-quickstart| - -============================================================================== -1. Introduction *nvim-python-intro* - -Through external Python 2/3 interpreters connected via |msgpack-rpc|, Nvim -offers some support for the legacy |python-vim| and |python3| interfaces. - -Note: For now only the old Vim 7.3 API is supported. - -============================================================================== -2. Quickstart *nvim-python-quickstart* - -If you used a package manager to install Nvim, there's a good chance that -it also provides the `neovim` Python package. If it doesn't, follow these -steps to install the package with Python's package manager, `pip`. - -Note: Depending on your system, `pip` might refer to Python 2 or Python 3, - which is why the following instructions mention `pip2` or `pip3` - explicitly. If one of these is not available for you, maybe `pip` - is what you want. - -To use Vim Python 2/3 plugins with Nvim, do the following: - -- For Python 2 plugins, make sure an interpreter for Python 2.6 or 2.7 is - available in your `$PATH`, then install the `neovim` Python package systemwide: - > - $ sudo pip2 install neovim -< - or for the current user: -> - $ pip2 install --user neovim -< -- For Python 3 plugins, make sure an interpreter for Python 3.3 or above is - available in your `$PATH`, then install the `neovim` Python package systemwide: - > - $ sudo pip3 install neovim -< - or for the current user: -> - $ pip3 install --user neovim -< -Note: If you previously installed the package, get the latest version by - appending the `--upgrade` flag to the commands above. - -============================================================================== - *g:python_host_prog* - -To point Nvim to a specific Python 2 interpreter, set |g:python_host_prog|: -> - let g:python_host_prog = '/path/to/python' -< - *g:python3_host_prog* - -To point Nvim to a specific Python 3 interpreter, set |g:python3_host_prog|: -> - let g:python3_host_prog = '/path/to/python3' -< - *g:loaded_python_provider* - -To disable Python 2 interface, set `g:loaded_python_provider` to 1: -> - let g:loaded_python_provider = 1 -< - *g:loaded_python3_provider* - -To disable Python 3 interface, set `g:loaded_python3_provider` to 1: -> - let g:loaded_python3_provider = 1 -< - *g:python_host_skip_check* - -To disable Python 2 interpreter check, set `g:python_host_skip_check` to 1: -Note: If you disable Python 2 check, you must install neovim module properly. -> - let g:python_host_skip_check = 1 -< - *g:python3_host_skip_check* - -To disable Python 3 interpreter check, set `g:python3_host_skip_check` to 1: -Note: If you disable Python 3 check, you must install neovim module properly. -> - let g:python3_host_skip_check = 1 -< -============================================================================== - vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/runtime/doc/nvim_terminal_emulator.txt b/runtime/doc/nvim_terminal_emulator.txt index 6ef3aaebaa..45695ccf02 100644 --- a/runtime/doc/nvim_terminal_emulator.txt +++ b/runtime/doc/nvim_terminal_emulator.txt @@ -1,34 +1,30 @@ -*nvim_terminal_emulator.txt* For Nvim. {Nvim} +*terminal_emulator.txt* {Nvim} NVIM REFERENCE MANUAL by Thiago de Arruda -Nvim integrated terminal emulator *nvim-terminal-emulator* +Embedded terminal emulator *terminal-emulator* -1. Introduction |nvim-terminal-emulator-introduction| -2. Spawning |nvim-terminal-emulator-spawning| -3. Input |nvim-terminal-emulator-input| -4. Configuration |nvim-terminal-emulator-configuration| +1. Introduction |terminal-emulator-intro| +2. Spawning |terminal-emulator-spawning| +3. Input |terminal-emulator-input| +4. Configuration |terminal-emulator-configuration| ============================================================================== -1. Introduction *nvim-terminal-emulator-introduction* +1. Introduction *terminal-emulator-intro* -One feature that distinguishes Nvim from Vim is that it implements a mostly -complete VT220/xterm-like terminal emulator. The terminal is presented to the -user as a special buffer type, one that is asynchronously updated to mirror -the virtual terminal display as data is received from the program connected -to it. For most purposes, terminal buffers behave a lot like normal buffers -with 'nomodifiable' set. +Nvim offers a mostly complete VT220/xterm terminal emulator. The terminal is +presented as a special buffer type, asynchronously updated to mirror the +virtual terminal display as data is received from the program connected to it. +For most purposes, terminal buffers behave a lot like normal buffers with +'nomodifiable' set. - -The implementation is powered by libvterm[1], a powerful abstract terminal -emulation library. - -[1]: http://www.leonerd.org.uk/code/libvterm/ +The implementation is powered by libvterm, a powerful abstract terminal +emulation library. http://www.leonerd.org.uk/code/libvterm/ ============================================================================== -2. Spawning *nvim-terminal-emulator-spawning* +2. Spawning *terminal-emulator-spawning* There are 3 ways to create a terminal buffer: @@ -46,7 +42,7 @@ Note that |:mksession| will "save" the terminal buffers by restarting all programs when the session is restored. ============================================================================== -3. Input *nvim-terminal-emulator-input* +3. Input *terminal-emulator-input* Sending input is possible by entering terminal mode, which is achieved by pressing any key that would enter insert mode in a normal buffer (|i| or |a| @@ -90,7 +86,7 @@ Mouse input is also fully supported, and has the following behavior: the terminal wont lose focus and the hovered window will be scrolled. ============================================================================== -4. Configuration *nvim-terminal-emulator-configuration* +4. Configuration *terminal-emulator-configuration* Terminal buffers can be customized through the following global/buffer-local variables (set via the |TermOpen| autocmd): diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 105be1cd77..50b1262347 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -1172,8 +1172,7 @@ A jump table for the options with a short description can be found at |Q_op|. help help buffer (you are not supposed to set this manually) terminal terminal buffer, this is set automatically when a - terminal is created. See |nvim-terminal-emulator| for - more information. + terminal is created. |terminal-emulator| This option is used together with 'bufhidden' and 'swapfile' to specify special kinds of buffers. See |special-buffers|. @@ -1353,7 +1352,7 @@ A jump table for the options with a short description can be found at |Q_op|. used regardless of whether "unnamed" is in 'clipboard' or not. The clipboard register can always be explicitly accessed using the "* notation. Also see - |gui-clipboard|. + |clipboard|. *clipboard-unnamedplus* unnamedplus A variant of the "unnamed" flag which uses the @@ -1363,7 +1362,7 @@ A jump table for the options with a short description can be found at |Q_op|. register. When "unnamed" is also included to the option, yank and delete operations (but not put) will additionally copy the text into register - '*'. See |nvim-clipboard|. + '*'. See |clipboard|. *clipboard-autoselect* autoselect Works like the 'a' flag in 'guioptions': If present, @@ -6070,7 +6069,8 @@ A jump table for the options with a short description can be found at |Q_op|. feature use `has('tablineat')`. < - Where to truncate line if too long. Default is at the start. No width fields allowed. - = - Separation point between left and right aligned items. + = - Separation point between alignment sections. Each section will + be separated by an equal number of spaces. No width fields allowed. # - Set highlight group. The name must follow and then a # again. Thus use %#HLname# for highlight group HLname. The same diff --git a/runtime/doc/provider.txt b/runtime/doc/provider.txt new file mode 100644 index 0000000000..db5c61879c --- /dev/null +++ b/runtime/doc/provider.txt @@ -0,0 +1,139 @@ +*provider.txt* {Nvim} + + + NVIM REFERENCE MANUAL by Thiago de Arruda + + +Providers *provider* + +Nvim delegates some features to dynamic "providers". + +============================================================================== +Python integration *provider-python* + +Nvim supports the Vim legacy |python-vim| and |python3| interfaces via +external Python interpreters connected via |RPC|, + +Note: Only the Vim 7.3 API is supported; bindeval (Vim 7.4) is not. + + +PYTHON QUICKSTART ~ + +If you used a package manager to install Nvim there's a good chance that +it also provides the `neovim` Python package. If it doesn't, follow these +steps to install the package with Python's package manager, `pip`. + +Note: Depending on your system, `pip` might refer to Python 2 or Python 3, + which is why the following instructions mention `pip2` or `pip3` + explicitly. If one of these is not available, try `pip`. + +To use Vim Python 2/3 plugins with Nvim: + +- For Python 2 plugins, make sure an interpreter for Python 2.6 or 2.7 is + available in your `$PATH`, then install the `neovim` Python package systemwide: > + $ sudo pip2 install --upgrade neovim +< + or for the current user: > + $ pip2 install --user --upgrade neovim +< +- For Python 3 plugins, make sure an interpreter for Python 3.3 or above is + available in your `$PATH`, then install the `neovim` Python package systemwide: > + $ sudo pip3 install --upgrade neovim +< + or for the current user: > + $ pip3 install --user --upgrade neovim +< +Note: The `--upgrade` flag ensures you have the latest version even if + a previous version was already installed. + +PYTHON PROVIDER CONFIGURATION ~ + *g:python_host_prog* +Set `g:python_host_prog` to point Nvim to a specific Python 2 interpreter: > + let g:python_host_prog = '/path/to/python' +< + *g:python3_host_prog* +Set `g:python3_host_prog` to point Nvim to a specific Python 3 interpreter: > + let g:python3_host_prog = '/path/to/python3' +< + *g:loaded_python_provider* +To disable Python 2 support: > + let g:loaded_python_provider = 1 +< + *g:loaded_python3_provider* +To disable Python 3 support: > + let g:loaded_python3_provider = 1 +< + *g:python_host_skip_check* +Set `g:python_host_skip_check` to disable the Python 2 interpreter check. +Note: This requires you to install the python-neovim module properly. > + let g:python_host_skip_check = 1 +< + *g:python3_host_skip_check* +Set `g:python3_host_skip_check` to disable the Python 3 interpreter check. +Note: This requires you to install the python3-neovim module properly. > + let g:python3_host_skip_check = 1 + + +TROUBLESHOOTING *python-trouble* + +If you have trouble with a plugin that uses the `neovim` Python client, use +the |:CheckHealth| command to diagnose your setup. + + *:CheckHealth* +:CheckHealth[!] Check your setup for common problems that may be keeping a + plugin from functioning correctly. Include the output of + this command in bug reports to help reduce the amount of + time it takes to address your issue. With "!" the output + will be placed in a new buffer which can make it easier to + save to a file or copy to the clipboard. + +============================================================================== +Clipboard integration *provider-clipboard* *clipboard* + +Nvim has no direct connection to the system clipboard. Instead it is +accessible through a |provider| which transparently uses shell commands for +communicating with the clipboard. + +Clipboard access is implicitly enabled if any of the following clipboard tools +are found in your `$PATH`. + + - xclip + - xsel (newer alternative to xclip) + - pbcopy/pbpaste (Mac OS X) + - lemonade (for SSH) https://github.com/pocke/lemonade + - doitclient (for SSH) http://www.chiark.greenend.org.uk/~sgtatham/doit/ + +The presence of a suitable clipboard tool implicitly enables the '+' and '*' +registers. + +If you want to ALWAYS use the clipboard for ALL operations (as opposed +to interacting with the '+' and/or '*' registers explicitly), set the +following option: +> + set clipboard+=unnamedplus +< +See 'clipboard' for details and more options. + +============================================================================== +X11 selection mechanism *clipboard-x11* *x11-selection* + +The clipboard providers for X11 store text in what is known as "selections". +Selections are "owned" by an application, so when the application is closed, +the selection text is lost. + +The contents of selections are held by the originating application (e.g., upon +a copy), and only passed on to another application when that other application +asks for them (e.g., upon a paste). + + *quoteplus* *quote+* + +There are three documented X11 selections: `PRIMARY`, `SECONDARY`, and `CLIPBOARD`. +`CLIPBOARD` is typically used in X11 applications for copy/paste operations +(`Ctrl-c`/`v`), while `PRIMARY` is used for the last selected text, which is +generally inserted with the middle mouse button. + +Nvim's X11 clipboard providers only utilize the `PRIMARY` and `CLIPBOARD` +selections, used for the '*' and '+' registers, respectively. + +============================================================================== + vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/runtime/doc/remote_plugin.txt b/runtime/doc/remote_plugin.txt index 139fcd83b9..d906096a86 100644 --- a/runtime/doc/remote_plugin.txt +++ b/runtime/doc/remote_plugin.txt @@ -16,8 +16,8 @@ Nvim support for remote plugins *remote-plugin* Extensibility is a primary goal of Nvim. Any programming language may be used to extend Nvim without changes to Nvim itself. This is achieved with remote -plugins, coprocesses that have a direct communication channel (via -|msgpack-rpc|) with the Nvim process. +plugins, coprocesses that have a direct communication channel (via |RPC|) with +the Nvim process. Even though these plugins run in separate processes they can call, be called, and receive events just as if the plugin's code were executed in the main @@ -33,9 +33,9 @@ check whether a plugin host is available for their chosen programming language. Plugin hosts are programs that provide a high-level environment for plugins, taking care of most boilerplate involved in defining commands, autocmds, and -functions that are implemented over |msgpack-rpc| connections. Hosts are -loaded only when one of their registered plugins require it, keeping Nvim's -startup as fast as possible, even if many plugins/hosts are installed. +functions that are implemented over |RPC| connections. Hosts are loaded only +when one of their registered plugins require it, keeping Nvim's startup as +fast as possible, even if many plugins/hosts are installed. ============================================================================== 3. Example *remote-plugin-example* diff --git a/runtime/doc/spell.txt b/runtime/doc/spell.txt index a767f6cbbf..0902d5d10f 100644 --- a/runtime/doc/spell.txt +++ b/runtime/doc/spell.txt @@ -1,4 +1,4 @@ -*spell.txt* For Vim version 7.4. Last change: 2016 Jan 08 +*spell.txt* VIM REFERENCE MANUAL by Bram Moolenaar @@ -11,10 +11,6 @@ Spell checking *spell* 3. Generating a spell file |spell-mkspell| 4. Spell file format |spell-file-format| -Note: There also is a vimspell plugin. If you have it you can do ":help -vimspell" to find about it. But you will probably want to get rid of the -plugin and use the 'spell' option instead, it works better. - ============================================================================== 1. Quick start *spell-quickstart* *E756* @@ -1633,4 +1629,111 @@ WORDCHARS (Hunspell) *spell-WORDCHARS* is no need to separate words before checking them (using a trie instead of a hashtable). +============================================================================== +5. Spell checker design *develop-spell* + +When spell checking was going to be added to Vim a survey was done over the +available spell checking libraries and programs. Unfortunately, the result +was that none of them provided sufficient capabilities to be used as the spell +checking engine in Vim, for various reasons: + +- Missing support for multi-byte encodings. At least UTF-8 must be supported, + so that more than one language can be used in the same file. + Doing on-the-fly conversion is not always possible (would require iconv + support). +- For the programs and libraries: Using them as-is would require installing + them separately from Vim. That's mostly not impossible, but a drawback. +- Performance: A few tests showed that it's possible to check spelling on the + fly (while redrawing), just like syntax highlighting. But the mechanisms + used by other code are much slower. Myspell uses a hashtable, for example. + The affix compression that most spell checkers use makes it slower too. +- For using an external program like aspell a communication mechanism would + have to be setup. That's complicated to do in a portable way (Unix-only + would be relatively simple, but that's not good enough). And performance + will become a problem (lots of process switching involved). +- Missing support for words with non-word characters, such as "Etten-Leur" and + "et al.", would require marking the pieces of them OK, lowering the + reliability. +- Missing support for regions or dialects. Makes it difficult to accept + all English words and highlight non-Canadian words differently. +- Missing support for rare words. Many words are correct but hardly ever used + and could be a misspelled often-used word. +- For making suggestions the speed is less important and requiring to install + another program or library would be acceptable. But the word lists probably + differ, the suggestions may be wrong words. + + +Spelling suggestions *develop-spell-suggestions* + +For making suggestions there are two basic mechanisms: +1. Try changing the bad word a little bit and check for a match with a good + word. Or go through the list of good words, change them a little bit and + check for a match with the bad word. The changes are deleting a character, + inserting a character, swapping two characters, etc. +2. Perform soundfolding on both the bad word and the good words and then find + matches, possibly with a few changes like with the first mechanism. + +The first is good for finding typing mistakes. After experimenting with +hashtables and looking at solutions from other spell checkers the conclusion +was that a trie (a kind of tree structure) is ideal for this. Both for +reducing memory use and being able to try sensible changes. For example, when +inserting a character only characters that lead to good words need to be +tried. Other mechanisms (with hashtables) need to try all possible letters at +every position in the word. Also, a hashtable has the requirement that word +boundaries are identified separately, while a trie does not require this. +That makes the mechanism a lot simpler. + +Soundfolding is useful when someone knows how the words sounds but doesn't +know how it is spelled. For example, the word "dictionary" might be written +as "daktonerie". The number of changes that the first method would need to +try is very big, it's hard to find the good word that way. After soundfolding +the words become "tktnr" and "tkxnry", these differ by only two letters. + +To find words by their soundfolded equivalent (soundalike word) we need a list +of all soundfolded words. A few experiments have been done to find out what +the best method is. Alternatives: +1. Do the sound folding on the fly when looking for suggestions. This means + walking through the trie of good words, soundfolding each word and + checking how different it is from the bad word. This is very efficient for + memory use, but takes a long time. On a fast PC it takes a couple of + seconds for English, which can be acceptable for interactive use. But for + some languages it takes more than ten seconds (e.g., German, Catalan), + which is unacceptable slow. For batch processing (automatic corrections) + it's too slow for all languages. +2. Use a trie for the soundfolded words, so that searching can be done just + like how it works without soundfolding. This requires remembering a list + of good words for each soundfolded word. This makes finding matches very + fast but requires quite a lot of memory, in the order of 1 to 10 Mbyte. + For some languages more than the original word list. +3. Like the second alternative, but reduce the amount of memory by using affix + compression and store only the soundfolded basic word. This is what Aspell + does. Disadvantage is that affixes need to be stripped from the bad word + before soundfolding it, which means that mistakes at the start and/or end + of the word will cause the mechanism to fail. Also, this becomes slow when + the bad word is quite different from the good word. + +The choice made is to use the second mechanism and use a separate file. This +way a user with sufficient memory can get very good suggestions while a user +who is short of memory or just wants the spell checking and no suggestions +doesn't use so much memory. + + +Word frequency + +For sorting suggestions it helps to know which words are common. In theory we +could store a word frequency with the word in the dictionary. However, this +requires storing a count per word. That degrades word tree compression a lot. +And maintaining the word frequency for all languages will be a heavy task. +Also, it would be nice to prefer words that are already in the text. This way +the words that appear in the specific text are preferred for suggestions. + +What has been implemented is to count words that have been seen during +displaying. A hashtable is used to quickly find the word count. The count is +initialized from words listed in COMMON items in the affix file, so that it +also works when starting a new file. + +This isn't ideal, because the longer Vim is running the higher the counts +become. But in practice it is a noticeable improvement over not using the word +count. + vim:tw=78:sw=4:ts=8:ft=help:norl: diff --git a/runtime/doc/starting.txt b/runtime/doc/starting.txt index c9cb849164..ad2649b765 100644 --- a/runtime/doc/starting.txt +++ b/runtime/doc/starting.txt @@ -350,6 +350,9 @@ argument. *-W* -W {scriptout} Like -w, but do not append, overwrite an existing file. + *--api-info* +--api-info Print msgpack-encoded |api-metadata| and exit. + ============================================================================== 2. Initialization *initialization* *startup* diff --git a/runtime/doc/various.txt b/runtime/doc/various.txt index a2c0f45b23..e6b05e1ab1 100644 --- a/runtime/doc/various.txt +++ b/runtime/doc/various.txt @@ -220,7 +220,7 @@ g8 Print the hex values of the bytes used in the Like |:enew|, it will fail if the current buffer is modified, but can be forced with "!". See |termopen()| - and |nvim-terminal-emulator| for more information. + and |terminal-emulator|. To switch to terminal mode automatically: > @@ -415,8 +415,9 @@ m *+xpm_w32* Win32 GUI only: pixmap support |w32-xpm-support| To stop the messages and commands from being echoed to the screen, put the commands in a function and call it with ":silent call Function()". - An alternative is to use the 'verbosefile' option, - this can be used in combination with ":redir". + Alternatives are the 'verbosefile' option or + |capture()| function, these can be used in combination + with ":redir". :redi[r] >> {file} Redirect messages to file {file}. Append if {file} already exists. diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 508712ca75..d30b0833db 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -12,8 +12,8 @@ these differences. 1. Configuration |nvim-configuration| 2. Defaults |nvim-defaults| -3. Changed features |nvim-features-changed| -4. New features |nvim-features-new| +3. New features |nvim-features| +4. Changed features |nvim-features-changed| 5. Missing legacy features |nvim-features-missing| 6. Removed features |nvim-features-removed| @@ -58,7 +58,58 @@ these differences. - 'wildmenu' is set by default ============================================================================== -3. Changed features *nvim-features-changed* +3. New Features *nvim-features* + + +MAJOR FEATURES ~ + +Embedded terminal emulator |terminal-emulator| +Shared data |shada| +RPC API |RPC| +Job control |job-control| +Remote plugins |remote-plugin| +Python plugins |provider-python| +Clipboard integration |provider-clipboard| + + +OTHER FEATURES ~ + +|bracketed-paste-mode| is built-in and enabled by default. + +Meta (alt) chords are recognized (even in the terminal). + <M-1>, <M-2>, ... + <M-BS>, <M-Del>, <M-Ins>, ... + <M-/>, <M-\>, ... + <M-Space>, <M-Enter>, <M-=>, <M-->, <M-?>, <M-$>, ... + + Note: Meta chords are case-sensitive (<M-a> is distinguished from <M-A>). + +Some `CTRL-SHIFT-...` key chords are distinguished from `CTRL-...` variants +(even in the terminal). Specifically, the following are known to work: + <C-Tab>, <C-S-Tab> + <C-BS>, <C-S-BS> + <C-Enter>, <C-S-Enter> + +Options: + 'statusline' supports unlimited alignment sections + +Commands: + |:CheckHealth| + +Events: + |TabNew| + |TabNewEntered| + |TabClosed| + |TermOpen| + |TermClose| + +Highlight groups: + |hl-EndOfBuffer| + |hl-TermCursor| + |hl-TermCursorNC| + +============================================================================== +4. Changed features *nvim-features-changed* Nvim always builds with all features, in contrast to Vim which may have certain features removed/added at compile-time. This is like if Vim's "HUGE" @@ -68,7 +119,7 @@ build). If a Python interpreter is available on your `$PATH`, |:python| and |:python3| are always available and may be used simultaneously in separate plugins. The `neovim` pip package must be installed to use Python plugins in Nvim (see -|nvim-python|). +|provider-python|). |mkdir()| behaviour changed: 1. Assuming /tmp/foo does not exist and /tmp can be written to @@ -141,39 +192,6 @@ Additional differences: - ShaDa file keeps search direction (|v:searchforward|), viminfo does not. ============================================================================== -4. New Features *nvim-features-new* - -See |nvim-intro| for a list of Nvim's largest new features. - -|bracketed-paste-mode| is built-in and enabled by default. - -Meta (alt) chords are recognized (even in the terminal). - <M-1>, <M-2>, ... - <M-BS>, <M-Del>, <M-Ins>, ... - <M-/>, <M-\>, ... - <M-Space>, <M-Enter>, <M-=>, <M-->, <M-?>, <M-$>, ... - - Note: Meta chords are case-sensitive (<M-a> is distinguished from <M-A>). - -Some `CTRL-SHIFT-...` key chords are distinguished from `CTRL-...` variants -(even in the terminal). Specifically, the following are known to work: - <C-Tab>, <C-S-Tab> - <C-BS>, <C-S-BS> - <C-Enter>, <C-S-Enter> - -Events: - |TabNew| - |TabNewEntered| - |TabClosed| - |TermOpen| - |TermClose| - -Highlight groups: - |hl-EndOfBuffer| - |hl-TermCursor| - |hl-TermCursorNC| - -============================================================================== 5. Missing legacy features *nvim-features-missing* *if_ruby* *if_lua* *if_perl* *if_mzscheme* *if_tcl* diff --git a/runtime/plugin/health.vim b/runtime/plugin/health.vim new file mode 100644 index 0000000000..db094a03a4 --- /dev/null +++ b/runtime/plugin/health.vim @@ -0,0 +1 @@ +command! -bang CheckHealth call health#check(<bang>0) diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index 4aaae5172f..feb17e070e 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -98,7 +98,6 @@ set(CONV_SOURCES mbyte.c memline.c message.c - ops.c regexp.c screen.c search.c diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 71ec20c788..72724b0ffd 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -2849,7 +2849,7 @@ typedef enum { /// is "curwin". /// /// Items are drawn interspersed with the text that surrounds it -/// Specials: %-<wid>(xxx%) => group, %= => middle marker, %< => truncation +/// Specials: %-<wid>(xxx%) => group, %= => separation marker, %< => truncation /// Item: %-<minwid>.<maxwid><itemch> All but <itemch> are optional /// /// If maxwidth is not zero, the string will be filled at any middle marker @@ -2893,7 +2893,7 @@ int build_stl_str_hl( Normal, Empty, Group, - Middle, + Separate, Highlight, TabPage, ClickFunc, @@ -2994,14 +2994,14 @@ int build_stl_str_hl( continue; } - // STL_MIDDLEMARK: Separation place between left and right aligned items. - if (*fmt_p == STL_MIDDLEMARK) { + // STL_SEPARATE: Separation place between left and right aligned items. + if (*fmt_p == STL_SEPARATE) { fmt_p++; // Ignored when we are inside of a grouping if (groupdepth > 0) { continue; } - item[curitem].type = Middle; + item[curitem].type = Separate; item[curitem++].start = out_p; continue; } @@ -3840,27 +3840,53 @@ int build_stl_str_hl( width = maxwidth; // If there is room left in our statusline, and room left in our buffer, - // add characters at the middle marker (if there is one) to + // add characters at the separate marker (if there is one) to // fill up the available space. } else if (width < maxwidth - && STRLEN(out) + maxwidth - width + 1 < outlen) { - for (int item_idx = 0; item_idx < itemcnt; item_idx++) { - if (item[item_idx].type == Middle) { - // Move the statusline to make room for the middle characters - char_u *middle_end = item[item_idx].start + (maxwidth - width); - STRMOVE(middle_end, item[item_idx].start); - - // Fill the middle section with our fill character - for (char_u *s = item[item_idx].start; s < middle_end; s++) - *s = fillchar; + && STRLEN(out) + maxwidth - width + 1 < outlen) { + // Find how many separators there are, which we will use when + // figuring out how many groups there are. + int num_separators = 0; + for (int i = 0; i < itemcnt; i++) { + if (item[i].type == Separate) { + num_separators++; + } + } - // Adjust the offset of any items after the middle - for (item_idx++; item_idx < itemcnt; item_idx++) - item[item_idx].start += maxwidth - width; + // If we have separated groups, then we deal with it now + if (num_separators) { + // Create an array of the start location for each + // separator mark. + int separator_locations[STL_MAX_ITEM]; + int index = 0; + for (int i = 0; i < itemcnt; i++) { + if (item[i].type == Separate) { + separator_locations[index] = i; + index++; + } + } - width = maxwidth; - break; + int standard_spaces = (maxwidth - width) / num_separators; + int final_spaces = (maxwidth - width) - + standard_spaces * (num_separators - 1); + + for (int i = 0; i < num_separators; i++) { + int dislocation = (i == (num_separators - 1)) ? + final_spaces : standard_spaces; + char_u *sep_loc = item[separator_locations[i]].start + dislocation; + STRMOVE(sep_loc, item[separator_locations[i]].start); + for (char_u *s = item[separator_locations[i]].start; s < sep_loc; s++) { + *s = fillchar; + } + + for (int item_idx = separator_locations[i] + 1; + item_idx < itemcnt; + item_idx++) { + item[item_idx].start += dislocation; + } } + + width = maxwidth; } } diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 44aaedb9b4..03ef41f849 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -6952,8 +6952,8 @@ static void ins_reg(void) AppendCharToRedobuff(literally); AppendCharToRedobuff(regname); - do_put(regname, NULL, BACKWARD, 1L, - (literally == Ctrl_P ? PUT_FIXINDENT : 0) | PUT_CURSEND); + do_put(regname, NULL, BACKWARD, 1, + (literally == Ctrl_P ? PUT_FIXINDENT : 0) | PUT_CURSEND); } else if (insert_reg(regname, literally) == FAIL) { vim_beep(BO_REG); need_redraw = true; // remove the '"' @@ -7701,7 +7701,7 @@ static void ins_mouse(int c) undisplay_dollar(); tpos = curwin->w_cursor; - if (do_mouse(NULL, c, BACKWARD, 1L, 0)) { + if (do_mouse(NULL, c, BACKWARD, 1, 0)) { win_T *new_curwin = curwin; if (curwin != old_curwin && win_valid(old_curwin)) { diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 93816d3ee6..aa5cd676af 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -1891,7 +1891,7 @@ ex_let_one ( } } if (p != NULL) { - write_reg_contents(*arg == '@' ? '"' : *arg, p, -1, FALSE); + write_reg_contents(*arg == '@' ? '"' : *arg, p, STRLEN(p), false); arg_end = arg + 1; } xfree(ptofree); @@ -6684,6 +6684,7 @@ static struct fst { { "acos", 1, 1, f_acos }, // WJMc { "add", 2, 2, f_add }, { "and", 2, 2, f_and }, + { "api_info", 0, 0, f_api_info }, { "append", 2, 2, f_append }, { "argc", 0, 0, f_argc }, { "argidx", 0, 0, f_argidx }, @@ -6712,6 +6713,7 @@ static struct fst { { "byteidx", 2, 2, f_byteidx }, { "byteidxcomp", 2, 2, f_byteidxcomp }, { "call", 2, 3, f_call }, + { "capture", 1, 1, f_capture }, { "ceil", 1, 1, f_ceil }, { "changenr", 0, 0, f_changenr }, { "char2nr", 1, 2, f_char2nr }, @@ -7466,6 +7468,15 @@ static void f_and(typval_T *argvars, typval_T *rettv) & get_tv_number_chk(&argvars[1], NULL); } + +/// "api_info()" function +static void f_api_info(typval_T *argvars, typval_T *rettv) +{ + Dictionary metadata = api_metadata(); + (void)object_to_vim(DICTIONARY_OBJ(metadata), rettv, NULL); + api_free_dictionary(metadata); +} + /* * "append(lnum, string/list)" function */ @@ -7541,25 +7552,9 @@ static void f_argidx(typval_T *argvars, typval_T *rettv) static void f_arglistid(typval_T *argvars, typval_T *rettv) { rettv->vval.v_number = -1; - if (argvars[0].v_type != VAR_UNKNOWN) { - tabpage_T *tp = NULL; - if (argvars[1].v_type != VAR_UNKNOWN) { - long n = get_tv_number(&argvars[1]); - if (n >= 0) { - tp = find_tabpage(n); - } - } else { - tp = curtab; - } - - if (tp != NULL) { - win_T *wp = find_win_by_nr(&argvars[0], tp); - if (wp != NULL) { - rettv->vval.v_number = wp->w_alist->id; - } - } - } else { - rettv->vval.v_number = curwin->w_alist->id; + win_T *wp = find_tabwin(&argvars[0], &argvars[1]); + if (wp != NULL) { + rettv->vval.v_number = wp->w_alist->id; } } @@ -8089,6 +8084,38 @@ static void f_call(typval_T *argvars, typval_T *rettv) (void)func_call(func, &argvars[1], selfdict, rettv); } +// "capture(command)" function +static void f_capture(typval_T *argvars, typval_T *rettv) +{ + int save_msg_silent = msg_silent; + garray_T *save_capture_ga = capture_ga; + + if (check_secure()) { + return; + } + + garray_T capture_local; + capture_ga = &capture_local; + ga_init(capture_ga, (int)sizeof(char), 80); + + msg_silent++; + if (argvars[0].v_type != VAR_LIST) { + do_cmdline_cmd((char *)get_tv_string(&argvars[0])); + } else if (argvars[0].vval.v_list != NULL) { + for (listitem_T *li = argvars[0].vval.v_list->lv_first; + li != NULL; li = li->li_next) { + do_cmdline_cmd((char *)get_tv_string(&li->li_tv)); + } + } + msg_silent = save_msg_silent; + + ga_append(capture_ga, NUL); + rettv->v_type = VAR_STRING; + rettv->vval.v_string = capture_ga->ga_data; + + capture_ga = save_capture_ga; +} + /* * "ceil({float})" function */ @@ -10473,9 +10500,33 @@ find_win_by_nr ( return NULL; } -/* - * "getwinvar()" function - */ +/// Find window specified by "wvp" in tabpage "tvp". +static win_T *find_tabwin(typval_T *wvp, typval_T *tvp) +{ + win_T *wp = NULL; + tabpage_T *tp = NULL; + + if (wvp->v_type != VAR_UNKNOWN) { + if (tvp->v_type != VAR_UNKNOWN) { + long n = get_tv_number(tvp); + if (n >= 0) { + tp = find_tabpage(n); + } + } else { + tp = curtab; + } + + if (tp != NULL) { + wp = find_win_by_nr(wvp, tp); + } + } else { + wp = curwin; + } + + return wp; +} + +/// "getwinvar()" function static void f_getwinvar(typval_T *argvars, typval_T *rettv) { getwinvar(argvars, rettv, 0); @@ -14920,7 +14971,8 @@ static void f_setreg(typval_T *argvars, typval_T *rettv) } *curval++ = NULL; - write_reg_contents_lst(regname, lstval, -1, append, yank_type, block_len); + write_reg_contents_lst(regname, lstval, STRLEN(lstval), + append, yank_type, block_len); free_lstval: while (curallocval > allocval) @@ -14931,7 +14983,8 @@ free_lstval: if (strval == NULL) { return; } - write_reg_contents_ex(regname, strval, -1, append, yank_type, block_len); + write_reg_contents_ex(regname, strval, STRLEN(strval), + append, yank_type, block_len); } rettv->vval.v_number = 0; } diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index df4a6d52c4..247f86679f 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -2010,9 +2010,7 @@ void ex_argdelete(exarg_T *eap) maketitle(); } -/* - * ":argdo", ":windo", ":bufdo", ":tabdo", ":cdo", ":ldo", ":cfdo" and ":lfdo" - */ +/// ":argdo", ":windo", ":bufdo", ":tabdo", ":cdo", ":ldo", ":cfdo" and ":lfdo" void ex_listdo(exarg_T *eap) { int i; @@ -2060,9 +2058,9 @@ void ex_listdo(exarg_T *eap) buf_T *buf = curbuf; size_t qf_size = 0; - /* set pcmark now */ + // set pcmark now if (eap->cmdidx == CMD_bufdo) { - /* Advance to the first listed buffer after "eap->line1". */ + // Advance to the first listed buffer after "eap->line1". for (buf = firstbuf; buf != NULL && (buf->b_fnum < eap->line1 || !buf->b_p_bl); buf = buf->b_next) { diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index b66b5cf3a9..6864e2b914 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -1536,8 +1536,9 @@ static char_u * do_one_cmd(char_u **cmdlinep, } ea.cmd = skipwhite(ea.cmd); lnum = get_address(&ea, &ea.cmd, ea.addr_type, ea.skip, ea.addr_count == 0); - if (ea.cmd == NULL) /* error detected */ + if (ea.cmd == NULL) { // error detected goto doend; + } if (lnum == MAXLNUM) { if (*ea.cmd == '%') { /* '%' - all lines */ ++ea.cmd; @@ -4640,14 +4641,14 @@ static struct { char *name; } addr_type_complete[] = { - {ADDR_ARGUMENTS, "arguments"}, - {ADDR_LINES, "lines"}, - {ADDR_LOADED_BUFFERS, "loaded_buffers"}, - {ADDR_TABS, "tabs"}, - {ADDR_BUFFERS, "buffers"}, - {ADDR_WINDOWS, "windows"}, - {ADDR_QUICKFIX, "quickfix"}, - {-1, NULL} + { ADDR_ARGUMENTS, "arguments" }, + { ADDR_LINES, "lines" }, + { ADDR_LOADED_BUFFERS, "loaded_buffers" }, + { ADDR_TABS, "tabs" }, + { ADDR_BUFFERS, "buffers" }, + { ADDR_WINDOWS, "windows" }, + { ADDR_QUICKFIX, "quickfix" }, + { -1, NULL } }; /* @@ -7125,8 +7126,8 @@ static void ex_put(exarg_T *eap) eap->forceit = TRUE; } curwin->w_cursor.lnum = eap->line2; - do_put(eap->regname, NULL, eap->forceit ? BACKWARD : FORWARD, 1L, - PUT_LINE|PUT_CURSLINE); + do_put(eap->regname, NULL, eap->forceit ? BACKWARD : FORWARD, 1, + PUT_LINE|PUT_CURSLINE); } /* @@ -7135,7 +7136,7 @@ static void ex_put(exarg_T *eap) static void ex_copymove(exarg_T *eap) { long n = get_address(eap, &eap->arg, eap->addr_type, false, false); - if (eap->arg == NULL) { /* error detected */ + if (eap->arg == NULL) { // error detected eap->nextcmd = NULL; return; } @@ -7354,10 +7355,11 @@ static void ex_redir(exarg_T *eap) /* Can use both "@a" and "@a>". */ if (*arg == '>') arg++; - /* Make register empty when not using @A-@Z and the - * command is valid. */ - if (*arg == NUL && !isupper(redir_reg)) - write_reg_contents(redir_reg, (char_u *)"", -1, FALSE); + // Make register empty when not using @A-@Z and the + // command is valid. + if (*arg == NUL && !isupper(redir_reg)) { + write_reg_contents(redir_reg, (char_u *)"", 0, false); + } } } if (*arg != NUL) { diff --git a/src/nvim/globals.h b/src/nvim/globals.h index f618e5ffc4..42fde50bee 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -836,8 +836,8 @@ EXTERN int* (*iconv_errno)(void); EXTERN int State INIT(= NORMAL); /* This is the current state of the * command interpreter. */ -EXTERN int finish_op INIT(= FALSE); /* TRUE while an operator is pending */ -EXTERN long opcount INIT(= 0); /* count for pending operator */ +EXTERN bool finish_op INIT(= false); // true while an operator is pending +EXTERN long opcount INIT(= 0); // count for pending operator /* * ex mode (Q) state @@ -985,10 +985,11 @@ EXTERN int keep_help_flag INIT(= FALSE); /* doing :ta from help file */ */ EXTERN char_u *empty_option INIT(= (char_u *)""); -EXTERN int redir_off INIT(= FALSE); /* no redirection for a moment */ -EXTERN FILE *redir_fd INIT(= NULL); /* message redirection file */ -EXTERN int redir_reg INIT(= 0); /* message redirection register */ -EXTERN int redir_vname INIT(= 0); /* message redirection variable */ +EXTERN int redir_off INIT(= false); // no redirection for a moment +EXTERN FILE *redir_fd INIT(= NULL); // message redirection file +EXTERN int redir_reg INIT(= 0); // message redirection register +EXTERN int redir_vname INIT(= 0); // message redirection variable +EXTERN garray_T *capture_ga INIT(= NULL); // capture() buffer EXTERN char_u langmap_mapchar[256]; /* mapping for language keys */ diff --git a/src/nvim/message.c b/src/nvim/message.c index 521db85cf0..77e8f0e4f2 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -493,10 +493,11 @@ int emsg(char_u *s) * when the message should be ignored completely (used for the * interrupt message). */ - if (cause_errthrow(s, severe, &ignore) == TRUE) { - if (!ignore) - did_emsg = TRUE; - return TRUE; + if (cause_errthrow(s, severe, &ignore) == true) { + if (!ignore) { + did_emsg = true; + } + return true; } // set "v:errmsg", also when using ":silent! cmd" @@ -511,41 +512,43 @@ int emsg(char_u *s) p = get_emsg_source(); if (p != NULL) { STRCAT(p, "\n"); - redir_write(p, -1); + redir_write(p, STRLEN(p)); xfree(p); } p = get_emsg_lnum(); if (p != NULL) { STRCAT(p, "\n"); - redir_write(p, -1); + redir_write(p, STRLEN(p)); xfree(p); } - redir_write(s, -1); - return TRUE; + redir_write(s, STRLEN(s)); + return true; } - /* Reset msg_silent, an error causes messages to be switched back on. */ + // Reset msg_silent, an error causes messages to be switched back on. msg_silent = 0; cmd_silent = FALSE; - if (global_busy) /* break :global command */ - ++global_busy; + if (global_busy) { // break :global command + global_busy++; + } - if (p_eb) - beep_flush(); /* also includes flush_buffers() */ - else - flush_buffers(FALSE); /* flush internal buffers */ - did_emsg = TRUE; /* flag for DoOneCmd() */ + if (p_eb) { + beep_flush(); // also includes flush_buffers() + } else { + flush_buffers(false); // flush internal buffers + } + did_emsg = true; // flag for DoOneCmd() } - emsg_on_display = TRUE; /* remember there is an error message */ - ++msg_scroll; /* don't overwrite a previous message */ - attr = hl_attr(HLF_E); /* set highlight mode for error messages */ - if (msg_scrolled != 0) - need_wait_return = TRUE; /* needed in case emsg() is called after - * wait_return has reset need_wait_return - * and a redraw is expected because - * msg_scrolled is non-zero */ + emsg_on_display = true; // remember there is an error message + msg_scroll++; // don't overwrite a previous message + attr = hl_attr(HLF_E); // set highlight mode for error messages + if (msg_scrolled != 0) { + need_wait_return = true; // needed in case emsg() is called after + } // wait_return has reset need_wait_return + // and a redraw is expected because + // msg_scrolled is non-zero /* * Display name and line number for the source of the error. @@ -2389,6 +2392,19 @@ static void redir_write(char_u *str, int maxlen) char_u *s = str; static int cur_col = 0; + if (maxlen == 0) { + return; + } + + // Append output to capture(). + if (capture_ga) { + size_t len = 0; + while (str[len] && (maxlen < 0 ? 1 : (len < (size_t)maxlen))) { + len++; + } + ga_concat_len(capture_ga, (const char *)str, len); + } + /* Don't do anything for displaying prompts and the like. */ if (redir_off) return; @@ -2401,22 +2417,27 @@ static void redir_write(char_u *str, int maxlen) /* If the string doesn't start with CR or NL, go to msg_col */ if (*s != '\n' && *s != '\r') { while (cur_col < msg_col) { - if (redir_reg) - write_reg_contents(redir_reg, (char_u *)" ", -1, TRUE); - else if (redir_vname) + if (redir_reg) { + write_reg_contents(redir_reg, (char_u *)" ", 1, true); + } else if (redir_vname) { var_redir_str((char_u *)" ", -1); - else if (redir_fd != NULL) + } else if (redir_fd != NULL) { fputs(" ", redir_fd); - if (verbose_fd != NULL) + } + if (verbose_fd != NULL) { fputs(" ", verbose_fd); - ++cur_col; + } + cur_col++; } } - if (redir_reg) - write_reg_contents(redir_reg, s, maxlen, TRUE); - if (redir_vname) + if (redir_reg) { + size_t len = maxlen == -1 ? STRLEN(s) : (size_t)maxlen; + write_reg_contents(redir_reg, s, len, true); + } + if (redir_vname) { var_redir_str(s, maxlen); + } /* Write and adjust the current column. */ while (*s != NUL && (maxlen < 0 || (int)(s - str) < maxlen)) { diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 48791384a6..d72d8e8513 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -178,12 +178,11 @@ open_line ( if (curbuf->b_p_ai || do_si ) { - /* - * count white space on current line - */ - newindent = get_indent_str(saved_line, (int)curbuf->b_p_ts, FALSE); - if (newindent == 0 && !(flags & OPENLINE_COM_LIST)) - newindent = second_line_indent; /* for ^^D command in insert mode */ + // count white space on current line + newindent = get_indent_str(saved_line, (int)curbuf->b_p_ts, false); + if (newindent == 0 && !(flags & OPENLINE_COM_LIST)) { + newindent = second_line_indent; // for ^^D command in insert mode + } /* * Do smart indenting. @@ -612,7 +611,7 @@ open_line ( if (curbuf->b_p_ai || do_si ) - newindent = get_indent_str(leader, (int)curbuf->b_p_ts, FALSE); + newindent = get_indent_str(leader, (int)curbuf->b_p_ts, false); /* Add the indent offset */ if (newindent + off < 0) { diff --git a/src/nvim/normal.c b/src/nvim/normal.c index d4055ac1ef..c95e5e1a15 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -1795,10 +1795,11 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) if (oap->line_count < 2) oap->line_count = 2; if (curwin->w_cursor.lnum + oap->line_count - 1 > - curbuf->b_ml.ml_line_count) + curbuf->b_ml.ml_line_count) { beep_flush(); - else { - do_join(oap->line_count, oap->op_type == OP_JOIN, true, true, true); + } else { + do_join((size_t)oap->line_count, oap->op_type == OP_JOIN, + true, true, true); auto_format(false, true); } break; @@ -7666,7 +7667,7 @@ static void nv_join(cmdarg_T *cap) prep_redo(cap->oap->regname, cap->count0, NUL, cap->cmdchar, NUL, NUL, cap->nchar); - do_join(cap->count0, cap->nchar == NUL, true, true, true); + do_join((size_t)cap->count0, cap->nchar == NUL, true, true, true); } } diff --git a/src/nvim/ops.c b/src/nvim/ops.c index adfd0424f0..cb068aa37f 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1,6 +1,6 @@ /* * ops.c: implementation of various operators: op_shift, op_delete, op_tilde, - * op_change, op_yank, do_put, do_join + * op_change, op_yank, do_put, do_join */ #include <assert.h> @@ -257,8 +257,7 @@ void op_shift(oparg_T *oap, int curs_top, int amount) * shift the current line one shiftwidth left (if left != 0) or right * leaves cursor on first blank in the line */ -void -shift_line ( +void shift_line( int left, int round, int amount, @@ -369,18 +368,18 @@ static void shift_block(oparg_T *oap, int amount) memset(newp + bd.textcol + i, ' ', (size_t)j); /* the end */ memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len); - } else { /* left */ - colnr_T destination_col; /* column to which text in block will - be shifted */ - char_u *verbatim_copy_end; /* end of the part of the line which is - copied verbatim */ - colnr_T verbatim_copy_width; /* the (displayed) width of this part - of line */ - unsigned fill; /* nr of spaces that replace a TAB */ - unsigned new_line_len; /* the length of the line after the - block shift */ - size_t block_space_width; - size_t shift_amount; + } else { // left + colnr_T destination_col; // column to which text in block will + // be shifted + char_u *verbatim_copy_end; // end of the part of the line which is + // copied verbatim + colnr_T verbatim_copy_width; // the (displayed) width of this part + // of line + size_t fill; // nr of spaces that replace a TAB + size_t new_line_len; // the length of the line after the + // block shift + colnr_T block_space_width; + colnr_T shift_amount; char_u *non_white = bd.textstart; colnr_T non_white_col; @@ -409,11 +408,10 @@ static void shift_block(oparg_T *oap, int amount) block_space_width = non_white_col - oap->start_vcol; /* We will shift by "total" or "block_space_width", whichever is less. */ - shift_amount = (block_space_width < (size_t)total - ? block_space_width : (size_t)total); + shift_amount = (block_space_width < total ? block_space_width : total); - /* The column to which we will shift the text. */ - destination_col = (colnr_T)(non_white_col - shift_amount); + // The column to which we will shift the text. + destination_col = non_white_col - shift_amount; /* Now let's find out how much of the beginning of the line we can * reuse without modification. */ @@ -439,20 +437,21 @@ static void shift_block(oparg_T *oap, int amount) /* If "destination_col" is different from the width of the initial * part of the line that will be copied, it means we encountered a tab * character, which we will have to partly replace with spaces. */ - fill = destination_col - verbatim_copy_width; - - /* The replacement line will consist of: - * - the beginning of the original line up to "verbatim_copy_end", - * - "fill" number of spaces, - * - the rest of the line, pointed to by non_white. */ - new_line_len = (unsigned)(verbatim_copy_end - oldp) - + fill - + (unsigned)STRLEN(non_white) + 1; - - newp = (char_u *) xmalloc((size_t)(new_line_len)); - memmove(newp, oldp, (size_t)(verbatim_copy_end - oldp)); - memset(newp + (verbatim_copy_end - oldp), ' ', (size_t)fill); - STRMOVE(newp + (verbatim_copy_end - oldp) + fill, non_white); + assert(destination_col - verbatim_copy_width >= 0); + fill = (size_t)(destination_col - verbatim_copy_width); + + assert(verbatim_copy_end - oldp >= 0); + size_t verbatim_diff = (size_t)(verbatim_copy_end - oldp); + // The replacement line will consist of: + // - the beginning of the original line up to "verbatim_copy_end", + // - "fill" number of spaces, + // - the rest of the line, pointed to by non_white. + new_line_len = verbatim_diff + fill + STRLEN(non_white) + 1; + + newp = (char_u *) xmalloc(new_line_len); + memmove(newp, oldp, verbatim_diff); + memset(newp + verbatim_diff, ' ', fill); + STRMOVE(newp + verbatim_diff + fill, non_white); } /* replace the line */ ml_replace(curwin->w_cursor.lnum, newp, FALSE); @@ -469,21 +468,20 @@ static void shift_block(oparg_T *oap, int amount) static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def *bdp) { int p_ts; - int count = 0; /* extra spaces to replace a cut TAB */ - int spaces = 0; /* non-zero if cutting a TAB */ - colnr_T offset; /* pointer along new line */ - unsigned s_len; /* STRLEN(s) */ - char_u *newp, *oldp; /* new, old lines */ - linenr_T lnum; /* loop var */ + int count = 0; // extra spaces to replace a cut TAB + int spaces = 0; // non-zero if cutting a TAB + colnr_T offset; // pointer along new line + size_t s_len = STRLEN(s); + char_u *newp, *oldp; // new, old lines + linenr_T lnum; // loop var int oldstate = State; - - State = INSERT; /* don't want REPLACE for State */ - s_len = (unsigned)STRLEN(s); + State = INSERT; // don't want REPLACE for State for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) { - block_prep(oap, bdp, lnum, TRUE); - if (bdp->is_short && b_insert) - continue; /* OP_INSERT, line ends before block start */ + block_prep(oap, bdp, lnum, true); + if (bdp->is_short && b_insert) { + continue; // OP_INSERT, line ends before block start + } oldp = ml_get(lnum); @@ -523,25 +521,26 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def count -= off; } - newp = (char_u *) xmalloc((size_t)(STRLEN(oldp) + s_len + count + 1)); + assert(count >= 0); + newp = (char_u *)xmalloc(STRLEN(oldp) + s_len + (size_t)count + 1); - /* copy up to shifted part */ - memmove(newp, oldp, (size_t)(offset)); + // copy up to shifted part + memmove(newp, oldp, (size_t)offset); oldp += offset; - /* insert pre-padding */ + // insert pre-padding memset(newp + offset, ' ', (size_t)spaces); - /* copy the new text */ - memmove(newp + offset + spaces, s, (size_t)s_len); - offset += s_len; + // copy the new text + memmove(newp + offset + spaces, s, s_len); + offset += (int)s_len; if (spaces && !bdp->is_short) { - /* insert post-padding */ + // insert post-padding memset(newp + offset + spaces, ' ', (size_t)(p_ts - spaces)); - /* We're splitting a TAB, don't copy it. */ + // We're splitting a TAB, don't copy it. oldp++; - /* We allowed for that TAB, remember this now */ + // We allowed for that TAB, remember this now count++; } @@ -804,7 +803,7 @@ yankreg_T *copy_register(int name) copy->y_array = NULL; } else { copy->y_array = xcalloc(copy->y_size, sizeof(char_u *)); - for (linenr_T i = 0; i < copy->y_size; i++) { + for (size_t i = 0; i < copy->y_size; i++) { copy->y_array[i] = vim_strsave(reg->y_array[i]); } } @@ -888,7 +887,7 @@ static void set_yreg_additional_data(yankreg_T *reg, dict_T *additional_data) /* * Stuff string "p" into yank register "regname" as a single line (append if - * uppercase). "p" must have been alloced. + * uppercase). "p" must have been alloced. * * return FAIL for failure, OK otherwise */ @@ -940,10 +939,8 @@ do_execreg ( int silent /* set "silent" flag in typeahead buffer */ ) { - long i; - char_u *p; + char_u *p; int retval = OK; - int remap; if (regname == '@') { /* repeat previous one */ if (execreg_lastc == NUL) { @@ -1001,21 +998,20 @@ do_execreg ( if (reg->y_array == NULL) return FAIL; - /* Disallow remaping for ":@r". */ - remap = colon ? REMAP_NONE : REMAP_YES; + // Disallow remaping for ":@r". + int remap = colon ? REMAP_NONE : REMAP_YES; /* * Insert lines into typeahead buffer, from last one to first one. */ put_reedit_in_typebuf(silent); - for (i = reg->y_size - 1; i >= 0; i--) { - char_u *escaped; - + char_u *escaped; + for (size_t i = reg->y_size; i-- > 0;) { // from y_size - 1 to 0 included // insert NL between lines and after last line if type is kMTLineWise - if (reg->y_type == kMTLineWise || i < reg->y_size - 1 - || addcr) { - if (ins_typebuf((char_u *)"\n", remap, 0, TRUE, silent) == FAIL) + if (reg->y_type == kMTLineWise || i < reg->y_size - 1 || addcr) { + if (ins_typebuf((char_u *)"\n", remap, 0, true, silent) == FAIL) { return FAIL; + } } escaped = vim_strsave_escape_csi(reg->y_array[i]); retval = ins_typebuf(escaped, remap, 0, TRUE, silent); @@ -1045,7 +1041,7 @@ static void put_reedit_in_typebuf(int silent) buf[1] = 'R'; buf[2] = NUL; } else { - buf[0] = restart_edit == 'I' ? 'i' : restart_edit; + buf[0] = (char_u)(restart_edit == 'I' ? 'i' : restart_edit); buf[1] = NUL; } if (ins_typebuf(buf, REMAP_NONE, 0, TRUE, silent) == OK) @@ -1059,8 +1055,7 @@ static void put_reedit_in_typebuf(int silent) * When "esc" is TRUE it is to be taken literally: Escape CSI characters and * no remapping. */ -static int -put_in_typebuf ( +static int put_in_typebuf( char_u *s, int esc, int colon, /* add ':' before the line */ @@ -1098,13 +1093,11 @@ put_in_typebuf ( * * return FAIL for failure, OK otherwise */ -int -insert_reg ( +int insert_reg( int regname, int literally /* insert literally, not as if typed */ ) { - long i; int retval = OK; char_u *arg; int allocated; @@ -1132,10 +1125,10 @@ insert_reg ( xfree(arg); } else { /* name or number register */ yankreg_T *reg = get_yank_register(regname, YREG_PASTE); - if (reg->y_array == NULL) + if (reg->y_array == NULL) { retval = FAIL; - else { - for (i = 0; i < reg->y_size; i++) { + } else { + for (size_t i = 0; i < reg->y_size; i++) { stuffescaped(reg->y_array[i], literally); // Insert a newline between lines and after last line if // y_type is kMTLineWise. @@ -1185,8 +1178,7 @@ static void stuffescaped(char_u *arg, int literally) * If "regname" is a special register, return TRUE and store a pointer to its * value in "argp". */ -int -get_spec_reg ( +int get_spec_reg( int regname, char_u **argp, int *allocated, /* return: TRUE when value was allocated */ @@ -1273,13 +1265,11 @@ get_spec_reg ( /// @returns FAIL for failure, OK otherwise bool cmdline_paste_reg(int regname, bool literally, bool remcr) { - long i; - yankreg_T *reg = get_yank_register(regname, YREG_PASTE); if (reg->y_array == NULL) return FAIL; - for (i = 0; i < reg->y_size; i++) { + for (size_t i = 0; i < reg->y_size; i++) { cmdline_paste_str(reg->y_array[i], literally); // Insert ^M between lines and after last line if type is kMTLineWise. @@ -1311,12 +1301,14 @@ int op_delete(oparg_T *oap) struct block_def bd; linenr_T old_lcount = curbuf->b_ml.ml_line_count; - if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to do */ + if (curbuf->b_ml.ml_flags & ML_EMPTY) { // nothing to do return OK; + } - /* Nothing to delete, return here. Do prepare undo, for op_change(). */ - if (oap->empty) + // Nothing to delete, return here. Do prepare undo, for op_change(). + if (oap->empty) { return u_save_cursor(); + } if (!MODIFIABLE(curbuf)) { EMSG(_(e_modifiable)); @@ -1431,23 +1423,21 @@ int op_delete(oparg_T *oap) curwin->w_cursor.coladd = 0; } - /* n == number of chars deleted - * If we delete a TAB, it may be replaced by several characters. - * Thus the number of characters may increase! - */ + // n == number of chars deleted + // If we delete a TAB, it may be replaced by several characters. + // Thus the number of characters may increase! n = bd.textlen - bd.startspaces - bd.endspaces; oldp = ml_get(lnum); - newp = (char_u *) xmalloc((size_t)(STRLEN(oldp) + 1 - n)); - /* copy up to deleted part */ + newp = (char_u *)xmalloc(STRLEN(oldp) - (size_t)n + 1); + // copy up to deleted part memmove(newp, oldp, (size_t)bd.textcol); - /* insert spaces */ - memset(newp + bd.textcol, ' ', - (size_t)(bd.startspaces + bd.endspaces)); - /* copy the part after the deleted part */ + // insert spaces + memset(newp + bd.textcol, ' ', (size_t)(bd.startspaces + bd.endspaces)); + // copy the part after the deleted part oldp += bd.textcol + bd.textlen; STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp); - /* replace the line */ - ml_replace(lnum, newp, FALSE); + // replace the line + ml_replace(lnum, newp, false); } check_cursor_col(); @@ -1552,7 +1542,7 @@ int op_delete(oparg_T *oap) curwin->w_cursor.coladd = 0; } - (void)del_bytes((long)n, !virtual_op, + (void)del_bytes((colnr_T)n, !virtual_op, oap->op_type == OP_DELETE && !oap->is_VIsual); } else { // delete characters between lines @@ -1572,7 +1562,7 @@ int op_delete(oparg_T *oap) // delete from start of line until op_end n = (oap->end.col + 1 - !oap->inclusive); curwin->w_cursor.col = 0; - (void)del_bytes((long)n, !virtual_op, + (void)del_bytes((colnr_T)n, !virtual_op, oap->op_type == OP_DELETE && !oap->is_VIsual); curwin->w_cursor = curpos; // restore curwin->w_cursor (void)do_join(2, false, false, false, false); @@ -1611,7 +1601,8 @@ static void mb_adjust_opend(oparg_T *oap) */ static inline void pchar(pos_T lp, int c) { - *(ml_get_buf(curbuf, lp.lnum, TRUE) + lp.col) = c;; + assert(c <= UCHAR_MAX); + *(ml_get_buf(curbuf, lp.lnum, true) + lp.col) = (char_u)c; } /* @@ -1695,15 +1686,16 @@ int op_replace(oparg_T *oap, int c) oldp = get_cursor_line_ptr(); oldlen = STRLEN(oldp); - newp = (char_u *) xmalloc((size_t)(oldlen + 1 + n)); - memset(newp, NUL, (size_t)(oldlen + 1 + n)); - /* copy up to deleted part */ + assert(n >= 0); + newp = (char_u *)xmalloc(oldlen + 1 + (size_t)n); + memset(newp, NUL, oldlen + 1 + (size_t)n); + // copy up to deleted part memmove(newp, oldp, (size_t)bd.textcol); oldp += bd.textcol + bd.textlen; - /* insert pre-spaces */ + // insert pre-spaces memset(newp + bd.textcol, ' ', (size_t)bd.startspaces); - /* insert replacement chars CHECK FOR ALLOCATED SPACE */ - /* -1/-2 is used for entering CR literally. */ + // insert replacement chars CHECK FOR ALLOCATED SPACE + // -1/-2 is used for entering CR literally. if (had_ctrl_v_cr || (c != '\r' && c != '\n')) { if (has_mbyte) { n = (int)STRLEN(newp); @@ -1718,8 +1710,8 @@ int op_replace(oparg_T *oap, int c) STRMOVE(newp + STRLEN(newp), oldp); } } else { - /* Replacing with \r or \n means splitting the line. */ - after_p = (char_u *) xmalloc((size_t)(oldlen + 1 + n - STRLEN(newp))); + // Replacing with \r or \n means splitting the line. + after_p = (char_u *)xmalloc(oldlen + 1 + (size_t)n - STRLEN(newp)); STRMOVE(after_p, oldp); } /* replace the line */ @@ -1992,7 +1984,7 @@ void op_insert(oparg_T *oap, long count1) // already disabled, but still need it when calling // coladvance_force(). if (curwin->w_cursor.coladd > 0) { - int old_ve_flags = ve_flags; + unsigned old_ve_flags = ve_flags; ve_flags = VE_ALL; if (u_save_cursor() == FAIL) @@ -2066,8 +2058,8 @@ void op_insert(oparg_T *oap, long count1) if (oap->op_type == OP_INSERT && oap->start.col + oap->start.coladd != curbuf->b_op_start_orig.col + curbuf->b_op_start_orig.coladd) { - size_t t = getviscol2(curbuf->b_op_start_orig.col, - curbuf->b_op_start_orig.coladd); + int t = getviscol2(curbuf->b_op_start_orig.col, + curbuf->b_op_start_orig.coladd); oap->start.col = curbuf->b_op_start_orig.col; pre_textlen -= t - oap->start_vcol; oap->start_vcol = t; @@ -2075,8 +2067,8 @@ void op_insert(oparg_T *oap, long count1) && oap->end.col + oap->end.coladd >= curbuf->b_op_start_orig.col + curbuf->b_op_start_orig.coladd) { - size_t t = getviscol2(curbuf->b_op_start_orig.col, - curbuf->b_op_start_orig.coladd); + int t = getviscol2(curbuf->b_op_start_orig.col, + curbuf->b_op_start_orig.coladd); oap->start.col = curbuf->b_op_start_orig.col; /* reset pre_textlen to the value of OP_INSERT */ pre_textlen += bd.textlen; @@ -2109,14 +2101,13 @@ void op_insert(oparg_T *oap, long count1) firstline = ml_get(oap->start.lnum) + bd.textcol; if (oap->op_type == OP_APPEND) firstline += bd.textlen; - if (pre_textlen >= 0 - && (ins_len = (long)STRLEN(firstline) - pre_textlen) > 0) { - ins_text = vim_strnsave(firstline, (int)ins_len); - /* block handled here */ - if (u_save(oap->start.lnum, - (linenr_T)(oap->end.lnum + 1)) == OK) - block_insert(oap, ins_text, (oap->op_type == OP_INSERT), - &bd); + ins_len = (long)STRLEN(firstline) - pre_textlen; + if (pre_textlen >= 0 && ins_len > 0) { + ins_text = vim_strnsave(firstline, (size_t)ins_len); + // block handled here + if (u_save(oap->start.lnum, (linenr_T)(oap->end.lnum + 1)) == OK) { + block_insert(oap, ins_text, (oap->op_type == OP_INSERT), &bd); + } curwin->w_cursor.col = oap->start.col; check_cursor(); @@ -2139,8 +2130,10 @@ int op_change(oparg_T *oap) long ins_len; long pre_textlen = 0; long pre_indent = 0; - char_u *firstline; - char_u *ins_text, *newp, *oldp; + char_u *newp; + char_u *firstline; + char_u *ins_text; + char_u *oldp; struct block_def bd; l = oap->start.col; @@ -2198,14 +2191,14 @@ int op_change(oparg_T *oap) long new_indent = (long)(skipwhite(firstline) - firstline); pre_textlen += new_indent - pre_indent; - bd.textcol += new_indent - pre_indent; + bd.textcol += (colnr_T)(new_indent - pre_indent); } ins_len = (long)STRLEN(firstline) - pre_textlen; if (ins_len > 0) { /* Subsequent calls to ml_get() flush the firstline data - take a * copy of the inserted text. */ - ins_text = (char_u *) xmalloc((size_t)(ins_len + 1)); + ins_text = (char_u *)xmalloc((size_t)(ins_len + 1)); STRLCPY(ins_text, firstline + bd.textcol, ins_len + 1); for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum; linenr++) { @@ -2218,11 +2211,13 @@ int op_change(oparg_T *oap) if (bd.is_short) { vpos.lnum = linenr; (void)getvpos(&vpos, oap->start_vcol); - } else + } else { vpos.coladd = 0; + } oldp = ml_get(linenr); - newp = (char_u *) xmalloc((size_t)(STRLEN(oldp) + vpos.coladd + ins_len + 1)); - /* copy up to block start */ + newp = xmalloc(STRLEN(oldp) + (size_t)vpos.coladd + + (size_t)ins_len + 1); + // copy up to block start memmove(newp, oldp, (size_t)bd.textcol); offset = bd.textcol; memset(newp + offset, ' ', (size_t)vpos.coladd); @@ -2272,9 +2267,7 @@ void free_register(yankreg_T *reg) { set_yreg_additional_data(reg, NULL); if (reg->y_array != NULL) { - long i; - - for (i = reg->y_size - 1; i >= 0; i--) { + for (size_t i = reg->y_size; i-- > 0;) { // from y_size - 1 to 0 included xfree(reg->y_array[i]); } xfree(reg->y_array); @@ -2311,30 +2304,27 @@ bool op_yank(oparg_T *oap, bool message) static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) { - long y_idx; /* index in y_array[] */ - yankreg_T *curr; /* copy of current register */ - yankreg_T newreg; /* new yank register when appending */ - char_u **new_ptr; - linenr_T lnum; /* current line number */ - long j; + yankreg_T newreg; // new yank register when appending + char_u **new_ptr; + linenr_T lnum; // current line number + size_t j; MotionType yank_type = oap->motion_type; - long yanklines = oap->line_count; + size_t yanklines = (size_t)oap->line_count; linenr_T yankendlnum = oap->end.lnum; - char_u *p; - char_u *pnew; + char_u *p; + char_u *pnew; struct block_def bd; - curr = reg; - /* append to existing contents */ - if (append && reg->y_array != NULL) + yankreg_T *curr = reg; // copy of current register + // append to existing contents + if (append && reg->y_array != NULL) { reg = &newreg; - else - free_register(reg); /* free previously yanked lines */ + } else { + free_register(reg); // free previously yanked lines + } - /* - * If the cursor was in column 1 before and after the movement, and the - * operator is not inclusive, the yank is always linewise. - */ + // If the cursor was in column 1 before and after the movement, and the + // operator is not inclusive, the yank is always linewise. if (oap->motion_type == kMTCharWise && oap->start.col == 0 && !oap->inclusive @@ -2353,7 +2343,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) reg->additional_data = NULL; reg->timestamp = os_time(); - y_idx = 0; + size_t y_idx = 0; // index in y_array[] lnum = oap->start.lnum; if (yank_type == kMTBlockWise) { @@ -2481,7 +2471,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) yanklines = 0; } // Some versions of Vi use ">=" here, some don't... - if (yanklines > p_report) { + if (yanklines > (size_t)p_report) { // redisplay now, so message is not deleted update_topline_redraw(); if (yanklines == 1) { @@ -2512,10 +2502,10 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) return; } -static void yank_copy_line(yankreg_T *reg, struct block_def *bd, long y_idx) +static void yank_copy_line(yankreg_T *reg, struct block_def *bd, size_t y_idx) { - char_u *pnew = xmallocz(bd->startspaces + bd->endspaces + bd->textlen); - + char_u *pnew = xmallocz((size_t)(bd->startspaces + bd->endspaces + + bd->textlen)); reg->y_array[y_idx] = pnew; memset(pnew, ' ', (size_t)bd->startspaces); pnew += bd->startspaces; @@ -2548,7 +2538,7 @@ static void yank_do_autocmd(oparg_T *oap, yankreg_T *reg) // the yanked text list_T *list = list_alloc(); - for (linenr_T i = 0; i < reg->y_size; i++) { + for (size_t i = 0; i < reg->y_size; i++) { list_append_string(list, reg->y_array[i], -1); } list->lv_lock = VAR_FIXED; @@ -2565,7 +2555,7 @@ static void yank_do_autocmd(oparg_T *oap, yankreg_T *reg) dict_add_nr_str(dict, "regname", 0, (char_u *)buf); // kind of operation (yank/delete/change) - buf[0] = get_op_char(oap->op_type); + buf[0] = (char)get_op_char(oap->op_type); buf[1] = NUL; dict_add_nr_str(dict, "operator", 0, (char_u *)buf); @@ -2582,23 +2572,24 @@ static void yank_do_autocmd(oparg_T *oap, yankreg_T *reg) /* * Put contents of register "regname" into the text. * Caller must check "regname" to be valid! - * "flags": PUT_FIXINDENT make indent look nice - * PUT_CURSEND leave cursor after end of new text - * PUT_LINE force linewise put (":put") + * "flags": PUT_FIXINDENT make indent look nice + * PUT_CURSEND leave cursor after end of new text + * PUT_LINE force linewise put (":put") dir: BACKWARD for 'P', FORWARD for 'p' */ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) { - char_u *ptr; - char_u *newp, *oldp; + char_u *ptr; + char_u *newp; + char_u *oldp; int yanklen; - int totlen = 0; /* init for gcc */ + size_t totlen = 0; // init for gcc linenr_T lnum; colnr_T col; - long i; // index in y_array[] + size_t i; // index in y_array[] MotionType y_type; - long y_size; - int oldlen; - long y_width = 0; + size_t y_size; + size_t oldlen; + int y_width = 0; colnr_T vcol; int delcount; int incr = 0; @@ -2705,7 +2696,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) if (curbuf->terminal) { for (int i = 0; i < count; i++) { // feed the lines to the terminal - for (int j = 0; j < y_size; j++) { + for (size_t j = 0; j < y_size; j++) { if (j) { // terminate the previous line terminal_send(curbuf->terminal, "\n", 1); @@ -2736,7 +2727,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) if (dir == FORWARD && *p != NUL) { mb_ptr_adv(p); } - ptr = vim_strnsave(oldp, p - oldp); + ptr = vim_strnsave(oldp, (size_t)(p - oldp)); ml_replace(curwin->w_cursor.lnum, ptr, false); nr_lines++; dir = FORWARD; @@ -2761,11 +2752,13 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) } if (y_type == kMTBlockWise) { - lnum = curwin->w_cursor.lnum + y_size + 1; - if (lnum > curbuf->b_ml.ml_line_count) + lnum = curwin->w_cursor.lnum + (linenr_T)y_size + 1; + if (lnum > curbuf->b_ml.ml_line_count) { lnum = curbuf->b_ml.ml_line_count + 1; - if (u_save(curwin->w_cursor.lnum - 1, lnum) == FAIL) + } + if (u_save(curwin->w_cursor.lnum - 1, lnum) == FAIL) { goto end; + } } else if (y_type == kMTLineWise) { lnum = curwin->w_cursor.lnum; /* Correct line number for closed fold. Don't move the cursor yet, @@ -2811,7 +2804,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) * Block mode */ if (y_type == kMTBlockWise) { - char c = gchar_cursor(); + int c = gchar_cursor(); colnr_T endcol2 = 0; if (dir == FORWARD && c != NUL) { @@ -2864,7 +2857,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) } /* get the old line and advance to the position to insert at */ oldp = get_cursor_line_ptr(); - oldlen = (int)STRLEN(oldp); + oldlen = STRLEN(oldp); for (ptr = oldp; vcol < col && *ptr; ) { /* Count a tab for what it's worth (if list mode not on) */ incr = lbr_chartabsize_adv(oldp, &ptr, (colnr_T)vcol); @@ -2901,10 +2894,11 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) if (spaces < 0) spaces = 0; - /* insert the new text */ - totlen = count * (yanklen + spaces) + bd.startspaces + bd.endspaces; - newp = (char_u *) xmalloc((size_t)(totlen + oldlen + 1)); - /* copy part up to cursor to new line */ + // insert the new text + totlen = (size_t)(count * (yanklen + spaces) + + bd.startspaces + bd.endspaces); + newp = (char_u *) xmalloc(totlen + oldlen + 1); + // copy part up to cursor to new line ptr = newp; memmove(ptr, oldp, (size_t)bd.textcol); ptr += bd.textcol; @@ -2925,10 +2919,10 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) /* may insert some spaces after the new text */ memset(ptr, ' ', (size_t)bd.endspaces); ptr += bd.endspaces; - /* move the text after the cursor to the end of the line. */ + // move the text after the cursor to the end of the line. memmove(ptr, oldp + bd.textcol + delcount, - (size_t)(oldlen - bd.textcol - delcount + 1)); - ml_replace(curwin->w_cursor.lnum, newp, FALSE); + (size_t)((int)oldlen - bd.textcol - delcount + 1)); + ml_replace(curwin->w_cursor.lnum, newp, false); ++curwin->w_cursor.lnum; if (i == 0) @@ -2943,7 +2937,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) /* adjust '] mark */ curbuf->b_op_end.lnum = curwin->w_cursor.lnum - 1; - curbuf->b_op_end.col = bd.textcol + totlen - 1; + curbuf->b_op_end.col = bd.textcol + (colnr_T)totlen - 1; curbuf->b_op_end.coladd = 0; if (flags & PUT_CURSEND) { colnr_T len; @@ -2994,13 +2988,13 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) */ if (y_type == kMTCharWise && y_size == 1) { do { - totlen = count * yanklen; + totlen = (size_t)(count * yanklen); if (totlen > 0) { oldp = ml_get(lnum); newp = (char_u *) xmalloc((size_t)(STRLEN(oldp) + totlen + 1)); memmove(newp, oldp, (size_t)col); ptr = newp + col; - for (i = 0; i < count; i++) { + for (i = 0; i < (size_t)count; i++) { memmove(ptr, y_array[0], (size_t)yanklen); ptr += yanklen; } @@ -3037,7 +3031,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) // Then append y_array[0] to first line. lnum = new_cursor.lnum; ptr = ml_get(lnum) + col; - totlen = (int)STRLEN(y_array[y_size - 1]); + totlen = STRLEN(y_array[y_size - 1]); newp = (char_u *) xmalloc((size_t)(STRLEN(ptr) + totlen + 1)); STRCPY(newp, y_array[y_size - 1]); STRCAT(newp, ptr); @@ -3217,22 +3211,19 @@ int get_register_name(int num) */ void ex_display(exarg_T *eap) { - int i, n; - long j; - char_u *p; - yankreg_T *yb; + char_u *p; + yankreg_T *yb; int name; - int attr; - char_u *arg = eap->arg; + char_u *arg = eap->arg; int clen; if (arg != NULL && *arg == NUL) arg = NULL; - attr = hl_attr(HLF_8); + int attr = hl_attr(HLF_8); /* Highlight title */ MSG_PUTS_TITLE(_("\n--- Registers ---")); - for (i = -1; i < NUM_REGISTERS && !got_int; i++) { + for (int i = -1; i < NUM_REGISTERS && !got_int; i++) { name = get_register_name(i); if (arg != NULL && vim_strchr(arg, name) == NULL) { @@ -3261,8 +3252,8 @@ void ex_display(exarg_T *eap) msg_putchar(name); MSG_PUTS(" "); - n = (int)Columns - 6; - for (j = 0; j < yb->y_size && n > 1; ++j) { + int n = (int)Columns - 6; + for (size_t j = 0; j < yb->y_size && n > 1; j++) { if (j) { MSG_PUTS_ATTR("^J", attr); n -= 2; @@ -3438,7 +3429,7 @@ static char_u *skip_comment(char_u *line, int process, int include_space, int *i // to set those marks. // // return FAIL for failure, OK otherwise -int do_join(long count, +int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions, @@ -3461,24 +3452,21 @@ int do_join(long count, && has_format_option(FO_REMOVE_COMS); int prev_was_comment; - assert(count > 1); - if (save_undo && u_save((linenr_T)(curwin->w_cursor.lnum - 1), - (linenr_T)(curwin->w_cursor.lnum + count)) == FAIL) + if (save_undo && u_save(curwin->w_cursor.lnum - 1, + curwin->w_cursor.lnum + (linenr_T)count) == FAIL) { return FAIL; - - /* Allocate an array to store the number of spaces inserted before each - * line. We will use it to pre-compute the length of the new line and the - * proper placement of each original line in the new one. */ + } + // Allocate an array to store the number of spaces inserted before each + // line. We will use it to pre-compute the length of the new line and the + // proper placement of each original line in the new one. spaces = xcalloc(count, 1); if (remove_comments) { comments = xcalloc(count, sizeof(*comments)); } - /* - * Don't move anything, just compute the final line length - * and setup the array of space strings lengths - */ - for (t = 0; t < count; ++t) { + // Don't move anything, just compute the final line length + // and setup the array of space strings lengths + for (t = 0; t < (linenr_T)count; t++) { curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); if (t == 0 && setmark) { // Set the '[ mark. @@ -3558,7 +3546,7 @@ int do_join(long count, * column. This is not Vi compatible, but Vi deletes the marks, thus that * should not really be a problem. */ - for (t = count - 1;; --t) { + for (t = (linenr_T)count - 1;; t--) { cend -= currsize; memmove(cend, curr, (size_t)currsize); if (spaces[t] > 0) { @@ -3595,8 +3583,8 @@ int do_join(long count, * have moved up (last line deleted), so the current lnum is kept in t. */ t = curwin->w_cursor.lnum; - ++curwin->w_cursor.lnum; - del_lines(count - 1, FALSE); + curwin->w_cursor.lnum++; + del_lines((long)count - 1, false); curwin->w_cursor.lnum = t; /* @@ -3778,8 +3766,8 @@ fex_format ( * Set v:lnum to the first line number and v:count to the number of lines. * Set v:char to the character to be inserted (can be NUL). */ - set_vim_var_nr(VV_LNUM, lnum); - set_vim_var_nr(VV_COUNT, count); + set_vim_var_nr(VV_LNUM, (varnumber_T)lnum); + set_vim_var_nr(VV_COUNT, (varnumber_T)count); set_vim_var_char(c); /* @@ -4473,7 +4461,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) firstdigit = 'a'; } } else { - firstdigit -= Prenum1; + firstdigit -= (int)Prenum1; } } else { if (26 - CharOrd(firstdigit) - 1 < Prenum1) { @@ -4483,7 +4471,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) firstdigit = 'z'; } } else { - firstdigit += Prenum1; + firstdigit += (int)Prenum1; } } curwin->w_cursor.col = col; @@ -4591,7 +4579,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) // Prepare the leading characters in buf1[]. // When there are many leading zeros it could be very long. // Allocate a bit too much. - buf1 = xmalloc(length + NUMBUFLEN); + buf1 = xmalloc((size_t)length + NUMBUFLEN); if (buf1 == NULL) { goto theend; } @@ -4604,7 +4592,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) length--; } if (pre == 'b' || pre == 'B' || pre == 'x' || pre == 'X') { - *ptr++ = pre; + *ptr++ = (char_u)pre; length--; } @@ -4767,8 +4755,6 @@ static void *get_reg_wrap_one_line(char_u *s, int flags) /// @returns NULL for error. void *get_reg_contents(int regname, int flags) { - long i; - // Don't allow using an expression register inside an expression. if (regname == '=') { if (flags & kGRegNoExpr) { @@ -4804,7 +4790,7 @@ void *get_reg_contents(int regname, int flags) if (flags & kGRegList) { list_T *list = list_alloc(); - for (int i = 0; i < reg->y_size; i++) { + for (size_t i = 0; i < reg->y_size; i++) { list_append_string(list, reg->y_array[i], -1); } @@ -4815,7 +4801,7 @@ void *get_reg_contents(int regname, int flags) * Compute length of resulting string. */ size_t len = 0; - for (i = 0; i < reg->y_size; i++) { + for (size_t i = 0; i < reg->y_size; i++) { len += STRLEN(reg->y_array[i]); /* * Insert a newline between lines and after last line if @@ -4832,7 +4818,7 @@ void *get_reg_contents(int regname, int flags) * Copy the lines of the yank register into the string. */ len = 0; - for (i = 0; i < reg->y_size; i++) { + for (size_t i = 0; i < reg->y_size; i++) { STRCPY(retval + len, reg->y_array[i]); len += STRLEN(retval + len); @@ -4888,7 +4874,7 @@ void write_reg_contents(int name, const char_u *str, ssize_t len, void write_reg_contents_lst(int name, char_u **strings, int maxlen, bool must_append, MotionType yank_type, - long block_len) + colnr_T block_len) { if (name == '/' || name == '=') { char_u *s = strings[0]; @@ -4913,7 +4899,8 @@ void write_reg_contents_lst(int name, char_u **strings, int maxlen, return; } - str_to_reg(reg, yank_type, (char_u *) strings, -1, block_len, true); + str_to_reg(reg, yank_type, (char_u *)strings, STRLEN((char_u *)strings), + block_len, true); finish_write_reg(name, reg, old_y_previous); } @@ -4941,7 +4928,7 @@ void write_reg_contents_ex(int name, ssize_t len, bool must_append, MotionType yank_type, - long block_len) + colnr_T block_len) { if (len < 0) { len = (ssize_t) STRLEN(str); @@ -4991,7 +4978,7 @@ void write_reg_contents_ex(int name, // Copy the input string into the adjusted memory at the specified // offset. expr_line = xrealloc(expr_line, totlen + 1); - memcpy(expr_line + offset, str, (size_t) len); + memcpy(expr_line + offset, str, (size_t)len); expr_line[totlen] = NUL; return; @@ -5005,7 +4992,7 @@ void write_reg_contents_ex(int name, if (!(reg = init_write_reg(name, &old_y_previous, must_append))) { return; } - str_to_reg(reg, yank_type, str, len, block_len, false); + str_to_reg(reg, yank_type, str, (size_t)len, block_len, false); finish_write_reg(name, reg, old_y_previous); } @@ -5061,7 +5048,7 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, (y_ptr->y_size + newlines) * sizeof(char_u *)); y_ptr->y_array = pp; - linenr_T lnum = y_ptr->y_size; // The current line number. + size_t lnum = y_ptr->y_size; // The current line number. // If called with `blocklen < 0`, we have to update the yank reg's width. size_t maxlen = 0; @@ -5080,7 +5067,9 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, for (const char_u *start = str, *end = str + len; start < end + extraline; start += line_len + 1, lnum++) { - line_len = (const char_u *) xmemscan(start, '\n', end - start) - start; + assert(end - start >= 0); + line_len = (size_t)((char_u *)xmemscan(start, '\n', + (size_t)(end - start)) - start); if (line_len > maxlen) { maxlen = line_len; } @@ -5090,7 +5079,7 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, char_u *s = xmallocz(line_len + extra); memcpy(s, pp[lnum], extra); memcpy(s + extra, start, line_len); - ssize_t s_len = extra + line_len; + size_t s_len = extra + line_len; if (append) { xfree(pp[lnum]); @@ -5474,7 +5463,7 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet) free_register(reg); list_T *args = list_alloc(); - char_u regname = name; + char_u regname = (char_u)name; list_append_string(args, ®name, 1); typval_T result = eval_call_provider("clipboard", "get", args); @@ -5519,8 +5508,8 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet) reg->y_type = kMTUnknown; } - reg->y_array = xcalloc(lines->lv_len, sizeof(uint8_t *)); - reg->y_size = lines->lv_len; + reg->y_array = xcalloc((size_t)lines->lv_len, sizeof(uint8_t *)); + reg->y_size = (size_t)lines->lv_len; reg->additional_data = NULL; reg->timestamp = 0; // Timestamp is not saved for clipboard registers because clipboard registers @@ -5551,14 +5540,15 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet) } if (reg->y_type == kMTBlockWise) { - int maxlen = 0; - for (int i = 0; i < reg->y_size; i++) { - int rowlen = STRLEN(reg->y_array[i]); + size_t maxlen = 0; + for (size_t i = 0; i < reg->y_size; i++) { + size_t rowlen = STRLEN(reg->y_array[i]); if (rowlen > maxlen) { maxlen = rowlen; } } - reg->y_width = maxlen-1; + assert(maxlen <= INT_MAX); + reg->y_width = (int)maxlen - 1; } *target = reg; @@ -5566,7 +5556,7 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet) err: if (reg->y_array) { - for (int i = 0; i < reg->y_size; i++) { + for (size_t i = 0; i < reg->y_size; i++) { xfree(reg->y_array[i]); } xfree(reg->y_array); @@ -5590,7 +5580,7 @@ static void set_clipboard(int name, yankreg_T *reg) list_T *lines = list_alloc(); - for (int i = 0; i < reg->y_size; i++) { + for (size_t i = 0; i < reg->y_size; i++) { list_append_string(lines, reg->y_array[i], -1); } @@ -5615,7 +5605,7 @@ static void set_clipboard(int name, yankreg_T *reg) } list_append_string(args, ®type, 1); - char_u regname = name; + char_u regname = (char_u)name; list_append_string(args, ®name, 1); (void)eval_call_provider("clipboard", "set", args); @@ -5678,8 +5668,8 @@ const void *op_register_iter(const void *const iter, char *const name, if (iter_reg - &(y_regs[0]) == NUM_SAVED_REGISTERS || reg_empty(iter_reg)) { return NULL; } - size_t iter_off = iter_reg - &(y_regs[0]); - *name = (char) get_register_name(iter_off); + int iter_off = (int)(iter_reg - &(y_regs[0])); + *name = (char)get_register_name(iter_off); *reg = *iter_reg; while (++iter_reg - &(y_regs[0]) < NUM_SAVED_REGISTERS) { if (!reg_empty(iter_reg)) { diff --git a/src/nvim/ops.h b/src/nvim/ops.h index 8c8a586957..44df2e9e0c 100644 --- a/src/nvim/ops.h +++ b/src/nvim/ops.h @@ -79,7 +79,7 @@ enum GRegFlags { /// Definition of one register typedef struct yankreg { char_u **y_array; ///< Pointer to an array of line pointers. - linenr_T y_size; ///< Number of lines in y_array. + size_t y_size; ///< Number of lines in y_array. MotionType y_type; ///< Register type colnr_T y_width; ///< Register width (only valid for y_type == kBlockWise). Timestamp timestamp; ///< Time when register was last modified. diff --git a/src/nvim/option.c b/src/nvim/option.c index c8a25e8b75..52a1fd8558 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3403,9 +3403,10 @@ char_u *check_stl_option(char_u *s) if (!*s) break; s++; - if (*s != '%' && *s != ')') - ++itemcnt; - if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK) { + if (*s != '%' && *s != ')') { + itemcnt++; + } + if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_SEPARATE) { s++; continue; } @@ -4030,15 +4031,16 @@ set_num_option ( errmsg = e_invarg; curwin->w_p_fdc = 12; } - } - /* 'shiftwidth' or 'tabstop' */ - else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts) { - if (foldmethodIsIndent(curwin)) + // 'shiftwidth' or 'tabstop' + } else if (pp == &curbuf->b_p_sw || pp == (long *)&curbuf->b_p_ts) { + if (foldmethodIsIndent(curwin)) { foldUpdateAll(curwin); - /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes: - * parse 'cinoptions'. */ - if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0) + } + // When 'shiftwidth' changes, or it's zero and 'tabstop' changes: + // parse 'cinoptions'. + if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0) { parse_cino(curbuf); + } } /* 'maxcombine' */ else if (pp == &p_mco) { @@ -5657,7 +5659,7 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_isk = save_p_isk; else { buf->b_p_isk = vim_strsave(p_isk); - did_isk = TRUE; + did_isk = true; buf->b_p_ts = p_ts; buf->b_help = false; if (buf->b_p_bt[0] == 'h') diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h index 904e97f8ca..b1a2b00bdb 100644 --- a/src/nvim/option_defs.h +++ b/src/nvim/option_defs.h @@ -258,7 +258,7 @@ enum { STL_ARGLISTSTAT = 'a', ///< Argument list status as (x of y). STL_PAGENUM = 'N', ///< Page number (when printing). STL_VIM_EXPR = '{', ///< Start of expression to substitute. - STL_MIDDLEMARK = '=', ///< Separation between left and right. + STL_SEPARATE = '=', ///< Separation between alignment sections. STL_TRUNCMARK = '<', ///< Truncation mark if line is too long. STL_USER_HL = '*', ///< Highlight from (User)1..9 or 0. STL_HIGHLIGHT = '#', ///< Highlight name. @@ -274,7 +274,7 @@ enum { STL_HELPFLAG, STL_HELPFLAG_ALT, STL_FILETYPE, STL_FILETYPE_ALT, \ STL_PREVIEWFLAG, STL_PREVIEWFLAG_ALT, STL_MODIFIED, STL_MODIFIED_ALT, \ STL_QUICKFIX, STL_PERCENTAGE, STL_ALTPERCENT, STL_ARGLISTSTAT, STL_PAGENUM, \ - STL_VIM_EXPR, STL_MIDDLEMARK, STL_TRUNCMARK, STL_USER_HL, STL_HIGHLIGHT, \ + STL_VIM_EXPR, STL_SEPARATE, STL_TRUNCMARK, STL_USER_HL, STL_HIGHLIGHT, \ STL_TABPAGENR, STL_TABCLOSENR, STL_CLICK_FUNC, \ 0, \ }) diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 51c8597d53..380d955f63 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -1422,7 +1422,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags) } if (!op_register_set(cur_entry.data.reg.name, (yankreg_T) { .y_array = (char_u **) cur_entry.data.reg.contents, - .y_size = (linenr_T) cur_entry.data.reg.contents_size, + .y_size = cur_entry.data.reg.contents_size, .y_type = cur_entry.data.reg.type, .y_width = (colnr_T) cur_entry.data.reg.width, .timestamp = cur_entry.timestamp, @@ -2745,7 +2745,7 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, if (name == NUL) { break; } - if (limit_reg_lines && reg.y_size > max_reg_lines) { + if (limit_reg_lines && reg.y_size > (size_t)max_reg_lines) { continue; } wms->registers[op_reg_index(name)] = (PossiblyFreedShadaEntry) { diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 9e4dc0204f..05141eaf1e 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -6952,8 +6952,23 @@ highlight_color ( else if (!(TOLOWER_ASC(what[0]) == 'b' && TOLOWER_ASC(what[1]) == 'g')) return NULL; if (modec == 'g') { - if (fg) + if (what[2] == '#' && ui_rgb_attached()) { + if (fg) { + n = HL_TABLE()[id - 1].sg_rgb_fg; + } else if (sp) { + n = HL_TABLE()[id - 1].sg_rgb_sp; + } else { + n = HL_TABLE()[id - 1].sg_rgb_bg; + } + if (n < 0 || n > 0xffffff) { + return NULL; + } + snprintf((char *)name, sizeof(name), "#%06x", n); + return name; + } + if (fg) { return HL_TABLE()[id - 1].sg_rgb_fg_name; + } if (sp) { return HL_TABLE()[id - 1].sg_rgb_sp_name; } diff --git a/src/nvim/testdir/runtest.vim b/src/nvim/testdir/runtest.vim index 2712fb9371..578d64efde 100644 --- a/src/nvim/testdir/runtest.vim +++ b/src/nvim/testdir/runtest.vim @@ -61,12 +61,13 @@ endif " Locate Test_ functions and execute them. set nomore redir @q -function /^Test_ +silent function /^Test_ redir END let tests = split(substitute(@q, 'function \(\k*()\)', '\1', 'g')) " Execute the tests in alphabetical order. for test in sort(tests) + echo 'Executing ' . test if exists("*SetUp") call SetUp() endif diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index 3a136a4b1d..be256f3ebc 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -139,6 +139,9 @@ static void forward_modified_utf8(TermInput *input, TermKeyKey *key) if (key->type == TERMKEY_TYPE_KEYSYM && key->code.sym == TERMKEY_SYM_ESCAPE) { len = (size_t)snprintf(buf, sizeof(buf), "<Esc>"); + } else if (key->type == TERMKEY_TYPE_KEYSYM + && key->code.sym == TERMKEY_SYM_SUSPEND) { + len = (size_t)snprintf(buf, sizeof(buf), "<C-Z>"); } else { len = termkey_strfkey(input->tk, buf, sizeof(buf), key, TERMKEY_FORMAT_VIM); } diff --git a/src/nvim/version.c b/src/nvim/version.c index 1a66589080..5364fee953 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -341,7 +341,7 @@ static int included_patches[] = { // 1355 NA // 1354 NA // 1353 NA - // 1352, + 1352, // 1351 NA // 1350 NA // 1349 NA @@ -567,7 +567,7 @@ static int included_patches[] = { // 1129 NA // 1128 NA // 1127 NA - // 1126, + 1126, // 1125 NA // 1124 NA 1123, @@ -1904,21 +1904,15 @@ void intro_message(int colon) N_("by Bram Moolenaar et al."), N_("Vim is open source and freely distributable"), "", - N_("First time using a vi-like editor?"), - N_("Type :Tutor<Enter> to get started!"), + N_("Type \":Tutor\" or \":help nvim\" to get started!"), "", - N_("Already know your way around Vim?"), - N_("See :help nvim-intro for an introduction to Neovim."), + N_("Still have questions? https://neovim.io/community"), "", - N_("Still have questions?"), - N_("Reach out to the Neovim community at neovim.io/community."), + N_("type :q<Enter> to exit "), + N_("type :help<Enter> or <F1> for on-line help"), "", N_("Help poor children in Uganda!"), N_("type :help iccf<Enter> for information "), - "", - N_("type :q<Enter> to exit "), - N_("type :help<Enter> or <F1> for on-line help"), - N_("type :help nvim<Enter> for Neovim help "), }; // blanklines = screen height - # message lines diff --git a/test/functional/eval/capture_spec.lua b/test/functional/eval/capture_spec.lua new file mode 100644 index 0000000000..d9265f1b5b --- /dev/null +++ b/test/functional/eval/capture_spec.lua @@ -0,0 +1,86 @@ +local helpers = require('test.functional.helpers')(after_each) +local eq = helpers.eq +local eval = helpers.eval +local clear = helpers.clear +local source = helpers.source +local redir_exec = helpers.redir_exec +local exc_exec = helpers.exc_exec +local funcs = helpers.funcs +local Screen = require('test.functional.ui.screen') +local feed = helpers.feed + +describe('capture()', function() + before_each(clear) + + it('returns the same result with :redir', function() + eq(redir_exec('messages'), funcs.capture('messages')) + end) + + it('returns the output of the commands if the argument is List', function() + eq("foobar", funcs.capture({'echon "foo"', 'echon "bar"'})) + eq("\nfoo\nbar", funcs.capture({'echo "foo"', 'echo "bar"'})) + end) + + it('supports the nested redirection', function() + source([[ + function! g:Foo() + let a = '' + redir => a + silent echon "foo" + redir END + return a + endfunction + function! g:Bar() + let a = '' + redir => a + call g:Foo() + redir END + return a + endfunction + ]]) + eq('foo', funcs.capture('call g:Bar()')) + + eq('42', funcs.capture([[echon capture("echon capture('echon 42')")]])) + end) + + it('returns the transformed string', function() + eq('^A', funcs.capture('echon "\\<C-a>"')) + end) + + it('returns the empty string if the argument list is empty', function() + eq('', funcs.capture({})) + eq(0, exc_exec('let g:ret = capture(v:_null_list)')) + eq('', eval('g:ret')) + end) + + it('returns the errors', function() + local ret + ret = exc_exec('call capture(0.0)') + eq('Vim(call):E806: using Float as a String', ret) + ret = exc_exec('call capture(v:_null_dict)') + eq('Vim(call):E731: using Dictionary as a String', ret) + ret = exc_exec('call capture(function("tr"))') + eq('Vim(call):E729: using Funcref as a String', ret) + ret = exc_exec('call capture(["echo 42", 0.0, "echo 44"])') + eq('Vim(call):E806: using Float as a String', ret) + ret = exc_exec('call capture(["echo 42", v:_null_dict, "echo 44"])') + eq('Vim(call):E731: using Dictionary as a String', ret) + ret = exc_exec('call capture(["echo 42", function("tr"), "echo 44"])') + eq('Vim(call):E729: using Funcref as a String', ret) + end) + + it('silences command run inside', function() + local screen = Screen.new(20, 5) + screen:attach() + screen:set_default_attr_ignore({{bold=true, foreground=255}}) + feed(':let g:mes = capture("echon 42")<CR>') + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + | + ]]) + eq('42', eval('g:mes')) + end) +end) diff --git a/test/functional/ex_cmds/menu_spec.lua b/test/functional/ex_cmds/menu_spec.lua index 10bcc5b7bb..52df9e1592 100644 --- a/test/functional/ex_cmds/menu_spec.lua +++ b/test/functional/ex_cmds/menu_spec.lua @@ -39,7 +39,7 @@ describe(':emenu', function() end) it('executes correct bindings in command mode', function() - feed('ithis is a sentence<esc>^"+yiwo<esc>') + feed('ithis is a sentence<esc>^yiwo<esc>') -- Invoke "Edit.Paste" in normal-mode. nvim('command', 'emenu Edit.Paste') diff --git a/test/functional/ex_cmds/write_spec.lua b/test/functional/ex_cmds/write_spec.lua index 83513d747f..7f5eba1fc8 100644 --- a/test/functional/ex_cmds/write_spec.lua +++ b/test/functional/ex_cmds/write_spec.lua @@ -6,10 +6,13 @@ local eq, eval, clear, write_file, execute, source = helpers.execute, helpers.source describe(':write', function() - it('&backupcopy=auto preserves symlinks', function() - clear('set backupcopy=auto') + after_each(function() os.remove('test_bkc_file.txt') os.remove('test_bkc_link.txt') + end) + + it('&backupcopy=auto preserves symlinks', function() + clear('set backupcopy=auto') write_file('test_bkc_file.txt', 'content0') execute("silent !ln -s test_bkc_file.txt test_bkc_link.txt") source([[ @@ -23,8 +26,6 @@ describe(':write', function() it('&backupcopy=no replaces symlink with new file', function() clear('set backupcopy=no') - os.remove('test_bkc_file.txt') - os.remove('test_bkc_link.txt') write_file('test_bkc_file.txt', 'content0') execute("silent !ln -s test_bkc_file.txt test_bkc_link.txt") source([[ diff --git a/test/functional/legacy/eval_spec.lua b/test/functional/legacy/eval_spec.lua index b7317045be..3684fe714d 100644 --- a/test/functional/legacy/eval_spec.lua +++ b/test/functional/legacy/eval_spec.lua @@ -5,11 +5,6 @@ local feed, insert, source = helpers.feed, helpers.insert, helpers.source local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect local eq, eval, write_file = helpers.eq, helpers.eval, helpers.write_file -local function has_clipboard() - clear() - return 1 == eval("has('clipboard')") -end - describe('eval', function() setup(function() write_file('test_eval_setup.vim', [[ @@ -539,8 +534,13 @@ describe('eval', function() =: type v; value: abc/]].."\000 (['abc/\000"..[[']), expr: "abc/]]..'\000'..[[" (['"abc/]]..'\000'..[["'])]]) end) - if has_clipboard() then - it('system clipboard', function() + describe('system clipboard', function() + before_each(function() + execute('let &runtimepath = "test/functional/fixtures,".&runtimepath') + execute('call getreg("*")') -- force load of provider + end) + + it('works', function() insert([[ Some first line (this text was at the top of the old test_eval.in). @@ -570,9 +570,7 @@ describe('eval', function() *: type V; value: clipboard contents]]..'\00'..[[ (['clipboard contents']), expr: clipboard contents]]..'\00'..[[ (['clipboard contents']) *: type V; value: something else]]..'\00'..[[ (['something else']), expr: something else]]..'\00'..[[ (['something else'])]]) end) - else - pending('system clipboard not available', function() end) - end + end) it('errors', function() source([[ diff --git a/test/functional/legacy/getcwd_spec.lua b/test/functional/legacy/getcwd_spec.lua new file mode 100644 index 0000000000..3bb9930b74 --- /dev/null +++ b/test/functional/legacy/getcwd_spec.lua @@ -0,0 +1,86 @@ +-- Tests for getcwd(), haslocaldir(), and :lcd + +local helpers = require('test.functional.helpers')(after_each) +local eq, eval, source = helpers.eq, helpers.eval, helpers.source +local call, clear, execute = helpers.call, helpers.clear, helpers.execute + +describe('getcwd', function() + before_each(clear) + + after_each(function() + helpers.rmdir('Xtopdir') + end) + + it('is working', function() + source([[ + function! GetCwdInfo(win, tab) + let tab_changed = 0 + let mod = ":t" + if a:tab > 0 && a:tab != tabpagenr() + let tab_changed = 1 + exec "tabnext " . a:tab + endif + let bufname = fnamemodify(bufname(winbufnr(a:win)), mod) + if tab_changed + tabprevious + endif + if a:win == 0 && a:tab == 0 + let dirname = fnamemodify(getcwd(), mod) + let lflag = haslocaldir() + elseif a:tab == 0 + let dirname = fnamemodify(getcwd(a:win), mod) + let lflag = haslocaldir(a:win) + else + let dirname = fnamemodify(getcwd(a:win, a:tab), mod) + let lflag = haslocaldir(a:win, a:tab) + endif + return bufname . ' ' . dirname . ' ' . lflag + endfunction + ]]) + execute('new') + execute('let cwd=getcwd()') + call('mkdir', 'Xtopdir') + execute('silent cd Xtopdir') + call('mkdir', 'Xdir1') + call('mkdir', 'Xdir2') + call('mkdir', 'Xdir3') + execute('new a') + execute('new b') + execute('new c') + execute('3wincmd w') + execute('silent lcd Xdir1') + eq('a Xdir1 1', eval('GetCwdInfo(0, 0)')) + execute('wincmd W') + eq('b Xtopdir 0', eval('GetCwdInfo(0, 0)')) + execute('wincmd W') + execute('silent lcd Xdir3') + eq('c Xdir3 1', eval('GetCwdInfo(0, 0)')) + eq('a Xdir1 1', eval('GetCwdInfo(bufwinnr("a"), 0)')) + eq('b Xtopdir 0', eval('GetCwdInfo(bufwinnr("b"), 0)')) + eq('c Xdir3 1', eval('GetCwdInfo(bufwinnr("c"), 0)')) + execute('wincmd W') + eq('a Xdir1 1', eval('GetCwdInfo(bufwinnr("a"), tabpagenr())')) + eq('b Xtopdir 0', eval('GetCwdInfo(bufwinnr("b"), tabpagenr())')) + eq('c Xdir3 1', eval('GetCwdInfo(bufwinnr("c"), tabpagenr())')) + + execute('tabnew x') + execute('new y') + execute('new z') + execute('3wincmd w') + eq('x Xtopdir 0', eval('GetCwdInfo(0, 0)')) + execute('wincmd W') + execute('silent lcd Xdir2') + eq('y Xdir2 1', eval('GetCwdInfo(0, 0)')) + execute('wincmd W') + execute('silent lcd Xdir3') + eq('z Xdir3 1', eval('GetCwdInfo(0, 0)')) + eq('x Xtopdir 0', eval('GetCwdInfo(bufwinnr("x"), 0)')) + eq('y Xdir2 1', eval('GetCwdInfo(bufwinnr("y"), 0)')) + eq('z Xdir3 1', eval('GetCwdInfo(bufwinnr("z"), 0)')) + execute('let tp_nr = tabpagenr()') + execute('tabrewind') + eq('x Xtopdir 0', eval('GetCwdInfo(3, tp_nr)')) + eq('y Xdir2 1', eval('GetCwdInfo(2, tp_nr)')) + eq('z Xdir3 1', eval('GetCwdInfo(1, tp_nr)')) + end) +end) diff --git a/test/functional/terminal/highlight_spec.lua b/test/functional/terminal/highlight_spec.lua index 8876c68673..8d7c7451d3 100644 --- a/test/functional/terminal/highlight_spec.lua +++ b/test/functional/terminal/highlight_spec.lua @@ -165,24 +165,49 @@ end) describe('synIDattr()', function() local screen - before_each(function() clear() screen = Screen.new(50, 7) - execute('highlight Normal ctermfg=1 guifg=#ff0000') + execute('highlight Normal ctermfg=252 guifg=#ff0000 guibg=Black') + -- Salmon #fa8072 Maroon #800000 + execute('highlight Keyword ctermfg=79 guifg=Salmon guisp=Maroon') + end) + + it('returns cterm-color if RGB-capable UI is _not_ attached', function() + eq('252', eval('synIDattr(hlID("Normal"), "fg")')) + eq('252', eval('synIDattr(hlID("Normal"), "fg#")')) + eq('-1', eval('synIDattr(hlID("Normal"), "bg")')) + eq('-1', eval('synIDattr(hlID("Normal"), "bg#")')) + eq('79', eval('synIDattr(hlID("Keyword"), "fg")')) + eq('79', eval('synIDattr(hlID("Keyword"), "fg#")')) + eq('', eval('synIDattr(hlID("Keyword"), "sp")')) + eq('', eval('synIDattr(hlID("Keyword"), "sp#")')) end) - after_each(function() - screen:detach() + it('returns gui-color if "gui" arg is passed', function() + eq('Black', eval('synIDattr(hlID("Normal"), "bg", "gui")')) + eq('Maroon', eval('synIDattr(hlID("Keyword"), "sp", "gui")')) + end) + + it('returns gui-color if RGB-capable UI is attached', function() + screen:attach(true) + eq('#ff0000', eval('synIDattr(hlID("Normal"), "fg")')) + eq('Black', eval('synIDattr(hlID("Normal"), "bg")')) + eq('Salmon', eval('synIDattr(hlID("Keyword"), "fg")')) + eq('Maroon', eval('synIDattr(hlID("Keyword"), "sp")')) end) - it('returns RGB number if GUI', function() + it('returns #RRGGBB value for fg#/bg#/sp#', function() screen:attach(true) - eq('#ff0000', eval('synIDattr(hlID("Normal"), "fg")')) + eq('#ff0000', eval('synIDattr(hlID("Normal"), "fg#")')) + eq('#000000', eval('synIDattr(hlID("Normal"), "bg#")')) + eq('#fa8072', eval('synIDattr(hlID("Keyword"), "fg#")')) + eq('#800000', eval('synIDattr(hlID("Keyword"), "sp#")')) end) it('returns color number if non-GUI', function() screen:attach(false) - eq('1', eval('synIDattr(hlID("Normal"), "fg")')) + eq('252', eval('synIDattr(hlID("Normal"), "fg")')) + eq('79', eval('synIDattr(hlID("Keyword"), "fg")')) end) end) diff --git a/test/functional/ui/highlight_spec.lua b/test/functional/ui/highlight_spec.lua index b156f13885..6ef40fff62 100644 --- a/test/functional/ui/highlight_spec.lua +++ b/test/functional/ui/highlight_spec.lua @@ -38,7 +38,6 @@ describe('manual syntax highlight', function() os.remove('Xtest-functional-ui-highlight.tmp.vim') end) - -- test with "set hidden" even if the bug did not occur this way it("works with buffer switch and 'hidden'", function() execute('e tmp1.vim') execute('e Xtest-functional-ui-highlight.tmp.vim') diff --git a/test/functional/viml/function_spec.lua b/test/functional/viml/function_spec.lua index 776e760aaf..f0a4406593 100644 --- a/test/functional/viml/function_spec.lua +++ b/test/functional/viml/function_spec.lua @@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq +local eval = helpers.eval local exc_exec = helpers.exc_exec describe('Up to MAX_FUNC_ARGS arguments are handled by', function() @@ -27,3 +28,11 @@ describe('Up to MAX_FUNC_ARGS arguments are handled by', function() eq('Vim(call):E740: Too many arguments for function rpcnotify', ret) end) end) + +describe('api_info()', function() + before_each(clear) + it('has the right keys', function() + local api_keys = eval("sort(keys(api_info()))") + eq({'error_types', 'functions', 'types'}, api_keys) + end) +end) diff --git a/test/unit/buffer_spec.lua b/test/unit/buffer_spec.lua index b7f82064d7..317c9be6e7 100644 --- a/test/unit/buffer_spec.lua +++ b/test/unit/buffer_spec.lua @@ -1,10 +1,9 @@ -local assert = require("luassert") local helpers = require("test.unit.helpers") local to_cstr = helpers.to_cstr +local get_str = helpers.ffi.string local eq = helpers.eq -local neq = helpers.neq local NULL = helpers.NULL local globals = helpers.cimport("./src/nvim/globals.h") @@ -211,93 +210,246 @@ describe('buffer functions', function() end) describe('build_stl_str_hl', function() + local buffer_byte_size = 100 + local STL_MAX_ITEM = 80 + local output_buffer = '' + + -- This function builds the statusline + -- + -- @param arg Optional arguments are: + -- .pat The statusline format string + -- .fillchar The fill character used in the statusline + -- .maximum_cell_count The number of cells available in the statusline + local function build_stl_str_hl(arg) + output_buffer = to_cstr(string.rep(" ", buffer_byte_size)) + + local pat = arg.pat or '' + local fillchar = arg.fillchar or (' '):byte() + local maximum_cell_count = arg.maximum_cell_count or buffer_byte_size - local output_buffer = to_cstr(string.rep(" ", 100)) - - local build_stl_str_hl = function(pat) return buffer.build_stl_str_hl(globals.curwin, output_buffer, - 100, + buffer_byte_size, to_cstr(pat), false, - 32, - 80, + fillchar, + maximum_cell_count, NULL, NULL) end - it('should copy plain text', function() - local width = build_stl_str_hl("this is a test") - - eq(14, width) - eq("this is a test", helpers.ffi.string(output_buffer, width)) - - end) - - it('should print no file name', function() - local width = build_stl_str_hl("%f") - - eq(9, width) - eq("[No Name]", helpers.ffi.string(output_buffer, width)) - - end) - - it('should print the relative file name', function() - buffer.setfname(globals.curbuf, to_cstr("Makefile"), NULL, 1) - local width = build_stl_str_hl("%f") - - eq(8, width) - eq("Makefile", helpers.ffi.string(output_buffer, width)) - - end) - - it('should print the full file name', function() - buffer.setfname(globals.curbuf, to_cstr("Makefile"), NULL, 1) - - local width = build_stl_str_hl("%F") - - assert.is_true(8 < width) - neq(NULL, string.find(helpers.ffi.string(output_buffer, width), "Makefile")) - - end) - - it('should print the tail file name', function() - buffer.setfname(globals.curbuf, to_cstr("src/nvim/buffer.c"), NULL, 1) - - local width = build_stl_str_hl("%t") - - eq(8, width) - eq("buffer.c", helpers.ffi.string(output_buffer, width)) - - end) - - it('should print the buffer number', function() - buffer.setfname(globals.curbuf, to_cstr("src/nvim/buffer.c"), NULL, 1) - - local width = build_stl_str_hl("%n") - - eq(1, width) - eq("1", helpers.ffi.string(output_buffer, width)) - end) - - it('should print the current line number in the buffer', function() - buffer.setfname(globals.curbuf, to_cstr("test/unit/buffer_spec.lua"), NULL, 1) - - local width = build_stl_str_hl("%l") - - eq(1, width) - eq("0", helpers.ffi.string(output_buffer, width)) - - end) - - it('should print the number of lines in the buffer', function() - buffer.setfname(globals.curbuf, to_cstr("test/unit/buffer_spec.lua"), NULL, 1) - - local width = build_stl_str_hl("%L") + -- Use this function to simplify testing the comparison between + -- the format string and the resulting statusline. + -- + -- @param description The description of what the test should be doing + -- @param statusline_cell_count The number of cells available in the statusline + -- @param input_stl The format string for the statusline + -- @param expected_stl The expected result string for the statusline + -- + -- @param arg Options can be placed in an optional dictionary as the last parameter + -- .expected_cell_count The expected number of cells build_stl_str_hl will return + -- .expected_byte_length The expected byte length of the string + -- .file_name The name of the file to be tested (useful in %f type tests) + -- .fillchar The character that will be used to fill any 'extra' space in the stl + local function statusline_test (description, + statusline_cell_count, + input_stl, + expected_stl, + arg) + + -- arg is the optional parameter + -- so we either fill in option with arg or an empty dictionary + local option = arg or {} + + local fillchar = option.fillchar or (' '):byte() + local expected_cell_count = option.expected_cell_count or statusline_cell_count + local expected_byte_length = option.expected_byte_length or expected_cell_count + + it(description, function() + if option.file_name then + buffer.setfname(globals.curbuf, to_cstr(option.file_name), NULL, 1) + else + buffer.setfname(globals.curbuf, nil, NULL, 1) + end + + local result_cell_count = build_stl_str_hl{pat=input_stl, + maximum_cell_count=statusline_cell_count, + fillchar=fillchar} + + eq(expected_stl, get_str(output_buffer, expected_byte_length)) + eq(expected_cell_count, result_cell_count) + end) + end - eq(1, width) - eq("1", helpers.ffi.string(output_buffer, width)) + -- file name testing + statusline_test('should print no file name', 10, + '%f', '[No Name]', + {expected_cell_count=9}) + statusline_test('should print the relative file name', 30, + '%f', 'test/unit/buffer_spec.lua', + {file_name='test/unit/buffer_spec.lua', expected_cell_count=25}) + statusline_test('should print the full file name', 40, + '%F', '/test/unit/buffer_spec.lua', + {file_name='/test/unit/buffer_spec.lua', expected_cell_count=26}) + + -- fillchar testing + statusline_test('should handle `!` as a fillchar', 10, + 'abcde%=', 'abcde!!!!!', + {fillchar=('!'):byte()}) + statusline_test('should handle `~` as a fillchar', 10, + '%=abcde', '~~~~~abcde', + {fillchar=('~'):byte()}) + statusline_test('should put fillchar `!` in between text', 10, + 'abc%=def', 'abc!!!!def', + {fillchar=('!'):byte()}) + statusline_test('should put fillchar `~` in between text', 10, + 'abc%=def', 'abc~~~~def', + {fillchar=('~'):byte()}) + statusline_test('should print the tail file name', 80, + '%t', 'buffer_spec.lua', + {file_name='test/unit/buffer_spec.lua', expected_cell_count=15}) + + -- standard text testing + statusline_test('should copy plain text', 80, + 'this is a test', 'this is a test', + {expected_cell_count=14}) + + -- line number testing + statusline_test('should print the buffer number', 80, + '%n', '1', + {expected_cell_count=1}) + statusline_test('should print the current line number in the buffer', 80, + '%l', '0', + {expected_cell_count=1}) + statusline_test('should print the number of lines in the buffer', 80, + '%L', '1', + {expected_cell_count=1}) + + -- truncation testing + statusline_test('should truncate when standard text pattern is too long', 10, + '0123456789abcde', '<6789abcde') + statusline_test('should truncate when using =', 10, + 'abcdef%=ghijkl', 'abcdef<jkl') + statusline_test('should truncate centered text when using ==', 10, + 'abcde%=gone%=fghij', 'abcde<ghij') + statusline_test('should respect the `<` marker', 10, + 'abc%<defghijkl', 'abc<ghijkl') + statusline_test('should truncate at `<` with one `=`, test 1', 10, + 'abc%<def%=ghijklmno', 'abc<jklmno') + statusline_test('should truncate at `<` with one `=`, test 2', 10, + 'abcdef%=ghijkl%<mno', 'abcdefghi>') + statusline_test('should truncate at `<` with one `=`, test 3', 10, + 'abc%<def%=ghijklmno', 'abc<jklmno') + statusline_test('should truncate at `<` with one `=`, test 4', 10, + 'abc%<def%=ghij', 'abcdefghij') + statusline_test('should truncate at `<` with one `=`, test 4', 10, + 'abc%<def%=ghijk', 'abc<fghijk') + + statusline_test('should truncate at `<` with many `=`, test 4', 10, + 'ab%<cdef%=g%=h%=ijk', 'ab<efghijk') + + statusline_test('should truncate at the first `<`', 10, + 'abc%<def%<ghijklm', 'abc<hijklm') + + -- alignment testing + statusline_test('should right align when using =', 20, + 'neo%=vim', 'neo vim') + statusline_test('should, when possible, center text when using %=text%=', 20, + 'abc%=neovim%=def', 'abc neovim def') + statusline_test('should handle uneven spacing in the buffer when using %=text%=', 20, + 'abc%=neo_vim%=def', 'abc neo_vim def') + statusline_test('should have equal spaces even with non-equal sides when using =', 20, + 'foobar%=test%=baz', 'foobar test baz') + statusline_test('should have equal spaces even with longer right side when using =', 20, + 'a%=test%=longtext', 'a test longtext') + statusline_test('should handle an empty left side when using ==', 20, + '%=test%=baz', ' test baz') + statusline_test('should handle an empty right side when using ==', 20, + 'foobar%=test%=', 'foobar test ') + statusline_test('should handle consecutive empty ==', 20, + '%=%=test%=', ' test ') + statusline_test('should handle an = alone', 20, + '%=', ' ') + statusline_test('should right align text when it is alone with =', 20, + '%=foo', ' foo') + statusline_test('should left align text when it is alone with =', 20, + 'foo%=', 'foo ') + + statusline_test('should approximately center text when using %=text%=', 21, + 'abc%=neovim%=def', 'abc neovim def') + statusline_test('should completely fill the buffer when using %=text%=', 21, + 'abc%=neo_vim%=def', 'abc neo_vim def') + statusline_test('should have equal spaces even with non-equal sides when using =', 21, + 'foobar%=test%=baz', 'foobar test baz') + statusline_test('should have equal spaces even with longer right side when using =', 21, + 'a%=test%=longtext', 'a test longtext') + statusline_test('should handle an empty left side when using ==', 21, + '%=test%=baz', ' test baz') + statusline_test('should handle an empty right side when using ==', 21, + 'foobar%=test%=', 'foobar test ') + + statusline_test('should quadrant the text when using 3 %=', 40, + 'abcd%=n%=eovim%=ef', 'abcd n eovim ef') + statusline_test('should work well with %t', 40, + '%t%=right_aligned', 'buffer_spec.lua right_aligned', + {file_name='test/unit/buffer_spec.lua'}) + statusline_test('should work well with %t and regular text', 40, + 'l%=m_l %t m_r%=r', 'l m_l buffer_spec.lua m_r r', + {file_name='test/unit/buffer_spec.lua'}) + statusline_test('should work well with %=, %t, %L, and %l', 40, + '%t %= %L %= %l', 'buffer_spec.lua 1 0', + {file_name='test/unit/buffer_spec.lua'}) + + statusline_test('should quadrant the text when using 3 %=', 41, + 'abcd%=n%=eovim%=ef', 'abcd n eovim ef') + statusline_test('should work well with %t', 41, + '%t%=right_aligned', 'buffer_spec.lua right_aligned', + {file_name='test/unit/buffer_spec.lua'}) + statusline_test('should work well with %t and regular text', 41, + 'l%=m_l %t m_r%=r', 'l m_l buffer_spec.lua m_r r', + {file_name='test/unit/buffer_spec.lua'}) + statusline_test('should work well with %=, %t, %L, and %l', 41, + '%t %= %L %= %l', 'buffer_spec.lua 1 0', + {file_name='test/unit/buffer_spec.lua'}) + + statusline_test('should work with 10 %=', 50, + 'aaaa%=b%=c%=d%=e%=fg%=hi%=jk%=lmnop%=qrstuv%=wxyz', + 'aaaa b c d e fg hi jk lmnop qrstuv wxyz') + + -- maximum stl item testing + statusline_test('should handle a much larger amount of = than buffer locations', 20, + ('%='):rep(STL_MAX_ITEM - 1), + ' ') -- Should be fine, because within limit + statusline_test('should handle a much larger amount of = than stl max item', 20, + ('%='):rep(STL_MAX_ITEM + 1), + ' E541') -- Should show the VIM error + statusline_test('should handle many extra characters', 20, + 'a' .. ('a'):rep(STL_MAX_ITEM * 4), + '<aaaaaaaaaaaaaaaaaaa') -- Does not show the error because there are no items + statusline_test('should handle almost maximum of characters and flags', 20, + 'a' .. ('%=a'):rep(STL_MAX_ITEM - 1), + 'a<aaaaaaaaaaaaaaaaaa') -- Should not show the VIM error + statusline_test('should handle many extra characters and flags', 20, + 'a' .. ('%=a'):rep(STL_MAX_ITEM), + 'a<aaaaaaaaaaaaa E541') -- Should show the VIM error + statusline_test('should handle many extra characters and flags', 20, + 'a' .. ('%=a'):rep(STL_MAX_ITEM * 2), + 'a<aaaaaaaaaaaaa E541') -- Should show the VIM error + statusline_test('should handle many extra characters and flags with truncation', 20, + 'aaa%<' .. ('%=a'):rep(STL_MAX_ITEM), + 'aaa<aaaaaaaaaaa E541') -- Should show the VIM error + statusline_test('should handle many characters and flags before and after truncation', 20, + 'a%=a%=a%<' .. ('%=a'):rep(STL_MAX_ITEM), + 'aaa<aaaaaaaaaaa E541') -- Should show the VIM error + + + -- multi-byte testing + statusline_test('should handle multibyte characters', 10, + 'Ĉ%=x', 'Ĉ x', + {expected_byte_length=11}) + statusline_test('should handle multibyte characters and different fillchars', 10, + 'Ą%=mid%=end', 'Ą@mid@@end', + {fillchar=('@'):byte(), expected_byte_length=11}) - end) end) end) |