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

Commenting Problem w/Icon mode

Expand Messages
  • Jeremy Cowgar
    I have been using my Icon mode for a few days now and it s working very well, indenting properly all around. I have one last thing I would like to implement
    Message 1 of 3 , Nov 29, 2006
    • 0 Attachment
      I have been using my Icon mode for a few days now and it's working
      very well, indenting properly all around. I have one last thing I
      would like to implement and along with that a problem.

      I would like the continuation of comments like in the C mode, but I
      cannot seem to make it work. There are no block comments in Icon.
      Only line comments, they are the # character. So, when I type:

      ##

      I would like it to begin a comment block for me and continue to
      comment with "# " like the C comments continue with " * ".

      Now, the current problem I am having with comments (aside from the
      above) is when I use C-c C-c to comment out a line, the comment
      always begins on Column 1. i.e.

      if 1 then {
      write("Hello") | {
      @@write("Hello did not work
      }
      }

      If at the @@ I press C-c C-c I will get:

      if 1 then {
      write("Hello") | {
      # write("Hello did not work
      }
      }

      I would like to have:

      if 1 then {
      write("Hello") | {
      # write("Hello did not work
      }
      }

      Any help on these two issues would be greatly appriciated. I have
      placed my hkicon.emf file on the net so others can view and tell me
      maybe what I am doing wrong.

      http://jeremy.cowgar.com/files/hkicon.emf

      Jeremy
    • Jon Green
      ... For single line comments it does not work like this i.e. when you do // on C++ (or even C). What I normally do is to carry on typing and when it wants to
      Message 2 of 3 , Nov 30, 2006
      • 0 Attachment
        Jeremy Cowgar wrote:
        > I have been using my Icon mode for a few days now and it's working
        > very well, indenting properly all around. I have one last thing I
        > would like to implement and along with that a problem.
        >
        > I would like the continuation of comments like in the C mode, but I
        > cannot seem to make it work. There are no block comments in Icon.
        > Only line comments, they are the # character. So, when I type:
        >
        > ##
        >
        > I would like it to begin a comment block for me and continue to
        > comment with "# " like the C comments continue with " * ".
        >

        For single line comments it does not work like this i.e. when you do //
        on C++ (or even C). What I normally do is to carry on typing and when it
        wants to wrap (i.e. starts to scroll horizontally) then do a quick esc-o
        to reformat the comment and then carry on typing,


        > Now, the current problem I am having with comments (aside from the
        > above) is when I use C-c C-c to comment out a line, the comment
        > always begins on Column 1. i.e.
        >
        > if 1 then {
        > write("Hello") | {
        > @@write("Hello did not work
        > }
        > }
        >
        > If at the @@ I press C-c C-c I will get:
        >
        > if 1 then {
        > write("Hello") | {
        > # write("Hello did not work
        > }
        > }
        >
        > I would like to have:
        >
        > if 1 then {
        > write("Hello") | {
        > # write("Hello did not work
        > }
        > }
        >
        > Any help on these two issues would be greatly appriciated. I have
        > placed my hkicon.emf file on the net so others can view and tell me
        > maybe what I am doing wrong.

        For your icon template then define your own comment-line macro and then
        you need to over-ride the default comment handling i.e

        First you need to make sure that the standard comment template is loaded.

        ; Make sure that the comment definitions are loaded before we define our own
        ; comment line handling because we want to use the standard comment
        ; definitions set up by buffer-init.
        !if ¬ &exi "comment-get-def"
        !force exec-file "comment"
        !endif


        Then set up you buffer command over-rides i.e. in the following example
        I have added the key binding C-c C-c at command-3 to execute our own
        icon macro to handle the line commenting. If you have no special
        commands then you will only define a command-0 entry with the comment
        line entry.

        set-variable .fhook-hkt.command-0
        "|th||expand-abbrev-handle|A-q|Complete co\Hmmand|"
        set-variable .fhook-hkt.command-1 "|thbo||hkt-quote-command|A-q|Complete
        co\Hmmand|"
        set-variable .fhook-hkt.command-2 "|b||hkt-quote-command|C-c C-q|\HQuote
        command|"
        set-variable .fhook-hkt.command-3 "|b||icon-comment-line|C-c C-c|Comment
        \HLine|"


        Then take the standard comment-line macro and modify it a bit for
        insertion at the first valid character. Call it something different
        specific to the template.

        ; comment line ie xxx -> <comment start>xxx
        ; or xxx -> <comment start>xxx<comment end>
        ; Redefined so the comment is placed at the correct indent.
        define-macro icon-comment-line
        0 comment-get-def
        set-variable #l1 &lget #l9 1
        set-variable #l2 &trl &lget #l9 2
        beginning-of-line
        !while &gre &pdec @# 1 0
        ; Find the first non-white space of the line.
        !if &sin @wc " \t\n" ; NEW
        forward-char ; NEW
        !jump -2 ; NEW
        !endif ; NEW
        insert-string #l1
        !if ¬ &seq #l2 ""
        end-of-line
        insert-string #l2
        !endif
        beginning-of-line
        forward-line
        !done
        !emacro

        I have used !jump here because I cannot use a nested !while. !jump is a
        dirty relative !goto and -2 is backward 2 lines.

        If you wanted to over-ride the behaviour of the comment-line macro for
        all files then you would do the following in your user.emf:

        First you need to make sure that the standard comment template is loaded.

        ; Make sure that the comment definitions are loaded before we define our own
        ; comment line handling because we want to use the standard comment
        ; definitions set up by buffer-init.
        !if ¬ &exi "comment-get-def"
        !force exec-file "comment"
        !endif

        This would force line-comment to be defined, you would now redefine the
        macro globally and it would be used in preference to the system one.
        This is the same as above except we have called it by the same name as
        the system wide one.

        ; comment line ie xxx -> <comment start>xxx
        ; or xxx -> <comment start>xxx<comment end>
        ; Redefined so the comment is placed at the correct indent.
        define-macro comment-line
        0 comment-get-def
        set-variable #l1 &lget #l9 1
        set-variable #l2 &trl &lget #l9 2
        beginning-of-line
        !while &gre &pdec @# 1 0
        ; Find the first non-white space of the line.
        !if &sin @wc " \t\n" ; NEW
        forward-char ; NEW
        !jump -2 ; NEW
        !endif ; NEW
        insert-string #l1
        !if ¬ &seq #l2 ""
        end-of-line
        insert-string #l2
        !endif
        beginning-of-line
        forward-line
        !done
        !emacro

        The other way of doing this is to copy comment.emf to your user area and
        then modify it - either way will work.

        Hope that helps
        Jon,


        >
        > http://jeremy.cowgar.com/files/hkicon.emf
        >
        > Jeremy
        >
        >
        >
        > __________________________________________________________________________
        >
        > This is an unmoderated list. JASSPA is not responsible for the content of
        > any material posted to this list.
        >
        > To unsubscribe, send a mail message to
        >
        > mailto:jasspa-unsubscribe@yahoogroups.com
        >
        > or visit http://groups.yahoo.com/group/jasspa and
        > modify your account settings manually.
        >
        >
        >
        > Yahoo! Groups Links
        >
        >
        >
        >
      • Jeremy Cowgar
        ... Jon, The problem I see with this solution is that the problem is not specific to my Icon mode I have found. It does it in C also. i.e. if (1=1) { if (2=2)
        Message 3 of 3 , Nov 30, 2006
        • 0 Attachment
          > For your icon template then define your own comment-line macro and
          > then
          > you need to over-ride the default comment handling i.e

          Jon,

          The problem I see with this solution is that the problem is not
          specific to my Icon mode I have found. It does it in C also. i.e.

          if (1=1) {
          if (2=2) {
          @@printf("HELLO");
          }
          }

          When at the @@ line, I do C-c C-c, I get:

          if (1=1) {
          if (2=2) {
          /* printf("HELLO"); */
          }
          }

          Then, when I restyle the buffer:

          if (1=1) {
          if (2=2) {
          /* printf("HELLO"); */
          }
          }

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