Provides support for the F# language in Emacs. Includes the following features:
- Support for F# Interactive
- Displays type signatures and tooltips
- Provides syntax highlighting and indentation.
The following features are under development:
- Intelligent indentation
- Intellisense support.
Requires Emacs 24+.
fsharp-mode
is available on MELPA and can
be installed using the built-in package manager.
If you're not already using MELPA, add the following to your init.el:
;;; Initialize MELPA
(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/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)
-
Clone this repo and run
make install
:git clone git://github.com/fsharp/fsharpbinding.git cd fsharpbinding/emacs make install
-
Add the following to your init.el:
(add-to-list 'load-path "~/.emacs.d/fsharp-mode/") (autoload 'fsharp-mode "fsharp-mode" "Major mode for editing F# code." t) (add-to-list 'auto-mode-alist '("\\.fs[iylx]?$" . fsharp-mode))
Note that if you do not use make install
, which attempts to download
the dependencies from MELPA for you, then you must ensure that you have
installed them yourself. A list can be found in fsharp-mode-pkg.el
.
If you run into any problems with installation, please check that you
have Emacs 24 on your PATH using emacs --version
.
Note that OSX comes with Emacs 22 by default and installing a .app of
Emacs 24 will not add it to your PATH. One option is:
alias emacs='/Applications/Emacs.app/Contents/MacOS/Emacs'
fsharp-mode should launch automatically whenever you open an F# buffer. If the current file is part of an F# project, and the intellisense process is not running, it will be launched, and the current project loaded.
Currently intellisense features can be offered for just one project at a time. To load a new F# project, use C-c C-p.
While a project is loaded, the following features will be available:
- Type information for symbol at point will be displayed in the minibuffer
- Errors and warnings will be automatically highlighted, with mouseover text.
- To display a tooltip, move the cursor to a symbol and press C-c C-t (default).
- To jump to the definition of a symbol at point, use C-c C-d.
- Completion will be invoked automatically on dot, as in Visual Studio.
It may be invoked manually using
completion-at-point
, often bound to M-TAB and C-M-i. - To stop the intellisense process for any reason, use C-c C-q.
In the event of any trouble, please open an issue on Github with the label Emacs
.
The F# compiler and interpreter should be set to good defaults for your OS as long as the relevant executables can be found on your PATH. If you have a non-standard setup you may need to configure these paths manually.
On Windows:
(setq inferior-fsharp-program "\"c:\\Path\To\Fsi.exe\"")
(setq fsharp-compiler "\"c:\\Path\To\Fsc.exe\"")
On Unix-like systems, you must use the --readline- flag to ensure F#
Interactive will work correctly with Emacs. Typically fsi
and fsc
are
invoked through the shell scripts fsharpi
and fsharpc
.
(setq inferior-fsharp-program "path/to/fsharpi --readline-")
(setq fsharp-compiler "path/to/fsharpc")
There are a few variables you can adjust to change how fsharp-mode behaves:
-
fsharp-ac-use-popup
: Show tooltips using a popup at the cursor position. If set to nil, display the tooltip in a split window. -
fsharp-doc-idle-delay
: Set the time (in seconds) to wait before showing type information in the minibuffer. -
fsharp-ac-intellisense-enabled
: This mode overrides some aspects of auto-complete configuration and runs the background process automatically. Set to nil to prevent this.
If you are new to Emacs, you might want to use the menu (call menu-bar-mode if you don't see it). However, it's usually faster to learn a few useful bindings:
- C-c C-r: Evaluate region
- C-c C-f: Load current buffer into toplevel
- C-c C-e: Evaluate current toplevel phrase
- C-M-x: Evaluate current toplevel phrase
- C-M-h: Mark current toplevel phrase
- C-c C-s: Show interactive buffer
- C-c C-c: Compile with fsc
- C-c x: Run the executable
- C-c C-a: Open alternate file (.fsi or .fs)
- C-c l: Shift region to left
- C-c r: Shift region to right
- C-c : Move cursor to the beginning of the block
- C-c C-p: Load a project for autocompletion and tooltips
- C-c C-d: Jump to definition of symbol at point
- C-c C-t: Request a tooltip for symbol at point
- C-c C-q: Quit current background compiler process
- M-n: Go to next error
- M-p: Go to previous error
To interrupt the interactive mode, use C-c C-c. This is useful if your code does an infinite loop or a very long computation.
If you want to shift the region by 2 spaces, use: M-2 C-c r
In the interactive buffer, use M-RET to send the code without
explicitly adding the ;;
thing.
For key bindings that will be more familiar to users of Visual Studio, adding
the following to your init.el
may be a good start:
(add-hook 'fsharp-mode-hook
(lambda ()
(define-key fsharp-mode-map (kbd "M-RET") 'fsharp-eval-region)
(define-key fsharp-mode-map (kbd "C-SPC") 'completion-at-point)))
This project is maintained by the F# Software Foundation, with the repository hosted on GitHub.
Pull requests are welcome. Please run the test-suite with make test-all
before submitting a pull request.