简体   繁体   English

在emacs中运行Powershell脚本

[英]Run powershell scripts in emacs

I installed powershell package in emacs. 我在emacs中安装了powershell软件包。 I launched the powershell using Mx powershell. 我使用Mx powershell启动了powershell。 In the powershell window, I am able to run command like ls etc, but I am not able to execute powershell scripts. 在powershell窗口中,我可以运行ls等命令,但不能执行powershell脚本。 I tried to use cmd as a default shell in emacs and execute the powershell script from it as described here; 我试图将cmd用作emacs中的默认shell,并按此处所述从cmd执行powershell脚本。

How to run PowerShell in CMD 如何在CMD中运行PowerShell

but it freezes. 但它冻结了。 Similarly, when I am try to run vim in powershell/cmd within emacs it freezes. 同样,当我尝试在emacs中的powershell / cmd中运行vim时,它会冻结。 I want to point out that scripts and vim is working fine in powershell and cmd, if I am running it outside emacs. 我想指出的是,如果我在emacs之外运行脚本和vim,则它们在powershell和cmd中可以正常工作。

In Mx powershell and Mx shell , the terminal is "dumb" and only understands programs that print , but not programs that go fullscreen . Mx powershellMx shell ,终端是“哑巴”,并且仅理解可打印的程序,而不能理解全屏的程序。

So, it will work with ls , cat , and cd , but will fail on vim , man , and less . 因此,它将与lscatcd ,但在vimmanless上将失败。 I bet your script tries to open vim , no? 我敢打赌,您的脚本试图打开vim ,不是吗?

This restriction exists for a reason: when a program goes fullscreen, it captures all keyboard input. 存在此限制是有原因的:程序进入全屏模式时,它将捕获所有键盘输入。 So if you open vim and type Cx , does it run the Emacs command for Cx or the Vim command? 所以,如果你打开vim和类型Cx ,它运行Emacs的命令Cx或Vim命令? 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. 如果您始终运行Emacs命令,这意味着当您键入j ,它将把j插入Emacs缓冲区中,而不是在Vim中向下滚动。 Vim will become unusable. Vim将变得无法使用。 If you always run the Vim command, that means you can no longer use Cx Cc to get out of Emacs, since the command will be absorbed by Vim. 如果始终运行Vim命令,则意味着您将无法再使用Cx Cc退出Emacs,因为该命令将被Vim吸收。

One workaround is to use Mx term . 一种解决方法是使用Mx term In term all keystrokes are sent to the program, so you can open and use Vim like normal. term所有击键都发送到程序,因此您可以像平常一样打开和使用Vim。 To run an Emacs command, start with Cc . 要运行Emacs命令,请从Cc开始。 You can read more about it here . 您可以在此处了解更多信息。 I'm not sure it it exists in Windows. 我不确定它是否存在于Windows中。

Another workaround to use emacsclient : 使用emacsclient另一种解决方法:

;; in init.el
(server-start)

# in a shell
$ emacsclient file.txt

This will open the file in your existing Emacs window. 这将在您现有的Emacs窗口中打开文件。 When you're done editting the file, press Cx # to go back to the shell. 编辑完文件后,按Cx #返回到Shell。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM