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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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