Skip to content

Commit b5fce6f

Browse files
authored
Merge pull request #7 from ubaldot/pandoc_check_tests
Pandoc check tests
2 parents ff1953a + 6274688 commit b5fce6f

File tree

2 files changed

+35
-40
lines changed

2 files changed

+35
-40
lines changed

ftplugin/markdown.vim

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ nnoremap <buffer> <backspace> <ScriptCmd>funcs.GoToPrevVisitedBuffer()<cr>
1919
2020

2121
# -------------- prettier ------------------------
22+
#
2223
if markdown_extras.use_prettier
2324
if exists('g:markdown_extras_config') != 0
2425
&& has_key(g:markdown_extras_config, 'formatprg')
@@ -41,11 +42,6 @@ endif
4142
# --------------End prettier ------------------------
4243

4344
# -------------------- pandoc -----------------------
44-
if exists('g:markdown_extras_config') != 0
45-
&& has_key(g:markdown_extras_config, 'use_pandoc')
46-
use_pandoc = g:markdown_extras_config['use_pandoc']
47-
endif
48-
4945
if markdown_extras.use_pandoc
5046
# All the coreography happening inside here relies on the compiler
5147
# pandoc.
@@ -66,6 +62,8 @@ if markdown_extras.use_pandoc
6662
# TIP2: redraw! is used to avoid the "PRESS ENTER" thing
6763
echo cmd->matchstr('.*\ze2>&1') | redraw!
6864

65+
# TODO: pandoc compiler returns v:shell_error = 0 even if there are
66+
# errors. Add a condition on v:shell_error once pandoc compiler is fixed.
6967
if exists(':Open') != 0
7068
exe $'Open {output_file}'
7169
endif

plugin/markdown_extras.vim

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ elseif !has('patch-9.1.1071')
1616
finish
1717
endif
1818

19-
2019
if exists('g:markdown_extras_loaded')
2120
finish
2221
endif
23-
g:markdown_extras_loaded = true
2422

2523
augroup MARKDOWN_EXTRAS_VISITED_BUFFERS
2624
autocmd!
@@ -29,53 +27,52 @@ augroup MARKDOWN_EXTRAS_VISITED_BUFFERS
2927
\ funcs.RemoveVisitedBuffer(bufnr())
3028
augroup END
3129

32-
# Check if prettier can/shall be used or not
30+
# Check prettier executable
3331
export var use_prettier = true
3432

3533
if exists('g:markdown_extras_config') != 0
3634
&& has_key(g:markdown_extras_config, 'use_prettier')
3735
use_prettier = g:markdown_extras_config['use_prettier']
3836
endif
3937

40-
if use_prettier
41-
def PrettierInstalledCheck()
42-
if !executable('prettier')
43-
utils.Echowarn("'prettier' not installed!'")
44-
use_prettier = false
45-
endif
46-
enddef
47-
48-
augroup MARKDOWN_EXTRAS_PRETTIER_CHECK
49-
autocmd!
50-
# TODO: Changing BufReadPre with FileType markdown won't work because
51-
# FileType markdown autocmd is executed after ftplugin/markdown.vim is sourced,
52-
# and therefore ftplugin/markdown.vim would see use_prettier = true all
53-
# the time. Hence, the hack is to use BufReadPre and to specify all the
54-
# possible file extensions.
55-
autocmd BufReadPre *.md,*.markdown,*.mdown,*.mkd ++once
56-
\ PrettierInstalledCheck()
57-
augroup END
38+
# If user wants to use prettier but it is not available...
39+
if use_prettier && !executable('prettier')
40+
use_prettier = false
41+
# If vim is called with args, like vim README.md
42+
if &filetype == 'markdown'
43+
utils.Echowarn("'prettier' not installed!'")
44+
else
45+
# As soon as we open a markdown file, the error is displayed
46+
augroup MARKDOWN_EXTRAS_PRETTIER_ERROR
47+
autocmd!
48+
autocmd FileType markdown ++once {
49+
utils.Echowarn("'prettier' not installed!'")
50+
}
51+
augroup END
52+
endif
5853
endif
5954

60-
# Check if pandoc can/shall be used or not
55+
# Check pandoc executable
6156
export var use_pandoc = true
6257

6358
if exists('g:markdown_extras_config') != 0
6459
&& has_key(g:markdown_extras_config, 'use_pandoc')
6560
use_pandoc = g:markdown_extras_config['use_pandoc']
6661
endif
6762

68-
if use_pandoc
69-
def PandocInstalledCheck()
70-
if !executable('pandoc')
71-
utils.Echowarn("'pandoc' not installed!'")
72-
use_pandoc = false
73-
endif
74-
enddef
75-
76-
augroup MARKDOWN_EXTRAS_PANDOC_CHECK
77-
autocmd!
78-
autocmd BufReadPre *.md,*.markdown,*.mdown,*.mkd ++once
79-
\ PandocInstalledCheck()
80-
augroup END
63+
# If user wants to use pandoc but it is not available...
64+
if use_pandoc && !executable('pandoc')
65+
use_pandoc = false
66+
if &filetype == 'markdown'
67+
utils.Echowarn("'pandoc' not installed!'")
68+
else
69+
augroup MARKDOWN_EXTRAS_PANDOC_ERROR
70+
autocmd!
71+
autocmd FileType markdown ++once {
72+
utils.Echowarn("'pandoc' not installed!'")
73+
}
74+
augroup END
75+
endif
8176
endif
77+
78+
g:markdown_extras_loaded = true

0 commit comments

Comments
 (0)