From 6f23725552fa9b39d85e0ed53d402318fa4d3c15 Mon Sep 17 00:00:00 2001 From: Enno Date: Sun, 1 Dec 2024 09:23:03 +0100 Subject: [PATCH 1/2] add pytest compiler See https://github.com/vim/vim/pull/16130 This includes a refinement of the resetting of the compiler --- python.vim | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/python.vim b/python.vim index c000296..9fb2e03 100644 --- a/python.vim +++ b/python.vim @@ -3,8 +3,9 @@ " Maintainer: Tom Picton " Previous Maintainer: James Sully " Previous Maintainer: Johannes Zellner -" Last Change: 2024/05/13 -" https://github.com/tpict/vim-ftplugin-python +" Repository: https://github.com/tpict/vim-ftplugin-python +" Last Change: 2024/05/13 +" 2024 Dec 01 use pytest compiler (#16130) if exists("b:did_ftplugin") | finish | endif let b:did_ftplugin = 1 @@ -134,6 +135,11 @@ elseif executable('python') setlocal keywordprg=python\ -m\ pydoc endif +if expand('%:t') =~# '\v^test_.*\.py$|_test\.py$' && executable('pytest') + compiler pytest + let &l:makeprg .= ' %:S' +endif + " Script for filetype switching to undo the local stuff we may have changed let b:undo_ftplugin = 'setlocal cinkeys<' \ . '|setlocal comments<' @@ -189,5 +195,9 @@ let b:undo_ftplugin = 'setlocal cinkeys<' \ . '|unlet! b:prev_toplevel' \ . '|unlet! b:undo_ftplugin' +if get(b:, 'current_compiler', '') ==# 'pytest' + let b:undo_ftplugin .= '| compiler make' +endif + let &cpo = s:keepcpo unlet s:keepcpo From 42198ecf3ea42000b61c452027fe20c2c08d1e3f Mon Sep 17 00:00:00 2001 From: Enno Date: Mon, 21 Apr 2025 17:07:03 +0200 Subject: [PATCH 2/2] lift up the regex into a global variable so users can tweak it if they choose to change Pytest's python_files setting See https://github.com/tpict/vim-ftplugin-python/pull/23#issuecomment-2818636285 --- python.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python.vim b/python.vim index 9fb2e03..fcfeaf3 100644 --- a/python.vim +++ b/python.vim @@ -135,7 +135,7 @@ elseif executable('python') setlocal keywordprg=python\ -m\ pydoc endif -if expand('%:t') =~# '\v^test_.*\.py$|_test\.py$' && executable('pytest') +if expand('%:t') =~# get(g:, python_files, '\v^test_.*\.py$|_test\.py$') && executable('pytest') compiler pytest let &l:makeprg .= ' %:S' endif