Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Syntax Highlighting for M (how-to)

Hi all,

 

I have discovered that if you want syntax highlighting and automatic indenting when writing M code there is a pretty easy way without too much work.

 

Use fsharp-mode in Emacs.

 

It isn't perfect but it is pretty close. 

 

I am sure that you could probably use a F# mode in other editors and you would get a similar affect.

3 REPLIES 3
prateekraina
Memorable Member
Memorable Member

Hi @Anonymous,

 

Can you please elaborate or provide some steps in order to do this.

Will be helpful for people who have no idea about Emacs.

 

Prateek Raina

Anonymous
Not applicable

Sure thing.

 

It is quite involved for someone who doesn't use emacs, but if you use emacs this will seem pretty straight forward.

 

More instructions can be found here:

 

https://github.com/fsharp/emacs-fsharp-mode

 

1) Install emacs. Now emacs is kind of a heavy duty text editor and does require a learning curve. I would suspect other text editors such as atom, Notepad++ or VS Code probably have F# syntax high-lighting as well. They would probably be easier to use.

 

2) In your .emacs file (which is the config file for emacs, and generally found in the home directory) you need to have code to load the melpa package managing which is something like this:

 

(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
                    (not (gnutls-available-p))))
       (url (concat (if no-ssl "http" "https") "://melpa.org/packages/")))
  (add-to-list 'package-archives (cons "melpa" url) t))
(when (< emacs-major-version 24)
  ;; For important compatibility libraries like cl-lib
  (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
(package-initialize)

 

3) Then you need to reload the .emacs file do so by M-x eval-buffer (which means press the meta key and x and then enter the command eval-buffer)

 

4) Then run the command (M-x package-list-packages)

 

5) find the pachage fsharp-mode and install this. Generally done by pressing i when the test is selected, and then press x to install.

 

6) Then when you have a file which contains M code in it you can run the command (M-x fsharp-mode).

 

 

Quick Addition, if you want to add melpa and install fsharp-mode at the same time, add this to your .emacs (init.el) file:

 

;;; Initialize MELPA
(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(unless package-archive-contents (package-refresh-contents))
(package-initialize)

;;; Install fsharp-mode
(unless (package-installed-p 'fsharp-mode)
  (package-install 'fsharp-mode))

(require 'fsharp-mode)

 

Per the github repository (which has other install methods for use-package and others).

 

Thanks very much for the tip @Anonymous, I've never used F# so this never would have occurred to me. Finally I can halfway escape the woefully inadequate power query "advanced" editor.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.