hubFS: THE place for F#

. . . are you on The Hub?
Welcome to hubFS: THE place for F# Sign in | Join | Help
in Search

F# mode in Emacs

Last post 05-16-2008, 4:42 by LLB. 7 replies.
Sort Posts: Previous Next
  •  11-09-2007, 15:11 4004

    F# mode in Emacs

    Hi,

    I know some people here sometimes use Emacs. People use the Caml-mode from Inria (or tuareg-mode) and some of them have written some patches (for example in this discussion).

    I've been using F# for nearly one year, I sometimes use Emacs (both on Windows and Unix ; both with fsc and fsi) and I also wrote a few patches (for comments syntax, for new keywords, and a few other things). I thought it would be very nice to have a real fsharp-mode, and gather the patches from different people.

    I've registered a project on sourceforge (fsharp-mode) for that purpose. It's still empty, because I'd like to know first if someone has made interesting things in Emacs for F#. I have used Emacs for years and I know a little Emacs-lisp, but I'm not an expert. So, help is welcome (comments are welcome too).

    The code will be released under GPL (because Caml-mode is GPL).



    Laurent.
  •  11-12-2007, 5:52 4024 in reply to 4004

    Re: F# mode in Emacs

    I think it is a great idea, especially because now F# is getting a different syntax than Caml. I think that a look to Python mode may be helpful to get the right indentation. However just syntax highlight and indentation would be very helpful. I hope to spare enough time to contribute, though it is not a promise...

     

    Antonio

  •  11-17-2007, 8:35 4065 in reply to 4004

    Re: F# mode in Emacs

    I'm using a slightly modified tuareg mode. Even though I can's speak elisp, it's not difficult to persuade tuareg to cooperate with fsharp. Sure it's far from perfect, but roughly working.

    On the other hand, is there any hope to get some VS features such as code completion and type hints on emacs? Pure syntactic analysis surely won't work. How does lisp modes such as slime acheive this? external agent plus communication protocol?

  •  11-19-2007, 13:12 4084 in reply to 4065

    Re: F# mode in Emacs

    Hi,

    The main goal is to have a clean mode for F#, with coloration, indentation and interactive mode. I don't expect to get advanced VS features. Emacs has several advantages compared to VS: it's free, it's light and fast, it's cross-platform. I guess people using Unix will be happy to have an F#-mode. Moreover, many people already use Emacs with other languages (e.g. it's one of the best editors for OCaml), so that won't need to learn/get a new editor if they try F#.


    Thanks for the comments. I still haven't started, but I'll write here when I have things working.

    Laurent.
  •  04-23-2008, 15:10 5825 in reply to 4004

    Re: F# mode in Emacs

    Hi,

    I wanted to release the files earlier, but I forgot. Anyway, here it is. You can download the fsharp-mode on Sourceforge: http://sourceforge.net/projects/fsharp-mode.

    Features:
    - Syntax highlighter (adapted from the caml-mode)
    - Interactive F# mode (adapted from the caml-mode)
    - Indentation (adapted from Python mode)


    It's far from perfect, but I enjoy it. Feel free to contribute, there are still many things to do (e.g. send line numbers to fsi to get relevant locations on errors).

    Yes, there's no completion or real-time type checking like in Visual Studio. But you have a better indentation than in VS. :)

    I think this will be useful for Emacs-fans and Unix users. Please tell me if you plan to use it, if you want to contribute or if you have problems during "installation". Please do not report bugs, except if you have patches. :)


    PS: Intellisense is great in VS. There's no such feature in fsharp-mode. If you need to know which methods are available, you can use introspection in fsi. For example (you can improve it to see parameters type, return type, if the method is static, etc.):
    let view_methods<'a>() =
        [for i in typeof<'a>.GetMethods() -> i.Name]

    view_methods<int>()



    Laurent.
  •  05-15-2008, 17:35 5914 in reply to 5825

    Re: F# mode in Emacs

    Thanks, this is much appreciated!
  •  05-15-2008, 20:19 5916 in reply to 5825

    Re: F# mode in Emacs

    This also works on object instances:

    let dm (o:obj) =
        [for i in o.GetType().GetMethods() -> i.Name]

    However, this requires casting to obj at the call site:

    let rootDir = new System.IO.DirectoryInfo( "C:\\" );
    dm( rootDir :> obj )

    Not sure why the following does not work, though:

    let dm (o:#obj) =
        [for i in o.GetType().GetMethods() -> i.Name]

    F:\test.fsx(4,14): error FS0072: Lookup on object of indeterminate type. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved


    "It seems that perfection is reached, not when there is nothing left to add, but rather when nothing more can be taken away." -- Antoine de St. Exupéry
  •  05-16-2008, 4:42 5922 in reply to 5916

    Re: F# mode in Emacs

    You can use this:

    let dm o =
        [for i in (o :> obj).GetType().GetMethods() -> i.Name]

    Or:

    let dm<'a> (o: 'a) =
        [for i in typeof<'a>.GetMethods() -> i.Name]

View as RSS news feed in XML
Powered by Community Server, by Telligent Systems