News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Try RichEditCtrl and syntaxhighlight

Started by minor28, June 11, 2014, 06:22:49 AM

Previous topic - Next topic

minor28

I have continued to work on the syntax highlighter that I previously posted. Please try and make suggestions for improvements.

RuiLoureiro


jj2007

Works fine, except that pasting a long text (in this case: the MasmBasic source :P) causes an exception at 403E0d (and tilts the system-wide clipboard on that occasion :().

Check also your handling of tabs.

Besides, I prefer individual colouring - it helps when you are in line 14,500 of a source you wrote months ago, and you can't remember what you did there. Same code seen with two editors:



minor28

Thank you.
Quote
Works fine, except that pasting a long text
How long text is MasmBasic? I copied 1MB and pasted. It took some time but did work.

Quote
Check also your handling of tabs.
What about tabs. I change

invoke SendMessage,hRED1,EM_SETTABSTOPS,12,offset TabStopArray
to
invoke SendMessage,hRED1,EM_SETTABSTOPS,1,offset TabStopArray

Was that the meaning of your comment or is it how indent works?

Quote
Besides, I prefer individual colouring
I am not sure I understand. Do you mean a different way to do highlighting or
do you mean to do a selection and color it with a separate color and be able
to save it?

jj2007

Quote from: minor28 on June 11, 2014, 04:42:32 PM
How long text is MasmBasic? I copied 1MB and pasted. It took some time but did work.
MB is 580k, but try \Masm32\include\windows.inc, it crashes at the same address.

Quote
What about tabs. I change

invoke SendMessage,hRED1,EM_SETTABSTOPS,12,offset TabStopArray
to
invoke SendMessage,hRED1,EM_SETTABSTOPS,1,offset TabStopArray

Was that the meaning of your comment or is it how indent works?

Compare the screenshots above - which one looks better? It's a very tricky issue, though. Assembler is a "vertical" language, many small strings (mov eax, ecx) distributed over many lines. But some coders, me included, also use multiple .if .elseif etc constructs. That makes the choice of the "right" TabStopArray difficult. RichMasm has three different arrays, one for "vertical" code, one for multiple indents, and one for the .data section. This makes sense only if you can save the formatting, of course.

Quote
Quote
Besides, I prefer individual colouring
I am not sure I understand. Do you mean a different way to do highlighting or do you mean to do a selection and color it with a separate color and be able to save it?

The latter. Automatic highlighting is one thing, saving individual formatting is another. I have lived a long time with automatic highlighting, my favourite Basic dialect had it (Gfa), but for assembler I went the other road, simply because you often have code sections that are extremely difficult to read; and these benefit from highly selective colouring. For example, this code is size-efficient but you would be completely lost in a normal editor:

  mov eax, [esp+4+4]      ; #n, Basic file number
  mov eax, [MbFH+4*eax]   ; Windows handle
  push edx                ; create the bytes read slot
  mov edx, esp            ; pointer to the slot
; five bytes shorter, and returns bytes read
  invoke ReadFile, eax, [esp+28], [esp+28], edx, 0     
; invoke ReadFile, eax, tgt,      bytes,    addr locBytes, 0
  call TestRetVal         ; throw an error if needed
  pop eax
  mov edx, [esp+4+8]      ; return target buffer

minor28

Neither coping/pasting nor opening windows.inc will cause an exception on my computer (Win7 32).
But the time to load the text is very long. Also problem with line numbering when scrolling.
The margin must also be flexible.

I have skiped the tab array and only use the first element as distance between all tabs. Multiple
indents, OK the first EM_SETTABSTOPS line limited the multiple to 12 but not with the wParam set to 1.
Besides I use rtf code and tabstop is set to deftab480 which overrides the EM_SETTABSTOPS when
opening or pasting text. The other two tab types I'll think about. However as for now I save the
text as plain text.

Quote
Compare the screenshots above
I agree that the RichMasm pic is better readable as the code is written. I don't know how other write
code but with my style I think RichEd_minor pic suits me better. I like line numbering.

Quote
Besides, I prefer individual colouring - it helps when you are in line 14,500 of a source you wrote months ago, and you can't remember what you did there.
To remeber what I did there I usally use comments and and special marking like

;##################################

I must admit that my intentions are not to write a new editor. It was originally intended as a
demo to show how to use the dictionary in the static library. For fun, I worked on with the
demonstration project.

jj2007

Quote from: minor28 on June 11, 2014, 07:30:05 PM
Neither coping/pasting nor opening windows.inc will cause an exception on my computer (Win7 32).

Opening works, pasting doesn't - tested on XP SP3 and Win7-32. Anybody else having that problem?

minor28

Quote
Opening works, pasting doesn't -
It's weird pasting and opening use the same streaming code. The difference is that one reads
the characters from memory and the other from the file.

jj2007

I see "downloaded 15 times" in reply #1 - nobody else wants to report if pasting Windows.inc content makes it crash or not?

FORTRANS

Quote from: jj2007 on June 12, 2014, 03:24:51 AM
I see "downloaded 15 times" in reply #1 - nobody else wants to report if pasting Windows.inc content makes it crash or not?

Hi,

   Does not appear to do anything here.  (Does not run, and
just returns to the prompt.)  P-III and Win2k.  Will try later with
Win XP, but that will require a bit of setup to move Windows.inc.

Steve

FORTRANS

Hi,

   Setting things up was easier than I thought, or at least faster.
It worked on the XP computer.  Loading from -> File -> Open,
was very slow and showed some odd behavior (name changed).
Loading from the clipboard was fast and did not crash.

HTH,

Steve N.

minor28

After many attempts best solution seems to be to use the DrawText in a compatible bitmap.

So far I have not adjusted the code for other versions of RichEdit than version 3.0

Remaining work that I would appreciate comments on is

- how to solve selection of text. See code below (file Scanner.asm line 176)
- commented text block with comment keyword. Only OK if comment is visible. Test on    windows.inc
- any other comments


invoke SendMessage,hWin,EM_EXGETSEL,0,addr txtrange.chrg
mov eax,txtrange.chrg.cpMin
.if eax<txtrange.chrg.cpMax
lea eax,buffer
mov txtrange.lpstrText,eax
invoke SendMessage,hWin,EM_GETTEXTRANGE,0,addr txtrange

invoke SetBkMode,cDC,OPAQUE
invoke SetBkColor,cDC,0FF0000h
invoke SetTextColor,cDC,0FFFFFFh

invoke SendMessage,hWin,EM_GETRECT,0,addr rect
invoke SendMessage,hRED1,EM_POSFROMCHAR,addr rect,txtrange.chrg.cpMin
mov eax,3 ;why 3, I want 4.
shl eax,8
add eax,DT_LEFT or DT_NOCLIP or DT_EXPANDTABS or DT_TABSTOP
invoke DrawText,cDC,addr buffer,-1,addr rect,eax

.endif


jj2007

Pasting windows.inc does no longer crash the app :t

After some playing with the pasted wininc, the highlighting stops working, and instead I see the original formatting of the pasted code.

minor28

I also pasted wininc and played around without highlighting stops working. Do you remember what you did when it stopped working?

qWord

The application from reply #11 does have a GDI handle leak.
MREAL macros - when you need floating point arithmetic while assembling!