Text Editor: Improvements

Hello there! I would like to help improving blender’s text editor and I’ve been playing with it to see if I could build a simple auto close relevant characters like brackets and parenthesis. At the moment I have it working like this:

It also has the functionality of deleting the closing pair if it’s empty:

Any feedback or suggestions would be really appreciated!

19 Likes

Now it has the option to enable and disable this behavior.

6 Likes

I think this should be called ‘Auto-Completion’.

I also thought about that, but since it only closes brackets and things like that at the moment, I don’t know if that would be a good name.

Something like “Auto Pairing” (“Auto-Pairing”) looks more appropriate, since it not only closes, but also removes the pair.

@Matheus-Santos If you need more inspiration for Text Editor improvements: Essential Text Editor add-ons for coders - Released Scripts and Themes - Blender Artists Community

Especially the Textension add-on adds many essential text editing features: https://github.com/K-410/textension

I think Kaio included this script into Textension: https://github.com/K-410/blender-scripts/blob/master/2.8/text_insert2.py

3 Likes

Nice, that’s a good naming for sure.

That’s awesome, I’ll try to add these features as well.

2 Likes

Just make sure, before spending time on coding stuff, that the Text Editor module owner, @ideasman42 agrees to it, so you’ll not end up wasting your time.

Yep for sure! There’s already an ongoing patch D13119 with the auto close/pair on.

Now the auto close option is also available as a user pref on the Editing tab. Since I’d like to add more functionalities, I created a new panel to group them.

5 Likes

This is great! The better the native text editor gets the easier it is to get people into trying python scripting. Looking forward to seeing where you take this project :smiley:

1 Like

It would be nice to improve Toggle Comments, right now it just puts a # at the beginning of the line, while it should keep the current indentation level. And the indentation itself can also be improved, I would like to use Cmd+[ and Cmd+] for this, but the current implementation of the text.indent does not allow this.

1 Like

I would need to understand a bit better how that works, but I can try improving it as well! At the moment I’m trying to get a better indent when pressing enter inside empty brackets and also the surround of selected text shown in the gif above.

1 Like

In fact, what I’m talking about is much simpler than what you’re already doing.

The TEXT_OT_indent is designed to work with Tab key, so if there is no selected text, then it inserts a tab:

  if (txt_has_sel(text)) {
    txt_order_cursors(text, false);
    txt_indent(text);
  }
  else {
    txt_add_char(text, '\t');
  }

It probably also has something to do with TEXT_OT_indent_or_autocomplete.

You can just add ot->invoke to know which key the operator is called with and make an exception for Tab, well, or some smarter way. I mean that any other key could indent/un-indent regardless of whether there is a selection or not.

For comments, it’s a little more complicated, you need to look at txt_select_prefix and txt_select_unprefix. But I think it should be simple.

1 Like

There are plenty of very basic things missing from the Text Editor:

Etc. but since the Text Editor is officially in maintenance mode, again, ensure the greenlight of the module owner before you invest in implementing a new feature or a fix in the Text Editor.

4 Likes

Those are some awesome changes, I’ll try to get in touch with @ideasman42 and improve what I can.

2 Likes

Imagine if you got rid of Blender’s existing text editor engine, and replaced it with an embedded copy of Emacs. Then you would have instant access to a customization/automation engine that has been refined and extended for over half a century.

3 Likes

I’ve just sent this patch. It’s still to be revised though.

2 Likes