Emacs: Format PowerShell Code 🚀

By Xah Lee. Date: .

put this in your Emacs Init File:

(defvar xah-powershell-path
  "PowerShell path or name.
A string.
It can be just a program name such as powershell or pwsh, or full path to one of them.
Used by many commands that need to launch program via Powershell.")

(defun xah-pwsh-format-code ()
  "Format PowerShell code of current buffer file.
Buffer must be a file buffer. It is saved first.
Requires xah-format-PowerShell-script at
URL `http://xahlee.info/powershell/powershell_format_script.html'

URL `http://xahlee.info/emacs/emacs/emacs_format_powershell_code.html'
Created: 2021-09-13
Version: 2023-08-12"
  (if buffer-file-name
      (let ((xcmdstr
             (format "%s -Command xah-format-PowerShell-script %s"
        (shell-command xcmdstr)
        (revert-buffer t t t))
    (user-error "%s: current buffer must be a file %s" real-this-command (buffer-name))))

need PowerShell: Pretty Format PowerShell Code 🚀

part of Emacs: Xah PowerShell Mode 📦

Emacs, Format Code