# HG changeset patch # User Ludovic Chabant # Date 1670742406 28800 # Sat Dec 10 23:06:46 2022 -0800 # Node ID 40181bd0ffcd7142c4ee6d103ba066dbccd38240 # Parent b5ce60d1e6b411447f689dca0f09d4eda124b5c2 Add support for %-paths in commands auto-completion diff --git a/autoload/lawrencium.vim b/autoload/lawrencium.vim --- a/autoload/lawrencium.vim +++ b/autoload/lawrencium.vim @@ -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