The MASM Forum

Projects => MasmBasic & the RichMasm IDE => Topic started by: jj2007 on October 03, 2022, 10:12:25 PM

Title: About the Joy of Writing an Editor
Post by: jj2007 on October 03, 2022, 10:12:25 PM
Quote from: MichaelW on July 14, 2012, 02:22:40 AM
I use SciTE for almost everything.
Quote from: NoCforMe on September 03, 2022, 06:54:23 AM
It seems to be all the rage to create yet another editor for assembly code, so here's mine.
Quote from: zedd151 on September 03, 2022, 09:17:14 AMOh, yeah I've got SimplEd. A dialog box based richedit editor. Have made a lot of additions and enhancements to it, mostly for formatting code in my particular (peculiar?) style.
Quote from: hutch-- on September 03, 2022, 11:54:47 AMCode editors are like girlfriends, you pick what you like if it works for you. QE is a pure ASCII editor, programmable menus
Quote from: jj2007 on May 24, 2012, 08:22:24 AM
TinyIDE is a 7.0 kBytes editor that offers a little bit more than Notepad, at least to the assembler programmer :biggrin:

Many of our members have programmed their own editor. Recently I got seriously p*ssed of because when I typed e.g. myDword in the find box, the listbox said "no matches". So I had to click on "Case" to make the search case-insensitive.

One click too much for my taste, so I opened the source and fixed the problem (solution: if there are no matches, I relaunch the find in case-insensitive mode, pick the first match, correct the find box to MyDword and relaunch in case-sensitive mode). So from now on, I'll find matches for wm_command even if the search mode is case-sensitive.

Of course, it took me some time to dig through code that I hadn't touched for years, but the joy of making that beast (http://masm32.com/board/index.php?topic=5314.0) obey to my wishes was worth every minute I spent on this :tongue:

Below a screenshot (taken a few minutes ago) of my very first editor, written over 30 years ago. It had permanent bookmarks (I couldn't live without, I even had them in MS Word), a sophisticated listbox showing search matches, embedded graphics, and even a plot function. The screen and printer drivers were mine, programmed in 68000 Assembly. The less demanding parts I wrote in GfaBasic. I wrote and printed a whole book with this editor, and a renowned publisher took the photocopies "as is" to publish the book.

(http://www.jj2007.eu/pics/DbBookmarks.png)
Title: Re: About the Joy of Writing an Editor
Post by: HSE on October 03, 2022, 11:16:34 PM
Ambar monitor?
Title: Re: About the Joy of Writing an Editor
Post by: jj2007 on October 03, 2022, 11:20:48 PM
Quote from: HSE on October 03, 2022, 11:16:34 PM
Ambar monitor?

(https://www.maedicke.de/atari/hardware/pictures/sm124_1.jpg)

By far the best black and white monitor of the 1990ies. My screenshot is taken from the Steem emulator (http://masm32.com/board/index.php?topic=10363.msg113859#msg113859), though.
Title: Re: About the Joy of Writing an Editor
Post by: zedd151 on October 03, 2022, 11:32:07 PM
Ich spreche kein deutsch :tongue:  "I don't speak German"
I've failed my German language tutoring by our neighbor Mrs. Kuckla (when I was a tot). But google I think does a fair job.
Title: Re: About the Joy of Writing an Editor
Post by: jj2007 on October 04, 2022, 12:56:33 AM
Btw where is your SimpleEd? Did you post it somewhere?

Quote from: zedd151 on September 03, 2022, 09:17:14 AM
Oh, yeah I've got SimplEd. A dialog box based richedit editor. Have made a lot of additions and enhancements to it, mostly for formatting code in my particular (peculiar?) style. Another one that is the base code for one of my plugin builder (for qeditor) programs, and a coupla two or three more editors that are less noteworthy unless I've already sent them to the circular file
Title: Re: About the Joy of Writing an Editor
Post by: zedd151 on October 04, 2022, 03:39:52 AM
Oh no, I'd never post THAT code (SimplEd). At least in its current form.  :tongue:
I  could clean it up a bit and also use more standard functions where I thought I had better alternatives at the time. Some of that code is rather clunky for lack of a better term. It all works though, so I keep it for writing code for qeditor plugins as it has its own plugin interface.  :biggrin:
I have also renamed it some time ago to "Plugin Tester". After I finish my current project I'll look into making it 'ready for the masses' (clean it up and add some comments when needed) and post it for anyone interested.
edited to add:
Found a semi-usable version of SimplEd. Will post it later today if I have the time to clean it up a bit and add some comments. Look for it in a thread near you.  :cool:

Here -->  SimpleEd  (http://masm32.com/board/index.php?topic=10402.msg114149#msg114149)
Title: Re: About the Joy of Writing an Editor
Post by: jj2007 on October 06, 2022, 07:18:21 PM
Some basic features I expect from an editor ;-)

(http://www.jj2007.eu/pics/RmFeatures.png)

See the "a" to the upper right of the Find: box? That's the edit history, my MFUF (Most Frequently Used Feature). I rarely use the arrows to the left and right, because the keyboard shortcut is easier to use: Alt right arrow.

Let's say I work on an invoke line, and I need a variable name from a different location. I click on the bookmark that takes me there, copy the name, and then hit Alt right arrow. A millisecond later I can paste it directly to complete the edit.
Title: Unicode bookmarks
Post by: jj2007 on October 08, 2022, 11:22:56 AM
The new feature needs some more testing, but I am confident that I can release it in the coming week :tongue:

(http://www.jj2007.eu/pics/UcBookmarks.png)
Title: Re: About the Joy of Writing an Editor
Post by: NoCforMe on October 08, 2022, 12:42:32 PM
Quote from: jj2007 on October 03, 2022, 11:20:48 PM
By far the best black and white monitor of the 1990ies.

Um, sorry, no: that would have been the Wyse grayscale monitor I had on my (work) desktop in the very late 1980s. Forget the resolution but the display was gorgeous. It could also be turned on its side for portrait mode. Great piece of gear.
Title: Better word selection
Post by: jj2007 on October 10, 2022, 09:25:56 PM
It has bugged me for a while that after clicking on some$, SPI_GETWORKAREA or EM_EXSETSEL I had to manually correct the selection to get the missing red bits selected. So, inspired by Z's editor thread (http://masm32.com/board/index.php?topic=10411.msg114607#msg114607), I solved the little problem :tongue:

  .elseif uMsg==WM_LBUTTONDBLCLK
  call GetTickCount
  mov LbDbl, eax
or ReDblClk, -1 ; a global variable
  .elseif uMsg==WM_LBUTTONUP
.if ReDblClk
and ReDblClk, 0
sm hRE, EM_EXGETSEL, 0, addr txrg
mov eax, txrg.chrg.cpMax
.if eax>txrg.chrg.cpMin ; seltyp==SEL_MULTICHAR doesn't work
sub txrg.chrg.cpMin, 5
inc txrg.chrg.cpMax ; include the character after the end of the selection
lea esi, tmpBuffer
mov txrg.lpstrText, esi
sm hRE, EM_GETTEXTRANGE, 0, addr txrg
lea edx, [esi+4]
xor ecx, ecx ; flag
.if byte ptr [edx]=="_"
inc ecx ; cpMin was decreased
.Repeat
    dec txrg.chrg.cpMin
    dec edx
.Until edx==esi || byte ptr [edx]<"A"
.endif
add txrg.chrg.cpMin, 5
mov eax, txrg.chrg.cpMax
sub eax, txrg.chrg.cpMin
inc ecx
.if byte ptr [esi+eax+2]!="$"
dec txrg.chrg.cpMax
dec ecx
.endif
jecxz @F
invoke SendMessage, hRE, EM_EXSETSEL, 0, addr txrg
@@:
.endif
.endif


if 0         ; timings for double-click correction
         16 µs for selecting MoveWindow
         18 µs for selecting null
         16 µs for selecting ecx,
         18 µs for selecting RECT.
         18 µs for selecting bottom]
         3670 µs for selecting some$
         2353 µs for selecting GETWORKAREA
endif
Title: Re: About the Joy of Writing an Editor
Post by: jj2007 on October 20, 2022, 06:52:30 AM
For the curious, this is the plugin-related section of \Masm32\MasmBasic\Res\MenusRM.ini:

[System & Plugins] ; heading
Calculator,calc.exe ; entry
Control Panel,control.exe
Notepad,notepad.exe
Freecell,Freecell.exe ; spaces can be used
-
Import C structure§Converts MSDN structure on\nclipboard to Masm syntax,Plugins\Cstruct2Asm.exe
Find on disk VC§Find files containing\ntwo different strings in C headers,Plugins\FindOnDiskVC.exe #
Find on disk M32§Find files containing\ntwo different strings in Masm32 includes,Plugins\FindOnDisk.exe #
-
#plugins#

[&Help]


Exactly, it's the #plugins# line that makes you see Calculate selection and the Select e.g. '100/4+3' ... tooltip :cool:

(the technique is described here (http://masm32.com/board/index.php?topic=10411.msg114863#msg114863), replies #152 and #154)
Title: About the Joy of Writing an Editor: Table of Contents
Post by: jj2007 on October 23, 2022, 08:09:49 PM
A little luxury for myself: With one click, I get the most relevant matches for a variety of issues. After 14 years of coding for the editor, I don't always remember where I treated certain issues. So I created the TOC option, and it really helps me to find my way in this 24,000 lines monster :tongue:

(http://www.jj2007.eu/pics/TOC.png)
Title: Re: About the Joy of Writing an Editor
Post by: jj2007 on November 11, 2022, 01:07:54 PM
I had the bright idea to allow true Unicode bookmarks, for our Chinese, Russian or Arabic friends who want to write their comments in their own language.

The good news: It works, see below :biggrin:

The bad news: In order to achieve this little feature, I had to change from RichEdit20A to RichEdit20W, and from RichEd20.dll to MsftEdit.dll - and that's a nightmare if your code is over 23k LOC (see also RichEdit wrap (http://masm32.com/board/index.php?topic=10459.msg115355#msg115355)).

After numerous nights of bug chasing and fixing, RichMasm is now stable enough to be released - get it here (http://masm32.com/board/index.php?topic=94.0).

(http://www.jj2007.eu/pics/RichMasmUC.png)
Title: Re: About the Joy of Writing an Editor
Post by: jj2007 on November 15, 2022, 11:16:30 PM
Updated, with minor changes (http://masm32.com/board/index.php?topic=94.msg115672#msg115672) :cool:
Title: Just another simple editor
Post by: jj2007 on December 02, 2022, 01:14:21 PM
Just for fun, a new simple editor - just 111 lines of code :biggrin:

Features:
- search with listbox for found matches (RichMasm style)
- select a word and hit F3 to find all matches
- build all button (or hit F6; you need to extract the bldall.bat to the same folder)
- multilingual interface
- remembers last document opened, i.e. just launch the exe to see the last source you worked on
- 8 files MRU menu
- reads plain text *.asm and Rich Text Format (*.asc, *.rtf) sources
- handles spaces in folders and filenames properly
- drag and drop enabled
- handles Unicode filenames properly
- no need to save your current edits, just hit the F6 key (but do save that precious stuff when closing the editor...)

(http://www.jj2007.eu/pics/SimpleEditor.png)

The file above is \Masm32\examples\exampl02\dispatch\dispatch.asm.
Title: Re: About the Joy of Writing an Editor
Post by: jj2007 on December 06, 2022, 11:06:51 AM
Quote from: jj2007 on December 02, 2022, 01:14:21 PM
Just for fun, a new simple editor - just 111 lines of code :biggrin:

Features:
- search with listbox for found matches (RichMasm style)
- select a word and hit F3 to find all matches
- build all button (or hit F6; you need to extract the bldall.bat to the same folder)
- multilingual interface
- remembers last document opened, i.e. just launch the exe to see the last source you worked on
- 8 files MRU menu
- reads plain text *.asm and Rich Text Format (*.asc, *.rtf) sources
- handles spaces in folders and filenames properly
- drag and drop enabled
- handles Unicode filenames properly
- no need to save your current edits, just hit the F6 key (but do save that precious stuff when closing the editor...)

Version 3 attached, with small improvements but still 111 119 lines short. The archive contains everything needed to build the editor with MasmBasic version 6 December (http://masm32.com/board/index.php?topic=94.0) (check the Rsrc section for proper locations) - please let me know if there are any problems :thup:

Inter alia,
- the language menu is now a submenu of &File
- the chosen language will be remembered when reopening the editor
- there is a Project menu with Console vs Windows build, plus an item "copy source path to clipboard"
- added some checks for safer editing

Attached is also the Excel spreadsheet that defines the GUI elements - over 700 strings. I am aware of Biteriders thread (http://masm32.com/board/index.php?topic=10486.msg115793#msg115793), and wish him luck :thup: in his endeavour. However, I believe that the GUI is too complex to hand it over to a Google API.

(http://www.jj2007.eu/pics/SimpleEditorV3.png)

I chose to rename the batch file to buildSE.bat, in order to avoid name conflicts. There is still no provision for linking resources; usually, I check for the presence of <filename>.rc, then for rsrc.rc

Note that SimpleEditor != RichMasm (http://masm32.com/board/index.php?topic=5314.0). Big Brother's source stands currently at over 24,000 lines, and obviously many features are missing in this simple editor (like autoindent, bookmarks, WinApi tooltips help, edit history...). The image below shows the SimpleEditor source in RichMasm:

(http://www.jj2007.eu/pics/SimpleEditorInRichMasm.png)
Title: MRU
Post by: jj2007 on December 08, 2022, 08:56:31 PM
Below the snippets necessary to create and manage the most recently used list in SmallEditor's File menu:

  SetMru "EditorDemo.ini"            ; use this ini file for the most recently used files list
  void Ini$()                                   ; load SimpleEditor.ini
  SetMenuLanguage Val(Ini$("Language"))
  SetGlobals MyEd$="Simple editor:", CurrentFile$, x$
  Let CurrentFile$=uCL$()                      ; get the commandline
  xchg eax, ecx
  If_ byte ptr [ecx]=="#" Then Let CurrentFile$=Mru$(0)         ; load the last file (unless a file was passed in the commandline)

...
Event Menu
  Switch_ MenuID
  Case_ MruFirst .. MruLast: <xCall @Open, MruText$()>          ; open file from Most Recently Used menu

...
Event Close
  StoreUtf8 Cat$(MbExeFolder$+"\EditorDemo.ini"), Mru$(), 8    ; register up to 8 filenames

...
AddMru CurrentFile$     ; add to recent files menu

In SmallEditor, the MRU looks exactly as RichMasm's MRU, see below. In order to ease navigation, the name of the current folder is being added (there is an option to add more levels, PM me for details).

Since I have always several projects running in parallel, I couldn't live without a decent MRU implementation. Actually, I struggle to keep it below the 25 files maximum :biggrin:

(http://www.jj2007.eu/pics/RichMasmFeatures.png)
Title: Re: About the Joy of Writing an Editor
Post by: jj2007 on December 26, 2022, 09:04:10 PM
Quote from: hutch-- on December 26, 2022, 02:52:19 PM
jj,

Where we differ is in something very fundamental, the idea of automated actions combining a number of things together. While it is no big deal to auto-format in much the same way as the old GFABASIC editor, long ago I learnt that it comes with a multitude of evils. When it does something that you don't want, you have to try and undo it and with auto formatting, that is not always an easy task.

I wanted back then a pure ASCII editor which I eventually wrote that was entirely free of automated actions. My later editors all have the same brain, NO automated combined actions, each user choice is a separate action, not something the editor overrides. A liking for pure ASCII characteristics delivers a predictable and reliable means of writing code.

Now they do have a few tricks, block indent, tabs replaced with spacers and a reliable autoindent that does what it was designed to do, indent the following line with the same indent as the current one.

Dear Hutch,

Of course, I understand your KISS (Keep it simple, stupid) logic, and for a n00b who arrives here to write his first "Hello World", it's perfect. However, at currently over 6,000 source files in *.asc format, my needs are different. The n00b learns to drive, so a simple, small car is perfect for him; I need a Mercedes, a Bentley or a Tesla.

You are not a fan of MRU's, for example. Ok for n00bs, but I struggle with my 29 files limit.
Your Find & Replace dialog is Windows standard, mine is very advanced
Your F3 key makes the user jump to the next found item, I need to see the hundreds of matches in my 30k LOC source.
QEditor has no history, and that's ok. But I work on a source that, according to MS Word, has 634 pages. If I have to switch all the time between pages 9, 512 and 312, I appreciate that I can do it by simply pressing Alt arrow left/right, because RichMasm remembers the last 8 edit places.
QEditor has no shortcut keys, and that's ok for n00bs. But I appreciate that ism<space> expands to invoke SendMessage, - typing that a hundred times is tiresome. \Masm32\MasmBasic\Res\Keywords.ini has over a hundred shortcuts, and most of them I've never used. But I would go mad if I didn't have that feature.
Do I need over 30 entries in the Help menu? Not every day, and not all of them.
Do I need 15 AutoCode entries? Not every day, and not all of them, sure, but I need them, and I also need the tooltips in the menu explaining to me what each of them does.
Do I need manual colouring to understand a tricky sequence that I coded 10 years ago? Absolutely, I would be lost without that feature.
Could I live without WinAPI tooltips, see below in the lower left corner? Difficult.
Could I live without bookmarks, see below? NO.

You are a prolific coder, too, and I have a deep respect of your work for this site. That you can do that without a MRU list is, ehm, interesting. Maybe we just have very different coding styles: you work sequentially, i.e. you finish one library item at a time, while I have always a dozen projects running in parallel, and never finish them ;-)

Keep up the good work :thup:

(http://www.jj2007.eu/pics/RichMasmFeatures.png)
Title: Re: About the Joy of Writing an Editor
Post by: hutch-- on December 27, 2022, 12:01:53 PM
jj,

It has to do with the narrowness of focus that I undertake, I write editors essentially to write code and while they handle plain text documents as well, the primary focus is ASCII format code. I do have a RTF editor for making my current format help files but that is only for display purposes so the help files are easy to read.

You are doing a much wider range of things that I undertake with coding editors and I would imagine that has much to do with the difference in approach.

If I am guilty of anything, its austerity, a version of Occam's razor, do what you must do and make sure it works correctly but do nothing more. While its easy enough to do, my editors do not play music, show video, write WORD documents, Excel spreadsheets, they just write ASCII code for compilers and assemblers.
Title: Beta testers please
Post by: jj2007 on January 15, 2023, 02:11:54 AM
The transition from RichEd20.dll to mfstedit.dll is done, and it was really tough - buggy monsters, both of them, but with different problems. It's a long story. Inter alia, I had to dive into COM, i.e. the dreaded TOM interfaces (https://learn.microsoft.com/en-us/windows/win32/controls/text-object-model).

Attached a beta, grateful for feedback on bugs, handling glitches, etc :thup:

Among the changes:
- RichMasm is now over twice as fast in loading files, compared to the fast RichEd20.dll versions. The source, for example, loads its 24,000 lines in 0.4 seconds on my trusty old i5. Once upon a time I had inserted a complaint on Murray Sargent's blog (http://masm32.com/board/index.php?topic=5383.msg57691#msg57691), but they removed it :tongue:
- a new function HexDump of selected text (that was useful for chasing bugs, so I added it)

There is much more, but I didn't keep a log :sad:

(http://www.jj2007.eu/pics/DlgCar.png)

P.S.: RichMasm has a built-in profiling function (http://masm32.com/board/index.php?topic=9854.0). Press F9, hold Ctrl and click NO to see it.

Name              #called   total time   per call
FindBookmark           11       220 s    20057 ms
GetIncludeText      22340       210 s     9404 us
SubRE               65136       181 s     2783 us
SetLcBufferP          356       162 s      456 ms
DrawPics              353       161 s      457 ms
CbTimer             10477       132 s       12 ms
StartFind               4        95 s    23949 ms
MyTest                 14        65 s     4674 ms
WndProc             10426        20 s     2003 us

after adding tfHasINCLUDE and tfHasPics:
Name              #called   total time   per call
SubRE              102262        22 s      220 us
WndProc              8707        16 s     1840 us
CbTimer              1283        12 s     9703 us
ReOpenFile              1        11 s    11634 ms
SubList             52065        10 s      203 us
LbSel                 409      8580 ms      20 ms
SetSelFromB           411      8575 ms      20 ms
SetLcBufferP            3      8334 ms    2778 ms
ShowLineCol           103      7386 ms      71 ms


After discovering that the GetIncludeText and DrawPics functions cost an awful lot of cycles, I added two switches, and now it's at least a factor 20 faster with big files.

For example, my bible.txt*50 with over 200MB loads very smoothly, with really fast search results. However, it loads a factor 3 faster on my ten-year-old trusty old i5 on Win7, compared to my brand new Athlon Gold 3150 (https://www.cpubenchmark.net/cpu.php?cpu=AMD+Athlon+Gold+3150U&id=3777). That could be the cpu (unlikely, it should be 50% faster then the old i5-2450 (https://www.cpubenchmark.net/cpu.php?cpu=Intel+Core+i5-2450M+%40+2.50GHz&id=800)), but it could also be the fault of Windows 10. A slow msftedit.dll maybe?
Title: Re: About the Joy of Writing an Editor
Post by: jj2007 on February 23, 2023, 11:10:00 AM
The MasmBasic package has been updated (http://masm32.com/board/index.php?topic=94.0). Here is a list of recent macros, most of which are documented in \Masm32\MasmBasic\MbGuide.rtf (PM me if not):

2022-07-28 GuiImageSet
2022-07-28 MbProfile
2022-07-28 SetIni$
2022-08-11 Json$
2022-10-02 Choose$
2022-10-02 FontExist
2022-10-27 ClipboardImageWH
2022-10-27 uBytes
2022-12-07 CenterWindow
2022-12-07 Guid$
2022-12-07 IntAsWords$
2022-12-07 xCall
2023-01-11 BitSort
2023-02-23 _dw
2023-02-23 VirtualPath$


RichMasm (http://masm32.com/board/index.php?topic=5314.0) (included in the package) runs now with C:\Windows\System32\msftedit.dll, RichEdit50W. It is the buggiest RichEdit version so far, but I found workarounds for all problems. I've chosen this one because a) it's full Unicode and b) it's so far the fastest version I've found, at least on Win7. If you are running Win10, PM me for a faster version.
Title: Re: About the Joy of Writing an Editor
Post by: jj2007 on March 07, 2024, 08:58:07 PM
Quote from: jj2007 on December 02, 2022, 01:14:21 PMJust for fun, a new simple editor - just 111 lines of code :biggrin:

Now it has 444 lines of source code, and it moved to the Simple editor thread (https://masm32.com/board/index.php?topic=11754.0).