PICO-8.vim icon indicating copy to clipboard operation
PICO-8.vim copied to clipboard

Set working directory when calling pico8 -run

Open merwok opened this issue 4 years ago • 6 comments

Hello and thanks for this package!

My projects are in sub-sub-directories of the pico-8 carts location, or in other directories entirely. I usually run !pico8 -run % which works as pico-8 interprets the relative path correctly (I have autochangedir note), it does not try to load the filename from its carts directory. With :Pico8Run I get loading errors. I think the current working directory should be set for the pico-8 process, or the absolute file path should be passed.

merwok avatar Feb 18 '22 23:02 merwok

Thank you for your report! I could not reproduce the problem on my Windows environment, but it seems better to pass the absolute file path. Please update the plugin and check if your problem has been resolved.

Bakudankun avatar Feb 19 '22 05:02 Bakudankun

Thanks for the quick reply!

I updated and still have a loading error with the absolute path. I will try to find more info!

merwok avatar Feb 19 '22 10:02 merwok

I ran with strace and found that this path is tried:

openat(AT_FDCWD, "/home/user/working/dir/'/home/user/working/dir/cart.p8'", O_RDONLY) = -1 ENOENT

So pico8 is already aware of the working directory, but passing a full path leads to bad concatenation. I am reverting the change you did to see the original issue.

merwok avatar Feb 20 '22 17:02 merwok

The original issue was a bad path too: "/home/user'/home/user/working/dir/cart.p8'" Feels that pico-8 wants an unexpanded, unquoted relative path!

merwok avatar Feb 20 '22 17:02 merwok

This change works for me with the autochdir option active, but not without!

diff --git a/autoload/pico8.vim b/autoload/pico8.vim
index a4ff0ae..c869a58 100644
--- a/autoload/pico8.vim
+++ b/autoload/pico8.vim
@@ -14,7 +14,7 @@ endfunction
 
 
 function! pico8#run(mods, options) abort
-  let cmdline = '"' . pico8#get_config('pico8_path', 'pico8') . '" -run ' . expand('%:p:S')
+  let cmdline = '"' . pico8#get_config('pico8_path', 'pico8') . '" -run ' . expand('%')
   if has('win32')
     " PICO-8 on Windows does not output logs if run directly.
     let cmdline = $ComSpec . ' /C "' . cmdline . '"'
``

merwok avatar Feb 20 '22 17:02 merwok