0

I installed powershell package in emacs. I launched the powershell using M-x powershell. In the powershell window, I am able to run command like ls etc, but I am not able to execute powershell scripts. I tried to use cmd as a default shell in emacs and execute the powershell script from it as described here;

How to run PowerShell in CMD

but it freezes. Similarly, when I am try to run vim in powershell/cmd within emacs it freezes. I want to point out that scripts and vim is working fine in powershell and cmd, if I am running it outside emacs.

Community
  • 1
  • 1
Yogi
  • 446
  • 3
  • 9

1 Answers1

1

In M-x powershell and M-x shell, the terminal is "dumb" and only understands programs that print, but not programs that go fullscreen.

So, it will work with ls, cat, and cd, but will fail on vim, man, and less. I bet your script tries to open vim, no?

This restriction exists for a reason: when a program goes fullscreen, it captures all keyboard input. So if you open vim and type C-x, does it run the Emacs command for C-x or the Vim command? If you always run the Emacs command, that means when you type j, it will insert j into the Emacs buffer instead of scrolling down in Vim. Vim will become unusable. If you always run the Vim command, that means you can no longer use C-x C-c to get out of Emacs, since the command will be absorbed by Vim.

One workaround is to use M-x term. In term all keystrokes are sent to the program, so you can open and use Vim like normal. To run an Emacs command, start with C-c. You can read more about it here. I'm not sure it it exists in Windows.

Another workaround to use emacsclient:

;; in init.el
(server-start)

# in a shell
$ emacsclient file.txt

This will open the file in your existing Emacs window. When you're done editting the file, press C-x # to go back to the shell.

Brian Malehorn
  • 2,627
  • 14
  • 15
  • No the script is not trying to open vim. Is is just compiling stuffs, set up some environment variable. I think something wrong with the powershell.el thing. – Yogi Dec 18 '15 at 04:26
  • What error message do you get when the script fails? – Brian Malehorn Dec 18 '15 at 19:15
  • It is working now. I was using auto-complete, which was not adding .\ at the beginning of the path. After I added .\ it is working. However, when I am running a script using, powershell -noexit "& ""D:\build.ps1""", it is getting stuck like vim. So it may be the same reason like vim. – Yogi Dec 20 '15 at 06:25