# Emacs Major Modes for Power BI

After many years of using Vim I finally understood the Emacs way. What I was trying to do all along was trying to make Vim behave exactly like Emacs.

To celebrate this I made some bad Elisp code and shared it on GitHub. I based my code on the Simple Emacs Major Mode for Syntax Coloring by Xah Lee.

## Power Query Mode

This mode gives you syntax coloring and code completion inside Emacs. It has all the functions listed by '#shared' and color codes them. For more details on listing all Power Query functions you can check the post from RADACAD.

I still need to create an indent/pretty print function for this.

## Dax Mode

To obtain all the function names I’ve extracted the names from the DAX Syntax Highlighting for Notepad++, and added a small function:

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26  (defun dax-pretty-print () "Pretty print the DAX buffer via DaxFormatter API." (interactive) (goto-char (point-min)) (while (search-forward ";" nil t) (replace-match ",")) (goto-char (point-min)) (let* ( (url-request-method "POST") (url-request-extra-headers '(("Content-Type" . "application/json"))) (url-request-data (json-encode (("Dax" ., (delete-and-extract-region (point-min) (point-max)) )))) (buf (current-buffer)) (newbuff (url-retrieve-synchronously "http://www.daxformatter.com/api/daxformatter/DaxFormat/")) ) (set-buffer newbuff) (goto-char (point-min)) (re-search-forward "^\$") (delete-region (point) (point-min)) (setq noQuotes (substring (buffer-string) 2 -9)) (setq noRN (replace-regexp-in-string "\\\\r\\\\n" " " noQuotes)) (setq noBars (replace-regexp-in-string "\\\\" "" noRN)) (princ noBars buf) (kill-buffer newbuff) ) )`

That uses the same API as Dax Studio to format/pretty print dax queries.

Hope this helps you in some way. If you have ideas of how I’ve could done this better please feel free to do a pull request or message me.

Have fun!!