Emacs PowerShell Modes
There are 2 emacs modes for powershell. One is powershell-mode, that does syntax coloring for your PowerShell scripts. The other lets you run powershell interactively inside emacs.
If you are using ErgoEmacs on Windows, then these are already installed and ready to use. When you open a file ending in “.ps1”, powershell mode is automatically loaded. To call the PowerShell interface, call the command “powershell”.
If you are not using ErgoEmacs, following are instructions for installation.
PowerShell Interactive Shell in Emacs
To setup emacs to run PowerShell as a interactive shell in emacs, install the elisp file by Dino Chiesa, at: Source www.emacswiki.org. (You can read his original blog at msdn here: msdn.com.)
After download, open the file, then type 【Alt+x eval-buffer】. Now, you can type 【Alt+x powershell】, then you'll have a interactive powershell in emacs.
To have emacs automatically have the command “powershell” available, and load it when you call it, do the following.
First, place the file in the
~/.emacs.d/ directory, so you have:
put the following lines in your emacs init file (
;; add the dir to load path (add-to-list 'load-path "~/.emacs.d/") ;; autoload powershell interactive shell (autoload 'powershell "powershell" "Start a interactive shell of PowerShell." t)
powershell-mode for PowerShell Scripts
To get a PowerShell mode for emacs,
powershell-mode.el by Vivek Sharma @ http://www.viveksharma.com/techlog/attache/powershell-mode.el.txt. This lets you edit PowerShell scripts with syntax highlighting etc.
Note: as of version 0.5 of powershell-mode, it has a bug that generats the error 「(wrong-type-argument stringp t)」. This error is quite harmless but you can get rid of it by commenting out the devar of powershell-imenu-expressions (line 167-170), and comment out the defun of powershell-setup-imenu (line 171-179), and comment out line 206 of 「(powershell-setup-imenu)」.
After download, open the file, then type 【Alt+x eval-buffer】. Now, open any PowerShell source code file, then type 【Alt+x powershell-mode】, you'll see the source code syntax colored.
To have emacs automatically load and use the mode when opening files ending in “.ps1”, do the following.
Put the file in the emacs user lib dir, at
~/.emacs.d/, so you have
~/.emacs.d/powershell-mode.el. Now, put the following lines in your emacs init file (
;; add dir to load path (add-to-list 'load-path "~/.emacs.d/") ;; powershell-mode (autoload 'powershell-mode "powershell-mode" "A editing mode for Microsoft PowerShell." t) (add-to-list 'auto-mode-alist '("\\.ps1\\'" . powershell-mode)) ; PowerShell script