Recent

Author Topic: Really cool Coderush feature it would be nice to have.  (Read 5689 times)

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Really cool Coderush feature it would be nice to have.
« on: July 10, 2017, 06:19:10 pm »
A very useful CodeRush feature which would be nice to have was the ability to set the option so that a Paste operation would entirely select and replace the token where the caret is positioned. It sounds as if it would be too obtrusive but I found it to be incredibly useful and it didn't hinder my editing at all. Is there any way to achieve this using Lazarus 1.8.0 RC3 or is it a job for the CodeTools experts?
« Last Edit: July 10, 2017, 06:38:48 pm by carl_caulkett »
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: Really cool Coderush feature it would be nice to have.
« Reply #1 on: July 10, 2017, 08:41:23 pm »
You can try editor macros http://wiki.lazarus.freepascal.org/IDE_Window:_Editor_Macros

Maybe with Pascal script:
http://wiki.lazarus.freepascal.org/Editor_Macros_PascalScript

Then assign the macro to ctrl-v.
This will however NOT work for paste via the (context-)menu or mouse middle button.

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Really cool Coderush feature it would be nice to have.
« Reply #2 on: July 10, 2017, 11:07:37 pm »
Thanks, Martin. I already use keyboard macros back only in the limited sense that applied to Delphi. I hadn't really investigated the Lazarus version of Keyboard Macros, but I can see straight away that they look much more powerful. I'll check them out, and then. if I'm still stuck, I'll look at Pascal Script. I've dealt with the author Carlo Kok, in his RemObjects capacity and he's a clever boy, so I'm sure that will be good. 
« Last Edit: July 11, 2017, 01:17:15 am by carl_caulkett »
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Really cool Coderush feature it would be nice to have.
« Reply #3 on: July 10, 2017, 11:35:46 pm »
begin
ecWordLeft;
ecSelWordRight;
ecSelLeft;
ecDeleteChar;
ecPaste;
end.

OK. That works a treat - as long as the caret is already positioned at a token you want to delete/paste over. What I need now is a way of doing an If operation in the above script. If not, I guess I'm looking at Pascal Script. That looks a bit more challenging!

I have to say, just as a general observeation, I first dealt with Lazarus maybe 7 years ago, and while it was intriguing, it just wasn't sophisticated or stable enough for me. How it has changed! It's a beautiful piece of software that keeps on surprising and delighting me! Thanks Martin, and all of your fellow Lazarus/FPC colleagues.

"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Really cool Coderush feature it would be nice to have.
« Reply #4 on: July 11, 2017, 12:16:34 am »
Code: Pascal  [Select][+][-]
  1. begin
  2. if Caller.SelAvail then
  3.   begin
  4.     ecWordLeft;
  5.     ecSelWordRight;
  6.     ecSelLeft;
  7.     ecDeleteChar;
  8.     ecPaste;
  9.   end
  10. else
  11.   ecPaste;
  12. end.
  13.  

I've discovered that Pascal Script is integrated right into Editor Macros. Wow! I'm still reeling from the massive implications of this. This makes Lazarus so powerful. Now the only limitation is me and my lack of knowledge - hopefully, that will change soon!

The script above works perfectly as long as a small section of the token to be replaced is selected. I just haven't worked out how to get a boolean from Caller to tell me if the caret is sitting in a token, selected or not. I'm using the list of SynEdit properties listed on this page http://wiki.lazarus.freepascal.org/Editor_Macros_PascalScript - I'm hoping that maybe this page is slightly out of date and the latest version of Pascal Script surfaces more of the SynEdit properties and methods.
« Last Edit: July 11, 2017, 12:24:44 am by carl_caulkett »
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: Really cool Coderush feature it would be nice to have.
« Reply #5 on: July 11, 2017, 03:48:56 am »
The page is up to date.
Exposing more, well patches welcome ;)

You can use LogicalCaretXY (that is x = byte pos, easier with utf8). http://wiki.lazarus.freepascal.org/SynEdit#Logical.2FPhysical_caret_position

Then get the line (Caller.LineAtCaret or Caller.Lines[y-1]) for y, and scan in from x in both directions until you hit a space, tab or line bounds. Or if you prefer until none a-z0-9_ So ;,- are word bounds.

Or even easier (not tested)

Code: Pascal  [Select][+][-]
  1. Caller.SelectWord;
  2. ecDeleteChar;
  3. ecPaste;
  4.  
Afaik select word will also find the next word if you are the middle of some spaces...
But keep the old x pos and compare against BlockBegin.x

not tested, but something like:
Code: Pascal  [Select][+][-]
  1. var x: integer
  2. begin
  3.   x := Caller.LogicalCaretX;
  4.   Caller.SelectWord;
  5.   if x >= caller.BlockBegin.x then begin
  6.     ecDeleteChar;
  7.     ecPaste;
  8.   end;
  9. end;
  10.  
« Last Edit: July 11, 2017, 03:51:45 am by Martin_fr »

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Really cool Coderush feature it would be nice to have.
« Reply #6 on: July 11, 2017, 02:27:23 pm »
Lazarus 1.8.0 RC3
macOS 10.12.5

Code: Pascal  [Select][+][-]
  1. var
  2.   x: Integer;
  3. begin
  4.   x := Caller.LogicalCaretX;
  5.   Caller.SelectWord;
  6.   if x >= caller.BlockBegin.x then
  7.     ecDeleteChar;
  8.   ecPaste;
  9. end;
  10.  

OK. I've tweaked this slightly but for some reason, I'm getting an access violation when I try to save the buffer. This is consistent, even after restarting Lazarus.
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: Really cool Coderush feature it would be nice to have.
« Reply #7 on: July 11, 2017, 04:49:42 pm »
1) I cant reproduce the crash. Do you get a stacktrace?
- try running the ide: lazarus.exe --debug-log=c:\logfile.txt
- or try opening ide/lazarus.lpi and run in debugger.

2)
I found a few issues.
Code: Pascal  [Select][+][-]
  1. var
  2.   x: Integer;
  3.   p:Tpoint;
  4. begin
  5.       x := Caller.LogicalCaretX;
  6.       Caller.SelectWord;
  7.       p:=caller.BlockBegin;
  8.       if x >= p.x then
  9.         ecDeleteChar;
  10.       ecPaste;
  11. end.
  12.  

for some reason caller.BlockBegin.x did not compile (its an older version of pascalscript)
 
and the end on the last line needed to be "end." not "end;".

Then the "if" for ecDelete only matters if your options exclude "overwrite selection", otherwise the paste will replace the selection.
Code: Pascal  [Select][+][-]
  1. var
  2.   x: Integer;
  3.   p:Tpoint;
  4. begin
  5.       x := Caller.LogicalCaretX;
  6.       Caller.SelectWord;
  7.       p:=caller.BlockBegin;
  8.       if x < p.x then
  9.         Caller.LogicalCaretX := x; // undo select
  10.       ecPaste;
  11. end.
  12.  

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Really cool Coderush feature it would be nice to have.
« Reply #8 on: July 11, 2017, 05:48:09 pm »
How do I get the log file on an Apple Mac?
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Really cool Coderush feature it would be nice to have.
« Reply #9 on: July 11, 2017, 06:12:40 pm »
I've tried going to my /Applications folder at the command line and entering open lazarus.app --debug-log=~/lazarus.txt but nothing happen, although open lazarus.app by itself runs Lazarus just fine.
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: Really cool Coderush feature it would be nice to have.
« Reply #10 on: July 11, 2017, 09:55:07 pm »
How do I get the log file on an Apple Mac?
http://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#Log_info_for_debug_session

Ignore the --debug-enable on that wiki page, just --debug-log=

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Really cool Coderush feature it would be nice to have.
« Reply #11 on: July 11, 2017, 10:39:43 pm »
I was able to launch Lazarus from the command line with lazarus.app/Contents/MacOS/lazarus --debug-log=~/laz.log

The laz.log file is attached. Duplicate lines snipped -8<-

"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: Really cool Coderush feature it would be nice to have.
« Reply #12 on: July 12, 2017, 12:19:54 am »
Thanks.
Unfortunately it has no line info. (The IDE needs to be recompiled with -gl enabled / or -gs or -gw)

Anyway, it is likely due to the older version of p-script.
If you can still get the error after adding line info, then I can see if it is p-script or something else.
But no hassle.

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 306
Re: Really cool Coderush feature it would be nice to have.
« Reply #13 on: July 12, 2017, 12:45:19 am »
I tried putting -gl in the Options memo field in "Tools" -> "Build Lazarus with Profile: Normal IDE" but it didn't seem to add any line number info to the log file. It's getting late and I'm tired so it can wait until tomorrow morning. Thanks for your help, so far, Martin!
"It builds... ship it!"

Mac Mini M1
macOS 13.6 Ventura
Lazarus 2.2.6 (release version)
FPC 3.2.2 (release version)

 

TinyPortal © 2005-2018