Problem
Currently every Lua API is a function call, which is fine, but most of them are similar to others only having different arguments and uses same call under the hood. This is not extensible if we want to create a new mode #17 and have slight maintenance burden.
Solution
Using setmetatable we can probably build-up the API as we go. This will be extensible and have less maintenance overhead. By using metatable, the API will look something like this.
All API functions are dot repeatable except *.count()
require('Comment.api').toggle.linewise()
require('Comment.api').toggle.linewise.current()
require('Comment.api').toggle.linewise.count()
require('Comment.api').toggle.blockwise()
require('Comment.api').toggle.blockwise.current()
require('Comment.api').toggle.blockwise.count()
require('Comment.api').comment.linewise()
require('Comment.api').comment.linewise.current()
require('Comment.api').comment.linewise.count()
require('Comment.api').comment.blockwise()
require('Comment.api').comment.blockwise.current()
require('Comment.api').comment.blockwise.count()
require('Comment.api').uncomment.linewise()
require('Comment.api').uncomment.linewise.current()
require('Comment.api').uncomment.linewise.count()
require('Comment.api').uncomment.blockwise()
require('Comment.api').uncomment.blockwise.current()
require('Comment.api').uncomment.blockwise.count()
Problem
Currently every Lua API is a function call, which is fine, but most of them are similar to others only having different arguments and uses same call under the hood. This is not extensible if we want to create a new mode #17 and have slight maintenance burden.
Solution
Using
setmetatablewe can probably build-up the API as we go. This will be extensible and have less maintenance overhead. By using metatable, the API will look something like this.