|
Post by Stefan on Sept 11, 2021 9:19:29 GMT -5
Guys,
Even within the SPFLite universe, this is a 'first world' issue, and implementation effort may well outweigh the benefits.
Like many, I typically add some comments to the end of source code statements. To make the listing look tidy, the comments often start in specific columns (depending on stmt length), e.g. 50, 55, 60, ... etc
To avoid shifting the comments about endlessly, a I redefined the INSERT and DELETE keys.
INSERT now performs (DataInsert) by default and (Insert) when pressed with CTRL. DELETE still performs (Delete) by default but I added (DataBackSpace) when pressed with CTRL. (I used CTRL instead of SHIFT 'cos it's easier to hit reliably)
The implementation differs slightly because (Insert) and (DataInsert) are 'sticky' (i.e. they toggle on/off) while (Delete) and (DataBackSpace) just 'do' what they do on each button press.
So far, so good, but...
Sometimes, I'd like to bump a whole section of text (eg. a comment) along from one tab stop to the next/previous tab stop. In their new forms, INSERT and DELETE help with this, but of course, I have to insert/delete the appropriate number of intervening spaces.
I thought a couple of new keyboard primitives might be useful. To illustrate, let's call them (TabIns) and (TabDel).
(TabIns) should work exactly like (Tab), UNLESS... (DataInsert) mode is active AND there is a tab position defined to the right of the cursor (ie cursor doesn't jump to a new line). In this case, instead of just moving the cursor, (TabIns) would effectively 'type blanks' (using DataInsert) between the current cursor position and the next tab stop.
As such, this primitive could be assigned to either the TAB or the INSERT key, using SHIFT or CTRL as required.
(TabDel) should work logically like (BackTab), UNLESS... there is a tab position defined to the left of the current cursor position.
In this case, instead of just moving the cursor, (TabDel) would effectively 'type (DataBackSpace)' between the current cursor position and the previous tab stop. As such, this primitive could be assigned to either the TAB or the DELETE key, using SHIFT or CTRL as required.
All views welcome.
|
|
|
Post by George on Sept 11, 2021 12:58:35 GMT -5
Robert: Stefan: Like you, I comment on the right side, an old habit from 35+ years of Assembler coding. And like you, alignment is important.
I've been using the following macro for a very long time, and have it assigned to my right mouse button. It could as easily be assigned to a key, but the mouse allows the position to be set at the same time by the click.
To use, just right click anywhere in the whitespace between the code and the comment. It will drag the comment left or right as needed to get it to the 'standard' column. If the code exceeds the comment column, is places it one space past the end of the code.
Yes, it doesn't handle block mode, but right-clicking a bunch of lines doesn't take much, and usually all that's needed is a correction to a few lines.
George
' CAlign.macro ' Align comments at the 'normal' column dim tt, Cmnt, Code as string dim lno, lcol,WCCol as long dim CCol as long = 67 ' Default comment column '----- Do some validation if is_line_Cmd then halt(fail, "Calign macro was not invoked as a primary command") lno = Get_Csr_Lptr ' Csr line lcol = Get_Csr_Col ' And column if isfalse Is_Data(lno) then halt(fail, "Calign macro was not invoked on a Data line") tt = rtrim$(Get_Line$(lno)) ' Get the line text if len(tt) >= lcol and mid$(tt, lcol, 1) <> " " then halt(fail, "Calign macro was not invoked within whitespace")
Code = rtrim$(left$(tt, lcol)) ' Get the code portion Cmnt = trim$(mid$(tt, lcol)) ' Get the code portion WCCol = iif(len(Code) > CCol - 1, Len(Code) + 2, CCol) ' Set working Comment Column tt = lset$(Code, WCCol - 1) ' Build the adjusted line tt += Cmnt ' Set_Line(lno, tt) ' Stuff it back halt ' Done
|
|
|
Post by George on Sept 12, 2021 14:37:49 GMT -5
Robert: Have you forgotten (Lift)?
And regardless, I hardly think marking text, cutting it, then positioning the cursor and then a paste is "simpler" than a simple right-click with my macro. Yes, it's a specialized macro, but we're discussing comment alignment, and that's exactly what it does.
George
|
|
|
Post by Stefan on Sept 13, 2021 4:17:43 GMT -5
Robert, Thank you, but I probably didn't explain my requirement clearly,
I'm not working with (rectangular) blocks of data in the way you describe. I need to adjust the comments on multiple lines, but they're not necessarily on consecutive lines. Even if they are, the comments will have started in a neat rectangular block but, after my edits to the code, are now misaligned, possibly interleaving code lines each of which lengthened by a different amount.
And in general, dating back to 3270 ISP/PDF, I eschew having to constantly move my hand from keyboard to mouse and back again to achieve simple changes. So currently I 'fix' my issue by a key sequence of <INSERT> (DataInsert) then <SPACEBAR> a variable number of times to bump the /* comment along without moving the */ end comment marker. Also, I start comments according to a series of tab stops set at 5 column intervals from 50 to 75, with the */ always at column 89. That's why a "TAB-related spaceing" function would be handy. George, Thanks for the macro text. I just thought I would place a suggestion prior to embarking on a macro. Now thinking about a line command macro so it can be easily invoked on a single or range of lines.
It might be quite light-weight, only capturing cursor column and next tab stop, calculating the distance and building a suitable SPF_POST_DO command for a variable number of spaces.
|
|
|
Post by George on Sept 13, 2021 8:31:02 GMT -5
Stefan: As I indicated, the macro (any macro) can be assigned to a key, it doesn't have to be mouse-based. I'd certainly go for a line macro for your tab based requirement
George
|
|
|
Post by George on Sept 13, 2021 10:46:52 GMT -5
Robert: Don't worry about forgetting it. I did as well, but I was sure the function was in there, but didn't know what it was called, so I had to read through the list of Primitives in the Appendix till I spotted it.
George
===> Since Stefan brought up this topic, I've been experimenting with (Lift) a little more. It's actually a good command to use, you just have to remember that it exists and get in the mind set of using it. Like everything else in SPFLite, you can do almost anything if can remember how :-)
R
|
|