1
0
Fork 0
mirror of synced 2024-12-25 00:03:20 -05:00

Adding vim-marked.

This commit is contained in:
Maksim Pecherskiy 2014-04-19 14:18:51 -07:00
parent a1561315cb
commit 03a762fb74
3 changed files with 77 additions and 1 deletions

@ -1 +0,0 @@
Subproject commit a7c1cba232cabd96af800f82aad21cc180a09764

View file

@ -0,0 +1,22 @@
# marked.vim
Open the current Markdown buffer in [Marked.app](http://markedapp.com/).
## Usage
This plugin adds the following commands to Markdown buffers:
:MarkedOpen[!] Open the current Markdown buffer in Marked.app.
Call with a bang to prevent Marked.app from stealing
focus from Vim.
:MarkedQuit Close the current Markdown buffer in Marked.app.
Quit Marked.app if no other documents are open.
If you run `:MarkedOpen`, the document in Marked.app will be automatically
closed when Vim exists, and Marked.app will quit if no other documents are
open.
## License
Same as Vim itself, see `:help license`.

View file

@ -0,0 +1,55 @@
" marked.vim
" Author: Joshua Priddle <jpriddle@me.com>
" URL: https://github.com/itspriddle/vim-marked
" Version: 0.4.0
" License: Same as Vim itself (see :help license)
if &cp || exists("g:marked_loaded") && g:marked_loaded
finish
endif
let g:marked_loaded = 1
let s:save_cpo = &cpo
set cpo&vim
function s:OpenMarked(background)
let l:filename = expand("%:p")
silent exe "!open -a Marked.app ".(a:background ? '-g' : '')." '".l:filename."'"
silent exe "augroup marked_autoclose_".l:filename
autocmd!
silent exe 'autocmd VimLeavePre * call s:QuitMarked("'.l:filename.'")'
augroup END
redraw!
endfunction
function s:QuitMarked(path)
silent exe "augroup marked_autoclose_".a:path
autocmd!
augroup END
silent exe "augroup! marked_autoclose_".a:path
let cmd = " -e 'try'"
let cmd .= " -e 'if application \"Marked\" is running then'"
let cmd .= " -e 'tell application \"Marked\"'"
let cmd .= " -e 'close (first document whose path is equal to \"".a:path."\")'"
let cmd .= " -e 'if count of every window is equal to 0 then'"
let cmd .= " -e 'quit'"
let cmd .= " -e 'end if'"
let cmd .= " -e 'end tell'"
let cmd .= " -e 'end if'"
let cmd .= " -e 'end try'"
silent exe "!osascript ".cmd
redraw!
endfunction
augroup marked_commands
autocmd!
autocmd FileType markdown,mkd command! -buffer -bang MarkedOpen :call s:OpenMarked(<bang>0)
autocmd FileType markdown,mkd command! -buffer MarkedQuit :call s:QuitMarked(expand('%:p'))
augroup END
let &cpo = s:save_cpo
unlet s:save_cpo
" vim:ft=vim:fdm=marker:ts=2:sw=2:sts=2:et