orbitalquark / textadept

Textadept is a fast, minimalist, and remarkably extensible cross-platform text editor for programmers.
https://orbitalquark.github.io/textadept
MIT License
640 stars 38 forks source link

convert anonymous functions to named functions and add to API #227

Closed mhwombat closed 2 years ago

mhwombat commented 2 years ago

Some of the default keymaps for Textadept use anonymous functions (see example below). It would be great if all of them, or at least the most useful ones, could be converted into named functions and exported by the API. If you would like me to make the change and do a pull request, let me know.

As it stands, in order to remap these functions I have to copy and paste your code. If later on you were to make improvements to them, I wouldn't get the improvements unless I noticed that you had modified the code. But if they were API functions, I would automatically have the latest version.

  {_L['Enclose as XML Tags'], function()
    buffer:begin_undo_action()
    enc('<', '>')
    for i = 1, buffer.selections do
      local s, e = buffer.selection_n_start[i], buffer.selection_n_end[i]
      while buffer.char_at[s - 1] ~= 60 do s = s - 1 end -- '<'
      buffer:set_target_range(e, e)
      buffer:replace_target('</' .. buffer:text_range(s, e))
      buffer.selection_n_start[i], buffer.selection_n_end[i] = e, e
    end
    buffer:end_undo_action()
  end},
orbitalquark commented 2 years ago

You can ask the menubar for those functions. For example, my ~/.textadept remaps a lot of the existing key bindings such as here: https://github.com/orbitalquark/.textadept/blob/235d6aeca4e36cd56ed7f1fb7e83dcac310bd776/modules/textadept/keys.lua#L57

Will that work for you?

mhwombat commented 2 years ago

Yes, that works for me.