Loading ...
Sorry, an error occurred while loading the content.

Making new language mode: Erlang

Expand Messages
  • cp200205
    Greetings, I am creating a new language mode for Erlang (http://www.erlang.org) and I am having a bit of troubles with the indentation. Here are a few examples
    Message 1 of 4 , Feb 10, 2004
    • 0 Attachment
      Greetings,

      I am creating a new language mode for Erlang (http://www.erlang.org)
      and I am having a bit of troubles with the indentation. Here are a
      few examples of simple things (to get an idea for the indentation).

      (I added the prefixing '.' characters for space indents).

      say_hello() -> io:format("Hello, World!\n");
      say_hello(Name) ->
      ....io:format("Hello, ~w\n", [Name]),
      ....io:format("How are you doing?\n", []).

      That was easy and is fully functional. Here's one area I am having a
      problem with though:

      say_bye() ->
      ....case to_who() of
      ........person ->
      ............io:format("Bye Person");
      ........Other ->
      ............io:format("Bye Other")
      ....end.

      The above example is correct but I cannot make it work like this.

      First, the io:format("Bye Other") does not contain any special
      character on the end of it to indicate an outdent, but it should be
      outdented -4.

      Second, the "end."... the "end" part should indicate outdent this
      line -4, but then the "." on the end of the "end." line should
      indicate outdent the next line -4. So, it's like a multipart end.
      Now, I did make this part work ("end.") by matching "end." and
      outdenting it -8, but that was confusing to read because it aligned
      with the person, Other selection not the "case" in which it end's.

      For the indent engine, this is what I currently have. If anyone
      could be of assistance with this I would greatly appriciate it.

      !if &sin "d" .fhook-erlang.setup
      ; define indentation scheme
      0 indent .hilight.erlang 0 10

      indent .hilight.erlang n "->" 4
      indent .hilight.erlang n "case" 4
      indent .hilight.erlang n "\\." -4
      indent .hilight.erlang n "end." -8
      indent .hilight.erlang o "end" -4
      indent .hilight.erlang n "[;.]" -4
      indent .hilight.erlang b "(" ")"

      indent .hilight.erlang i "fun.*end"

      indent .hilight.erlang i "%"
      !endif

      P.S. please respond to the list as I do not yet have email back up
      and working after the hack to my main server.

      Jeremy
    • cp200205
      Ok, I figured some things out after playing for a while, but I am still having just 1 problem. Here s the code block: say_bye() - ....case what_name(fun () -
      Message 2 of 4 , Feb 10, 2004
      • 0 Attachment
        Ok, I figured some things out after playing for a while, but I am
        still having just 1 problem. Here's the code block:

        say_bye() ->
        ....case what_name(fun () -> 0 end) of
        ........person ->
        ............io:format("Sorry to see you leaving\n", []),
        ............io:format("Bye Person\n");
        ........Other ->
        ............io:format("Bye Other\n")
        ....end.

        Ok, that's formatted properly, and it was done totally by
        MicroEmacs! Yippie! Here is the indent section that makes that all
        work:

        !if &sin "d" .fhook-erlang.setup
        ; define indentation scheme
        0 indent .hilight.erlang 0 10

        ;indent .hilight.erlang b "(" ")"
        indent .hilight.erlang b "{" "}"
        indent .hilight.erlang b "\\[" "\\]"

        indent .hilight.erlang n "->" 4
        indent .hilight.erlang n "of" 4
        indent .hilight.erlang n "receive" 4
        indent .hilight.erlang n "if" 4
        indent .hilight.erlang o "end" -4
        indent .hilight.erlang s "after" -4
        indent .hilight.erlang n "[^;,.>]$" -4
        indent .hilight.erlang n "[;.]$" -4

        indent .hilight.erlang i "%"
        !endif

        You will notice that my line:

        indent .hilight.erlang b "(" ")"

        is commented out. If I uncomment that line, then my indenting on the
        line:

        io:format("Bye Other\n")

        fails to work and

        end.

        is indented another 4 spaces which should not be. I do not
        understand why uncommenting the highlighting of the "(" ")" braces
        affects this. I did discover, however, that if I were to end that
        block with something like:

        ........Other ->
        ............io:format("Bye Other\n"),
        ............byebye
        ....end.

        then it works properly *with* the brace highlighting enabled. So, it
        has something to do with the braces on that particular line. This is
        very important, because although this example has the () braces in
        it, many times you will have both [...] and {...} as the only
        portions on the line, such as:

        ........Other ->
        ............{bad_request, "This function did not work"}
        ....end.

        the above is perfectly valid and used extensively.

        Thank you for any help you may be,

        Jeremy
      • Jon Green
        ... 0 indent .hilight.erl 0 10 indent .hilight.erl n - 4 indent .hilight.erl n case 4 indent .hilight.erl o end -4 indent .hilight.erl n
        Message 3 of 4 , Feb 10, 2004
        • 0 Attachment
          cp200205 wrote:
          > Greetings,
          >
          > I am creating a new language mode for Erlang (http://www.erlang.org)
          > and I am having a bit of troubles with the indentation. Here are a
          > few examples of simple things (to get an idea for the indentation).
          >
          > (I added the prefixing '.' characters for space indents).
          >
          > say_hello() -> io:format("Hello, World!\n");
          > say_hello(Name) ->
          > ....io:format("Hello, ~w\n", [Name]),
          > ....io:format("How are you doing?\n", []).
          >
          > That was easy and is fully functional. Here's one area I am having a
          > problem with though:
          >
          > say_bye() ->
          > ....case to_who() of
          > ........person ->
          > ............io:format("Bye Person");
          > ........Other ->
          > ............io:format("Bye Other")
          > ....end.
          >
          > The above example is correct but I cannot make it work like this.
          >
          > First, the io:format("Bye Other") does not contain any special
          > character on the end of it to indicate an outdent, but it should be
          > outdented -4.
          >
          > Second, the "end."... the "end" part should indicate outdent this
          > line -4, but then the "." on the end of the "end." line should
          > indicate outdent the next line -4. So, it's like a multipart end.
          > Now, I did make this part work ("end.") by matching "end." and
          > outdenting it -8, but that was confusing to read because it aligned
          > with the person, Other selection not the "case" in which it end's.
          >
          > For the indent engine, this is what I currently have. If anyone
          > could be of assistance with this I would greatly appriciate it.
          >
          > !if &sin "d" .fhook-erlang.setup
          > ; define indentation scheme
          > 0 indent .hilight.erlang 0 10
          >
          > indent .hilight.erlang n "->" 4
          > indent .hilight.erlang n "case" 4
          > indent .hilight.erlang n "\\." -4
          > indent .hilight.erlang n "end." -8
          > indent .hilight.erlang o "end" -4
          > indent .hilight.erlang n "[;.]" -4
          > indent .hilight.erlang b "(" ")"
          >
          > indent .hilight.erlang i "fun.*end"
          >
          > indent .hilight.erlang i "%"
          > !endif
          >
          > P.S. please respond to the list as I do not yet have email back up
          > and working after the hack to my main server.
          >
          > Jeremy
          >
          >

          0 indent .hilight.erl 0 10

          indent .hilight.erl n "->" 4
          indent .hilight.erl n "case" 4
          indent .hilight.erl o "end" -4
          indent .hilight.erl n "[;\\.][ \t]*$" -4
          indent .hilight.erl n ")[ \t]*$" -4
          ; indent .hilight.erl b "(" ")"
          indent .hilight.erl i "fun.*end"

          indent .hilight.erl i "%"

          By loosing the "b" on () token then it seems to work
          better and use the fact that the a ) at the end of
          a line causes an indent. Then the ends are the
          same and the '.' also moves back an indent.

          There are problems with the bracket when
          you define a bracket then you cannot cause
          an indent on the bracket token. This is
          a bit of a shame it would be nice to
          be able to define the bracket and still
          have the indent detect that a )$ causes
          an indent. The "end." works nicely as
          the end causes the current line to be
          indented by -4 and then . indents
          the next by -4.

          Jon.
        • cp200205
          ... Please see my previous message that I posted in response to my own, but let me ask... is there no way around the b (), {}, [] problem? If no, then this
          Message 4 of 4 , Feb 10, 2004
          • 0 Attachment
            --- In jasspa@yahoogroups.com, Jon Green <jon@j...> wrote:

            > By loosing the "b" on () token then it seems to work
            > better and use the fact that the a ) at the end of
            > a line causes an indent. Then the ends are the
            > same and the '.' also moves back an indent.
            >
            > There are problems with the bracket when
            > you define a bracket then you cannot cause
            > an indent on the bracket token. This is
            > a bit of a shame it would be nice to
            > be able to define the bracket and still
            > have the indent detect that a )$ causes
            > an indent.

            Please see my previous message that I posted in response to my own,
            but let me ask... is there no way around the b (), {}, [] problem?
            If no, then this means that auto indentation in this language would
            be almost useless. For instance, if I were to do:

            say_hi(Name) ->
            ....io:format("This is a very long hello message, Hello ~w\n",
            ..............[Name]).

            I could do this manually, but anytime TAB'n through, or Restyling
            the buffer, this would happen:

            say_hi(Name) ->
            ....io:io:format("This is a very long hello message, Hello ~w\n",
            ....[Name]).

            which would make things a bit hard to read.

            Thanks for your input, and any input you may have on this matter.

            Jeremy
          Your message has been successfully submitted and would be delivered to recipients shortly.