dykstrom / basic-mode

Emacs major mode for editing BASIC code
GNU General Public License v3.0
7 stars 10 forks source link

Enable syntax highlighting without spaces #18

Closed dykstrom closed 1 year ago

dykstrom commented 1 year ago

Some BASIC interpreters allow spaces to be omitted. This commit enables syntax highlighting for code without spaces in some situations, namely when keywords are surrounded by numbers.

Closes #17

hackerb9 commented 1 year ago

By the way, caveat number one is a bigger issue than I had thought. I just found that if I set the variable using the basic-mode-hook, it doesn't take effect when I first open a BASIC file. I have to use M-x find-alternate-file to close and reopen it.

Also, I notice that it is only superficially recognizing the keywords. M-b and M-f still smoosh the keyword and the numbers together. (Maybe it'd work using syntax-propertize-rules?)

dykstrom commented 1 year ago

I was aware of caveat one, but I thought it would not be a big deal. I thought you either works with BASICs that require that kind of syntax highlighting, or not. I did not think you would switch between them often. But it seems I was wrong. :) If you have an idea of how to make the solution more dynamic, I'm open to suggestions. I guess there is no callback available when a customized variable is set?

dykstrom commented 1 year ago

It kind of works using syntax-propertize-rules and this expression:

(syntax-propertize-rules ("\\(\\_<REM\\_>\\)" (1 "<"))
                         ("\\([0-9]*\\)\\([a-zA-Z]+\\)\\([0-9]*\\)" (1 ".") (3 ".")))

But then numbers adjacent to ascii characters are just skipped, since they are punctuation. Another way to do it could be find-word-boundary-function-table as in subword-mode. That would require more work though.

hackerb9 commented 1 year ago

I was aware of caveat one, but I thought it would not be a big deal.

It was surprising to me when I set basic-syntax-highlighting-require-separator in the basic-mode-hook and it didn't work. Of course, one solution is to set it before the mode hook runs and that's what I'm doing now. (A reasonable question would be, why would anyone put it in the mode-hook? Because I had put all of the basic-mode variables in one place in my .emacs and some of them -- fill-column and comment-column -- are buffer local.)


[UPDATE: I wrote some responses which I now realize were mistaken as you were only referring to basic-syntax-highlighting-require-separator and not my 2nd caveat. I have deleted those as being irrelevant and I apologize for the confusion.]

dykstrom commented 1 year ago

I have fixed the cursor movement problem. Also M-d works as expected. I have not changed anything related to as I expect that to be solved in issue #20.

dykstrom commented 1 year ago

Looks good and works for me.

I do note that cursor movement by words works great for purely alphabetic identifiers, but breaks down where the identifier includes a number. For example, try M-b, M-f over the following:

T2$=TT$

Yes, that is because that code does not really know what a keyword is. That can maybe be fixed after #20.