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]
![](https://img-blog.csdnimg.cn/img_convert/c884d5a57cecb44af2a86efb39443660.png)
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]
![](https://img-blog.csdnimg.cn/img_convert/b22d64c944e4ac7da059164e744f5c6c.png)
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]
![](https://img-blog.csdnimg.cn/img_convert/92f7b931efb2942c47dc985e713463a7.png)
Add shortcut key code
[
{
"keys": ["ctrl+alt+x"],
"command": "add_commit_clipboard",
}
]
Save and restart sublime
Show results:
![](https://img-blog.csdnimg.cn/img_convert/5af4125ea52e168b3f0a93ff2603674c.gif)
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