1

I am formatting elixir files .ex with the help of a contributed plug-in for nvim like this on Windows:

cmd> nvim.exe -i NONE -n -E +"norm gg=G" -cwq c:/file.ex

This works fine when the command is called inside normal Windows command line prompt. However, if I run the same command in NodeJS using child_process the formatting gets wrong (not proper indentations).

Correct formatting:

defmodule BackendWeb.Endpoint do
  def go do
    IO.puts "go"
  end
end

Faulty formatting:

defmodule BackendWeb.Endpoint do
def go do
IO.puts "go"
end
end

Any idea what might be going on here?

Update

This formats the file badly:

require('child_process').exec('C:/opt/neovim/bin/nvim.exe -i NONE -n -E +"norm gg=G" -cwq ' + path, function puts(error, stdout, stderr) {});

This formats the file properly:

require('child_process').exec('start /MIN C:/opt/neovim/bin/nvim.exe -i NONE -n -E +"norm gg=G" -cwq ' + path, function puts(error, stdout, stderr) {});

Using start /MIN to run nvim solved the problem, but it creates for fraction of a second some task bar item (minified window).

  • working workaround.. I have created a simple c# console application which executes the above code line using Process(). From NodeJS, calling that c# executable formats the file just fine.. Maybe this issue is not related to vim at all, and has to do with some interaction between NodeJS and Windows shell. – W.M. Oct 18 '17 at 17:46
  • 1
    Can you be more specific about how the formatting/indentation is wrong? Sounds strange. – B Layer Oct 18 '17 at 18:10
  • Solved perfectly with no cmd windows by cmdow.exe /run /hid C:/opt/neovim/bin/nvim.exe -i NONE -n -E +"norm gg=G" -cwq [path-to-file]. Utility found at: ritchielawrence.github.io/cmdow – W.M. Oct 18 '17 at 21:32
  • 1
    At a guess: Is node running as a different user? Does it work using the following as the first argument to exec()? 'cmd /C "SET HOME=[path\to\home] && C:/opt/neovim/bin/nvim.exe -i NONE -n -E +"""norm gg=G""" -cwq ' + path + '"' – Rich Oct 19 '17 at 10:08
  • @Rich no, I am getting same faulty formatting. Formatting is correct when doing either 1) removing -E from arguments but then the execution takes some 2-3 seconds or 2) running nvim.exe with -E in argument list by start /MIN or cmdow.exe /run /hid – W.M. Oct 19 '17 at 11:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.