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

Re: [jasspa] Fancy Language Features (in C)

Expand Messages
  • Jon Green
    ... Should be fhook/lau above not pascal (shows my source !). Jon.
    Message 1 of 7 , Dec 22, 2003
    • 0 Attachment
      Jon Green wrote:
      > Jeremy Cowgar wrote:
      >
      >>Greetings...
      >>
      >>I notice that when I do:
      >>
      >>int main(int argc,[CR]
      >> char *args[])
      >>{
      >>}
      >>
      >>Enter where [CR] is indicated causes it to indent properly to the arg list. I am
      >>creating a mode for Lua, how can I accomplish this same task? When I hit enter on
      >>a function definition, it goes to the beginning of the line.
      >>
      >>Thanks,
      >>
      >>Jeremy
      >>
      >
      >
      > Use:
      >
      > indent .hilight.lau b "(" ")"
      >
      > A quick "lau" template "hklau.emf" may be
      > (after a 3 minute glance at reference page):-
      >
      > define-macro fhook-lau
      > set-variable $buffer-mask "luh1"
      > @# buffer-init "lau" #l0
      > buffer-init-hooks
      > !emacro
      >
      > ; buffer-init variables
      > set-variable .fhook-lau.setup ® "/history" "fhook/pascal" "bdghinopx"

      Should be "fhook/lau" above not pascal (shows my source !).
      Jon.

      > set-variable .fhook-lau.setup-mask "acdeghikmnopstux"
      > set-variable .fhook-lau.comment "|--||-|-- | //--"
      >
      > !if &and &sin "h" .fhook-lau.setup &band .hilight.flags 0x02
      > ; High-light Lau Mode
      > !if ¬ &exist .hilight.lau
      > set-variable .hilight.lau &pinc .hilight.next 1
      > !endif
      > 0 hilight .hilight.lau 3 50 $global-scheme
      > hilight .hilight.lau 2 "--" .scheme.comment
      > hilight .hilight.lau 4 "\"" "\"" "\\" .scheme.string
      >
      > hilight .hilight.lau 1 "and" .scheme.keyword
      > hilight .hilight.lau 1 "break" .scheme.keyword
      > hilight .hilight.lau 1 "do" .scheme.keyword
      > hilight .hilight.lau 1 "else" .scheme.keyword
      > hilight .hilight.lau 1 "elseif" .scheme.keyword
      > hilight .hilight.lau 1 "end" .scheme.keyword
      > hilight .hilight.lau 1 "false" .scheme.keyword
      > hilight .hilight.lau 1 "for" .scheme.keyword
      > hilight .hilight.lau 1 "function" .scheme.keyword
      > hilight .hilight.lau 1 "if" .scheme.keyword
      > hilight .hilight.lau 1 "in" .scheme.keyword
      > hilight .hilight.lau 1 "local" .scheme.keyword
      > hilight .hilight.lau 1 "nil" .scheme.keyword
      > hilight .hilight.lau 1 "not" .scheme.keyword
      > hilight .hilight.lau 1 "or" .scheme.keyword
      > hilight .hilight.lau 1 "repeat" .scheme.keyword
      > hilight .hilight.lau 1 "return" .scheme.keyword
      > hilight .hilight.lau 1 "then" .scheme.keyword
      > hilight .hilight.lau 1 "true" .scheme.keyword
      > hilight .hilight.lau 1 "until" .scheme.keyword
      > hilight .hilight.lau 1 "while" .scheme.keyword
      > !endif
      >
      > !if &sin "d" .fhook-lau.setup
      > !if ¬ &exist .hilight.lau
      > set-variable .hilight.lau &pinc .hilight.next 1
      > !endif
      > ; Define the indentation tokens
      > 0 indent .hilight.lau 1 20
      > indent .hilight.lau n "while" 2
      > indent .hilight.lau o "end" -2
      > indent .hilight.lau n "if" 2
      > indent .hilight.lau n "do" 2
      > indent .hilight.lau n "for" 2
      > indent .hilight.lau n "function" 2
      > indent .hilight.lau b "(" ")"
      > !endif
      >
    • Jeremy Cowgar
      ... Thanks! ... You can see my Lua template at: http://microemacs.cowgar.com/wiki.php/LuaLanguageTemplate (Note, I ve added just a bit more to it and fixed a
      Message 2 of 7 , Dec 22, 2003
      • 0 Attachment
        Quoting Jon Green <jon@...>:
        > > Use:
        > >
        > > indent .hilight.lau b "(" ")"

        Thanks!

        > > A quick "lau" template "hklau.emf" may be
        > > (after a 3 minute glance at reference page):-

        You can see my Lua template at:

        http://microemacs.cowgar.com/wiki.php/LuaLanguageTemplate

        (Note, I've added just a bit more to it and fixed a few
        errors since I posted that, but that will give you an idea.

        I think I'm just about their, with the addition above, and
        I'd also like to be able to make the comments work like they
        do in C, automatically inserting the "-- " until the user
        ends it with a "--" (no space).

        Anyway, let me know what you think.

        Oh, I also have their a LuaHtml template that mixes Lua and
        HTML. I've seen some examples, but have not seen it done
        like I've done (or as simply (that I can remember)). Maybe
        you can comment on it as well:

        http://microemacs.cowgar.com/wiki.php/LuaHtmlLanguageTemplate

        Oh, please note, that the language parser is goofing up one
        section of that template, the <?lua and ?> are correct if
        you view the source... I need to do a little tweaking to
        the PHP code that colorizes MicroEmacs's code.

        Jeremy
      • Jon Green
        ... Excellent. I suggest that you post a link to the source because you are missing some backslashes in the emf HTML version and it will not work as supplied
        Message 3 of 7 , Dec 22, 2003
        • 0 Attachment
          Jeremy Cowgar wrote:
          > Quoting Jon Green <jon@...>:
          >
          >>>Use:
          >>>
          >>> indent .hilight.lau b "(" ")"
          >
          >
          > Thanks!
          >
          >
          >>>A quick "lau" template "hklau.emf" may be
          >>>(after a 3 minute glance at reference page):-
          >
          >
          > You can see my Lua template at:
          >
          > http://microemacs.cowgar.com/wiki.php/LuaLanguageTemplate
          >
          > (Note, I've added just a bit more to it and fixed a few
          > errors since I posted that, but that will give you an idea.

          Excellent. I suggest that you post a link to the source
          because you are missing some backslashes in the emf HTML
          version and it will not work as supplied if copied.

          To convert to HTML then you can set up the
          printer to print HTML to a buffer in ME.

          >
          > I think I'm just about their, with the addition above, and
          > I'd also like to be able to make the comments work like they
          > do in C, automatically inserting the "-- " until the user
          > ends it with a "--" (no space).

          OK, comments. I do not understand the language,
          are you saying that

          a = 10 -- is a comment to the end of the line

          and ..

          a -- is a block comment ending in -- = 10

          So both statements with result in "a" being set to 10 ?

          If this is the case then I suggest that you
          implement the commenting hilighting as per
          hkasn1.emf which has a similar scheme. This
          type of commenting caused me some real problems
          and was the only way I could get around
          the hilighting anomolies.

          Formatting comments. You can add the comment
          formatting by adding the following lines in
          the template (note that one of the lines has
          wrapped below) i.e.

          set-variable .fhook-lau.comment "|--||--|-- | --||"
          set-variable .fhook-lau.command-flag "|bo|bo|"
          set-variable .fhook-lau.command-name "|comment-restyle|comment-restyle|"
          set-variable .fhook-lau.command-nbind "|||"
          set-variable .fhook-lau.command-kbind "|esc q|esc o|"
          set-variable .fhook-lau.command-desc "|||"

          For free then you get

          C-c C-c - comment line
          C-c C-d - uncomment line


          ASIDE:

          Note that I do not really like the way that
          indent (and C++) comment modes and indent
          are not in agreement in ME on the style at the
          moment - I think we need to fix this. Consider
          the following line.

          statement = 10 -- This is a very long comment ...

          If I format the comment (M-q) then the comment
          restyle may alter the line as follows:-

          statement = 10 -- This is a very
          -- long comment

          This is what you would expect, the line has
          been wrapped and continues on the next.

          However when you re-style then the indent
          code will drag the wrapped line back i.e.

          statement = 10 -- This is a very
          -- long comment

          So I actually think that the re-style
          should align comments on consecutive lines
          unless separated by a blank line. This would
          require a new indent command, something like:-

          indent .hilight.lau a "--"

          Where tha 'a' would denote 'align' meaning that
          the <token> should be aligned with any such
          token appearing on the previous line only.

          END ASIDE:

          Some more suggested indentation modes:-

          indent .hilight.lau n "if" 4
          indent .hilight.lau n "for" 4
          ; Alignment on brackets.
          indent .hilight.lau b "(" ")"
          indent .hilight.lau b "{" "}"
          ; Ignore text in a comment.
          indent .hilight.lau i "--"
          ; Ignore tokens in strings.
          indent .hilight.lau e "\"" "\"" "\\"
          indent .hilight.lau e "'" "'" "\\'"
          indent .hilight.lau e "\\[\\[" "\\]\\]" ""

          Also conditionally add numeric hilight as per hkc.emf
          (again some of the lines below are wrapped):-

          !if &band .hilight.flags 0x08
          ; hilight constants, e.g. numbers
          hilight .hilight.c 1 "[[:digit:]]+" .scheme.constant
          hilight .hilight.c 1 "-[[:digit:]]+" .scheme.constant
          hilight .hilight.c 1 "0[xX][[:xdigit:]]+" .scheme.constant
          hilight .hilight.c 1 "[[:digit:]]+\\.[[:digit:]]+"
          .scheme.constant
          hilight .hilight.c 1 "-[[:digit:]]+\\.[[:digit:]]+"
          .scheme.constant
          hilight .hilight.c 1 "[[:digit:]]+\\.[[:digit:]]+f"
          .scheme.constant
          hilight .hilight.c 1 "-[[:digit:]]+\\.[[:digit:]]+f"
          .scheme.constant
          !endif

          >
          > Anyway, let me know what you think.

          Good stuff.

          Regards
          Jon.

          >
          > Oh, I also have their a LuaHtml template that mixes Lua and
          > HTML. I've seen some examples, but have not seen it done
          > like I've done (or as simply (that I can remember)). Maybe
          > you can comment on it as well:

          Look in file htmlcore.emf, this has some of the vb script
          indent modes for HTML, may be they are similar ? Steve
          is the expert on this stuff he will probably be able to
          comment.

          >
          > http://microemacs.cowgar.com/wiki.php/LuaHtmlLanguageTemplate
          >
          > Oh, please note, that the language parser is goofing up one
          > section of that template, the <?lua and ?> are correct if
          > you view the source... I need to do a little tweaking to
          > the PHP code that colorizes MicroEmacs's code.
          >
          > Jeremy
          >
          >
        • Jeremy Cowgar
          ... hum, if and for have then s and do s at the end of them which causes an indent. I added that code and it indented twice. if 1 == 1 then or for i=1,10 do do
          Message 4 of 7 , Dec 23, 2003
          • 0 Attachment
            Quoting Jon Green <jon@...>:
            > indent .hilight.lau n "if" 4
            > indent .hilight.lau n "for" 4

            hum, if and for have then's and do's at the end of them which causes an indent. I added
            that code and it indented twice.

            if 1 == 1 then
            or

            for i=1,10 do

            do must be an indent word, because it can be a line of it's own:

            do
            local i = 10
            i = i * b
            print(i)
            end

            What do you think?

            My question would be, what if you have something like:

            if 1 == 1 and 2 == 2 and 3 == 3 and 4 == 4
            and 5 == 5 and 6 == 6 then
            print("If is working correctly")
            end

            What it turns out looking like is:

            if 1 == 1 and 2 == 2
            and 3 == 3 then
            print("If is working correctly")
            end

            -- the rest of my code at this level.

            Any way around this?

            Jeremy
          • Jon Green
            ... If you want to indent a do at the start of a line only then you can use:- indent .hilight.lau n ^ s *do 4 ... I do not know what you have added to
            Message 5 of 7 , Dec 23, 2003
            • 0 Attachment
              Jeremy Cowgar wrote:
              > Quoting Jon Green <jon@...>:
              >
              >> indent .hilight.lau n "if" 4
              >> indent .hilight.lau n "for" 4
              >
              >
              > hum, if and for have then's and do's at the end of them which causes an indent. I added
              > that code and it indented twice.
              >
              > if 1 == 1 then
              > or
              >
              > for i=1,10 do
              >
              > do must be an indent word, because it can be a line of it's own:
              >
              > do
              > local i = 10
              > i = i * b
              > print(i)
              > end
              >
              > What do you think?

              If you want to indent a 'do' at the
              start of a line only then you can use:-

              indent .hilight.lau n "^\\s *do" 4

              >
              > My question would be, what if you have something like:
              >
              > if 1 == 1 and 2 == 2 and 3 == 3 and 4 == 4
              > and 5 == 5 and 6 == 6 then
              > print("If is working correctly")
              > end
              >
              > What it turns out looking like is:
              >
              > if 1 == 1 and 2 == 2
              > and 3 == 3 then
              > print("If is working correctly")
              > end
              >
              > -- the rest of my code at this level.
              >
              > Any way around this?
              >
              > Jeremy
              >

              I do not know what you have added to your template
              to understand what is going on here. If you can
              send me your template and some sample
              code (ideally with all of the different
              if/then/do/end/... construct forms that
              need to be supported) then I can attempt
              to help you resolve any problems that
              you have remaining. Probably
              better to Mail directly to me.

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