Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check Marked 2 version before running commands #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/marked.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ name or path to the application in your |vimrc|: >
let g:marked_app = "/Applications/Setapp/Marked 2.app"
<
Note that this plugin requires Marked 2. If you are still using Marked 1, you
can use the 1.0.0 release of this plugin (see |marked-about|).
can use the 1.0.0 release of this plugin (see |marked-about|). If you still
have *g:marked_app* set to "Marked", you should update it to "Marked 2" or
remove it from your |vimrc|.

==============================================================================
ABOUT *marked-about*
Expand Down
34 changes: 34 additions & 0 deletions plugin/marked.vim
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,21 @@ function! s:MarkedOpenURI(background, command, args) abort
endfunction

function! s:MarkedOpen(background, path) abort
if s:MarkedVersionCheck() == 0
return
endif

call s:AddDocument(a:path)
call s:MarkedOpenURI(a:background, "open", { "file": a:path })

redraw!
endfunction

function! s:MarkedQuit(force, path) abort
if s:MarkedVersionCheck() == 0
return
endif

if a:force
let s:open_documents = []
call s:RunApplescript("quit")
Expand All @@ -58,6 +66,10 @@ function! s:MarkedQuit(force, path) abort
endfunction

function! s:MarkedPreview(background, line1, line2) abort
if s:MarkedVersionCheck() == 0
return
endif

let lines = getline(a:line1, a:line2)

call s:MarkedOpenURI(a:background, "preview", { "text": join(lines, "\n") })
Expand All @@ -73,6 +85,8 @@ let s:js =<< trim JS
return `error:Couldn't find Marked 2 application.`;
}

if (action == "version") return app.version();

if (!app.running()) return;

if (action == "quit") {
Expand Down Expand Up @@ -118,6 +132,26 @@ function! s:MarkedQuitVimLeave() abort
endif
endfunction

function! s:MarkedVersionCheck() abort
if !exists("s:marked_version")
let s:marked_version = s:RunApplescript("version")
endif

if s:marked_version =~ "^1"
echohl WarningMsg
echomsg "marked.vim requires Marked 2 but you've configured it to use Marked 1."
echomsg "See `:help g:marked_app` for more information."
echohl None
elseif s:marked_version !~ "^2"
echohl WarningMsg
echomsg "This plugin requires Marked 2."
echomsg "Visit https://marked2app.com to download it."
echohl None
end

return s:marked_version =~ "^2"
endfunction

function! s:RegisterCommands(filetype) abort
if index(g:marked_filetypes, a:filetype) >= 0
command! -buffer -bang MarkedOpen call s:MarkedOpen(<bang>0, expand('%:p'))
Expand Down