From c113c3626c0bb95610fa23cb7473a11586062a24 Mon Sep 17 00:00:00 2001 From: Francois Cabrol Date: Mon, 14 May 2018 23:07:03 -0400 Subject: [PATCH 1/4] New implementation for neovim without Bclose --- plugin/ranger.vim | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/plugin/ranger.vim b/plugin/ranger.vim index 5495ff4..346f186 100644 --- a/plugin/ranger.vim +++ b/plugin/ranger.vim @@ -41,17 +41,47 @@ endif if has('nvim') function! OpenRangerIn(path, edit_cmd) let currentPath = expand(a:path) - let rangerCallback = { 'name': 'ranger', 'edit_cmd': a:edit_cmd } + let rangerCallback = { + \'name': 'ranger', + \'edit_cmd': a:edit_cmd, + \'oldAltBuffer': bufnr('#'), + \'oldBuffer': bufnr('%'), + \'oldPath': expand('%') + \} function! rangerCallback.on_exit(job_id, code, event) - if a:code == 0 - silent! Bclose! - endif + let rangerBuff = bufnr('%') try if filereadable(s:choice_file_path) for f in readfile(s:choice_file_path) exec self.edit_cmd . f endfor call delete(s:choice_file_path) + let a:newFileBuff = bufnr('%') + if isdirectory(self.oldPath) + "Then it should remove this previous buffer + silent! execute 'bdelete! '. self.oldBuffer + else + silent! execute 'buffer '. self.oldBuffer + silent! execute 'buffer '.a:newFileBuff + endif + execute 'bdelete! '.rangerBuff + else + if a:code == 0 + silent! execute 'buffer '. self.oldAltBuffer + "if the previous buffer is a directory, it means that ranger ran + "while opening vim + if isdirectory(self.oldPath) + "Then it should remove this previous buffer + silent! execute 'bdelete! '. self.oldBuffer + "and then opening a new empty one + enew + "but in any other case + else + "it should move back to the previous buffer + silent! execute 'buffer '. self.oldBuffer + endif + execute 'bdelete! '.rangerBuff + endif endif endtry endfunction @@ -108,8 +138,6 @@ endfunction function! OpenRangerOnVimLoadDir(argv_path) let path = expand(a:argv_path) - " Delete empty buffer created by vim - Bclose! " Open Ranger call OpenRangerIn(path, 'edit') @@ -127,4 +155,3 @@ endif if !exists('g:ranger_map_keys') || g:ranger_map_keys map f :Ranger endif - From 722ef5144aa2845063019bdc0fe30bc5c9a6720d Mon Sep 17 00:00:00 2001 From: Francois Cabrol Date: Tue, 15 May 2018 08:21:13 -0400 Subject: [PATCH 2/4] Improve --- plugin/ranger.vim | 53 ++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/plugin/ranger.vim b/plugin/ranger.vim index 346f186..8871000 100644 --- a/plugin/ranger.vim +++ b/plugin/ranger.vim @@ -49,24 +49,33 @@ if has('nvim') \'oldPath': expand('%') \} function! rangerCallback.on_exit(job_id, code, event) + " Store the ranger buffer number for later let rangerBuff = bufnr('%') - try - if filereadable(s:choice_file_path) - for f in readfile(s:choice_file_path) - exec self.edit_cmd . f - endfor - call delete(s:choice_file_path) - let a:newFileBuff = bufnr('%') - if isdirectory(self.oldPath) - "Then it should remove this previous buffer - silent! execute 'bdelete! '. self.oldBuffer + "if ranger was closed regularly by selecting a file or quitting + if a:code == 0 + try + "try to read the file containing the choisen files list + if filereadable(s:choice_file_path) + "Open all the selected files + for f in readfile(s:choice_file_path) + exec self.edit_cmd . f + endfor + "delete the temporary file + call delete(s:choice_file_path) + "store the last opened buffer number for later + let a:newFileBuff = bufnr('%') + "if the old buffer was a directory + if isdirectory(self.oldPath) + "Then it should remove this buffer + silent! execute 'bdelete! '. self.oldBuffer + else + "but else it should select the old and then the last buffer to + "set correctly the buffer list + silent! execute 'buffer '. self.oldBuffer + silent! execute 'buffer '.a:newFileBuff + endif else - silent! execute 'buffer '. self.oldBuffer - silent! execute 'buffer '.a:newFileBuff - endif - execute 'bdelete! '.rangerBuff - else - if a:code == 0 + "Select the old alternate buffer (before opening ranger) silent! execute 'buffer '. self.oldAltBuffer "if the previous buffer is a directory, it means that ranger ran "while opening vim @@ -80,10 +89,16 @@ if has('nvim') "it should move back to the previous buffer silent! execute 'buffer '. self.oldBuffer endif - execute 'bdelete! '.rangerBuff endif - endif - endtry + endtry + "finally it remove the ranger's buffer + execute 'bdelete! '.rangerBuff + "if ranger was close by 'bd' + else + silent! execute 'bdelete! '. self.oldBuffer + enew + execute 'bdelete! '.rangerBuff + endif endfunction enew if isdirectory(currentPath) From 41e86e07b9e12bb7be113014916466ad4ca50910 Mon Sep 17 00:00:00 2001 From: Francois Cabrol Date: Tue, 15 May 2018 21:58:02 -0400 Subject: [PATCH 3/4] Fix and add comments --- plugin/ranger.vim | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/plugin/ranger.vim b/plugin/ranger.vim index 8871000..907436b 100644 --- a/plugin/ranger.vim +++ b/plugin/ranger.vim @@ -54,7 +54,7 @@ if has('nvim') "if ranger was closed regularly by selecting a file or quitting if a:code == 0 try - "try to read the file containing the choisen files list + "try to read the file containing the chosen files list if filereadable(s:choice_file_path) "Open all the selected files for f in readfile(s:choice_file_path) @@ -70,23 +70,28 @@ if has('nvim') silent! execute 'bdelete! '. self.oldBuffer else "but else it should select the old and then the last buffer to - "set correctly the buffer list + "set correctly the alternate buffer silent! execute 'buffer '. self.oldBuffer silent! execute 'buffer '.a:newFileBuff endif else - "Select the old alternate buffer (before opening ranger) - silent! execute 'buffer '. self.oldAltBuffer - "if the previous buffer is a directory, it means that ranger ran - "while opening vim + "Then check if the previous buffer is a directory + "it means that ranger ran while opening vim if isdirectory(self.oldPath) "Then it should remove this previous buffer silent! execute 'bdelete! '. self.oldBuffer - "and then opening a new empty one - enew + if self.oldAltBuffer + "select the old alternate buffer (before opening ranger) + silent! execute 'buffer '. self.oldAltBuffer + else + "or open a new empty one + enew + endif "but in any other case else - "it should move back to the previous buffer + "Select the old alternate buffer (before opening ranger) + silent! execute 'buffer '. self.oldAltBuffer + "Then move back to the previous buffer silent! execute 'buffer '. self.oldBuffer endif endif From dc116a00c359f3782927f0214a241a42f8d0d9b2 Mon Sep 17 00:00:00 2001 From: Francois Cabrol Date: Tue, 15 May 2018 22:00:33 -0400 Subject: [PATCH 4/4] Update the Readme --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index b51b25d..119fb99 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,6 @@ Install it with your favorite plugin manager. Example with vim-plug: Plug 'francoiscabrol/ranger.vim' -If you use neovim, you have to add the dependency to the plugin bclose.vim: - - Plug 'rbgrouleff/bclose.vim' - How to use it -------------