Really cool Coderush feature it would be nice to have. lazarus / 9-Editor ---------------------------------------------------------------------- carl_caulkett · 2017-07-10 16:19 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? ---------------------------------------------------------------------- Martin_fr · 2017-07-10 18:41 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 · 2017-07-10 21:07 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. ---------------------------------------------------------------------- carl_caulkett · 2017-07-10 21:35 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. ---------------------------------------------------------------------- carl_caulkett · 2017-07-10 22:16 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i beginif Caller.SelAvail then  begin    ecWordLeft;    ecSelWordRight;    ecSelLeft;    ecDeleteChar;    ecPaste;  endelse  ecPaste;end. 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. ---------------------------------------------------------------------- Martin_fr · 2017-07-11 01:48 The page is up to date. Exposing more, well patches welcome You can use LogicalCaretXY (that is x = byte pos, easier with utf8). h ttp://wiki.lazarus.freepascal.org/SynEdit#Logical.2FPhysical_caret_pos ition 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Caller.SelectWord;ecDeleteChar;ecPaste; 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var x: integerbegin  x := Caller.LogicalCaretX;   Caller.SelectWord;  if x >= caller.BlockBegin.x then begin    ecDeleteChar;    ecPaste;  end;end; ---------------------------------------------------------------------- carl_caulkett · 2017-07-11 12:27 Lazarus 1.8.0 RC3 macOS 10.12.5 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  x: Integer;begin  x := Caller.LogicalCaretX;  Caller.SelectWord;  if x >= caller.BlockBegin.x then    ecDeleteChar;  ecPaste;end; 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. ---------------------------------------------------------------------- Martin_fr · 2017-07-11 14:49 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  x: Integer;  p:Tpoint;begin      x := Caller.LogicalCaretX;      Caller.SelectWord;      p:=caller.BlockBegin;      if x >= p.x then      ecDeleteChar;      ecPaste;end.  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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  x: Integer;  p:Tpoint;begin      x := Caller.LogicalCaretX;      Caller.SelectWord;      p:=caller.BlockBegin;      if x < p.x then      Caller.LogicalCaretX := x; // undo select      ecPaste;end. ---------------------------------------------------------------------- carl_caulkett · 2017-07-11 15:48 How do I get the log file on an Apple Mac? ---------------------------------------------------------------------- carl_caulkett · 2017-07-11 16:12 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. ---------------------------------------------------------------------- Martin_fr · 2017-07-11 19:55 Quote from: carl_caulkett on July 11, 2017, 05:48:09 pmHow do I get the log file on an Apple Mac? http://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#Log_info_for_debu g_session Ignore the --debug-enable on that wiki page, just --debug-log= ---------------------------------------------------------------------- carl_caulkett · 2017-07-11 20:39 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<- ---------------------------------------------------------------------- Martin_fr · 2017-07-11 22:19 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 · 2017-07-11 22:45 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!