Editor doesn't insert TAB characters
Original Reporter info from Mantis: ggeldenhuys
-
Reporter name: Graeme Geldenhuys
Original Reporter info from Mantis: ggeldenhuys
- Reporter name: Graeme Geldenhuys
Description:
If I edit a .pas file with gedit (Gnome Editor which supports tab
charaters for indentation) and use tabs instead of spaces for
indentation, Lazarus displays it correctly. Lets say I used a tab
width of 8 in both gedit and Lazarus.
&LtPos;t> = tab
&LtPos;s> = space
-------------- sample pas file --------------------
begin
&LtPos;t>if (getGnome = null &
&LtPos;t>&LtPos;s>&LtPos;s>&LtPos;s>&LtPos;s>getKDE = null)
&LtPos;t>{
&LtPos;t>&LtPos;t>// do something
&LtPos;t>&LtPos;t>{ it has 2 tabs ahead }
&LtPos;t>}
end.
------------------ end --------------------------------
Now I edit this file in Lazarus, and add a third comment line and also
used 2 tabs infront of the comment. Everything looks fine in Lazarus,
so I save.
Now I change gedits tab with to 4 and open that source file. The
newly added line didn't line up with the other comments, because
spaces were inserted instead of tabs.
Another way of testing this is viewing that same file in Lazarus. Go
to the editor options and change the Tab Width to 4. All the lines
move, except the last line added using Lazarus.
Using the arrow keys, and pressing left or right, shows it is jumping
tabs, but again for that third comment line, it jumps single spaces.
Now in the editor options, I don't have the "Tabs to Spaces" ticked
and I don't have "Smart Tabs" ticked.
In synedit.pp at line 9625
Spaces := StringOfChar(' ', i);
overwrites what the previous line stored in the variable Spaces???
I commented it out and then noticed that the Tabs now get saved, but
there is still some problems.
------------- synedit.pp.patch --------------------
Index: synedit.pp
===================================================================
--- synedit.pp (revision 9377)
+++ synedit.pp (working copy)
@@ -9622,7 +9622,7 @@
// i now contains the needed spaces
Spaces := CreateTabsAndSpaces(CaretX,i,TabWidth,
not (eoTabsToSpaces in Options))+'|';
- Spaces := StringOfChar(' ', i);
+// Spaces := StringOfChar(' ', i);
//debugln('TCustomSynEdit.DoTabKey Spaces="',DbgStr(Spaces),'"
TabChar=',DbgStr(TabChar));
BeginUndoBlock;
----------------- end ---------------------------------
Steps to reproduce:
See description...
Additional information:
Response from Flávio Etrusco in the mailing list
Date: May 31, 2006 7:35 PM
Subject: Re: Lazarus doesn't insert TAB charaters
Disabling "Trim Trailing Spaces" should help you here.
But, a big WARNING: undo/redo has several bugs when dealing with tabs.
-Flávio
Now the long answer ;-)
First, "hard" tabs support is incomplete in SynEdit, even in the
latest official version (of SynEdit, and the component in Lazarus is
based on a quite old version).
The major problem here is "eoTrimTrailingSpaces" in Options, because
text is trimmed after every key press. So, disabling "Trim Trailing
Spaces" should at least preserve the tabs you explicitly typed/wrote.
The current official version of SynEdit has fixed most of the bugs
with tabs and remaining ones (that are known) only happen with
"TrimTrailingSpaces", but since we couldn't agree on the best fix for
"trim", for now we introduced a "end key jumps to nearest end" option.
TrimTrailing is disabled and SmartEndKey is enabled by default, btw.
Also, I've come to respect that people have different tastes for
indentation size (and thus at my workplace we standardized on using
tabs), so yes, I plan to fix the remaing tab bugs, and have an option
to "display" tabs and trailing empty chars. It would be simply a
subset of "show special chars" (which already exists) anyway.
Oh, and non-tabulated tabs :-/
Cheers,
Flávio
Mantis conversion info:
- Mantis ID: 7011
- OS: Ubuntu Linux
- OS Build: 5.10
- Build: 9381
- Platform: i386
- Version: 0.9.17 (SVN)
- Fixed in version: 0.9.27 (SVN)
- Fixed in revision: 18241 (#585bbf6e)
- Target version: 1.0.0
- LazTarget: 1.4