Recent

Author Topic: Tooltip formating  (Read 19266 times)

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: Tooltip formating
« Reply #15 on: July 23, 2015, 03:43:23 pm »
(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),' ','&nbsp;',[rfReplaceAll])+copy(Result,p+1,length(Result));
      end;
    '<': Result:=copy(Result,1,p-1)+'&lt;'+copy(Result,p+1,length(Result));
One Tab per line is ok,
ToDo: more than one tab & actual configured tabsize
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

yamer

  • Jr. Member
  • **
  • Posts: 87
Re: Tooltip formating
« Reply #16 on: July 23, 2015, 03:50:48 pm »
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

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: Tooltip formating
« Reply #17 on: July 23, 2015, 04:30:15 pm »
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.
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)
« Last Edit: July 23, 2015, 04:33:45 pm by jc99 »
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

yamer

  • Jr. Member
  • **
  • Posts: 87
Re: Tooltip formating
« Reply #18 on: July 23, 2015, 04:57:21 pm »
About #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

  • Jr. Member
  • **
  • Posts: 87
Re: Tooltip formating
« Reply #19 on: July 23, 2015, 05:17:02 pm »
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

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: Tooltip formating
« Reply #20 on: July 23, 2015, 09:44:32 pm »
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.
'ÿ' 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
 
« Last Edit: July 23, 2015, 10:02:19 pm by jc99 »
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

yamer

  • Jr. Member
  • **
  • Posts: 87
Re: Tooltip formating
« Reply #21 on: July 23, 2015, 10:14:05 pm »
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

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: Tooltip formating
« Reply #22 on: July 23, 2015, 11:50:16 pm »
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.
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)+'&nbsp;'+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)+'&nbsp;'+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<p) do
          begin
            if result [po] = #9 then
              pc := ((pc ) div TabSize) *TabSize +TabSize-1 ;
            if (result [po] in [#$C2,#$C3]) then
              dec(pc);
             inc(pc);
            inc(po);
          end;
          pc := TabSize - (pc mod TabSize);
        Result:=copy(Result,1,p-1)+DupeString('&nbsp;',pc)+copy(Result,p+1,length(Result));
      end;
    '<': Result:=copy(Result,1,p-1)+'&lt;'+copy(Result,p+1,length(Result));
    '>': Result:=copy(Result,1,p-1)+'&gt;'+copy(Result,p+1,length(Result));
    '&': Result:=copy(Result,1,p-1)+'&amp;'+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)+'<br>'+copy(Result,po+1,length(Result));
      end;
    end;
    dec(p);
  end;
end;

[EDIT]
Changed:
if (result [po] in [#$C2,#$C3]) then
Because of é ö ß ...
« Last Edit: July 24, 2015, 12:19:17 am by jc99 »
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: Tooltip formating
« Reply #23 on: July 24, 2015, 12:02:26 am »
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.
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/
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

yamer

  • Jr. Member
  • **
  • Posts: 87
Re: Tooltip formating
« Reply #24 on: July 24, 2015, 11:09:03 am »
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

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: Tooltip formating
« Reply #25 on: July 24, 2015, 01:36:17 pm »
@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.
 
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

rvk

  • Hero Member
  • *****
  • Posts: 6777
Re: Tooltip formating
« Reply #26 on: July 24, 2015, 02:24:09 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   :P

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

  • Hero Member
  • *****
  • Posts: 5368
Re: Tooltip formating
« Reply #27 on: July 24, 2015, 04:01:57 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   :P

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.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

rvk

  • Hero Member
  • *****
  • Posts: 6777
Re: Tooltip formating
« Reply #28 on: July 24, 2015, 04:12:19 pm »
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.
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

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: Tooltip formating
« Reply #29 on: July 24, 2015, 11:40:51 pm »
You are probably one of the few users who have "Tabs to spaces" disabled in the editor-settings   :P

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 <ul>-tag as a tab-replacement but not very successful.
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

 

TinyPortal © 2005-2018