Mercurial > vim-lawrencium
changeset 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 | b5ce60d1e6b4 |
children | e52c62ac52fc |
files | autoload/lawrencium.vim |
diffstat | 1 files changed, 24 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/autoload/lawrencium.vim Thu Nov 11 12:38:09 2021 -0800 +++ b/autoload/lawrencium.vim Sat Dec 10 23:06:46 2022 -0800 @@ -668,17 +668,37 @@ " Commands Auto-Complete {{{ +" Auto-complete %'d paths. +function! lawrencium#complete_percent_path(ArgLead) abort + if a:ArgLead[0] ==# '%' && (len(a:ArgLead) == 1 || a:ArgLead[1] == ':') + let l:fnname = bufname() + if len(a:ArgLead) > 1 + let l:fnmod = a:ArgLead[1:] + return [fnamemodify(l:fnname, l:fnmod)] + else + return [l:fnname] + endif + endif + return [] +endfunction + " Auto-complete function for commands that take repo-relative file paths. function! lawrencium#list_repo_files(ArgLead, CmdLine, CursorPos) abort - let l:matches = lawrencium#hg_repo().Glob(a:ArgLead . '*', 1) - call map(l:matches, 'lawrencium#normalizepath(v:val)') + let l:matches = lawrencium#complete_percent_path(a:ArgLead) + if empty(l:matches) + let l:matches = lawrencium#hg_repo().Glob(a:ArgLead . '*', 1) + call map(l:matches, 'lawrencium#normalizepath(v:val)') + endif return l:matches endfunction " Auto-complete function for commands that take repo-relative directory paths. function! lawrencium#list_repo_dirs(ArgLead, CmdLine, CursorPos) abort - let l:matches = lawrencium#hg_repo().Glob(a:ArgLead . '*/') - call map(l:matches, 'lawrencium#normalizepath(v:val)') + let l:matches = lawrencium#complete_percent_path(a:ArgLead) + if empty(l:matches) + let l:matches = lawrencium#hg_repo().Glob(a:ArgLead . '*/') + call map(l:matches, 'lawrencium#normalizepath(v:val)') + endif return l:matches endfunction