SlickEdit Community

SlickEdit Product Discussion => SlickEdit® => SlickEdit User Macros => Topic started by: ewendt on November 13, 2014, 11:38:13 PM

Title: suggestion for modification of 'codehelp.e' to change '.' automatically to '->' (SE 19, 2014)
Post by: ewendt on November 13, 2014, 11:38:13 PM
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
         //////////////////////////////////////////////////////////////////////////////////////////////////
Title: Re: suggestion for modification of 'codehelp.e' (SE 19, 2014)
Post by: ewendt 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
Title: Re: suggestion for modification of 'codehelp.e' to change '.' automatically to '->' (SE 19, 2014)
Post by: hs2 on November 15, 2014, 12:05:10 PM
@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
Title: Re: suggestion for modification of 'codehelp.e' to change '.' automatically to '->' (SE 19, 2014)
Post by: flethuseo on December 01, 2014, 04:59:03 PM
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