Skip to content

Latest commit

 

History

History
219 lines (156 loc) · 9.21 KB

README.md

File metadata and controls

219 lines (156 loc) · 9.21 KB

fsharp-mode

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+ and F# 3.0. Without F# 3.0 the background compiler process will not function correctly.

Installation

Package

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)

Manual installation

  1. Clone this repo and run make install:

    git clone git://github.com/fsharp/fsharpbinding.git
    cd fsharpbinding/emacs
    make test-all # optional
    make install
    
  2. 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'

Usage

fsharp-mode should launch automatically whenever you open an F# buffer. When the intellisense process is running, the following features will be available:

  1. Type information for symbol at point will be displayed in the minibuffer.
  2. Errors and warnings will be automatically highlighted, with mouseover text. Jump to the next and previous error using M-n and M-p.
  3. To display a tooltip, move the cursor to a symbol and press C-c C-t (default).
  4. To jump to the definition of a symbol at point, use C-c C-d.
  5. Completion will be invoked automatically on dot, as in Visual Studio. It may be invoked manually using fsharp-ac/complete-at-point, bound by default to C-c C-..
  6. To stop the intellisense process for any reason, use C-c C-q.

Projects

fsharp-mode offers intellisense for projects using the MSBuild/.fsproj format. This allows project files to be shared with other developers using Visual Studio and Xamarin Studio/Monodevelop. To create a new project file, it is recommended that you take an existing project file and modify the list of source files. One such project file can be found in the fsharp-mode repository here.

If, on loading a new .fs file, the intellisense process is not running and a .fsproj file is found in the current or an enclosing directory, the intellisense process will be launched, and the 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.

Scripts

F# scripts (.fsx files) are standalone, and require no project file. As a result, intellisense can be offered for many script files concurrently with a project. If you wish open a script file and the intellisense process is not yet running, it will be launched automatically.

Configuration

Compiler and REPL paths

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")

Behavior

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. Note that this will only prevent the background process from being launched in the future. If it is already running you will also need to quit it using C-c C-q.

Key Bindings

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") 'fsharp-ac/complete-at-point)))

Troubleshooting

fsharp-mode is still under development, so you may encounter some issues. Please report them so we can improve things! Either open an issue on Github with the label Emacs, or email the mailing list.

*fsharp-complete*

The buffer *fsharp-complete* contains partial messages received from the background process, before they form complete JSON objects.

fsharp-ac-debug

If you set the variable fsharp-ac-debug to a non-nil value, e.g. (setq fsharp-ac-debug 0), then some debug output will be seen in the buffer *fsharp-debug*. Setting fsharp-ac-debug to an 1 or 2 will cause a truncated or complete copy of communication between Emacs and the background intellisense process to be logged in *fsharp-debug*. This can make things rather slow, but would be useful for bug reports.

Error: F# completion process produced malformed JSON

This is probably the result of the background intellisense process crashing and printing a stacktrace in plain text. Please report the crash, preferably with how to reproduce, and the contents of the *fsharp-complete* buffer.

Windows completion menu performance

There are some issues with the pos-tip library used to display the documentation tooltips for completions. This can cause sluggish performance when scrolling through the list if you try to move up or down just before the tooltip is displayed. We are looking into proper solutions for this with the pos-tip maintainer. For now you can work around the issue with (setq ac-quick-help-prefer-pos-tip nil). This will use an alternative method for displaying these tooltips that is faster but uglier.

Installing from Git

If you installed by cloning the git repository and you are having problem, please sanity check by running make test-all in the emacs folder.

Contributing

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.