robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #41093 from barrettruth/feat/zip-finish434792787b

master
1.9 KiB112 linesraw
1if vim.g.loaded_nvim_zip_plugin ~= nil or vim.fn.exists('#zip') == 1 then
2  return
3end
4vim.g.loaded_nvim_zip_plugin = true
5
6local api = vim.api
7
8-- Extension aliases inherited from the legacy plugin:
9-- https://github.com/neovim/neovim/blob/7ba955fe079d4aa2554fea8e7235651fafd40efb/runtime/plugin/zipPlugin.vim#L34-L35
10---@type string[]
11local extensions = {
12  'aar',
13  'apk',
14  'cbz',
15  'celzip',
16  'crtx',
17  'docm',
18  'docx',
19  'dotm',
20  'dotx',
21  'ear',
22  'epub',
23  'gcsx',
24  'glox',
25  'gqsx',
26  'ja',
27  'jar',
28  'kmz',
29  'odb',
30  'odc',
31  'odf',
32  'odg',
33  'odi',
34  'odm',
35  'odp',
36  'ods',
37  'odt',
38  'otc',
39  'otf',
40  'otg',
41  'oth',
42  'oti',
43  'otp',
44  'ots',
45  'ott',
46  'oxt',
47  'pkpass',
48  'potm',
49  'potx',
50  'ppam',
51  'ppsm',
52  'ppsx',
53  'pptm',
54  'pptx',
55  'sldx',
56  'thmx',
57  'vdw',
58  'war',
59  'whl',
60  'wsz',
61  'xap',
62  'xlam',
63  'xlsb',
64  'xlsm',
65  'xlsx',
66  'xltm',
67  'xltx',
68  'xpi',
69  'zip',
70}
71---@type string[]
72local archive_patterns = {}
73for _, extension in ipairs(extensions) do
74  archive_patterns[#archive_patterns + 1] = ('*.%s'):format(extension)
75end
76vim.keymap.set('n', '<Plug>(nvim-zip-extract)', function()
77  require('nvim.zip')._extract()
78end, { silent = true, desc = 'Extract zip archive entry' })
79
80local group = api.nvim_create_augroup('nvim.zip', { clear = true })
81
82---@return boolean
83local function legacy_loaded()
84  return vim.fn.exists('#zip') == 1
85end
86
87api.nvim_create_autocmd('BufReadCmd', {
88  group = group,
89  pattern = 'zip://*',
90  desc = 'Read zip archive entry',
91  callback = function(ev)
92    if legacy_loaded() then
93      return true
94    end
95    require('nvim.zip').read(ev.buf, ev.match)
96  end,
97})
98
99api.nvim_create_autocmd('BufReadCmd', {
100  group = group,
101  pattern = archive_patterns,
102  desc = 'Browse zip archives',
103  callback = function(ev)
104    if legacy_loaded() then
105      return true
106    end
107    if ev.match:match('^%a[%w+.-]*://') then
108      return
109    end
110    require('nvim.zip').browse(ev.buf, ev.match)
111  end,
112})