Skip to content

Commit 4545533

Browse files
committed
refactor: make commands globally available (#59)
1 parent 111db61 commit 4545533

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

autoload/arduino.vim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ let s:SKETCHFILE = v:null
2525
" Initialization {{{1
2626
" Set up all user configuration variables
2727
function! arduino#InitializeConfig() abort
28+
if exists('g:arduino_did_initialize')
29+
return
30+
endif
31+
call arduino#LoadCache()
32+
2833
if !exists('g:arduino_board')
2934
if exists('g:_cache_arduino_board')
3035
let g:arduino_board = g:_cache_arduino_board
@@ -87,6 +92,7 @@ function! arduino#InitializeConfig() abort
8792
au!
8893
au BufReadPost *.ino call s:ReadSketchJson(expand('<amatch>:p:h'))
8994
aug END
95+
let g:arduino_did_initialize = 1
9096
endfunction
9197

9298
function! arduino#RunCmd(cmd) abort
@@ -429,6 +435,7 @@ function! s:ChooserItemOrder(i1, i2) abort
429435
endfunction
430436

431437
function! arduino#Attach(...) abort
438+
call arduino#InitializeConfig()
432439
if !s:has_cli
433440
echoerr 'ArduinoAttach requires arduino-cli'
434441
return
@@ -457,6 +464,7 @@ endfunction
457464
" Port selection {{{2
458465

459466
function! arduino#ChoosePort(...) abort
467+
call arduino#InitializeConfig()
460468
if a:0
461469
let g:arduino_serial_port = a:1
462470
return
@@ -480,6 +488,7 @@ let s:callback_data = {}
480488

481489
" Display a list of boards to the user and allow them to choose the active one
482490
function! arduino#ChooseBoard(...) abort
491+
call arduino#InitializeConfig()
483492
if a:0
484493
call arduino#SetBoard(a:1)
485494
return
@@ -532,6 +541,7 @@ endfunction
532541
" Programmer selection {{{2
533542

534543
function! arduino#ChooseProgrammer(...) abort
544+
call arduino#InitializeConfig()
535545
if a:0
536546
call arduino#SetProgrammer(a:1)
537547
return
@@ -567,6 +577,7 @@ function! arduino#SetBoard(board, ...) abort
567577
endfunction
568578

569579
function! arduino#Verify() abort
580+
call arduino#InitializeConfig()
570581
if g:arduino_use_cli
571582
let cmd = arduino#GetCLICompileCommand()
572583
else
@@ -578,6 +589,7 @@ function! arduino#Verify() abort
578589
endfunction
579590

580591
function! arduino#Upload() abort
592+
call arduino#InitializeConfig()
581593
if g:arduino_use_cli
582594
let cmd = arduino#GetCLICompileCommand('-u')
583595
else
@@ -594,13 +606,15 @@ function! arduino#Upload() abort
594606
endfunction
595607

596608
function! arduino#Serial() abort
609+
call arduino#InitializeConfig()
597610
let cmd = arduino#GetSerialCmd()
598611
if empty(cmd) | return | endif
599612

600613
call arduino#RunCmd(cmd)
601614
endfunction
602615

603616
function! arduino#UploadAndSerial()
617+
call arduino#InitializeConfig()
604618
" Since 'terminal!' is non-blocking '!' must be used to provide this functionality
605619
let termBackup = s:TERM
606620
let s:TERM = '!'
@@ -748,6 +762,7 @@ endfunction
748762

749763
" Print the current configuration
750764
function! arduino#GetInfo() abort
765+
call arduino#InitializeConfig()
751766
let port = arduino#GetPort()
752767
if empty(port)
753768
let port = 'none'

ftplugin/arduino.vim

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ if exists('b:did_arduino_ftplugin')
22
finish
33
endif
44
let b:did_arduino_ftplugin = 1
5-
if !exists('g:arduino_did_initialize')
6-
call arduino#LoadCache()
7-
call arduino#InitializeConfig()
8-
let g:arduino_did_initialize = 1
9-
endif
5+
call arduino#InitializeConfig()
106

117
" Use C rules for indentation
128
setl cindent
@@ -19,15 +15,3 @@ if g:arduino_auto_baud
1915
au BufReadPost,BufWritePost *.ino call arduino#SetAutoBaud()
2016
aug END
2117
endif
22-
23-
command! -buffer -bar -nargs=? ArduinoAttach call arduino#Attach(<f-args>)
24-
command! -buffer -bar -nargs=? ArduinoChooseBoard call arduino#ChooseBoard(<f-args>)
25-
command! -buffer -bar -nargs=? ArduinoChooseProgrammer call arduino#ChooseProgrammer(<f-args>)
26-
command! -buffer -bar ArduinoVerify call arduino#Verify()
27-
command! -buffer -bar ArduinoUpload call arduino#Upload()
28-
command! -buffer -bar ArduinoSerial call arduino#Serial()
29-
command! -buffer -bar ArduinoUploadAndSerial call arduino#UploadAndSerial()
30-
command! -buffer -bar ArduinoGetInfo call arduino#GetInfo()
31-
command! -buffer -bar ArduinoInfo call arduino#GetInfo()
32-
command! -buffer -bar -nargs=? ArduinoChoosePort call arduino#ChoosePort(<f-args>)
33-
command! -buffer -bar -nargs=1 ArduinoSetBaud call arduino#SetBaud(<f-args>)

plugin/arduino.vim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
command! -buffer -bar -nargs=? ArduinoAttach call arduino#Attach(<f-args>)
2+
command! -buffer -bar -nargs=? ArduinoChooseBoard call arduino#ChooseBoard(<f-args>)
3+
command! -buffer -bar -nargs=? ArduinoChooseProgrammer call arduino#ChooseProgrammer(<f-args>)
4+
command! -buffer -bar ArduinoVerify call arduino#Verify()
5+
command! -buffer -bar ArduinoUpload call arduino#Upload()
6+
command! -buffer -bar ArduinoSerial call arduino#Serial()
7+
command! -buffer -bar ArduinoUploadAndSerial call arduino#UploadAndSerial()
8+
command! -buffer -bar ArduinoGetInfo call arduino#GetInfo()
9+
command! -buffer -bar ArduinoInfo call arduino#GetInfo()
10+
command! -buffer -bar -nargs=? ArduinoChoosePort call arduino#ChoosePort(<f-args>)
11+
command! -buffer -bar -nargs=1 ArduinoSetBaud call arduino#SetBaud(<f-args>)

0 commit comments

Comments
 (0)