Code Duplication    Length = 28-30 lines in 2 locations

neovim/plugin/decorators.py 2 locations

@@ 121-150 (lines=30) @@
118
    return dec
119
120
121
def function(name, range=False, sync=False, allow_nested=False, eval=None):
122
    """Tag a function or plugin method as a Nvim function handler."""
123
    def dec(f):
124
        f._nvim_rpc_method_name = 'function:{}'.format(name)
125
        f._nvim_rpc_sync = sync
126
        f._nvim_bind = True
127
        f._nvim_prefix_plugin_path = True
128
129
        opts = {}
130
131
        if range:
132
            opts['range'] = '' if range is True else str(range)
133
134
        if eval:
135
            opts['eval'] = eval
136
137
        if not sync and allow_nested:
138
            rpc_sync = "urgent"
139
        else:
140
            rpc_sync = sync
141
142
        f._nvim_rpc_spec = {
143
            'type': 'function',
144
            'name': name,
145
            'sync': rpc_sync,
146
            'opts': opts
147
        }
148
        return f
149
    return dec
150
151
152
def shutdown_hook(f):
153
    """Tag a function or method as a shutdown hook."""
@@ 91-118 (lines=28) @@
88
    return dec
89
90
91
def autocmd(name, pattern='*', sync=False, allow_nested=False, eval=None):
92
    """Tag a function or plugin method as a Nvim autocommand handler."""
93
    def dec(f):
94
        f._nvim_rpc_method_name = 'autocmd:{}:{}'.format(name, pattern)
95
        f._nvim_rpc_sync = sync
96
        f._nvim_bind = True
97
        f._nvim_prefix_plugin_path = True
98
99
        opts = {
100
            'pattern': pattern
101
        }
102
103
        if eval:
104
            opts['eval'] = eval
105
106
        if not sync and allow_nested:
107
            rpc_sync = "urgent"
108
        else:
109
            rpc_sync = sync
110
111
        f._nvim_rpc_spec = {
112
            'type': 'autocmd',
113
            'name': name,
114
            'sync': rpc_sync,
115
            'opts': opts
116
        }
117
        return f
118
    return dec
119
120
121
def function(name, range=False, sync=False, allow_nested=False, eval=None):