Skip to content
This repository was archived by the owner on Mar 9, 2020. It is now read-only.

Commit d6b83f5

Browse files
committed
update readme; incorporate konfekt's pull request
1 parent ac9a095 commit d6b83f5

File tree

6 files changed

+363
-303
lines changed

6 files changed

+363
-303
lines changed

README.markdown

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
## VimFootnotes for Markdown with automatic footnote counter
22

3-
This fork derived from [this vim-plugin by David Sanson][1], which in turn is
3+
This fork is derived from a combination of [this fork][8] and
4+
[this pull request][7] of the [vim-pandoc vim-markdownfootnotes][1], which in turn is
45
a slight tweak of the venerable [vimfootnotes][2], for use with extended
56
markdown.
67

7-
The new script inserts footnotes in the widely supported extended markdown
8-
syntax with the addition of `fn` as a prefix to the current footnote number.
8+
Unlike derdennis's fork, this version doesn't use the `fn` notation, but keeps the restore
9+
functionality. It also changes the `<leader>f` insert mode mapping
10+
to `[]` to avoid annoying typing delays and accidental insertions of footnotes.
11+
Finally, it gets rid of the keyboard mappings to return from a footnote
12+
since it's easy enough to `:q` out of the minibuffer.
913

10-
~~~
11-
Here is some text.[^fn1]
14+
The remainder of this README is copied from derdennis's fork.
1215

13-
[^fn1]: Here is a note.
14-
~~~
16+
=====
1517

1618
The footnote number gets determined by an automatic counter whenever a new
1719
footnote gets inserted. This renders the commands `FootnoteNumber`,
@@ -79,7 +81,7 @@ These are mapped to `<Leader>f` and `<Leader>r` respectively.
7981
:FootnoteNumber 5
8082

8183
`FootnoteNumberRestore`
82-
: Restore old footnote number
84+
: Restore old footnote number
8385

8486
`FootnoteUndo`
8587
: Decrease footnote counter by 1
@@ -103,3 +105,5 @@ previous type, then the counter will not be restarted.
103105
[4]: https://raw.github.com/derdennis/vim-markdownfootnotes/master/footnotes.png
104106
[5]: http://slipsum.com/
105107
[6]: https://github.com/tpope/vim-pathogen
108+
[7]: https://github.com/Konfekt/vim-markdownfootnotes/commit/58a2ebd2d2f3826fa6c7effa91c09d11d1efdd94
109+
[8]: https://github.com/derdennis/vim-markdownfootnotes

autoload/markdownfootnotes.vim

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
function! markdownfootnotes#VimFootnoteNumber(newnumber)
2+
let g:oldvimfootnotenumber = g:vimfootnotenumber
3+
let g:vimfootnotenumber = a:newnumber - 1
4+
endfunction
5+
6+
function! markdownfootnotes#VimFootnoteNumberRestore()
7+
if exists(g:oldvimfootnotenumber)
8+
let g:vimfootnotenumber = g:oldvimfootnotenumber
9+
else
10+
return 0
11+
endif
12+
endfunction
13+
14+
function! markdownfootnotes#VimFootnoteMeta(...)
15+
let g:oldvimfootnotetype = g:vimfootnotetype
16+
let g:oldvimfootnotenumber = g:vimfootnotenumber
17+
if a:0 == "0"
18+
if (g:vimfootnotetype == "arabic")
19+
let g:vimfootnotetype = "alpha"
20+
else
21+
let g:vimfootnotetype = "arabic"
22+
endif
23+
else
24+
if (a:1 == g:vimfootnotetype)
25+
echomsg "You have chosen the same footnote type! Command won't affect."
26+
return 0
27+
else
28+
let g:vimfootnotetype = a:1
29+
endif
30+
endif
31+
let g:vimfootnotenumber = 0
32+
endfunction
33+
34+
function! markdownfootnotes#VimFootnoteRestore()
35+
if exists("g:oldvimfootnotenumber")
36+
let oldvimfootnotetype2 = g:vimfootnotetype
37+
let oldvimfootnotenumber2 = g:vimfootnotenumber
38+
let g:vimfootnotetype = g:oldvimfootnotetype
39+
let g:vimfootnotenumber = g:oldvimfootnotenumber
40+
let g:oldvimfootnotetype = oldvimfootnotetype2
41+
let g:oldvimfootnotenumber = oldvimfootnotenumber2
42+
else
43+
echomsg "You didn't change footnote type. Yet."
44+
return 0
45+
endif
46+
endfunction
47+
48+
function! markdownfootnotes#VimFootnoteType(footnumber)
49+
if (g:vimfootnotetype =~ "alpha\\|Alpha")
50+
if (g:vimfootnotetype == "alpha")
51+
let upper = "0"
52+
else
53+
let upper = "-32"
54+
endif
55+
if (a:footnumber <= 26)
56+
let ftnumber = nr2char(a:footnumber+96+upper)
57+
elseif (a:footnumber <= 52)
58+
let ftnumber = nr2char(a:footnumber+70+upper).nr2char(a:footnumber+70+upper)
59+
else
60+
let g:vimfootnotenumber = 1
61+
let ftnumber = nr2char(97+upper)
62+
endif
63+
elseif (g:vimfootnotetype == "star")
64+
let starnumber = 1
65+
let ftnumber = ""
66+
while (starnumber <= a:footnumber)
67+
let ftnumber = ftnumber . '*'
68+
let starnumber = starnumber + 1
69+
endwhile
70+
elseif (g:vimfootnotetype =~ "roman\\|Roman")
71+
let ftnumber = ""
72+
let oneroman = ""
73+
let counter = g:vimfootnotenumber
74+
if (counter >= 50)
75+
let ftnumber = "l"
76+
let counter = counter - 50
77+
endif
78+
if (counter > 39 && counter < 50)
79+
let ftnumber = "xl"
80+
let counter = counter - 40
81+
endif
82+
if (counter > 10)
83+
let tenmodulo = counter % 10
84+
let number_roman_ten = (counter - tenmodulo) / 10
85+
let romanten = 1
86+
while (romanten <= number_roman_ten)
87+
let ftnumber = ftnumber.'x'
88+
let romanten = romanten + 1
89+
endwhile
90+
elseif (counter == 10)
91+
let ftnumber = ftnumber.'x'
92+
let tenmodulo = ""
93+
else
94+
let tenmodulo = counter
95+
endif
96+
if (tenmodulo == 1)
97+
let oneroman = 'i'
98+
elseif (tenmodulo == 2)
99+
let oneroman = 'ii'
100+
elseif (tenmodulo == 3)
101+
let oneroman = 'iii'
102+
elseif (tenmodulo == 4)
103+
let oneroman = 'iv'
104+
elseif (tenmodulo == 5)
105+
let oneroman = 'v'
106+
elseif (tenmodulo == 6)
107+
let oneroman = 'vi'
108+
elseif (tenmodulo == 7)
109+
let oneroman = 'vii'
110+
elseif (tenmodulo == 8)
111+
let oneroman = 'viii'
112+
elseif (tenmodulo == 9)
113+
let oneroman = 'ix'
114+
elseif (tenmodulo == 0)
115+
let oneroman = ''
116+
endif
117+
let ftnumber = ftnumber . oneroman
118+
if (g:vimfootnotetype == "Roman")
119+
let ftnumber = substitute(ftnumber, ".*", "\\U\\0", "g")
120+
endif
121+
else
122+
let ftnumber = a:footnumber
123+
endif
124+
return ftnumber
125+
endfunction
126+
127+
function! markdownfootnotes#VimFootnotes(appendcmd)
128+
" save current position
129+
let markdownfootnotes#cur_pos = getpos(".")
130+
" Define search pattern for footnote definitions
131+
let l:pattern = '\v^\[\^(.+)\]:'
132+
let l:flags = 'eW'
133+
call cursor(1,1)
134+
" get first match
135+
let g:vimfootnotenumber = search(l:pattern, l:flags)
136+
if (g:vimfootnotenumber != 0)
137+
let l:temp = 1
138+
" count subsequent matches
139+
while search(l:pattern, l:flags) != 0
140+
let l:temp += 1
141+
if l:temp > 50
142+
redraw | echohl ErrorMsg | echo "Trouble in paradise: the while loop did not work"
143+
break
144+
endif
145+
endwhile
146+
let g:vimfootnotenumber = l:temp + 1
147+
" Return to position
148+
call setpos(".", markdownfootnotes#cur_pos)
149+
let g:vimfootnotemark = markdownfootnotes#VimFootnoteType(g:vimfootnotenumber)
150+
let cr = "\<cr>"
151+
else
152+
let g:vimfootnotenumber = 1
153+
" Return to position
154+
call setpos(".", markdownfootnotes#cur_pos)
155+
let g:vimfootnotemark = markdownfootnotes#VimFootnoteType(g:vimfootnotenumber)
156+
let cr = "\<cr>"
157+
endif
158+
exe "normal ".a:appendcmd."[^".g:vimfootnotemark."]\<esc>"
159+
:below 4split
160+
normal G
161+
exe "normal o".cr."[^".g:vimfootnotemark."]: "
162+
startinsert!
163+
endfunction
164+

doc/markdownfootnotes.txt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
markdown-footnotes, add footnotes in markdown *markdown-footnotes* *footnotes*
2+
3+
===========================================================================
4+
0. Introduction ~
5+
*markdown-footnotes-intro*
6+
7+
To insert a footnote, hit `<Leader>f` in normal mode or type `[]`. Then
8+
9+
- A footnote mark will be inserted after the cursor,
10+
- A matching footnote mark will be inserted at the end of the file, and
11+
- a split window at the bottom will open, ready to edit the new footnote.
12+
13+
When done, type `ZZ` to close the split and return to the main text.
14+
15+
===========================================================================
16+
1. Commands ~
17+
*markdown-footnotes-commands*
18+
19+
`AddVimFootnote`
20+
: inserts footnotemark at cursor location, inserts footnotemark on new
21+
line at end of file, opens a split window all ready for you to enter in
22+
the footnote.
23+
24+
`ReturnFromFootnote`
25+
: closes the split window and returns to the text in proper place.
26+
27+
These are mapped to `<Leader>f` and `<Leader>r` respectively.
28+
29+
`FootnoteNumber`
30+
: Change the current footnote number (one obligatory argument)
31+
:FootnoteNumber 5
32+
33+
`FootnoteNumberRestore`
34+
: Restore old footnote number
35+
36+
`FootnoteUndo`
37+
: Decrease footnote counter by 1
38+
39+
`FootnoteMeta [<footnotetype>]`
40+
: Change type of the footnotes and restart counter (1, a, A, i, I, *)
41+
42+
The `<footnotetype>` argument is optional. If omitted, and your previous
43+
footnote type was not `arabic`, the new type will be `arabic`; if it was
44+
arabic, the new type will be `alpha`. If the new type is the same as the
45+
previous type, then the counter will not be restarted.
46+
47+
48+
`FootnoteRestore`
49+
: Restore previous footnote type and counter.
50+
<
51+
===========================================================================
52+
2. Config ~
53+
*markdown-footnotes-config*
54+
55+
By default, footnote ids are arabic numerals. You can change this by
56+
setting `b:vimfootnotetype` in ~/.vim/ftplugin/markdown.vim:
57+
58+
+ `arabic`: 1, 2, 3...
59+
+ `alpha`: a, b, c, aa, bb..., zz, a...
60+
+ `Alpha`: A, B, C, AA, BB..., ZZ, A...
61+
+ `roman`: i, ii, iii... (displayed properly up to 89)
62+
+ `Roman`: I, II, III...
63+
+ `star`: \*, \*\*, \*\*\*...
64+
65+
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
" Maintainer: David Sanson <[email protected]>
2+
" Description: Extended Markdown Footnotes in Vim
3+
" Version: 1.0
4+
" URL: https://github.com/vim-pandoc/vim-markdownfootnotes
5+
"
6+
" I've taken the original and modified the output to fit the widely
7+
" supported extended markdown format for footnotes.[^note]
8+
"
9+
" [^note]: Like this.
10+
"
11+
" The original script either puts notes at the end, or before your
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
14+
" the end.
15+
"
16+
" Based On:
17+
" VimFootnotes
18+
" Author: Mikolaj Machowski <[email protected]>
19+
" Version: 0.6
20+
" Description: Footnotes in Vim
21+
" Installation: See below
22+
" Last Change: pon wrz 30 09:00 2002 C
23+
" URL: http://www.vim.org/scripts/script.php?script_id=431
24+
" Help Part:
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)
28+
" I added functions and turned it into vim script.
29+
"
30+
" Installation: Drop it to your plugin directory or use pathogen.
31+
"
32+
" Settings:
33+
"
34+
" By default, footnote ids are arabic numerals. You can change this by
35+
" setting b:vimfootnotetype,
36+
"
37+
" arabic (default) - [1] [2] [3] ...
38+
" alpha - [a] [b] ... [z] [aa] [bb] ... [zz] [a] ...
39+
" Alpha - as above but uppercase [A] ...
40+
" roman - [i] [ii] [iii] displayed properly up to 89
41+
" Roman - as above but uppercase [I] ...
42+
" star - [*] [**] [***] ...
43+
"
44+
" Commands:
45+
"
46+
" Those mappings correspond to two commands that you can use in your own
47+
" mappings:
48+
"
49+
" AddVimFootnote
50+
" ~ inserts footnotemark at cursor location, inserts footnotemark on new
51+
" line at end of file, opens a split window all ready for you to enter in
52+
" the footnote.
53+
54+
" ReturnFromFootnote
55+
" ~ closes the split window and returns to the text in proper place.
56+
"
57+
" These are mapped to <Leader>f and <Leader>r respectively.
58+
"
59+
" FootnoteNumber
60+
" ~ Change the current footnote number (one obligatory argument)
61+
" :FootnoteNumber 5
62+
"
63+
" FootnoteNumberRestore
64+
" ~ Restore old footnote number
65+
66+
" FootnoteUndo
67+
" ~ Decrease footnote counter by 1
68+
"
69+
" FootnoteMeta
70+
" ~ Change type of the footnotes and restart counter (1, a, A, i, I, *)
71+
" :FootnoteMeta
72+
" If your previous footnote type was alpha, Alpha, roman, Roman or star
73+
" new type will be arabic.
74+
" If your previous footnote type was arabic new type will be alpha.
75+
" :FootnoteMeta name_of_the_type
76+
" Change footnote type to name_of_the_type. If name_of_the_type is the
77+
" same as your current footnote type nothing would be changed.
78+
" You can change your default type of footnote before inserting first
79+
" footnote.
80+
"
81+
" FootnoteRestore
82+
" ~ Restore previous footnote type and counter. Unfortunately there is no easy
83+
" way to sort footnotes at the end of file without handmade :!sort on marked
84+
" lines (it doesn't work for 'star' type).
85+
" :FootnoteRestore
86+
"
87+
"""""""""""""""""""""""""""""""""""""""""""""""""""
88+
89+
if exists("b:loaded_footnote_vim") | finish | endif
90+
let b:loaded_footnote_vim = 1
91+
92+
let s:cpo_save = &cpo
93+
set cpo&vim
94+
95+
if !exists("g:vimfootnotetype")
96+
let g:vimfootnotetype = "arabic"
97+
endif
98+
99+
if !exists("g:vimfootnotenumber")
100+
let g:vimfootnotenumber = 0
101+
endif
102+
103+
" Mappings
104+
if !hasmapto('<Plug>AddVimFootnote', 'i')
105+
inoreabbrev <buffer> [] <c-o>:exe "normal \<Plug>AddVimFootnote"<cr>
106+
endif
107+
if !hasmapto('<Plug>AddVimFootnote', 'n')
108+
nmap <buffer> <Leader>f <Plug>AddVimFootnote
109+
endif
110+
111+
nnoremap <buffer> <Plug>AddVimFootnote :call markdownfootnotes#VimFootnotes('a')<CR>
112+
inoremap <buffer> <Plug>AddVimFootnote <C-O>:call markdownfootnotes#VimFootnotes('a')<CR>
113+
114+
" :Footnote commands
115+
command! -buffer -nargs=1 FootnoteNumber call markdownfootnotes#VimFootnoteNumber(<q-args>)
116+
command! -buffer -nargs=0 FootnoteNumberRestore call markdownfootnotes#VimFootnoteNumberRestore()
117+
command! -buffer -nargs=0 FootnoteUndo let g:vimfootnotenumber = g:vimfootnotenumber - 1
118+
command! -buffer -nargs=? FootnoteMeta call markdownfootnotes#VimFootnoteMeta(<f-args>)
119+
command! -buffer -nargs=0 FootnoteRestore call markdownfootnotes#VimFootnoteRestore()
120+
121+
let &cpo = s:cpo_save

ftplugin/pandoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
markdown

0 commit comments

Comments
 (0)