adamyg / mcwin32

Midnight Commander for Windows
https://sourceforge.net/projects/mcwin32/
210 stars 14 forks source link

External vim editor on windows #7

Closed silverqx closed 2 years ago

silverqx commented 3 years ago

Hi,

I'm not able to setup up an external vim editor on windows. I'm using mc 4.8.24.

mc correctly picks up EDITOR env. variable, but the final command looks like this:

vim /C E:/another_dir/file.txt

So vim tries to open two files:

The second problem is that file is not quoted, so when the command line looks like this:

vim /C E:/some dir/file.txt

Then it tries to open two folders and one file dir/file.txt.

I have also tried to add External parameters as is described in man pages:

[External editor or viewer parameters]
vim=%filename +%lineno

But without success, it looks like mc ignores this section, in the manpages is written: "The option name should be equal to the name (full pathname) of external editor or viewer."

I have tried various combinations.

The problem is also described here: https://superuser.com/questions/1119591/defining-midnight-commanders-external-editor-on-windows I have also created an issue on mc's trac issue track and some good guy tell me that a dedicated project exists for windows support, ticket is here.

Anyway, it is not crucial whether [External editor or viewer parameters] works or not on windows, would be absolutely enough to correctly generate external editor command on windows.

That means remove that /C parameter from the beginning or replace it with -C because startup parameters for vim have to start with a dash and quote filepaths.

adamyg commented 3 years ago

target build-221

silverqx commented 3 years ago

I have tested it, and now the generated command doesn't contain /C, but when the file contains whitespace it fails, the generated command looks like this:

vim E:/some dir/file.txt

So it opens empty file, still doesn't work correctly, it has to be quoted when it contains dangerous characters. @adamyg

adamyg commented 3 years ago

Further work required to quote args

silverqx commented 3 years ago

Yesterday, before I had gone to the bed, I have little looked at source code on GitHub ( not in an ide, so it might not be accurate ) and it looks like the file paths are passed without quotations for win and also for UNIX systems, on UNIX it works without problems. ( I checked this on my Gentoo install, but I will not describe it here ).

The call chain I have find out is edit_cmd() -> do_edit() -> edit_file_at_line() -> execute_external_editor_or_viewer() ... -> w32_shell(), ..., the path what_vpath which is obtained by fname = vfs_path_from_str (selection (current_panel)->fname); here is unquoted.

This path should be quoted somewhere around execute_external_editor_or_viewer(), I practically don't know anything about mc source code and it was 15min lookup to source code on github, so I can still be wrong. 🙂🤙 @adamyg

adamyg commented 3 years ago

Build-222 pending

eugenov commented 2 years ago

At least I was able to set Notepad3 as external editor with env variable EDITOR. It works as it should.

eugenov commented 2 years ago

Maybe does one know how to let mc open multiple files with external editor? Now mc panels are blocked (black screen) when file is opened with editor. Something like "&" at the end of command...

adamyg commented 2 years ago

Neither options are currently available; open an enhancement ticket and i'll consider