Author Topic: suggestion for modification of 'codehelp.e' to change '.' automatically to '->' (SE 19, 2014)  (Read 2622 times)

ewendt

  • Community Member
  • Posts: 42
  • Hero Points: 2
This is not very deep tested. Just a quick hack to add a feature.

While writing C/C++, sometimes it is convenient after typing the name of a pointer not to type "->" but a simple "." and SE will change this to "->" - if it is clear, that the variable is a pointer.

The module codehelp.e can be changed to support this feature. Beneath is a first proposal for additional code.

The modified module is attached to this post.

I know, modifying product modules is not very polite. So take my excuse, this is just to proof, that it is probably easy to add.



         //////////////////////////////////////////////////////////////////////////////////////////////////
         //since 2014-11-13 ewendt : replace operator . with -> if . is used on a pointer to a struct
         //
         // This is useful for C/C++.
         // while typing a '.' after the name of a pointer the operator triggers list_symbols(), which
         // calls _do_list_members() which will test for members and do find that a pointer can not
         // access members via '.'. An error msg is constructed for this. At this point the error message is
         // tested for the the format string index and operator for this special condition and the '.'
         // operator ist changed to '->'. list_symbols() ist called (recursive) to list the members
         // the pointer have access to.
         //
         // This works for example for code like this
         //
         //   struct S { int a,b; }
         //   S s;
         //   S *ps;
         //   int *i;
         //
         // Try typing
         //     s.
         //     ps.                             <- the operator should be replaced with '->'
         //     i.
         //
         // If the symbol can not be resoveld, another error msg is used and the operator remains unchanged.
         // 
         //--------------------------------------------------------------------------------------------------
         //
         //     This is to place in codehelp.e (SlickEdit 2014 Version 19.0.0.14) in function
         //     '_do_list_members(..)' after line 3701 :
         //   3686:       do {
         //   3687:          status = AutoCompleteUpdateInfo(true,
         //    ...
         //   3700:        if (status < 0) {
         //   3701:            msg := _CodeHelpRC(status, errorArgs);
         //
         //--------------------------------------------------------------------------------------------------
         //
         //- say(msg);
         //
         // testing for status text "Attempt to use operator '.', but variable '<VARIABLE>' is a pointer"
         if (status == -4607) {             // format string
            if (errorArgs._length()==3) {   // correct count of args
               if (errorArgs[1] == '.') {   // and the operator arg holds the '.'
                  //in this case, the operator can be changed from '.' to '->'
                  //- say("replace operator '.' with '->'");
                  left();
                  _delete_char();
                  _insert_text("->");
                  list_symbols();           // yes, recursiv, sorry - but now the members are listed
               }
            }
         }
         //end of since 2014-11-13
         //////////////////////////////////////////////////////////////////////////////////////////////////
« Last Edit: November 15, 2014, 09:36:07 am by ewendt »

ewendt

  • Community Member
  • Posts: 42
  • Hero Points: 2
Re: suggestion for modification of 'codehelp.e' (SE 19, 2014)
« Reply #1 on: November 14, 2014, 10:36:42 am »
seems to work better

check modified lines with tag "since 2014-11-14"

catches two different errors via status value now

this is just a demonstration

hs2

  • Senior Community Member
  • Posts: 2735
  • Hero Points: 287
@ewendt
Just a minor change/extension proposal:
Code: [Select]
         if ( (status == VSCODEHELPRC_DOT_FOR_POINTER) && (errorArgs._length() == 3) && (errorArgs[1] == '.') )
         {
            // change '.' to '->'
            _rubout();
            _insert_text("->");
         }
         else if ( (status == VSCODEHELPRC_DASHGREATER_FOR_NON_POINTER) && (errorArgs._length() == 3) && (errorArgs[1] == '->') )
         {
            // change '->' to '.'
            _rubout();_rubout();
            _insert_text(".");
         }
Thanks for sharing this nice patch !
HS2

flethuseo

  • Senior Community Member
  • Posts: 177
  • Hero Points: 2
Nice, VSAssistX uses this feature too.

I also noticed that the list_symbols() call at the end of the original code will cause an error "recursion too deep" (something like that); when I attempt to do something like:

object.member.member
« Last Edit: July 06, 2015, 05:20:20 pm by flethuseo »