@@ -81,9 +81,6 @@ function! arduino#InitializeConfig() abort
81
81
elseif g: arduino_use_cli && ! s: has_cli
82
82
echoerr ' arduino-cli: command not found'
83
83
endif
84
- if ! exists (' g:arduino_telescope_enabled' )
85
- let g: arduino_telescope_enabled = luaeval (" pcall(require, 'telescope')" )
86
- endif
87
84
call arduino#ReloadBoards ()
88
85
endfunction
89
86
@@ -421,7 +418,7 @@ function! arduino#ChoosePort(...) abort
421
418
if empty (ports)
422
419
echoerr " No likely serial ports detected!"
423
420
else
424
- call arduino#Choose (' Select Port' , ports, ' arduino#SelectPort' )
421
+ call arduino#chooser# Choose (' Select Port' , ports, ' arduino#SelectPort' )
425
422
endif
426
423
endfunction
427
424
@@ -440,7 +437,7 @@ function! arduino#ChooseBoard(...) abort
440
437
return
441
438
endif
442
439
let boards = arduino#GetBoards ()
443
- call arduino#Choose (' Select Board' , boards, ' arduino#SelectBoard' )
440
+ call arduino#chooser# Choose (' Select Board' , boards, ' arduino#SelectBoard' )
444
441
endfunction
445
442
446
443
" Callback from board selection. Sets the board and prompts for any options
@@ -463,7 +460,7 @@ function! arduino#ChooseBoardOption() abort
463
460
for opt in available_opts
464
461
if ! has_key (s: callback_data .opts, opt .option )
465
462
let s: callback_data .active_option = opt .option
466
- call arduino#Choose (opt .option_label, opt .values , ' arduino#SelectOption' )
463
+ call arduino#chooser# Choose (opt .option_label, opt .values , ' arduino#SelectOption' )
467
464
return
468
465
endif
469
466
endfor
@@ -485,7 +482,7 @@ function! arduino#ChooseProgrammer(...) abort
485
482
return
486
483
endif
487
484
let programmers = arduino#GetProgrammers ()
488
- call arduino#Choose (' Select Programmer' , programmers, ' arduino#SetProgrammer' )
485
+ call arduino#chooser# Choose (' Select Programmer' , programmers, ' arduino#SetProgrammer' )
489
486
endfunction
490
487
491
488
function ! arduino#SetProgrammer (programmer) abort
@@ -630,97 +627,6 @@ function! s:get_json_output(cmd) abort
630
627
return py3eval (' json.loads(vim.eval("output_str"))' )
631
628
endfunction
632
629
633
- let s: fzf_counter = 0
634
- function ! s: fzf_leave (callback, item)
635
- call function (a: callback )(a: item )
636
- let s: fzf_counter -= 1
637
- endfunction
638
- function ! s: mk_fzf_callback (callback)
639
- return { item - > s: fzf_leave (a: callback , s: ChooserValueFromLabel (item)) }
640
- endfunction
641
-
642
- function ! s: ConvertItemsToLabels (items ) abort
643
- let longest = 1
644
- for item in a: items
645
- if has_key (item, ' label' )
646
- let longest = max ([longest, strchars (item[' label' ])])
647
- endif
648
- endfor
649
- return map (copy (a: items ), ' s:ChooserItemLabel(v:val, ' . longest . ' )' )
650
- endfunction
651
-
652
- function ! s: ChooserItemLabel (item, ... ) abort
653
- let pad_amount = a: 0 ? a: 1 : 0
654
- if has_key (a: item , ' label' )
655
- let label = a: item [' label' ]
656
- let spacing = 1 + max ([pad_amount - strchars (label ), 0 ])
657
- return label . repeat (' ' , spacing) . ' [' . a: item [' value' ] . ' ]'
658
- endif
659
- return a: item [' value' ]
660
- endfunction
661
-
662
- function ! s: ChooserValueFromLabel (label ) abort
663
- " The label may be in the format 'label [value]'.
664
- " If so, we need to parse out the value
665
- let groups = matchlist (a: label , ' \[\(.*\)\]$' )
666
- if empty (groups)
667
- return a: label
668
- else
669
- return groups[1 ]
670
- endif
671
- endfunction
672
-
673
- " items should be a list of dictionary items with the following keys:
674
- " label (optional) The string to display
675
- " value The corresponding value passed to the callback
676
- " items may also be a raw list of strings. They will be treated as values
677
- function ! arduino#Choose (title , raw_items, callback) abort
678
- let items = []
679
- let dict_type = type ({})
680
- for item in a: raw_items
681
- if type (item) == dict_type
682
- call add (items , item)
683
- else
684
- call add (items , {' value' : item})
685
- endif
686
- endfor
687
-
688
- if g: arduino_telescope_enabled
689
- call luaeval (" require('arduino.telescope').choose('" .a: title ." ', _A, '" .a: callback ." ')" , items )
690
- elseif g: arduino_ctrlp_enabled
691
- let ext_data = get (g: ctrlp_ext_vars , s: ctrlp_idx )
692
- let ext_data.lname = a: title
693
- let s: ctrlp_list = items
694
- let s: ctrlp_callback = a: callback
695
- call ctrlp#init (s: ctrlp_id )
696
- elseif g: arduino_fzf_enabled
697
- let s: fzf_counter += 1
698
- call fzf#run ({
699
- \ ' source' : s: ConvertItemsToLabels (items ),
700
- \ ' sink' : s: mk_fzf_callback (a: callback ),
701
- \ ' options' : ' --prompt="' .a: title .' : "'
702
- \ })
703
- else
704
- let labels = map (copy (s: ConvertItemsToLabels (items )), {i , l - >
705
- \ i < 9
706
- \ ? ' ' .(i + 1 ).' ) ' .l
707
- \ : (i + 1 ).' ) ' .l
708
- \ })
709
- let labels = [" " . a: title ] + labels
710
- let choice = inputlist (labels)
711
- if choice > 0
712
- call call (a: callback , [items [choice- 1 ][' value' ]])
713
- endif
714
- endif
715
- endfunction
716
-
717
- function ! arduino#FindExecutable (name) abort
718
- let path = substitute (system (' command -v ' . a: name ), " \n *$" , ' ' , ' ' )
719
- if empty (path ) | return 0 | endif
720
- let abspath = resolve (path )
721
- return abspath
722
- endfunction
723
-
724
630
function ! s: CacheLine (lines , varname) abort
725
631
if exists (a: varname )
726
632
let value = eval (a: varname )
@@ -733,7 +639,7 @@ function! arduino#GetArduinoDir() abort
733
639
return g: arduino_dir
734
640
endif
735
641
let executable = arduino#GetArduinoExecutable ()
736
- let arduino_cmd = arduino#FindExecutable (executable )
642
+ let arduino_cmd = exepath (executable )
737
643
let arduino_dir = fnamemodify (arduino_cmd, ' :h' )
738
644
if s: OS == ' Darwin'
739
645
let arduino_dir = fnamemodify (arduino_dir, ' :h' ) . ' /Java'
@@ -771,40 +677,4 @@ function! arduino#GetInfo() abort
771
677
echo " CLI command : " . arduino#GetCLICompileCommand ()
772
678
endfunction
773
679
774
- " Ctrlp extension {{{1
775
- if exists (' g:ctrlp_ext_vars' )
776
- if ! exists (' g:arduino_ctrlp_enabled' )
777
- let g: arduino_ctrlp_enabled = 1
778
- endif
779
- let s: ctrlp_idx = len (g: ctrlp_ext_vars )
780
- call add (g: ctrlp_ext_vars , {
781
- \ ' init' : ' arduino#ctrlp_GetData()' ,
782
- \ ' accept' : ' arduino#ctrlp_Callback' ,
783
- \ ' lname' : ' arduino' ,
784
- \ ' sname' : ' arduino' ,
785
- \ ' type' : ' line' ,
786
- \ })
787
-
788
- let s: ctrlp_id = g: ctrlp_builtins + len (g: ctrlp_ext_vars )
789
- else
790
- let g: arduino_ctrlp_enabled = 0
791
- endif
792
-
793
- function ! arduino#ctrlp_GetData () abort
794
- return s: ConvertItemsToLabels (s: ctrlp_list )
795
- endfunction
796
-
797
- function ! arduino#ctrlp_Callback (mode , str) abort
798
- call ctrlp#exit ()
799
- let value = s: ChooserValueFromLabel (a: str )
800
- call call (s: ctrlp_callback , [value])
801
- endfunction
802
-
803
- " fzf extension {{{1
804
- if exists (" *fzf#run" ) && ! exists (' g:arduino_fzf_enabled' )
805
- let g: arduino_fzf_enabled = 1
806
- else
807
- let g: arduino_fzf_enabled = 0
808
- endif
809
-
810
680
" vim:fen :fdm = marker:fmr = {{{,}}}
0 commit comments