|
Post by davecheckley on Nov 2, 2022 9:32:15 GMT -5
I'm posting this in the macros forum because I'm trying to enhance the pair.macro with the ability to ignore comments or quotes. I'm trying to use the colorization provided by an .auto file as an aid to the character the macro is checking. But the Get_Clr_Line$ function is returning an empty line, so ther macro is pairing characters included in a comment.
I've attached my macro (unimaginatively named pairnew) in case I've made some obvious error...
Regards, Dave Checkley
Attachments:pairnew.macro (5.38 KB)
|
|
|
Post by Stefan on Nov 2, 2022 11:46:58 GMT -5
Hi Dave, Assuming I understand correctly, and peeking at your macro, you're trying to find certain 'words' in your edit file by checking their colour. If so, that isn't going to work. The Get_CLR_LINE$ function does not return any colours, because the AUTO colorisation you see, is literally, "for your eyes only". AUTO colorisation is applied at the time SPFLite 'draws' the screen, so the various language keywords, literals, comments, etc are just 'painted' in colour. None of those colours are in any way recorded in the file you have open for editing.
By contrast, the line referenced by Get_CLR_Line$ will retrieve the colour attributes for every character on a line, AFTER you have applied some colour to the data line. You can do this via Set_CLR_Line$ or more simply (and as I did below), using a FIND (or CHANGE) command.
A very crude macro to illustrate....
000001 ' SNCLR.MACRO 000002 FIND ALL "o" +RED' 000003 HALT(0,"["+Get_CLR_Line$(5)+"]") ' use lptr=5 rather than 4 because the TOP-OF-DATA line has lptr=1 000004 The quick brown fox jumps over the lazy dog
The FIND command applies the colour RED to every letter O.
And the HALT message will show an "R" corresponding to each 'o' in the data line.
|
|
|
Post by George on Nov 2, 2022 11:52:27 GMT -5
Stefan: Thanks for jumping in. Yes, the color line is solely related to HiLight colors, not colorization. And yes, you can HiLight areas in a colorized file. (It overrides the colorization for that area)
George
|
|
|
Post by davecheckley on Nov 4, 2022 5:48:57 GMT -5
Hi Stefan, George, Thanks very much for your explanations. So my lazy way of ignoring comments isn't going to work (it seemed to good to be true, anyway).
But how does auto work? Is there any way of tapping into that logic from a macro? The ability to know how a line, or character, has been characterized by the auto function would be very useful, I think.
Regards, Dave Checkley
|
|
|
Post by Stefan on Nov 4, 2022 8:32:19 GMT -5
As I said, the colours applied by AUTO colourisation are done as part of the display routine. There's no access to any of this from within a Macro. There's two ways to 'spot' comments in your text. 1. (boring and inflexible) is to hardcode the delimiters that surround comments, e.g /*, a single quote, the word REM, two dashes ( --) etc, etc I say 'inflexible' because comments are of course language-related and what works for a macro (in BASIC) won't work for a REXX file for instance.
2. (more flexible) is to use the name of the current edit PROFILE (Get_Profile$("NAME")) to obtain the name of the AUTO file which applies to whatever your editing, e.g. the SNcolor.MACRO file uses the MACRO profile and hence the MACRO.AUTO file. So what....? The you open the relevant AUTO file and read it like a normal file, grabbing the info you are after, e.g. "COMMENTn" lines for the comment markers. To get a macro to read a file you'll need to perform File I/O. SPFLite doesn't offer File-I/O functions, so you need to use a bit of native thinBASIC.
Type primary command HELP BASIC In the thinBasic help, set the left pane to the INDEX tab, type file in the search field and hit RETURN Ignore the #BUNDLE option and click on File below it. And I'm sure you'll figure out the rest ... away you go. (one more hint: Don't forget to add a USES "File" to your macro!)
Have fun!
|
|
|
Post by George on Nov 4, 2022 11:03:57 GMT -5
Guys: Like the hi-light colors, it might be possible to fetch the actual normal display colors for a line, but it would be messy. The attributes are held in a WSTRING format so that I could have 16 Attr bits per character. Assuming a WSTRING can be passed back to a macro, the bits would need extracting (the WSTRING character is actually 3 binary-bit fields) and then that would have to be matched against all the Screen and Scheme color assignments (which are also not available to a Macro) to determine what scheme it is, and then match that Scheme against the assignments in the AUTO file (meaning read and extract from the file).
It's hard enough to colorize and work all that out in one direction, reverse engineering it backward in a macro? Ugh!
It just ain't worth considering that route.
George
|
|
|
Post by mueh on Nov 4, 2022 12:30:30 GMT -5
Hi George ! For the pair macro to work with csr f.e. on FOR statement the Get_Profile$("WORD") should return a string with ABCD...Zabcd...z0123...9 as documented . In fact it returns A-Z a-z 0-9 Is this a bug or doc and pair macro change ? Thanks M P.S. found Get_WORDCHAR$ but ir returns more than alphabetic and numeric as specified in profile .
|
|
|
Post by George on Nov 4, 2022 13:54:28 GMT -5
MUEH: The final string can optionally include the international characters as well based on whether Options => General => "Only English A-Z and a-z are considered alphabetic" is selected or not.
George
|
|