Skip to content

Instantly share code, notes, and snippets.

@raggi
Created February 13, 2017 00:19
Show Gist options
  • Save raggi/3bcbb18183be138f3b24718891921d9b to your computer and use it in GitHub Desktop.
Save raggi/3bcbb18183be138f3b24718891921d9b to your computer and use it in GitHub Desktop.
From af6ffeb8fba6b33c7331ac74f68a635a7893cb47 Mon Sep 17 00:00:00 2001
From: James Tucker <jftucker@gmail.com>
Date: Sun, 12 Feb 2017 16:18:56 -0800
Subject: [PATCH] programs: expand :h and :p:h.
---
plugin/asyncrun.vim | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/plugin/asyncrun.vim b/plugin/asyncrun.vim
index d80e70d..b7c94c8 100644
--- a/plugin/asyncrun.vim
+++ b/plugin/asyncrun.vim
@@ -796,6 +796,8 @@ endfunc
"----------------------------------------------------------------------
function! asyncrun#run(bang, opts, args)
let l:macros = {}
+ let l:macros['%:p:h'] = expand("%:p:h")
+ let l:macros['%:h'] = expand("%:h")
let l:macros['VIM_FILEPATH'] = expand("%:p")
let l:macros['VIM_FILENAME'] = expand("%:t")
let l:macros['VIM_FILEDIR'] = expand("%:p:h")
@@ -819,13 +821,24 @@ function! asyncrun#run(bang, opts, args)
" extract options
let [l:command, l:opts] = s:ExtractOpt(l:command)
+ " process makeprg/grepprg in -program=?
+ let l:program = ""
+
+ if l:opts.program == 'make'
+ let l:program = &makeprg
+ elseif l:opts.program == 'grep'
+ let l:program = &grepprg
+ endif
+
" replace macros and setup environment variables
for [l:key, l:val] in items(l:macros)
- let l:replace = (l:key[0] != '<')? '$('.l:key.')' : l:key
- if l:key[0] != '<'
+ let l:replace = (l:key[0] != '<' && l:key[0] != '%')? '$('.l:key.')' : l:key
+ if l:key[0] != '<' && l:key[0] != '%'
exec 'let $'.l:key.' = l:val'
endif
+
let l:command = s:StringReplace(l:command, l:replace, l:val)
+ let l:program = s:StringReplace(l:program, l:replace, l:val)
let l:opts.cwd = s:StringReplace(l:opts.cwd, l:replace, l:val)
let l:opts.text = s:StringReplace(l:opts.text, l:replace, l:val)
endfor
@@ -855,15 +868,6 @@ function! asyncrun#run(bang, opts, args)
let l:mode = l:opts.mode
endif
- " process makeprg/grepprg in -program=?
- let l:program = ""
-
- if l:opts.program == 'make'
- let l:program = &makeprg
- elseif l:opts.program == 'grep'
- let l:program = &grepprg
- endif
-
if l:program != ''
if l:program =~# '\$\*'
let l:command = s:StringReplace(l:program, '\$\*', l:command)
--
2.11.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment