comparison autoload/lawrencium.vim @ 154:40181bd0ffcd

Add support for %-paths in commands auto-completion
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 10 Dec 2022 23:06:46 -0800
parents 62e054a2c4f0
children
comparison
equal deleted inserted replaced
153:b5ce60d1e6b4 154:40181bd0ffcd
666 666
667 " }}} 667 " }}}
668 668
669 " Commands Auto-Complete {{{ 669 " Commands Auto-Complete {{{
670 670
671 " Auto-complete %'d paths.
672 function! lawrencium#complete_percent_path(ArgLead) abort
673 if a:ArgLead[0] ==# '%' && (len(a:ArgLead) == 1 || a:ArgLead[1] == ':')
674 let l:fnname = bufname()
675 if len(a:ArgLead) > 1
676 let l:fnmod = a:ArgLead[1:]
677 return [fnamemodify(l:fnname, l:fnmod)]
678 else
679 return [l:fnname]
680 endif
681 endif
682 return []
683 endfunction
684
671 " Auto-complete function for commands that take repo-relative file paths. 685 " Auto-complete function for commands that take repo-relative file paths.
672 function! lawrencium#list_repo_files(ArgLead, CmdLine, CursorPos) abort 686 function! lawrencium#list_repo_files(ArgLead, CmdLine, CursorPos) abort
673 let l:matches = lawrencium#hg_repo().Glob(a:ArgLead . '*', 1) 687 let l:matches = lawrencium#complete_percent_path(a:ArgLead)
674 call map(l:matches, 'lawrencium#normalizepath(v:val)') 688 if empty(l:matches)
689 let l:matches = lawrencium#hg_repo().Glob(a:ArgLead . '*', 1)
690 call map(l:matches, 'lawrencium#normalizepath(v:val)')
691 endif
675 return l:matches 692 return l:matches
676 endfunction 693 endfunction
677 694
678 " Auto-complete function for commands that take repo-relative directory paths. 695 " Auto-complete function for commands that take repo-relative directory paths.
679 function! lawrencium#list_repo_dirs(ArgLead, CmdLine, CursorPos) abort 696 function! lawrencium#list_repo_dirs(ArgLead, CmdLine, CursorPos) abort
680 let l:matches = lawrencium#hg_repo().Glob(a:ArgLead . '*/') 697 let l:matches = lawrencium#complete_percent_path(a:ArgLead)
681 call map(l:matches, 'lawrencium#normalizepath(v:val)') 698 if empty(l:matches)
699 let l:matches = lawrencium#hg_repo().Glob(a:ArgLead . '*/')
700 call map(l:matches, 'lawrencium#normalizepath(v:val)')
701 endif
682 return l:matches 702 return l:matches
683 endfunction 703 endfunction
684 704
685 " }}} 705 " }}}
686 706