Updating README - Post-Update Hook
- Dominant language
- Vim Script
- Stars
- 35.8k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
# Problem
For building YouCompleteMe, as seen in the README, it uses Unix notation and doesn't take into account the version of Python specific to Vim. I'm hoping updating the code might save some people time and a headache or two.
I supplied the current code in the README, along with a couple of other versions that I tested. They don't include version support for Linux, but I've never had any serious issues on Linux with Python and Vim.
From the context of the README, it looks to be a basic explanation on the concept, but I don't imagine anyone complaining about a couple of extra lines that people are probably copying and pasting (like I did).
---
# Versions
Current Code
This is the specific error for the current code. Windows doesn't like the code being sent to it.
```
'.' is not recognized as an internal or external command,
operable program or batch file.
shell returned 1
```
``` vimscript
function! BuildYCM(info)
" info is a dictionary with 3 fields
" - name: name of the plugin
" - status: 'installed', 'updated', or 'unchanged'
" - force: set on PlugInstall! or PlugUpdate!
if a:info.status == 'installed' || a:info.force
!./install.py
endif
endfunction
Plug 'ycm-core/YouCompleteMe', { 'do': function('BuildYCM') }
```
Enhanced VimScript
Successfully installs using the correct version of Python.
Should _probably_ be updated for Linux as well.
``` vimscript
function! BuildYCM(info)
" info is a dictionary with 3 fields
" - name: name of the plugin
" - status: 'installed', 'updated', or 'unchanged'
" - force: set on PlugInstall! or PlugUpdate!
if a:info.status == 'installed' || a:info.force
if has('win32')
let py_version = py3eval('sys.version.split()[0].replace(".", "")')
let py_version = py_version[:0] . '.' . py_version[1:]
let command = printf('!py -%s %s', py_version, shellescape(expand('.\install.py')))
execute(command)
else
!./install.py
endif
endif
endfunction
Plug 'ycm-core/YouCompleteMe',
\ { 'do': function('BuildYCM') }
```
Python
Successfully installs the correct version on Windows.
It's a bit more verbose (mostly due to the docstring), but I think it's a lot easier to read for most people.
``` python
function! BuildYCM(info)
python3 << EOF
""" Post-Update Hook for YouCompleteMe using Vim-Plug.
Limitations
-----------
Only supports Windows and Linux
Arguments
---------
info : 3-dict
name : str
Name of the plugin.
status : {'installed', 'updated', or 'unchanged'}
force : bool
Set to True on `PlugInstall!` or `PlugUpdate!`.
"""
from pathlib import Path
info = vim.eval('a:info')
if info['status'] == 'installed' or info['force']:
py_version = sys.version.split()[0].replace('.', '')
py_version = py_version[:1] + '.' + py_version[1:]
os_specific = f'py -{py_version}' if sys.platform == 'win32' else ''
command = f'!{os_specific} {Path("./install.py")}'
vim.command(command)
EOF
endfunction
Plug 'ycm-core/YouCompleteMe',
\ { 'do': function('BuildYCM') }
```
Vimscript, but default Python version
Based on the original script, this solves the issue of Windows vs. Linux, but won't use the proper version.
This _may_ not be an issue with `python-x`, but I'm not that savvy.
``` vimscript
function! BuildYCM(info)
" info is a dictionary with 3 fields
" - name: name of the plugin
" - status: 'installed', 'updated', or 'unchanged'
" - force: set on PlugInstall! or PlugUpdate!
if a:info.status == 'installed' || a:info.force
execute('!' . shellescape(expand('./install.py')))
endif
endfunction
Plug 'ycm-core/YouCompleteMe',
\ { 'do': function('BuildYCM') }
```
------------------------------
# Additional Information
Version Information
```
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Dec 12 2019 13:30:17)
MS-Windows 32-bit GUI version with OLE support
Compiled by mool@tororo
Huge version with GUI. Features included (+) or not (-):
+acl +eval +multi_lang -tag_any_white
+arabic +ex_extra +mzscheme/dyn +tcl/dyn
+autocmd +extra_search +netbeans_intg -termguicolors
+autochdir -farsi +num64 +terminal
+autoservername +file_in_path +ole -termresponse
+balloon_eval +find_in_path +packages +textobjects
-balloon_eval_term +float +path_extra +textprop
+browse +folding +perl/dyn -tgetent
++builtin_terms -footer +persistent_undo +timers
+byte_offset +gettext/dyn +popupwin +title
+channel -hangul_input -postscript +toolbar
+cindent +iconv/dyn +printer +user_commands
+clientserver +insert_expand +profile +vartabs
+clipboard +job +python/dyn +vertsplit
+cmdline_compl +jumplist +python3/dyn +virtualedit
+cmdline_hist +keymap +quickfix +visual
+cmdline_info +lambda +reltime +visualextra
+comments +langmap +rightleft +viminfo
+conceal +libcall +ruby/dyn +vreplace
+cryptv +linebreak +scrollbind -vtp
+cscope +lispindent +signs +wildignore
+cursorbind +listcmds +smartindent +wildmenu
+cursorshape +localmap +sound +windows
+dialog_con_gui +lua/dyn +spell +writebackup
+diff +menu +startuptime -xfontset
+digraphs +mksession +statusline -xim
+directx +modify_fname -sun_workshop +xpm_w32
-dnd +mouse +syntax -xterm_save
-ebcdic +mouseshape +tag_binary
+emacs_tags +multi_byte_ime/dyn -tag_old_static
system vimrc file: "$VIM\vimrc"
user vimrc file: "$HOME\_vimrc"
2nd user vimrc file: "$HOME\vimfiles\vimrc"
3rd user vimrc file: "$VIM\_vimrc"
user exrc file: "$HOME\_exrc"
2nd user exrc file: "$VIM\_exrc"
system gvimrc file: "$VIM\gvimrc"
user gvimrc file: "$HOME\_gvimrc"
2nd user gvimrc file: "$HOME\vimfiles\gvimrc"
3rd user gvimrc file: "$VIM\_gvimrc"
defaults file: "$VIMRUNTIME\defaults.vim"
system menu file: "$VIMRUNTIME\menu.vim"
Compilation: cl -c /W3 /nologo -I. -Iproto -DHAVE_PATHDEF -DWIN32 -DFEAT_CSCOPE -DFEAT_TERMINAL -DFEAT_SOUND -DFEAT_NETBEANS_INTG -DFEAT_JOB_CHANNEL -DFEAT_XPM_W32 -DWINVER=0x0501 -D_WIN32_WINNT=0x0501 /MP -DHAVE_STDINT_H /Ox /GL -DNDEBUG /arch:IA32 /Zl /MT -DFEAT_OLE -DFEAT_MBYTE_IME -DDYNAMIC_IME -DFEAT_GUI_MSWIN -DFEAT_DIRECTX -DDYNAMIC_DIRECTX -DFEAT_DIRECTX_COLOR_EMOJI -DDYNAMIC_ICONV -DDYNAMIC_GETTEXT -DFEAT_TCL -DDYNAMIC_TCL -DDYNAMIC_TCL_DLL=\"tcl86t.dll\" -DDYNAMIC_TCL_VER=\"8.6\" -DFEAT_LUA -DDYNAMIC_LUA -DDYNAMIC_LUA_DLL=\"lua53.dll\" -DFEAT_PYTHON -DDYNAMIC_PYTHON -DDYNAMIC_PYTHON_DLL=\"python27.dll\" -DFEAT_PYTHON3 -DDYNAMIC_PYTHON3 -DDYNAMIC_PYTHON3_DLL=\"python36.dll\" -DFEAT_MZSCHEME -I "E:\Racket\include" -DMZ_PRECISE_GC -DDYNAMIC_MZSCHEME -DDYNAMIC_MZSCH_DLL=\"libracket3m_a36fs8.dll\" -DDYNAMIC_MZGC_DLL=\"libracket3m_a36fs8.dll\" -DFEAT_PERL -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DDYNAMIC_PERL -DDYNAMIC_PERL_DLL=\"perl524.dll\" -DFEAT_RUBY -DDYNAMIC_RUBY -DDYNAMIC_RUBY_VER=24 -DDYNAMIC_RUBY_DLL=\"msvcrt-ruby240.dll\" -DFEAT_HUGE /Fd.\ObjGXOULYHTRZi386/ /Zi
Linking: link /nologo /opt:ref /LTCG:STATUS oldnames.lib kernel32.lib advapi32.lib shell32.lib gdi32.lib comdlg32.lib ole32.lib netapi32.lib uuid.lib /machine:i386 gdi32.lib version.lib winspool.lib comctl32.lib advapi32.lib shell32.lib netapi32.lib /machine:i386 libcmt.lib oleaut32.lib user32.lib /nodefaultlib:lua53.lib /STACK:8388608 /nodefaultlib:python27.lib /nodefaultlib:python36.lib "E:\ActiveTcl\lib\tclstub86.lib" winmm.lib WSock32.lib xpm\x86\lib-vc14\libXpm.lib /PDB:gvim.pdb -debug
```
- Type:
- [x] Enhancement
- OS:
- [x] Windows
_Note: Please let me know if there's something I missed or if you know how to shorten the code for the Python version._
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.