Просмотр исходного кода

Allow deletion/wiping of Neovim terminal buffers.

For terminal buffers, both `:bd` and `:bw` require `!` to force removal.
On Vim, terminal buffers appear to be modified (so `&modified == 1`);
however, Neovim terminal buffers have `&modified == 0`, so BufExplorer
was not previously asking the user for confirmation nor using `!` during
buffer removal, causing removal to fail with errors such as:

```
Vim(bdelete):E89: term://~/testing//816579:/bin/bash will be killed (add ! to override)
```

To allow removal, require confirmation for terminal buffers and adjust
the confirmation prompt for clarity.  This addresses the majority of
issue #69, "Feature Request: Add an option to do :bd!", as it's now
possible to remove terminal buffers; however, the issue hints at a
desire to configure BufExplorer to force-remove buffers unconditionally,
which is not (yet) possible.
Michael Henry 9 месяцев назад
Родитель
Сommit
60a3f43789
1 измененных файлов с 11 добавлено и 7 удалено
  1. 11 7
      plugin/bufexplorer.vim

+ 11 - 7
plugin/bufexplorer.vim

@@ -1170,20 +1170,24 @@ function! s:RemoveBuffer(mode)
     end
 
     let bufNbr = str2nr(getline('.'))
+    let buf = s:raw_buffer_listing[bufNbr]
 
-    if !forced && getbufvar(bufNbr, '&modified')
+    if !forced && (buf.isterminal || getbufvar(bufNbr, '&modified'))
+        if buf.isterminal
+            let msg = "Buffer " . bufNbr . " is a terminal"
+        else
+            let msg = "No write since last change for buffer " . bufNbr
+        endif
         " Calling confirm() requires Vim built with dialog option.
         if !has("dialog_con") && !has("dialog_gui")
-            call s:Error("Sorry, no write since last change for buffer ".bufNbr.", unable to delete")
+            call s:Error(msg . "; cannot remove without 'force'")
             return
         endif
 
-        let answer = confirm('No write since last change for buffer '.bufNbr.'. Delete anyway?', "&Yes\n&No", 2)
+        let answer = confirm(msg . "; Remove anyway?", "&Yes\n&No", 2)
 
-        if a:mode == "delete" && answer == 1
-            let mode = "force_delete"
-        elseif a:mode == "wipe" && answer == 1
-            let mode = "force_wipe"
+        if answer == 1
+            let mode = 'force_' . mode
         else
             return
         endif