Lazarus

Using the Lazarus IDE => Editor => Topic started by: BosseB on February 15, 2020, 08:41:14 am

Title: Pasting line of code indents, why?
Post by: BosseB on February 15, 2020, 08:41:14 am
I want to paste a line,which should be at the left edge of the code window.
But when I paste it Lazarus indents the line no matter how I do it, and it will indent to a far right position, why?
And is there a possibility to change this?

I am on Raspberry Pi 4 with a fully updated Raspbian Buster operating system.
FPC 3.0.4 and Lazarus 2.0.6 both built from sources checked out on the release tags.

Title: Re: Pasting line of code indents, why?
Post by: Thaddy on February 15, 2020, 08:53:47 am
I can not reproduce this (tested on a RPi3 and a RPi4, Laz trunk 2.1 r62630, FPC Trunk r44177, Buster up-to-date)
Is it just one copy/paste from a particular string or does it always behave like that with any copy/paste?
Title: Re: Pasting line of code indents, why?
Post by: BosseB on February 15, 2020, 09:59:43 am
OK, let me exemplify, the example is pretty daft code-wise but shows the unwanted indentation:
I have a section of code looking like this:
Code: Pascal  [Select][+][-]
  1. begin
  2.   Result := false;
  3.   try
  4.     sCmdDir := ReadIniString('configuration', 'cmddir', '/monitorctrl/cmd', sCnfFile);
  5.     FL.Clear;
  6.     if DirectoryExists(sCmdDir) then
  7.     begin
  8.       //Now list the files in the cmd dir with extension .cmd
  9.       slCmdFiles := TStringList.Create;
  10.  
Now I want to paste a line containing a debug variable (deb_pos := 3;) into the code further down, so I select the line and Ctrl-C then place the cursor at the left margin of where I want to insert the line and Ctrl-V to paste it. I want it to be in the left margin so it easier to see when it is finally going to be removed...
But now the result looks like this:
Code: Pascal  [Select][+][-]
  1. begin
  2.   Result := false;
  3.   try
  4.     sCmdDir := ReadIniString('configuration', 'cmddir', '/monitorctrl/cmd', sCnfFile);
  5.     FL.Clear;
  6.     if DirectoryExists(sCmdDir) then
  7.     begin
  8.       //Now list the files in the cmd dir with extension .cmd
  9.       deb_pos := 3;
  10.       slCmdFiles := TStringList.Create;
  11.  
It should have looked like this:
Code: Pascal  [Select][+][-]
  1. begin
  2.   Result := false;
  3.   try
  4.     sCmdDir := ReadIniString('configuration', 'cmddir', '/monitorctrl/cmd', sCnfFile);
  5.     FL.Clear;
  6.     if DirectoryExists(sCmdDir) then
  7.     begin
  8.       //Now list the files in the cmd dir with extension .cmd
  9. deb_pos := 3;
  10.       slCmdFiles := TStringList.Create;
  11.  
In other cases with more complex statements and where I want to add something non-indented it is pushed right a long way.
And when I want to back it out using backspace key it just moves one position at a time rather than moving left by a tab size or even to the start position of the previous line...
In Delphi this worked a lot more "naturally".
I assume there is a CodeTools setting I have missed like how to set the Ctrl-Click move to the implementation if one does it on a function name (which I finally found after googling)...
Title: Re: Pasting line of code indents, why?
Post by: Thaddy on February 15, 2020, 10:11:22 am
If I make sure the cursor is at the begin of the line, the paste is also at the begin. Otherwise it is a feature, because in 99% of the cases you would want that behavior. (Auto indentation)
Title: Re: Pasting line of code indents, why?
Post by: Hartmut on February 15, 2020, 10:46:32 am
I often have the same problem. In Lazarus editor I place the cursor at the beginning of a line and then press CTRL-V to paste something there, but it's indented to the position, where the next line above starts. Mostly I face this when I have e.g. the following in my clipboard:
Code: Pascal  [Select][+][-]
  1. {$IFDEF LINUX}
  2.  
  3. {$ELSE}
  4.  
  5. {$ENDIF}
which I often steal from somewhere and I always want to have it at the beginnig of the lines. But often it is indented to the position, where the next line above starts and I have to move back all 3 lines to the beginning. Very annoying.

But it's not always! I swear I had it often in Lazarus 1.8.4 and 2.0.6, both in Windows 7 and Ubuntu 18.04. Just now I tried to reproduce it in Lazarus 1.8.4 and 2.0.6 and it never happened. Very strange. In the past I tried several times to find a setting to disable this, but didn't find something and gave up.

Would be very happy, if someone knows to disable this.
Title: Re: Pasting line of code indents, why?
Post by: howardpc on February 15, 2020, 11:49:23 am
The IDE Options dialog has a
  Codetools
     General
node/page which in the Indentation for Pascal sources section has a checkbox option

    On paste from clipboard
Title: Re: Pasting line of code indents, why?
Post by: BosseB on February 15, 2020, 12:58:05 pm
Thanks!
I unchecked the On Paste From Clipboard item and now the paste stays where I put it!
 :)
Title: Re: Pasting line of code indents, why?
Post by: Hartmut on February 16, 2020, 01:59:27 pm
For me it works too. Thanks a lot to howardpc.
TinyPortal © 2005-2018