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

Annoying bug in C/C++ mode

Expand Messages
  • salmankhilji
    I am using the default c/c++ tab/indentation style in ME. The indentation for a block of code from previous one is set to 4 spaces. Using ME, I can t seem to
    Message 1 of 6 , Mar 24, 2004
    • 0 Attachment
      I am using the default c/c++ tab/indentation style in ME. The
      indentation for a block of code from previous one is set to 4 spaces.
      Using ME, I can't seem to be able to edit someone else's code easily.
      Frequently, other people use different # of spaces for indenting
      blocks of code than what my ME does by default. When all want to do
      is edit one line in someone else's code, ME insists on using its own
      indentation style screwing up the exising one. For example, consider
      this:

      for(i=0; i<4; i++) {
      junk = foo;
      test = lab;
      }

      This is existing code and I wnat to add a line of code after 'junk'
      and before 'test'. The way I do is go after 'foo;' and hit return to
      make room for a new line. Then I would add my new line after foo.l

      As soon as I hi ENTER, the indentation on 'junk' line changes and ME
      adds two spaces before that. It looks like this:

      for(i=0; i<4; i++) {
      junk = foo;
      <cursor_position>
      test = lab;
      }


      I would like me to detect the current style by examining some fixed #
      of lines of code in the current context. Then ME should preserve and
      respect existing style. Without this, the user would have to manually
      set the # of indentation spaces to 2 from a default of 4.

      Right now, I am using XEmacs for this purpose because it does seem to
      be smarter than ME in this respect.

      BTW, can someone please tell me how to change my indentation
      preferences to 2 spaces? I tried to d this a long time ago by going
      thru documentation and online help and setting the value of a variable
      to 4, only to find out that I messed up something else.

      Salman
    • Jon Green
      ... As you are using electric c mode then you need to set $c-brace = -2 $c-case = -2 $c-statement = 2 You could write a macro c-indent to set all of these in
      Message 2 of 6 , Mar 24, 2004
      • 0 Attachment
        salmankhilji wrote:
        > I am using the default c/c++ tab/indentation style in ME. The
        > indentation for a block of code from previous one is set to 4 spaces.
        > Using ME, I can't seem to be able to edit someone else's code easily.
        > Frequently, other people use different # of spaces for indenting
        > blocks of code than what my ME does by default. When all want to do
        > is edit one line in someone else's code, ME insists on using its own
        > indentation style screwing up the exising one. For example, consider
        > this:
        >
        > for(i=0; i<4; i++) {
        > junk = foo;
        > test = lab;
        > }
        >
        > This is existing code and I wnat to add a line of code after 'junk'
        > and before 'test'. The way I do is go after 'foo;' and hit return to
        > make room for a new line. Then I would add my new line after foo.l
        >
        > As soon as I hi ENTER, the indentation on 'junk' line changes and ME
        > adds two spaces before that. It looks like this:
        >
        > for(i=0; i<4; i++) {
        > junk = foo;
        > <cursor_position>
        > test = lab;
        > }
        >
        >
        > I would like me to detect the current style by examining some fixed #
        > of lines of code in the current context. Then ME should preserve and
        > respect existing style. Without this, the user would have to manually
        > set the # of indentation spaces to 2 from a default of 4.
        >
        > Right now, I am using XEmacs for this purpose because it does seem to
        > be smarter than ME in this respect.
        >
        > BTW, can someone please tell me how to change my indentation
        > preferences to 2 spaces? I tried to d this a long time ago by going
        > thru documentation and online help and setting the value of a variable
        > to 4, only to find out that I messed up something else.

        As you are using electric c mode then you need to set

        $c-brace = -2
        $c-case = -2
        $c-statement = 2

        You could write a macro "c-indent" to set all of these in
        one go.

        However these are global variables and not buffer
        variables so changing to another buffer with another
        indentation will mean that this is incorrect. To
        fix properly then the b/ehook needs to be set up
        for 'C' (As example see docutl.emf for $fill-mode
        and $fill-col handling).

        All of the correct processing could be performed in
        your myc.emf. In the fhook you determine and initialise
        the indentation. In the b/ehook's you swap in and out the
        $c-xxx variables for your buffer settings.

        Having explained all of that it is actually quite easy.
        Hardest bit will be to determine the indentation. This
        is not all that hard either once you have found an
        opening or closing brace and have a snoop around the
        adjacent lines to detemine the indentation of the leading
        white space.

        Regards
        Jon.

        >
        > Salman
        >
      • Jon Green
        ... Attached is a starting point for you. Fairly simple, the hardest part is to determine the correct indentation. Need to do some more work to confirm the
        Message 3 of 6 , Mar 24, 2004
        • 0 Attachment
          salmankhilji wrote:
          > I am using the default c/c++ tab/indentation style in ME. The
          > indentation for a block of code from previous one is set to 4 spaces.
          > Using ME, I can't seem to be able to edit someone else's code easily.
          > Frequently, other people use different # of spaces for indenting
          > blocks of code than what my ME does by default. When all want to do
          > is edit one line in someone else's code, ME insists on using its own
          > indentation style screwing up the exising one. For example, consider
          > this:
          >
          > for(i=0; i<4; i++) {
          > junk = foo;
          > test = lab;
          > }
          >
          > This is existing code and I wnat to add a line of code after 'junk'
          > and before 'test'. The way I do is go after 'foo;' and hit return to
          > make room for a new line. Then I would add my new line after foo.l
          >
          > As soon as I hi ENTER, the indentation on 'junk' line changes and ME
          > adds two spaces before that. It looks like this:
          >
          > for(i=0; i<4; i++) {
          > junk = foo;
          > <cursor_position>
          > test = lab;
          > }
          >
          >
          > I would like me to detect the current style by examining some fixed #
          > of lines of code in the current context. Then ME should preserve and
          > respect existing style. Without this, the user would have to manually
          > set the # of indentation spaces to 2 from a default of 4.
          >
          > Right now, I am using XEmacs for this purpose because it does seem to
          > be smarter than ME in this respect.
          >
          > BTW, can someone please tell me how to change my indentation
          > preferences to 2 spaces? I tried to d this a long time ago by going
          > thru documentation and online help and setting the value of a variable
          > to 4, only to find out that I messed up something else.
          >
          > Salman
          >
          >

          Attached is a starting point for you. Fairly simple, the hardest
          part is to determine the correct indentation. Need to do some
          more work to confirm the correct indentation, also should
          consider literal TABs with non-standard tab width.

          Simply add myc.emf to your local user directory and should
          detect tab settings. I have spent less than 1/2 hour on this
          and have not covered the finer points. Seems to do what you
          want.

          Jon.
        • salmankhilji
          ... This did not work for me. I copied the contents to /home/salman/.jasspa/myc.emf. After not having luck with it, I started me, loaded myc.emf and did an
          Message 4 of 6 , Mar 29, 2004
          • 0 Attachment
            --- In jasspa@yahoogroups.com, Jon Green <jon@j...> wrote:
            >
            > Attached is a starting point for you. Fairly simple, the hardest
            > part is to determine the correct indentation. Need to do some
            > more work to confirm the correct indentation, also should
            > consider literal TABs with non-standard tab width.
            >
            > Simply add myc.emf to your local user directory and should
            > detect tab settings. I have spent less than 1/2 hour on this
            > and have not covered the finer points. Seems to do what you
            > want.
            >


            This did not work for me. I copied the contents to
            /home/salman/.jasspa/myc.emf. After not having luck with it, I
            started me, loaded myc.emf and did an 'execute-buffer' on it. Then I
            loaded a .c file and I still had problem with it.

            Could you please do me a favor? Could you please download the
            freetype project (www.freetype.org) and look at a file named
            /home/salman/Downloads/freetype2/include/freetype/freetype.h

            Go to line 210 in freetype.h. Now pretend that you are going to add
            more members to ths FT_Glyph_Metrics_ struct. For this, position your
            cursor after the line that says:

            FT_Pos horiAdvance; /* advance width for horizontal layout */

            and hit return to make room for the new line.

            You will see that me in its current state does not allow one to work
            on the FreeType project unless you turn off the auto-indent features
            completely (which I don't know how)

            I don't quite like this programming style, but I certainly don't want
            to change it for a few lines of code that I am adding to it. If I had
            this option, I would reformat the entire buffer and me would be happy.

            If you can find a fix for it, please try a few .c files from the
            project as well and see if ME can be used to edit FreeType source.

            Salman
          • Jon Green
            ... OK the problem is that the statements are indented here even though they are at the topmost level. The easiset way to edit it is to turn of cmode . Simply
            Message 5 of 6 , Mar 29, 2004
            • 0 Attachment
              salmankhilji wrote:

              > --- In jasspa@yahoogroups.com, Jon Green <jon@j...> wrote:
              >
              >>Attached is a starting point for you. Fairly simple, the hardest
              >>part is to determine the correct indentation. Need to do some
              >>more work to confirm the correct indentation, also should
              >>consider literal TABs with non-standard tab width.
              >>
              >>Simply add myc.emf to your local user directory and should
              >>detect tab settings. I have spent less than 1/2 hour on this
              >>and have not covered the finer points. Seems to do what you
              >>want.
              >>
              >
              >
              >
              > This did not work for me. I copied the contents to
              > /home/salman/.jasspa/myc.emf. After not having luck with it, I
              > started me, loaded myc.emf and did an 'execute-buffer' on it. Then I
              > loaded a .c file and I still had problem with it.
              >
              > Could you please do me a favor? Could you please download the
              > freetype project (www.freetype.org) and look at a file named
              > /home/salman/Downloads/freetype2/include/freetype/freetype.h
              >
              > Go to line 210 in freetype.h. Now pretend that you are going to add
              > more members to ths FT_Glyph_Metrics_ struct. For this, position your
              > cursor after the line that says:
              >
              > FT_Pos horiAdvance; /* advance width for horizontal layout */
              >
              > and hit return to make room for the new line.
              >
              > You will see that me in its current state does not allow one to work
              > on the FreeType project unless you turn off the auto-indent features
              > completely (which I don't know how)
              >
              > I don't quite like this programming style, but I certainly don't want
              > to change it for a few lines of code that I am adding to it. If I had
              > this option, I would reformat the entire buffer and me would be happy.
              >

              OK the problem is that the statements are indented here
              even though they are at the topmost level.

              The easiset way to edit it is to turn of "cmode". Simply
              right click on the mode line -> Buffer Modes and disable
              "cmode". There is no auto indentation but it works OK
              and does not mess up.

              If you are doing a lot of editing on these files then
              turn off cmode in a myc-fhook.

              Jon.

              > If you can find a fix for it, please try a few .c files from the
              > project as well and see if ME can be used to edit FreeType source.
              >
              > Salman
              >
              >
              >
              > __________________________________________________________________________
              >
              > 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
              >
              >
              >
              >
              >
              >
            • Phillips, Steven
              ... Or use buffer-setup and disable Setup Auto Indent Steve
              Message 6 of 6 , Mar 29, 2004
              • 0 Attachment
                > If you are doing a lot of editing on these files then
                > turn off cmode in a myc-fhook.

                Or use buffer-setup and disable 'Setup Auto Indent'

                Steve

                >
                > Jon.
                >
                > > If you can find a fix for it, please try a few .c files from the
                > > project as well and see if ME can be used to edit FreeType source.
                > >
                > > Salman
                > >
                > >
                > >
                > >
                > ______________________________________________________________
                > ____________
                > >
                > > 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
                > >
                > >
                > >
                > >
                > >
                > >
                >
                >
                >
                >
                > ______________________________________________________________
                > ____________
                >
                > 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
                >
                >
                >
                >
                >
                >
              Your message has been successfully submitted and would be delivered to recipients shortly.