Code Duplication    Length = 26-27 lines in 2 locations

neovim/plugin/decorators.py 2 locations

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