Author Topic: How to auto replace . with -> after pointers in C?  (Read 2870 times)

wt11yn

  • Junior Community Member
  • Posts: 7
  • Hero Points: 0
How to auto replace . with -> after pointers in C?
« on: August 01, 2016, 09:17:13 am »
In C/C++ file, after I typed a "." after an object or struct pointer, how to auto replace the "." with "->"?
Thanks!

Tim Kemp

  • Senior Community Member
  • Posts: 537
  • Hero Points: 91
Re: How to auto replace . with -> after pointers in C?
« Reply #1 on: August 01, 2016, 10:52:25 am »
In the Find and Replace dialog, use Match color->Other.

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 3396
  • Hero Points: 465
Re: How to auto replace . with -> after pointers in C?
« Reply #2 on: August 01, 2016, 04:11:29 pm »
I think what you are asking for is this:

Code: [Select]
struct Duck {
   void quack();
   void waddle();
};
void life(Duck *d) {
   d.      // you want "d." to be transformed to "d->"
}

We do not support this, and it has more to do with C++ than it has to do with the technical details for auto-correcting . vs -> in code.  It has to do with C++ preprocessing, overloaded operations, and smart pointers.  The combination of those, especially preprocessing, makes it impossible to be 100% certain that a . was supposed to be a ->

So, if we did the transformation, then there would be cases were we change a . to a -> and you'd have to hit undo to get what you actually typed.

I will add your feature request to our tracking.  It is still a valid one, especially if you write clean code and don't utilize preprocessing ugliness all over and don't use Boost.  I understand the frustration, it would be a time-saver.

Tim Kemp

  • Senior Community Member
  • Posts: 537
  • Hero Points: 91
Re: How to auto replace . with -> after pointers in C?
« Reply #3 on: August 01, 2016, 04:16:38 pm »
Dennis, I realize it probably isn't a solution in all cases, but using the Other color worked in all of the files I tried it in.

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 3396
  • Hero Points: 465
Re: How to auto replace . with -> after pointers in C?
« Reply #4 on: August 01, 2016, 04:22:45 pm »
@Tim, your solution works, but I think the OP was looking for SlickEdit to do a smart, automated replacement.

Tim Kemp

  • Senior Community Member
  • Posts: 537
  • Hero Points: 91
Re: How to auto replace . with -> after pointers in C?
« Reply #5 on: August 01, 2016, 09:30:22 pm »
Smart and automated would be nice, but just getting tools to automate things so I don't have to manually do them is usually good enough for me. That's why I use keyboard macros so much: I'm lazy.

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 3396
  • Hero Points: 465
Re: How to auto replace . with -> after pointers in C?
« Reply #6 on: August 01, 2016, 10:35:59 pm »
It was quick to implement, so I put the option in for beta3.  It is off by default, but can be enabled through Document > C/C++ Options... > C/C++ Parsing Options.

wt11yn

  • Junior Community Member
  • Posts: 7
  • Hero Points: 0
Re: How to auto replace . with -> after pointers in C?
« Reply #7 on: August 02, 2016, 12:22:21 am »
Thank you, Dennis and Tim .
It's exactly what I mean. I do want SE replace "." with "->" by itself, instead of by myself.
Hope for your beta3!

hs2

  • Senior Community Member
  • Posts: 2752
  • Hero Points: 291
Re: How to auto replace . with -> after pointers in C?
« Reply #8 on: August 02, 2016, 07:05:45 am »
@Dennis: Vey nice enhancement ++ I'm looking fwd. to remove a 'list-symbols' patch (hack) to do so interactively.
I guess the tagging engine has a much, much harder job nowadays with modern C++ e.g. due to 'auto' :o
Good luck finding a good way to catch up :)
HS2