8
8
" ======================================================================
9
9
10
10
11
+ " ----------------------------------------------------------------------
12
+ " initialize
13
+ " ----------------------------------------------------------------------
14
+ let s: windows = has (' win32' ) || has (' win64' ) || has (' win16' ) || has (' win95' )
15
+
16
+
17
+ " ----------------------------------------------------------------------
18
+ " special buffer
19
+ " ----------------------------------------------------------------------
20
+ function ! asyncrun#locator#special_buffer_path () abort
21
+ if &bt != ' '
22
+ return ' '
23
+ endif
24
+ let name = bufname (' %' )
25
+ if name = ~ ' \v^fugitive\:[\\\/][\\\/][\\\/]'
26
+ let path = strpart (name, s: windows ? 12 : 11 )
27
+ let pos = stridx (path , ' .git' )
28
+ if pos >= 0
29
+ let path = strpart (path , 0 , pos)
30
+ endif
31
+ return fnamemodify (path , ' :h' )
32
+ elseif name = ~ ' ^diffview:\/\/'
33
+ let part = strpart (name, 11 )
34
+ let pos = stridx (part, ' /.git/:' )
35
+ if pos > 0
36
+ return strpart (part, 0 , pos)
37
+ endif
38
+ endif
39
+ return ' '
40
+ endfunc
41
+
42
+
11
43
" ----------------------------------------------------------------------
12
44
" guess current buffer's directory
13
45
" ----------------------------------------------------------------------
14
- function ! asyncrun#locator#nofile_buffer_path ()
46
+ function ! asyncrun#locator#nofile_buffer_path () abort
15
47
if &bt == ' '
16
48
return ' '
17
49
elseif &bt == ' nofile'
@@ -35,6 +67,11 @@ function! asyncrun#locator#nofile_buffer_path()
35
67
return t
36
68
catch
37
69
endtry
70
+ elseif &ft == ' DiffviewFiles' && has (' nvim' )
71
+ let t = getline (1 )
72
+ if t != ' ' && isdirectory (t )
73
+ return t
74
+ endif
38
75
endif
39
76
if exists (' b:git_dir' )
40
77
return b: git_dir
@@ -49,7 +86,7 @@ endfunc
49
86
" ----------------------------------------------------------------------
50
87
function ! asyncrun#locator#detect ()
51
88
if &bt == ' '
52
- return ' '
89
+ return asyncrun#locator#special_buffer_path ()
53
90
endif
54
91
let path = asyncrun#locator#nofile_buffer_path ()
55
92
if path != ' ' && (isdirectory (path ) || filereadable (path ))
0 commit comments