Since the code segment cannot directly obtain the function line content, Lua's function annotation needs to be implemented in three steps:
Add comment snippet
Add a plug-in to obtain the content of the line where the function is located and pass the parameters to the comment code segment
Add trigger shortcut key
Create code snippet
Click [Tools]-[Plug-in Development]-[New Code Snippet]
Paste the following code into the file
<snippet>
<content><![CDATA[--@func: ${1:describe function}
${PARAM1/([^,]+)(,\s*)?/--@param: $1 description\n/g}--@return: ${5:nil}
]]></content>
<!--<tabTrigger>\\</tabTrigger> -->
<scope>source.lua</scope>
<description>commit function</description>
</snippet>
Save as [add_commit.sublime-snippet]
Create plugin
Click [Tools]-[Plug-in Development]-[New Plug-in]
Paste the following code into the file
import sublime
import sublime_plugin
import re
class AddCommitClipboardCommand(sublime_plugin.TextCommand):
def run(self, edit):
mark = self.view.sel()[0]
line = self.view.line(mark.a + 1)
ss = self.view.substr(line)
dd = re.findall(r"\((.*)\)",ss)
if len(dd) > 0 :
pasted = dd[0]#sublime.get_clipboard()
self.view.run_command("insert_snippet",
{
"name": "Packages/User/add_commit.sublime-snippet",
"PARAM1":pasted
}
)
Save as [add_commit_clipboard.py]
Add shortcut keys
Click [Preferences]-[Shortcut Key Settings]
Add shortcut key code
[
{
"keys": ["ctrl+alt+x"],
"command": "add_commit_clipboard",
}
]
Save and restart sublime
Show results:
Reference content:
Code snippet description: https://docs.sublimetext.io/guide/extensibility/snippets.html#snippets-file-format
Plug-in development API: http://www.sublimetext.com/docs/2/api_reference.html#sublime.RegionSet