Skip to content

Commit 4a9cb63

Browse files
committed
Improved checks on external tools such as prettier and pandoc
1 parent 0329960 commit 4a9cb63

File tree

2 files changed

+57
-19
lines changed

2 files changed

+57
-19
lines changed

ftplugin/markdown.vim

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ vim9script
33
import autoload "../autoload/mde_funcs.vim" as funcs
44
import autoload "../autoload/mde_links.vim" as links
55
import autoload '../autoload/mde_utils.vim' as utils
6-
import autoload '../autoload/mde_highlight.vim' as highlight
6+
import autoload '../autoload/mde_highlight.vim' as highlights
77
import autoload '../autoload/mde_constants.vim' as constants
88
import autoload '../autoload/mde_indices.vim' as indices
9+
import autoload '../plugin/markdown_extras.vim' as markdown_extras
910

1011
b:markdown_extras_links = links.RefreshLinksDict()
1112

@@ -18,14 +19,7 @@ nnoremap <buffer> <backspace> <ScriptCmd>funcs.GoToPrevVisitedBuffer()<cr>
1819
1920

2021
# -------------- prettier ------------------------
21-
var use_prettier = true
22-
if exists('g:markdown_extras_config') != 0
23-
&& has_key(g:markdown_extras_config, 'use_prettier')
24-
&& g:markdown_extras_config['use_prettier']
25-
use_prettier = g:markdown_extras_config['use_prettier']
26-
endif
27-
28-
if use_prettier && executable('prettier')
22+
if markdown_extras.use_prettier
2923
if exists('g:markdown_extras_config') != 0
3024
&& has_key(g:markdown_extras_config, 'formatprg')
3125
&l:formatprg = g:markdown_extras_config['formatprg']
@@ -47,14 +41,12 @@ endif
4741
# --------------End prettier ------------------------
4842

4943
# -------------------- pandoc -----------------------
50-
var use_pandoc = true
5144
if exists('g:markdown_extras_config') != 0
5245
&& has_key(g:markdown_extras_config, 'use_pandoc')
53-
&& g:markdown_extras_config['use_pandoc']
5446
use_pandoc = g:markdown_extras_config['use_pandoc']
5547
endif
5648

57-
if use_pandoc && executable('pandoc')
49+
if markdown_extras.use_pandoc
5850
# All the coreography happening inside here relies on the compiler
5951
# pandoc.
6052

@@ -198,7 +190,7 @@ if empty(maparg('<Plug>MarkdownRemove'))
198190
endif
199191

200192
def SetHighlightOpFunc()
201-
&l:opfunc = function(highlight.AddProp)
193+
&l:opfunc = function(highlights.AddProp)
202194
enddef
203195

204196
if empty(maparg('<Plug>MarkdownHighlight'))

plugin/markdown_extras.vim

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

19-
if !executable('prettier') && !exists('g:markdown_extras_loaded')
20-
utils.Echowarn("'prettier' not installed!'")
21-
endif
22-
if !executable('pandoc') && !exists('g:markdown_extras_loaded')
23-
utils.Echowarn("'pandoc' not installed!'")
24-
endif
2519

2620
if exists('g:markdown_extras_loaded')
2721
finish
@@ -33,3 +27,55 @@ augroup MARKDOWN_EXTRAS_VISITED_BUFFERS
3327
autocmd BufEnter *.md funcs.AddVisitedBuffer()
3428
autocmd BufDelete *.md funcs.RemoveVisitedBuffer(bufnr())
3529
augroup END
30+
31+
# Check if prettier can/shall be used or not
32+
export var use_prettier = true
33+
34+
if exists('g:markdown_extras_config') != 0
35+
&& has_key(g:markdown_extras_config, 'use_prettier')
36+
use_prettier = g:markdown_extras_config['use_prettier']
37+
endif
38+
39+
if use_prettier
40+
def PrettierInstalledCheck()
41+
if !executable('prettier')
42+
utils.Echowarn("'prettier' not installed!'")
43+
use_prettier = false
44+
endif
45+
enddef
46+
47+
if &filetype == "markdown"
48+
PrettierInstalledCheck()
49+
else
50+
augroup MARKDOWN_EXTRAS_PRETTIER_CHECK
51+
autocmd!
52+
autocmd BufReadPost *.md ++once PrettierInstalledCheck()
53+
augroup END
54+
endif
55+
endif
56+
57+
# Check if pandoc can/shall be used or not
58+
export var use_pandoc = true
59+
60+
if exists('g:markdown_extras_config') != 0
61+
&& has_key(g:markdown_extras_config, 'use_pandoc')
62+
use_pandoc = g:markdown_extras_config['use_pandoc']
63+
endif
64+
65+
if use_pandoc
66+
def PandocInstalledCheck()
67+
if !executable('pandoc')
68+
utils.Echowarn("'pandoc' not installed!'")
69+
use_pandoc = false
70+
endif
71+
enddef
72+
73+
if &filetype == "markdown"
74+
PandocInstalledCheck()
75+
else
76+
augroup MARKDOWN_EXTRAS_PANDOC_CHECK
77+
autocmd!
78+
autocmd BufReadPre *.md ++once PandocInstalledCheck()
79+
augroup END
80+
endif
81+
endif

0 commit comments

Comments
 (0)