Skip to content

Commit

Permalink
Check Marked 2 version before running commands
Browse files Browse the repository at this point in the history
  • Loading branch information
itspriddle committed Jun 7, 2024
1 parent fa5f6b2 commit 002e127
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
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 Down Expand Up @@ -73,6 +81,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 All @@ -89,6 +99,10 @@ let s:js =<< trim JS
JS

function! s:RunApplescript(...) abort
if a:000[0] == "version"
echom "ran version..."
endif

let app = get(g:, "marked_app", "Marked 2")

let args = join(map([app] + copy(a:000), "shellescape(v:val, 1)"), " ")
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

0 comments on commit 002e127

Please sign in to comment.