Tooltip formating lazarus / 11-Options ---------------------------------------------------------------------- yamer · 2015-07-21 13:06 Hi all, When I leave my mouse cursor on an identifier Lazarus displays a tooltip showing the comment just before the identifier declaration. See: tooltip.png Is there a way to tell Lararus keep original comment indentation ? Original comment: comment.png Thanks ---------------------------------------------------------------------- jc99 · 2015-07-21 23:09 It's maybe no solution, just a workaround Code: [Select]{** Procedure Execute   This procedure will :     - Go Up     - Go Down     - And Running again } Procedure Execute [...]      Replace every second space (#32) with specialspace (#255) then the trim-function has nothing to trim. ---------------------------------------------------------------------- yamer · 2015-07-22 16:34 Thank you, but I'm afraid that this approach makes the comments too difficult to edit for me. ---------------------------------------------------------------------- JuhaManninen · 2015-07-22 17:08 Quote from: yamer on July 21, 2015, 03:06:15 pmIs there a way to tell Lararus keep original comment indentation ? No but it should be kept. The rendering is done by the IPro package which is full of bugs. If somebody can improve the indentation, good. ---------------------------------------------------------------------- yamer · 2015-07-22 18:02 Quote from: JuhaManninen on July 22, 2015, 07:08:33 pmThe rendering is done by the IPro package which is full of bugs. If somebody can improve the indentation, good. I just tried without IPro package and the problem is still there. Maybe IPro is not involved. ---------------------------------------------------------------------- jc99 · 2015-07-22 18:14 Quote from: JuhaManninen on July 22, 2015, 07:08:33 pmQuote from: yamer on July 21, 2015, 03:06:15 pmIs there a way to tell Lararus keep original comment indentation ? No but it should be kept. The rendering is done by the IPro package which is full of bugs. If somebody can improve the indentation, good. Is it good for a bug-report ? ---------------------------------------------------------------------- yamer · 2015-07-22 20:17 I managed to improve the rendering with TurboPower IPro. I post the patch here so that interested people can test it and make corrections. If there are no major problems I'll post the patch to the bug tracker. ---------------------------------------------------------------------- rvk · 2015-07-22 21:08 Haha.. yeah, that works too. You just replace by

I was more thinking in the line of replacing space by   in
TCodeHelpManager.TextToHTML procedure.

Your method has the downside that is displays in courier font.

Code: [Select]function TCodeHelpManager.TextToHTML(Txt: string):
string;
var
  p: Integer;
begin
  Result:=Txt;
  p:=length(Result);
  while p>0 do
  begin
    case Result[p] of
    ' ':
Result:=copy(Result,1,p-1)+' '+copy(Result,p+1,length(Result));
// <-- this one
    '<':
Result:=copy(Result,1,p-1)+'<'+copy(Result,p+1,length(Result));
    '>':
Result:=copy(Result,1,p-1)+'>'+copy(Result,p+1,length(Result));
    '&':
Result:=copy(Result,1,p-1)+'&'+copy(Result,p+1,length(Result));

Works too and keeps a nice proportional font.

----------------------------------------------------------------------
yamer · 2015-07-22 21:38

Quote from: rvk on July 22, 2015, 11:08:36 pmYour method has the
downside that is displays in courier font.
...
Works too and keeps a nice proportional font.
For me it is a fixed width font, but not the courier font. The style
sheet 'lazdoc.css' asks for a fixed font and I guess it's your system
that chooses the courier font.

In my opinion, a monospace font seems a better choice since a comment
may contain code examples, tables, or ASCII art.

----------------------------------------------------------------------
rvk · 2015-07-22 21:58

Quote from: yamer on July 22, 2015, 11:38:43 pmQuote from: rvk on July
22, 2015, 11:08:36 pmYour method has the downside that is displays in
courier font.
For me it is a fixed width font, but not the courier font. The style
sheet 'lazdoc.css' asks for a fixed font and I guess it's your system
that chooses the courier font.

In my opinion, a monospace font seems a better choice since a comment
may contain code examples, tables, or ASCII art.
You are absolutely correct. I failed to apply the entire patch 

But for me the font is still proportional now. Indentation is correct.
Mmm, I must have done something else wrong.

But you're right. A fixed width font would be better because of
alignment in the source (which is also fixed width).

----------------------------------------------------------------------
rvk · 2015-07-22 22:17

I didn't find yet why the font is still proportional for me...

But I did find a potential problem.
You removed the TextToHTML-function call with LastComment.

That would mean that < and > is not translated into HTML.
This would mean tags in the comments will also be interpreted as HTML.

This could of course be an advantage (using tags in comments) but it's
not the same behavior as the standard.

Edit:
I do think you need to add Courier to the font-family line.
Code: [Select]/* comments in source fragments */
pre.comment {
  color: darkcyan;
  font-family: Courier, monospace;
}
This is also done on line 32 of that file (for tt, span.keyword, pre)
Otherwise it doesn't display a fixed width font for me.

(I'm puzzled why it would for you.)

Now I only have the problem that the urls in the hint don't work most
of the time

----------------------------------------------------------------------
yamer · 2015-07-23 11:14

Quote from: rvk on July 23, 2015, 12:17:30 amBut I did find a
potential problem.
You removed the TextToHTML-function call with LastComment.

That would mean that < and > is not translated into HTML.
This would mean tags in the comments will also be interpreted as HTML.

This is a big problem ! I'm going to correct it.

----------------------------------------------------------------------
yamer · 2015-07-23 11:30

rvk, your idea of using non-breaking spaces is much better than
mine.Your idea of using non-breaking spaces is much better than mine.

With your idea an a font change in the style sheet the result seems
pretty good. There is still a slight indentation problem of disposal
of the heading '{', '(*' and '//' from the comment.

----------------------------------------------------------------------
jc99 · 2015-07-23 11:53

I come across another problem, using the 
-tag instead of the span
and TextToHTML:
my comments in the Hint looked like this:
Code: [Select]Line 1

Line 2

Line 3
This is because in TextToHTML the 
is inserted before the CrLf With: Code: [Select]function TCodeHelpManager.TextToHTML(Txt: string): string; var   p,po: Integer; // <-- New Variable here begin   Result:=Txt;   p:=length(Result);   while p>0 do   begin     case Result[p] of     ' ',#255: Result:=copy(Result,1,p-1)+' '+copy(Result,p+1,length(Result));     '<': Result:=copy(Result,1,p-1)+'<'+copy(Result,p+1,length(Result));     '>': Result:=copy(Result,1,p-1)+'>'+copy(Result,p+1,length(Result));     '&': Result:=copy(Result,1,p-1)+'&'+copy(Result,p+1,length(Result));     #10,#13:       begin         po:=p; // <-- Saving the old Position         if (p>1) and (Result[p-1] in [#10,#13]) and (Result[p-1]<>Result[p]) then           dec(p);         Result:=copy(Result,1,p-1)+'
'+copy(Result,po+1,length(Result)); // <-- using the 'Old Position'       end;     end;     dec(p);   end; end; Removing the CrLf it works for me. Maybe a parameter preformated:boolean := false; is the more flexible solution. ---------------------------------------------------------------------- jc99 · 2015-07-23 12:08 I just noticed, there is also a problem with tabs (#9) Code: [Select]{** procedure Execute   This procedure will :         - Go Up     - Go Down       - And Running again }                  1. Line Blank only 2. Line 1 tab 3. Line 2 blank 1 tab Result in: see picture: ---------------------------------------------------------------------- jc99 · 2015-07-23 13:43 (partly) solution for the Tab-Problem: codehelp.pas Line 2820 ff Code: [Select]    case Result[p] of     ' ',#255: Result:=copy(Result,1,p-1)+' '+copy(Result,p+1,length(Result));     #9: //<- handling of Tab       begin         po := p;         while (po>1) and not (result[po] in [#10,#13]) do           dec(po); // <- Todo: Maybe a second loop to recount with tab.         po := 8-((p-po-1) mod 8) ; // <-  Todo: replace tab with the Actual.configured Tabsize         Result:=copy(Result,1,p-1)+StringReplace(StringOfChar(' ',po),' ',' ',[rfReplaceAll])+copy(Result,p+1,length(Result));       end;     '<': Result:=copy(Result,1,p-1)+'<'+copy(Result,p+1,length(Result)); One Tab per line is ok, ToDo: more than one tab & actual configured tabsize ---------------------------------------------------------------------- yamer · 2015-07-23 13:50 A new version of the patch: - Tabs are replaced by 8 spaces - Comments are fully displayed now (not only their content) this results in better indentation I think that we should not change #255 characters because I'm not sure they are spaces in all 8 bits encodings and I am almost certain that they are not valid UTF-8 characters. ---------------------------------------------------------------------- jc99 · 2015-07-23 14:30 Quote from: yamer on July 23, 2015, 03:50:48 pmA new version of the patch: - Tabs are replaced by 8 spaces - Comments are fully displayed now (not only their content) this results in better indentation I think that we should not change #255 characters because I'm not sure they are spaces in all 8 bits encodings and I am almost certain that they are not valid UTF-8 characters. It's a little better (than your old code) The thing with tabs is that it makes the Cursor go to fixed columns, configured by the Tab-Size (Config - Editor - General - Indentation and Tab)  So better start with my code. About #255: At least on PC and UTF-16 (16-bit Unicode) it is. And also in Lazarus-Editor (PC) (which is UTF-8) ---------------------------------------------------------------------- yamer · 2015-07-23 14:57 Quote from: jc99 on July 23, 2015, 04:30:15 pmAbout #255: At least on PC and UTF-16 (16-bit Unicode) it is. And also in Lazarus-Editor (PC) (which is UTF-8) To my knowledge, code point 255 is 'ÿ' in Unicode. And it is not encoded as a #255 char in UTF-8 but as #195+#191. ---------------------------------------------------------------------- yamer · 2015-07-23 15:17 The previous patch does not work well without IPro. This one works with and without IPro on (at least on my PC). Try it, please, and report bugs here. Tabs are not handled correctly but they were not before and it does not seem very important to me. ---------------------------------------------------------------------- jc99 · 2015-07-23 19:44 Quote from: yamer on July 23, 2015, 04:57:21 pmTo my knowledge, code point 255 is 'ÿ' in Unicode. And it is not encoded as a #255 char in UTF-8 but as #195+#191. 'ÿ' is 0255 (ALT-0255) ' ' is 255 (ALT-255) ' ' is 32 (ALT-32) or (Alt-0032) [Edit] I just checked with the editor and Hex-viewer The Alt-255 - is translated to #$C2A0 in UTF-8 and UTF-16 In Ansi it is #$A0 in DOS-OEM it is enoded as #$FF or #255 ---------------------------------------------------------------------- yamer · 2015-07-23 20:14 http://www.unicodemap.org/details/0x00FF/ All your ALT+xxx are juste windows shortcuts. And as non-breaking space has different codes in different encodings  it is not easy to handle it. ---------------------------------------------------------------------- jc99 · 2015-07-23 21:50 Quote from: yamer on July 23, 2015, 10:14:05 pmhttp://www.unicodemap.org/details/0x00FF/ All your ALT+xxx are juste windows shortcuts. And as non-breaking space has different codes in different encodings  it is not easy to handle it. It is ! See: Code: [Select]function TCodeHelpManager.TextToHTML(Txt: string): string; var   p,po,pc,TabSize: Integer; begin   Result:=Txt;   p:=length(Result);   while p>0 do   begin     case Result[p] of     ' ': Result:=copy(Result,1,p-1)+' '+copy(Result,p+1,length(Result));     #$A0:        if (p>1) and (Result[p-1] = #$c2) then          begin            dec(p);            Result:=copy(Result,1,p-1)+' '+copy(Result,p+2,length(Result));          end;     #9:       begin         po := p;         TabSize := 8;         while (po>1) and not (result[po] in [#10,#13]) do           dec(po);         inc(po);         pc := 0;         while (po': Result:=copy(Result,1,p-1)+'>'+copy(Result,p+1,length(Result));     '&': Result:=copy(Result,1,p-1)+'&'+copy(Result,p+1,length(Result));     #10,#13:       begin         po:=p;         if (p>1) and (Result[p-1] in [#10,#13]) and (Result[p-1]<>Result[p]) then           dec(p);         Result:=copy(Result,1,p-1)+'
'+copy(Result,po+1,length(Result));       end;     end;     dec(p);   end; end; [EDIT] Changed: if (result [po] in [#$C2,#$C3]) then Because of é ö ß ... ---------------------------------------------------------------------- jc99 · 2015-07-23 22:02 Quote from: yamer on July 23, 2015, 10:14:05 pmhttp://www.unicodemap.org/details/0x00FF/ All your ALT+xxx are juste windows shortcuts. And as non-breaking space has different codes in different encodings  it is not easy to handle it. It's not Windows, it's PC-BIOS to be exact. it's not 0x00FF, it's 0x00A0 see: http://www.unicodemap.org/details/0x00A0/ ---------------------------------------------------------------------- yamer · 2015-07-24 09:09 Here is an another patch that works better for me. Previous versions did not work with comments shifted to the right.  Like this one: Code: [Select]  procedure Style2;   begin   end;                         (*Procedure: Style3                           This procedure will :                             - Go Up < & >                             - Go Down                             - And Running again *)                         procedure Style3;                         begin                         end; @jc99 Your way of dealing with non-breaking spaces only works if Lazarus internally treats the source code in UTF-8 regardless of their actual encoding.  I'm not sure about that. This is why I think it's not so easy. But if a Lazarus guru can confirm that source codes are all considered UTF-8 internally I can include your code for non-breaking spaces and tabs.  While I think that non-breaking spaces and tabs must not be used for much in source code comments. ---------------------------------------------------------------------- jc99 · 2015-07-24 11:36 Quote from: yamer on July 24, 2015, 11:09:03 am@jc99 Your way of dealing with non-breaking spaces only works if Lazarus internally treats the source code in UTF-8 regardless of their actual encoding.  I'm not sure about that. This is why I think it's not so easy. But if a Lazarus guru can confirm that source codes are all considered UTF-8 internally I can include your code for non-breaking spaces and tabs.  While I think that non-breaking spaces and tabs must not be used for much in source code comments. The non-breaking-Space, that can be diskussed, but if you want to do tables you highly likely do it with tabs, because you formatting is kept pretty stable that way. And this thread is all about formatting. ---------------------------------------------------------------------- rvk · 2015-07-24 12:24 Quote from: jc99 on July 24, 2015, 01:36:17 pm... but if you want to do tables you highly likely do it with tabs, because you formatting is kept pretty stable that way.You are probably one of the few users who have "Tabs to spaces" disabled in the editor-settings  Myself, I hate tabs in source-code. One of the first things I do is remove them. When there are tabs and spaces mixed on a line and the text is too far indented and I want to remove some of the indentation I always delete the wrong character (i.e. the tab) because you can't see the difference. So mixing spaces and tabs before text is a big no no for me. But the default 8 spaces tab is too big for indenting code. I could set it to 2 spaces but what the point in that. So I never ever use tabs. (If on the other hand the tabs-spaces got another color it would be more clear, but still.) That said... tabs do exist. And some users prefer them. So taking them into account is a must. ---------------------------------------------------------------------- taazz · 2015-07-24 14:01 Quote from: rvk on July 24, 2015, 02:24:09 pmQuote from: jc99 on July 24, 2015, 01:36:17 pm... but if you want to do tables you highly likely do it with tabs, because you formatting is kept pretty stable that way.You are probably one of the few users who have "Tabs to spaces" disabled in the editor-settings    Myself, I hate tabs in source-code. One of the first things I do is remove them. When there are tabs and spaces mixed on a line and the text is too far indented and I want to remove some of the indentation I always delete the wrong character (i.e. the tab) because you can't see the difference. So mixing spaces and tabs before text is a big no no for me. But the default 8 spaces tab is too big for indenting code. I could set it to 2 spaces but what the point in that. So I never ever use tabs. The point is exactly that. You specify your indentation choice in spaces for the tab so you are fine when that is 2 some else prefers 3 and some else 4 (never seen any one use more than 4) by setting your tab to space ratio and adding tabs instead of spaces every can have hes/her own choice of indentation with out changing the a thing and raising the changed flag in cvs/svn etc. Saying that I have to admit that I never use them my self either. ---------------------------------------------------------------------- rvk · 2015-07-24 14:12 Quote from: taazz on July 24, 2015, 04:01:57 pmYou specify your indentation choice in spaces for the tab so you are fine when that is 2 some else prefers 3 and some else 4 (never seen any one use more than 4) by setting your tab to space ratio and adding tabs instead of spaces every can have hes/her own choice of indentation with out changing the a thing and raising the changed flag in cvs/svn etc.And the fact everyone can set their tab-spacing to their own value is also the reason you can't use tab in tables. If you do, and you have it set at say 6 spaces, the table would be mangled for somebody that has it at 2 spaces. So it is good for indentation for those that prefer it (as long as you don't mix it with spaces) but bad for layouts like tables and comments after the code-line. ---------------------------------------------------------------------- jc99 · 2015-07-24 21:40 Quote from: rvk on July 24, 2015, 02:24:09 pmYou are probably one of the few users who have "Tabs to spaces" disabled in the editor- settings    Myself, I hate tabs in source-code. Actually I have it enabled. i also have the show special character enabled I also don't like tabs in the code itself. The only time i use tabs, is in the comments, which i sometimes write in another editor. for me tabs are for formatting. And formatting only matters in comments. another example is multi-columned text with aligned columns. An excerpt from a CSV-file with tab as separater, then it's a good thing these columns are aligned. a tab should set the cursor to a place on the sheet, independent to font and fontsize but i havent found that (jet) in HTML I was making experiments with
    -tag as a tab-replacement but not very successful. ---------------------------------------------------------------------- rvk · 2015-07-24 22:16 Quote from: jc99 on July 24, 2015, 11:40:51 pmActually I have it enabled. i also have the show special character enabled Yes, that would help (the show special character). Just tried it again but... argh... once you get used to something you can't unlearn it easily. You don't want to know how long I stayed with the cursor keys on the numeric pad I was finally forced to kick that habit when I got a keyboard without numlock (temporary experiment from Logitech at the time, I guess). Quotefor me tabs are for formatting. And formatting only matters in comments. another example is multi-columned text with aligned columns. Did you ever test that multi-columned text with different tab- settings?? I'm not sure at what number you've got it but try setting it at something small (2 or 4) and reload your project. All your aligned text could get messed up because you expected it to align at a specific tab-setting. If you can force the setting to a specific number ("<>") in the source-code you might be save but there is no such setting. This (8 tab-space): (there is a tab before the |) Code: [Select]1234567890 |123456 |test |12     |test would become this (4 tab space): Code: [Select]1234567890 |123456 |test |12 |test So... yeah... really bad. Tab settings in source-code editors are not made for formatting layout. (They are only for indentation !!) The fact that they depend on a variable number of spaces a user can set determines that. If source-code editors always used the same tab setting or had an option to set tabs like in rtf they could be used for this, but they haven't. Quotea tab should set the cursor to a place on the sheet Correct... always to the same position... and again... that is not how a tab in a source-code editor works... So, don't use them like that. The layout will be messed up for somebody with different tab-settings. Quote... but i havent found that (jet) in HTML. I was making experiments with
      -tag as a tab-replacement but not very successful. In the past I made a rtf2html converter. You could try converting traditional tabs to html-tables but that's a real pain. I finally ended up using div-elements to place the following text at a specific location (according to the tab). Code: [Select]
      text
      So every tab I encountered would be translated to a "close-div" and an "open-div"-element. (Lines started and ended with a div too) ---------------------------------------------------------------------- jc99 · 2015-07-25 06:15 Quote from: rvk on July 25, 2015, 12:16:17 amYes, that would help (the show special character). Just tried it again but... argh... once you get used to something you can't unlearn it easily. You don't want to know how long I stayed with the cursor keys on the numeric pad I was finally forced to kick that habit when I got a keyboard without numlock (temporary experiment from Logitech at the time, I guess). LOL, me too, to me it was a Laptop without extra Num-Block Before that people could see that i was on the computer because the Num was lit, .... Quote from: rvk on July 25, 2015, 12:16:17 amDid you ever test that multi-columned text with different tab-settings?? I'm not sure at what number you've got it but try setting it at something small (2 or 4) and reload your project. All your aligned text could get messed up because you expected it to align at a specific tab-setting. If you can force the setting to a specific number ("<>") in the source-code you might be save but there is no such setting. This (8 tab-space): (there is a tab before the |) Code: [Select]1234567890 |123456 |test |12     |test would become this (4 tab space): Code: [Select]1234567890 |123456 |test |12 |test So... yeah... really bad. But that's only if someone else want to read your code, and if that someone changes the default-setting from 8 to something. In my opinion, changing the default, you have to know what you are doing. But even when it's 4 or 6 spaces, It's better readable than without tabs. Code: [Select]1234567890 |123456|test |12|test Quote from: rvk on July 25, 2015, 12:16:17 amTab settings in source- code editors are not made for formatting layout. (They are only for indentation !!) The fact that they depend on a variable number of spaces a user can set determines that. If source-code editors always used the same tab setting or had an option to set tabs like in rtf they could be used for this, but they haven't. What people used to do, and what the intention of the original developer was always differs. The most (normal) people (colleagues) ,i see, using a wordprocessor, use (Paragraph-)Break at the end of line, where they just could type on.  So I highly doubt, using habits as a meassuring device. (People are people, you know ....) Quote from: rvk on July 25, 2015, 12:16:17 amCorrect... always to the same position... and again... that is not how a tab in a source-code editor works... So, don't use them like that. The layout will be messed up for somebody with different tab-settings. Take Notepad++,Ultraedit or delphi there it works. (meaning You could set the font to a non-monospaced, and tab puts the cursor to the next tab-stop-position.  (BTW: setting the font to a non-monospaced in lazarus looks really ugly ...) Quote from: rvk on July 25, 2015, 12:16:17 amIn the past I made a rtf2html converter. You could try converting traditional tabs to html- tables but that's a real pain. I finally ended up using div-elements to place the following text at a specific location (according to the tab). Code: [Select]
      text
      So every tab I encountered would be translated to a "close-div" and an "open-div"-element. (Lines started and ended with a div too) Using html-tables, oh yeah,  thats'a pain ... Using
      maybe the only way... [/quote] ---------------------------------------------------------------------- yamer · 2015-07-25 09:02 These problems of non breaking spaces and tabs do not seem important to me. The patch seems to work well enough to answer my original question. So I will submit it. I hope it will be accepted. Thanks to all. ---------------------------------------------------------------------- yamer · 2015-07-25 11:01 Arrrgh! I submitted the patch in the wrong category. I had not seen the patch category. Can anyone fix this (it seems I can not do it) ? http://bugs.freepascal.org/view.php?id=28430