Thanks a lot for making geany one of the best IDEs out there. I have just a feature request which someone had already suggested, but still not implemented yet. It's about replacing tabs with spaces: what geany does is that during the editing the text, it inserts tabs, and when you save the file it converts them to spaces. While this is what replacing means, actually it sometimes messes up the text identation and configuration. Let me give an example here: let's assume that I'm writing the following text (with \t I mean presseing TAB key and we have set the tab to be 2 spaces width):
a\t\t= 1; b\t\t= 2; ab\t= 4;
What we expect to see is that = signs are all aligned nicely, which is what happens: a and b have 3 spaces in front while ab has 2.
Now when you save this text, geany replaces all tabs with 2 spaces, this makes the distance of a and b to the = sign as 4, while keeping the number of spaces in front of ab equal to 2. As a result, you lose the alignment you wished to have.
I think the solution is to just take the modular of the number of the where we press the TAB with the tab width and insert that amount of space instead of a fixed amount of it. I'm not familiar at all with geany's source, otherwise I would try to see how I can solve it.
Best Regards Amir
--------------------------------- Be a better Globetrotter. Get better travel answers from someone who knows. Yahoo! Answers - Check it out.
EDIT: Last paragraph:
I think the solution is to just take the modular of the COLUMN number of the where we press the TAB with the tab width and insert that amount of space instead of a fixed amount of it.
--------------------------------- Sucker-punch spam with award-winning protection. Try the free Yahoo! Mail Beta.
Amir R. Saffari A. A. wrote:
Thanks a lot for making geany one of the best IDEs out there. I have just a feature request which someone had already suggested, but still not implemented yet. It's about replacing tabs with spaces: what geany does is that during the editing the text, it inserts tabs, and when you save the file it converts them to spaces. While this is what replacing means, actually it sometimes messes up the text identation and configuration. Let me give an example here: let's assume that I'm writing the following text (with \t I mean presseing TAB key and we have set the tab to be 2 spaces width):
a\t\t= 1; b\t\t= 2; ab\t= 4;
What we expect to see is that = signs are all aligned nicely, which is what happens: a and b have 3 spaces in front while ab has 2.
Now when you save this text, geany replaces all tabs with 2 spaces, this makes the distance of a and b to the = sign as 4, while keeping the number of spaces in front of ab equal to 2. As a result, you lose the alignment you wished to have.
I think the solution is to just take the modular of the number of the where we press the TAB with the tab width and insert that amount of space instead of a fixed amount of it. I'm not familiar at all with geany's source, otherwise I would try to see how I can solve it.
Best Regards Amir
Sort of off-topic:
I've recently loaded a large Python project called Sonata in Geany and upon save, the indentation of ~30 lines got screwed up. Python doesn't like that...
I had to manually check and correct all lines in a ~7000 lines file...
So, I can confirm that replacing tabs with spaces is a bit 'buggy' at least...
Cheers!
-H-
On 6/6/07, Harold Aling h.aling@home.nl wrote:
I've recently loaded a large Python project called Sonata in Geany and upon save, the indentation of ~30 lines got screwed up. Python doesn't like that...
I had to manually check and correct all lines in a ~7000 lines file...
Ouch. Sorry to hear that.
So, I can confirm that replacing tabs with spaces is a bit 'buggy' at least...
Can you describe what exactly happened? In the past, the Geany developers have been quite responsive to detailed bug reports.
John Gabriele wrote:
So, I can confirm that replacing tabs with spaces is a bit 'buggy' at least...
Can you describe what exactly happened? In the past, the Geany developers have been quite responsive to detailed bug reports.
OK... Fair enough...
1. sudo geany /usr/lib/python2.5/site-packages/sonata.py 2. set Geany to replace tabs with spaces 3. save the file 4. run it (/usr/bin/sonata)
harold@DBWS439:~$ sonata Traceback (most recent call last): File "/usr/bin/sonata", line 28, in <module> import sonata File "/usr/lib/python2.5/site-packages/sonata.py", line 208 sys.exit() ^ IndentationError: unindent does not match any outer indentation level
---
The original source: (s=space, t=tab)
ttLine 206 stttLine 207 sttLine 208
This indentation is visibly aligned correctly and python doesn't complain about it, but it's incorrectly corrected by Geany upon save ;)
ssssssssLine 206 sssssssssssssLine 207 sssssssssLine 208
The single 'space' should be discarded in this case, since it's followed by a tab.
I don't know if the general rule can be something like:
"if (no. of spaces < tabWidthInSpaces) then discard spaces"
-or-
"if (no. of spaces < tabWidthInSpaces/2) then discard spaces else insert tabWidthInSpaces*space"
tabWidthInSpaces should default to 4...
Hope this helps...
-H-
Harold Aling wrote:
I don't know if the general rule can be something like:
"if (no. of spaces < tabWidthInSpaces) then discard spaces"
-or-
"if (no. of spaces < tabWidthInSpaces/2) then discard spaces else insert tabWidthInSpaces*space"
tabWidthInSpaces should default to 4...
After some tests I'd reckon that the best solution will be:
"if spaces are followed by a tab then { if (no. of spaces < tabWidthInSpaces) then discard spaces }"
Test it yourself saving a file with: (s=space, t=tab)
tLine 1 stLine 2 sstLine 3 ssstLine 4 sssst Line 5
Before save: Line 1 Line 2 Line 3 Line 4 Line 5
After save: Line 1 Line 2 Line 3 Line 4 Line 5
Cheers!
-H-
On Thu, 07 Jun 2007 11:12:07 +0200, Harold Aling h.aling@home.nl wrote:
Hi all,
you are right. Anyway, the current code for replacing tabs isn't buggy. It works as intended only the indention is a bit buggy. What I want to say, I wasn't aware of this problem but I agree that it should be improved to not only stupidly replace any tab by some spaces with the amount of tab_width.
After some tests I'd reckon that the best solution will be:
"if spaces are followed by a tab then { if (no. of spaces < tabWidthInSpaces) then discard spaces }"
Sounds good. But I won't work on this, at least not in the near future.
Any patches are welcome. If anyone want to work on this, the start should be document_replace_tabs() in src/document.c:1802.
Regards, Enrico
Hi list,
On Thu, 7 Jun 2007 17:13:59 +0200 Enrico Tröger enrico.troeger@uvena.de wrote:
On Thu, 07 Jun 2007 11:12:07 +0200, Harold Aling h.aling@home.nl wrote:
Hi all,
you are right. Anyway, the current code for replacing tabs isn't buggy. It works as intended only the indention is a bit buggy. What I want to say, I wasn't aware of this problem but I agree that it should be improved to not only stupidly replace any tab by some spaces with the amount of tab_width.
After some tests I'd reckon that the best solution will be:
"if spaces are followed by a tab then { if (no. of spaces < tabWidthInSpaces) then discard spaces }"
Sounds good.
Err, no. The solution is to use sci_get_col_from_position modulo tab_len to determine how many spaces the current \t is worth.
But I won't work on this, at least not in the near future.
Any patches are welcome. If anyone want to work on this, the start should be document_replace_tabs() in src/document.c:1802.
Patch attached & validated against the attached test file and sonata.py with tab_len = 8.
Many thanks for doing Geany.
François Cami & Guillaume Duviol
Hi List,
On Fri, 8 Jun 2007 01:20:50 +0200 FD Cami francois.cami@free.fr wrote:
Patch attached & validated against the attached test file and sonata.py with tab_len = 8.
The same patch without the obvious memory leak...
Cheers
François Cami & Guillaume Duviol
FD Cami wrote:
Hi List,
On Fri, 8 Jun 2007 01:20:50 +0200 FD Cami francois.cami@free.fr wrote:
Patch attached & validated against the attached test file and sonata.py with tab_len = 8.
The same patch without the obvious memory leak...
Cheers
François Cami & Guillaume Duviol
Excellent!
I just tried your (second) patch and it looks very promising!
Let's hope the Geany devs also think so...
Cheers!
-H-
Hi Cami,
Thanks a lot, now it's perfect.
Cheers Amir
FD Cami francois.cami@free.fr wrote: Hi List,
On Fri, 8 Jun 2007 01:20:50 +0200 FD Cami wrote:
Patch attached & validated against the attached test file and sonata.py with tab_len = 8.
The same patch without the obvious memory leak...
Cheers
François Cami & Guillaume Duviol --- ../geany-0.11/src/document.c 2007-05-21 17:36:37.000000000 +0200 +++ src/document.c 2007-06-08 07:06:17.000000000 +0200 @@ -1785,5 +1785,5 @@ void document_replace_tabs(gint idx) { - gint search_pos; + gint search_pos, pos_in_line, current_tab_true_length; gint tab_len; gchar *tab_str; @@ -1797,5 +1797,4 @@ ttf.chrg.cpMax = sci_get_length(doc_list[idx].sci); ttf.lpstrText = (gchar*)"\t"; - tab_str = g_strnfill(tab_len, ' ');
while (TRUE) @@ -1804,12 +1803,15 @@ if (search_pos == -1) break;
+ pos_in_line = sci_get_col_from_position(doc_list[idx].sci,search_pos); + current_tab_true_length = tab_len - (pos_in_line % tab_len) ; + tab_str = g_strnfill(current_tab_true_length, ' '); sci_target_start(doc_list[idx].sci, search_pos); sci_target_end(doc_list[idx].sci, search_pos + 1); sci_target_replace(doc_list[idx].sci, tab_str, FALSE); - ttf.chrg.cpMin = search_pos + tab_len - 1; // next search starts after replacement - ttf.chrg.cpMax += tab_len - 1; // update end of range now text has changed + g_free(tab_str); + ttf.chrg.cpMin = search_pos + current_tab_true_length - 1; // next search starts after replacement + ttf.chrg.cpMax += current_tab_true_length - 1; // update end of range now text has changed } sci_end_undo_action(doc_list[idx].sci); - g_free(tab_str); }
_______________________________________________ Geany mailing list Geany@uvena.de http://uvena.de/cgi-bin/mailman/listinfo/geany
--------------------------------- Pinpoint customers who are looking for what you sell.
On Fri, 8 Jun 2007 07:16:17 +0200, FD Cami francois.cami@free.fr wrote:
Hi List,
On Fri, 8 Jun 2007 01:20:50 +0200 FD Cami francois.cami@free.fr wrote:
Patch attached & validated against the attached test file and sonata.py with tab_len = 8.
The same patch without the obvious memory leak...
;-).
Thank you very much, applied in SVN r1603.
Regards, Enrico
On Sat, 9 Jun 2007 14:12:14 +0200 Enrico Tröger enrico.troeger@uvena.de wrote:
On Fri, 8 Jun 2007 07:16:17 +0200, FD Cami francois.cami@free.fr wrote:
Hi List,
On Fri, 8 Jun 2007 01:20:50 +0200 FD Cami francois.cami@free.fr wrote:
Patch attached & validated against the attached test file and sonata.py with tab_len = 8.
The same patch without the obvious memory leak...
;-).
Thank you very much, applied in SVN r1603.
My pleasure. Geany rocks :)
François