summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2020-08-24 09:33:07 +0100
committerw0rp <devw0rp@gmail.com>2020-08-24 09:33:07 +0100
commit3e2abe3f25493af63af91a6013447e378e09f6ec (patch)
treedceeaf74a9795138dff8335b6b1758b7420e57e2 /autoload
parent1a7366067af97cda00268d52de5a873827c52962 (diff)
downloadale-3e2abe3f25493af63af91a6013447e378e09f6ec.zip
#2556 - Support modifiers for formatted filenames
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/command.vim24
1 files changed, 20 insertions, 4 deletions
diff --git a/autoload/ale/command.vim b/autoload/ale/command.vim
index ec264a36..8f497169 100644
--- a/autoload/ale/command.vim
+++ b/autoload/ale/command.vim
@@ -135,13 +135,19 @@ endfunction
" Format a filename, converting it with filename mappings, if non-empty,
" and escaping it for putting into a command string.
-function! s:FormatFilename(filename, mappings) abort
+"
+" The filename can be modified.
+function! s:FormatFilename(filename, mappings, modifiers) abort
let l:filename = a:filename
if !empty(a:mappings)
let l:filename = ale#filename_mapping#Map(l:filename, a:mappings)
endif
+ if !empty(a:modifiers)
+ let l:filename = fnamemodify(l:filename, a:modifiers)
+ endif
+
return ale#Escape(l:filename)
endfunction
@@ -155,7 +161,7 @@ function! ale#command#FormatCommand(
\ command,
\ pipe_file_if_needed,
\ input,
-\ filename_mappings,
+\ mappings,
\) abort
let l:temporary_file = ''
let l:command = a:command
@@ -173,14 +179,24 @@ function! ale#command#FormatCommand(
" file.
if l:command =~# '%s'
let l:filename = fnamemodify(bufname(a:buffer), ':p')
- let l:command = substitute(l:command, '%s', '\=s:FormatFilename(l:filename, a:filename_mappings)', 'g')
+ let l:command = substitute(
+ \ l:command,
+ \ '\v\%s(%(:h|:t|:r|:e)*)',
+ \ '\=s:FormatFilename(l:filename, a:mappings, submatch(1))',
+ \ 'g'
+ \)
endif
if a:input isnot v:false && l:command =~# '%t'
" Create a temporary filename, <temp_dir>/<original_basename>
" The file itself will not be created by this function.
let l:temporary_file = s:TemporaryFilename(a:buffer)
- let l:command = substitute(l:command, '%t', '\=s:FormatFilename(l:temporary_file, a:filename_mappings)', 'g')
+ let l:command = substitute(
+ \ l:command,
+ \ '\v\%t(%(:h|:t|:r|:e)*)',
+ \ '\=s:FormatFilename(l:temporary_file, a:mappings, submatch(1))',
+ \ 'g'
+ \)
endif
" Finish formatting so %% becomes %.