Skip to content

Commit 5adc397

Browse files
committed
.
1 parent bacb76e commit 5adc397

File tree

3 files changed

+56
-40
lines changed

3 files changed

+56
-40
lines changed

autoload/mde_indices.vim

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ vim9script
33
import autoload "./mde_links.vim" as links
44
import autoload "./mde_utils.vim" as utils
55

6-
var indices: any
7-
var indices_id = -1
6+
var index: any
7+
var index_id = -1
88

99
def IndexCallback(id: number, idx: number)
1010
if idx > 0
1111

1212
var selection = ''
13-
if typename(indices) == "list<string>"
13+
if typename(index) == "list<string>"
1414
selection = getbufline(winbufnr(id), idx)[0]
15-
elseif typename(indices) == "list<list<string>>"
15+
elseif typename(index) == "list<list<string>>"
1616
selection = getbufline(winbufnr(id), idx)[0]
17-
var indices_names = indices->mapnew((_, val) => val[0])
18-
var ii = index(indices_names, selection)
19-
selection = indices[ii][1]
20-
elseif typename(indices) == "dict<string>"
17+
var index_names = index->mapnew((_, val) => val[0])
18+
var ii = index(index_names, selection)
19+
selection = index[ii][1]
20+
elseif typename(index) == "dict<string>"
2121
var selection_key = getbufline(winbufnr(id), idx)[0]
22-
selection = indices[selection_key]
22+
selection = index[selection_key]
2323
endif
2424

2525
if !empty(selection)
@@ -39,28 +39,28 @@ def IndexCallback(id: number, idx: number)
3939
endif
4040
endif
4141

42-
indices_id = -1
42+
index_id = -1
4343
endif
4444
enddef
4545

46-
export def ShowIndices(passed_indices: string='')
47-
var indices_found = false
46+
export def ShowIndex(passed_index: string='')
47+
var index_found = false
4848

49-
if !empty(passed_indices)
49+
if !empty(passed_index)
5050
# TODO: remove the eval() with something better
51-
indices = eval(passed_indices)
52-
indices_found = true
51+
index = eval(passed_index)
52+
index_found = true
5353
elseif exists('g:markdown_extras_index') != 0
5454
&& !empty('g:markdown_extras_index')
55-
indices = g:markdown_extras_index
56-
indices_found = true
55+
index = g:markdown_extras_index
56+
index_found = true
5757
else
58-
utils.Echoerr("Cannot find indices" )
58+
utils.Echoerr("Cannot find index" )
5959
endif
6060

61-
if indices_found
61+
if index_found
6262
const popup_width = (&columns * 2) / 3
63-
const popup_height = min([len(indices), &lines / 2])
63+
const popup_height = min([len(index), &lines / 2])
6464
var opts = {
6565
pos: 'center',
6666
border: [1, 1, 1, 1],
@@ -76,19 +76,19 @@ export def ShowIndices(passed_indices: string='')
7676
wrap: 0,
7777
drag: 0,
7878
}
79-
if typename(indices) == "list<string>"
80-
indices_id = popup_create(indices, opts)
81-
links.ShowPromptPopup(indices_id, indices, " indices: ")
82-
elseif typename(indices) == "list<list<string>>"
83-
var indices_names = indices->mapnew((_, val) => val[0])
84-
indices_id = popup_create(indices_names, opts)
85-
links.ShowPromptPopup(indices_id, indices_names, " indices: ")
86-
elseif typename(indices) == "dict<string>"
87-
indices_id = popup_create(keys(indices), opts)
88-
links.ShowPromptPopup(indices_id, keys(indices), " indices: ")
79+
if typename(index) == "list<string>"
80+
index_id = popup_create(index, opts)
81+
links.ShowPromptPopup(index_id, index, " index: ")
82+
elseif typename(index) == "list<list<string>>"
83+
var index_names = index->mapnew((_, val) => val[0])
84+
index_id = popup_create(index_names, opts)
85+
links.ShowPromptPopup(index_id, index_names, " index: ")
86+
elseif typename(index) == "dict<string>"
87+
index_id = popup_create(keys(index), opts)
88+
links.ShowPromptPopup(index_id, keys(index), " index: ")
8989
else
9090
utils.Echoerr("Wrong argument type passed to ':MDEIndex' "
91-
\ .. $" (you passed a {typename(indices)})")
91+
\ .. $" (you passed a {typename(index)})")
9292
endif
9393
endif
9494
enddef

doc/markdown_extras.txt

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ filling it with he various keys.
219219
Default: 0.
220220

221221

222-
*g:markdown_extras_indices*
223-
g:markdown_extras_indices list<string>, list<list<string>> or dict<string>.
222+
*g:markdown_extras_index*
223+
g:markdown_extras_index list<string>, list<list<string>> or dict<string>.
224224
If list<string>, contain the path of indices files.
225225
If list<string<string>> the first element of each
226226
item of the list is the alias, whereas the second
@@ -254,14 +254,30 @@ COMMANDS *markdown-extras-commands*
254254
:MDEIndex [{args}] Open a popup with what is specified in {args}.
255255
The type of {args} can be list<string>, list<list<string>>
256256
or dict<string>. If no argument is passed, then
257-
|g:markdown_extras_indices| is considered.
257+
|g:markdown_extras_index| is considered.
258+
259+
Note: This feature is the same as |:PoptoolsIndex| in
260+
vim-poptools plugin, although it originated for this
261+
plugin.
262+
258263
Example:
259264
>
260-
:MDEIndex # Uses g:markdown_extras_indices
261-
:MDEIndex ['local/path', 'some%20url', 'function("some_Funcref")']
262-
:MDEIndex {foo: 'local/path', bar: 'some%20url', 'function("some_Funcref")'}
263-
:MDEIndex [['foo', 'local/path'], ['bar', 'some%20url'],
264-
['baz', 'function("some_Funcref")']]
265+
:MDEIndex # Uses g:markdown_extras_index
266+
:MDEIndex [
267+
'local/path',
268+
'some%20url',
269+
'function("some_Funcref")'
270+
]
271+
:MDEIndex {
272+
foo: 'local/path',
273+
bar: 'some%20url',
274+
baz: 'function("some_Funcref")'
275+
}
276+
:MDEIndex [
277+
['foo', 'local/path'],
278+
['bar', 'some%20url'],
279+
['baz', 'function("some_Funcref")']
280+
]
265281
<
266282
Or it can be used in a script, like for example:
267283
>

plugin/markdown_extras.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,6 @@ if use_pandoc && !executable('pandoc')
146146
endif
147147

148148
command! -nargs=0 MDEReleaseNotes ShowReleaseNotes()
149-
command! -nargs=? MDEIndex indices.ShowIndices(<f-args>)
149+
command! -nargs=? MDEIndex indices.ShowIndex(<f-args>)
150150

151151
g:markdown_extras_loaded = true

0 commit comments

Comments
 (0)