@@ -16,11 +16,9 @@ elseif !has('patch-9.1.1071')
1616 finish
1717endif
1818
19-
2019if exists (' g:markdown_extras_loaded' )
2120 finish
2221endif
23- g: markdown_extras_loaded = true
2422
2523augroup MARKDOWN_EXTRAS_VISITED_BUFFERS
2624 autocmd !
@@ -29,53 +27,52 @@ augroup MARKDOWN_EXTRAS_VISITED_BUFFERS
2927 \ funcs.RemoveVisitedBuffer (bufnr ())
3028augroup END
3129
32- # Check if prettier can/shall be used or not
30+ # Check prettier executable
3331export var use_prettier = true
3432
3533if exists (' g:markdown_extras_config' ) != 0
3634 && has_key (g: markdown_extras_config , ' use_prettier' )
3735 use_prettier = g: markdown_extras_config [' use_prettier' ]
3836endif
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
5853endif
5954
60- # Check if pandoc can/shall be used or not
55+ # Check pandoc executable
6156export var use_pandoc = true
6257
6358if exists (' g:markdown_extras_config' ) != 0
6459 && has_key (g: markdown_extras_config , ' use_pandoc' )
6560 use_pandoc = g: markdown_extras_config [' use_pandoc' ]
6661endif
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
8176endif
77+
78+ g: markdown_extras_loaded = true
0 commit comments