Sublime develops Lua function comment code segments

Since the code segment cannot directly obtain the function line content, Lua's function annotation needs to be implemented in three steps:

  1. Add comment snippet

  1. 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

  1. Add trigger shortcut key

  1. 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]

  1. 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]

  1. 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

おすすめ

転載: blog.csdn.net/wangzizi12300/article/details/129675900