Loading the current buffer in F#
My primary editor for use with F# is Emacs. One feature that I missed in F# mode was the ability to load the file corresponding to the current buffer. Here’s some elisp to do it. Put this in your .emacs file, and then when you are editing an F# module you can load it at the toplevel by pressing C-c C-f.
(defun fsharp-load-buffer-file () |
"Load the filename corresponding to the present buffer in F# with #load" |
(interactive) |
(require 'inf-fsharp) |
(let* ((name buffer-file-name) |
(command (concat "#load \"" name "\""))) |
(when (buffer-modified-p) |
(when (y-or-n-p (concat "Do you want to save \"" name "\" before loading it? ")) |
(save-buffer))) |
(save-excursion (fsharp-run-process-if-needed)) |
(save-excursion (fsharp-simple-send inferior-fsharp-buffer-name command)))) |
(add-hook 'fsharp-mode-hook |
(lambda () |
(define-key fsharp-mode-map "\C-c\C-f" 'fsharp-load-buffer-file))) |
|