dykstrom / basic-mode

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

Add auto-numbering support #4

Closed pederkl closed 6 years ago

pederkl commented 6 years ago

Typing line numbers is tedious. Here is some rudimentary support for inserting line numbers automatically.

dykstrom commented 6 years ago

Thanks for your PR! I will have a look during the week when I can find some time. I like the functionality that you suggest. One thing that came to my mind however, is that you may want to use a larger auto-number-increment than 1, for example 10. So one idea could be to have a customizable variable basic-line-number-increment or similar. What do you think about that? BR, Johan

pederkl commented 6 years ago

The basic-auto-number defcustom does dual duty. If set to NIL, auto-numbering is turned off. If not NIL, it must be an integer, which is used as the increment. I prefer 10.

I can clarify the doc string. Also, the :type field for the defcustom is wrong, the customize system will not allow you to enter nil, as that is not of type 'integer. I have a fix for this in my local tree, will push an update along with doc fix when I get back to my home system this evening.

(coming up in my next PR will be renumbering-support, I have a patch nearly ready.)

dykstrom commented 6 years ago

So you already thought of that. :+1: I just did not look close enough. And renumbering would be great, kjempebra! But that is a much harder problem. You need to parse the code to find the gotos, and gosubs, and on-gotos etc. I thought of maybe writing an external program to do that and call it from Emacs, but if you can do it in elisp it would be much better!

pederkl commented 6 years ago

Oops. The defcustom for the renumbering feature leaked into those last two commits. Sorry, hope you don't mind.

pederkl commented 6 years ago

1: Hm. I thought it did. But I see that it doesn't "outdent" when typing e.g. "next". Is that what you meant? Fixed in my latest commit.

2 - Like I stated initially, this feature is rudimentary. My thought was that if you needed something more complex, it would be easier to just renumber the buffer (or a region). I can take a stab at refining the auto-numbering later, but I think it's useful as is. Especially in combination with the renumbering feature (which I have pushed to my repo, in its own branch, so feel free to take a look there. But since it depends on stuff in this PR, I haven't made a PR yet, I figured I'd wait for this one to go in first :) )

dykstrom commented 6 years ago
  1. Yes, that is exactly what I meant.
  2. Yes, the auto number feature is useful already. It takes good care of the normal case. And don't feel that you have to fix this if you don't have the time. I am happy that you wanted to contribute at all! :-)
pederkl commented 6 years ago

I feel no obligation, this is just fun :). I recently got into nostalgia mode, rediscovering the C64, and shortly afterwards discovered how painful editing is on that machine by modern standards. I far prefer emacs. So I started looking around for a basic-mode, and here it was! Saved me writing my own. The only things I missed, that my C64 could do (with appropriate cartridges), was auto-numbering and re-numbering. Hence my PRs. :)

dykstrom commented 6 years ago

auto-numbering works fine now, and is ready to merge. One question, do you want me to mention your name to give you credit, for example in the Change Log? I imagine that some people may want that, while others may not.

pederkl commented 6 years ago

I would enjoy the ego-boost of a mention, but it's not really a big deal for me. Do what you feel like. :)