3
3
" Version: 1.0
4
4
" URL: https://github.com/vim-pandoc/vim-markdownfootnotes
5
5
"
6
- " I've taken the original and modified the output to fit the widely
6
+ " I've taken the original and modified the output to fit the widely
7
7
" supported extended markdown format for footnotes.[^note]
8
8
"
9
9
" [^note]: Like this.
10
10
"
11
11
" The original script either puts notes at the end, or before your
12
12
" email sig line (i.e., if there is a line that consists of two dashes,
13
- " it puts the notes before that line). This version just puts them at
13
+ " it puts the notes before that line). This version just puts them at
14
14
" the end.
15
15
"
16
16
" Based On:
23
23
" URL: http://www.vim.org/scripts/script.php?script_id=431
24
24
" Help Part:
25
25
" Inspired by Emmanuel Touzery tip:
26
- " http://vim.sourceforge.net/tip_view.php?tip_id=332
27
- " and discussion below (thanks to Luc for pluginization hints)
26
+ " http://vim.sourceforge.net/tip_view.php?tip_id=332
27
+ " and discussion below (thanks to Luc for pluginization hints)
28
28
" I added functions and turned it into vim script.
29
29
"
30
30
" Installation: Drop it to your plugin directory or use pathogen.
38
38
" alpha - [a] [b] ... [z] [aa] [bb] ... [zz] [a] ...
39
39
" Alpha - as above but uppercase [A] ...
40
40
" roman - [i] [ii] [iii] displayed properly up to 89
41
- " Roman - as above but uppercase [I] ...
42
- " star - [*] [**] [***] ...
41
+ " Roman - as above but uppercase [I] ...
42
+ " star - [*] [**] [***] ...
43
43
"
44
44
" Commands:
45
- "
45
+ "
46
46
" Those mappings correspond to two commands that you can use in your own
47
47
" mappings:
48
48
"
49
49
" AddVimFootnote
50
- " ~ inserts footnotemark at cursor location, inserts footnotemark on new
50
+ " ~ inserts footnotemark at cursor location, inserts footnotemark on new
51
51
" line at end of file, opens a split window all ready for you to enter in
52
52
" the footnote.
53
53
54
54
" ReturnFromFootnote
55
- " ~ closes the split window and returns to the text in proper place.
55
+ " ~ closes the split window and returns to the text in proper place.
56
56
"
57
57
" These are mapped to <Leader>f and <Leader>r respectively.
58
- "
58
+ "
59
59
" FootnoteNumber
60
60
" ~ Change the current footnote number (one obligatory argument)
61
- " :FootnoteNumber 5
61
+ " :FootnoteNumber 5
62
62
"
63
63
" FootnoteNumberRestore
64
- " ~ Restore old footnote number
64
+ " ~ Restore old footnote number
65
65
66
66
" FootnoteUndo
67
67
" ~ Decrease footnote counter by 1
68
- "
68
+ "
69
69
" FootnoteMeta
70
70
" ~ Change type of the footnotes and restart counter (1, a, A, i, I, *)
71
71
" :FootnoteMeta
76
76
" Change footnote type to name_of_the_type. If name_of_the_type is the
77
77
" same as your current footnote type nothing would be changed.
78
78
" You can change your default type of footnote before inserting first
79
- " footnote.
80
- "
79
+ " footnote.
80
+ "
81
81
" FootnoteRestore
82
82
" ~ Restore previous footnote type and counter. Unfortunately there is no easy
83
83
" way to sort footnotes at the end of file without handmade :!sort on marked
84
84
" lines (it doesn't work for 'star' type).
85
- " :FootnoteRestore
85
+ " :FootnoteRestore
86
86
"
87
87
" """"""""""""""""""""""""""""""""""""""""""""""""""
88
88
@@ -95,8 +95,9 @@ set cpo&vim
95
95
if ! exists (" g:vimfootnotetype" )
96
96
let g: vimfootnotetype = " arabic"
97
97
endif
98
+
98
99
if ! exists (" g:vimfootnotenumber" )
99
- let g: vimfootnotenumber = 0
100
+ let g: vimfootnotenumber = 0
100
101
endif
101
102
102
103
" Mappings
@@ -173,7 +174,7 @@ function! s:VimFootnoteRestore()
173
174
return 0
174
175
endif
175
176
endfunction
176
-
177
+
177
178
function ! s: VimFootnoteType (footnumber)
178
179
if (g: vimfootnotetype = ~ " alpha\\ |Alpha" )
179
180
if (g: vimfootnotetype == " alpha" )
@@ -254,20 +255,41 @@ function! s:VimFootnoteType(footnumber)
254
255
endfunction
255
256
256
257
function ! s: VimFootnotes (appendcmd)
257
- if (g: vimfootnotenumber != 0 )
258
- let g: vimfootnotenumber = g: vimfootnotenumber + 1
259
- let g: vimfootnotemark = <sid> VimFootnoteType (g: vimfootnotenumber )
260
- let cr = " \<cr> "
261
- else
262
- let g: vimfootnotenumber = 1
263
- let g: vimfootnotemark = <sid> VimFootnoteType (g: vimfootnotenumber )
264
- let cr = " \<cr> "
265
- endif
266
- exe " normal " .a: appendcmd ." [^fn" .g: vimfootnotemark ." ]\<esc> "
267
- :below 4 split
268
- normal G
269
- exe " normal o" .cr ." [^fn" .g: vimfootnotemark ." ]: "
270
- startinsert !
258
+ " save current position
259
+ let s: cur_pos = getpos (" ." )
260
+ " Define search pattern for footnote definitions
261
+ let l: pattern = ' \v^\[\^fn(.+)\]:'
262
+ let l: flags = ' eW'
263
+ call cursor (1 ,1 )
264
+ " get first match
265
+ let g: vimfootnotenumber = search (l: pattern , l: flags )
266
+ if (g: vimfootnotenumber != 0 )
267
+ let l: temp = 1
268
+ " count subsequent matches
269
+ while search (l: pattern , l: flags ) != 0
270
+ let l: temp += 1
271
+ if l: temp > 50
272
+ redraw | echohl ErrorMsg | echo " Trouble in paradise: the while loop did not work"
273
+ break
274
+ endif
275
+ endwhile
276
+ let g: vimfootnotenumber = l: temp + 1
277
+ " Return to position
278
+ call setpos (" ." , s: cur_pos )
279
+ let g: vimfootnotemark = <sid> VimFootnoteType (g: vimfootnotenumber )
280
+ let cr = " \<cr> "
281
+ else
282
+ let g: vimfootnotenumber = 1
283
+ " Return to position
284
+ call setpos (" ." , s: cur_pos )
285
+ let g: vimfootnotemark = <sid> VimFootnoteType (g: vimfootnotenumber )
286
+ let cr = " \<cr> "
287
+ endif
288
+ exe " normal " .a: appendcmd ." [^fn" .g: vimfootnotemark ." ]\<esc> "
289
+ :below 4 split
290
+ normal G
291
+ exe " normal o" .cr ." [^fn" .g: vimfootnotemark ." ]: "
292
+ startinsert !
271
293
endfunction
272
294
273
295
let &cpo = s: cpo_save
0 commit comments