Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Move plugin to ftdetect,ftplugin #15

Merged
merged 2 commits into from
May 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ftdetect/ps1.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
autocmd BufNewFile,BufRead *.ps*1 setfiletype ps1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use https://github.com/PProvost/vim-ps1 so I used setfiletype here instead of set filetype. Vim doesn't detect *.ps*1 files by default so this should be fine.

12 changes: 5 additions & 7 deletions plugin/coc-powershell.vim → ftplugin/ps1.vim
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if exists('s:loaded_ftplugin')
finish
endif
let s:loaded_ftplugin = 1
let s:vimscript_dir = expand('<sfile>:p:h')
function! s:PSESSetup ()
let g:pses_dir = resolve(expand(s:vimscript_dir . '/../PowerShellEditorServices/PowerShellEditorServices'))
Expand Down Expand Up @@ -42,10 +46,4 @@ function! s:PSESSetup ()
\)
endfunction

" Set the file type to ps1 for ps1, psm1, and psd1
" 'ps1' is what vim-polyglot uses for styling
if(&filetype == "")
autocmd BufNewFile,BufRead *.ps*1 set filetype=ps1
endif

autocmd FileType ps1,psd1,psm1 call s:PSESSetup()
call s:PSESSetup()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this run every time the user opens a powershell file?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, only the first time, so if ftdetect is done properly we just need to fire it once. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if exists('s:loaded_ftplugin')
  finish
endif
let s:loaded_ftplugin = 1
call s:PSESetup()

Treat it like a plugin then with a guard?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup. that will do.