@@ -78,14 +78,34 @@ module.public = {
7878 --- Call attempt to edit a file, catches and suppresses the error caused by a swap file being
7979 --- present. Re-raises other errors via log.error
8080 --- @param path string
81- edit_file = function (path )
82- local ok , err = pcall (vim .cmd .edit , path )
81+ --- @param opts table ? Optional parameters
82+ --- @param opts .mode string ? The vim command to use for opening the file (default : " edit" )
83+ --- - "edit" (default) - open in current window
84+ --- - "tabedit" - open in new tab
85+ --- - "vsplit" - open in vertical split
86+ --- - "split" - open in horizontal split
87+ --- - "tab-drop" - open in new tab or switch to existing tab
88+ --- - "drop" - switch to existing buffer or open in current window
89+ edit_file = function (path , opts )
90+ opts = opts or {}
91+ local mode = opts .mode or " edit"
92+
93+ local ok , err
94+ -- Special handling for tab-drop and drop commands
95+ if mode == " tab-drop" or mode == " drop" then
96+ local cmd = mode == " tab-drop" and " tab drop" or " drop"
97+ ok , err = pcall (vim .cmd , cmd .. " " .. vim .fn .fnameescape (path ))
98+ else
99+ -- For edit, tabedit, vsplit, split
100+ ok , err = pcall (vim .cmd [mode ], path )
101+ end
102+
83103 if not ok then
84104 -- Vim:E325 is the swap file error, in which case, a lengthy message already shows to
85105 -- the user, and we don't have to crash out of this function (which creates a long and
86106 -- misleading error message).
87107 if err and not err :match (" Vim:E325" ) then
88- log .error (" Failed to edit file %s. Error:\n %s" ): format ( path , err )
108+ log .error (string.format ( " Failed to edit file %s. Error:\n %s" , path , err ) )
89109 end
90110 end
91111 end ,
0 commit comments