Merge commit '513e852552e60e580dfc8feff1410fadc98ac56f' as 'vim/bundle/instant-markdown'
commit
72f3f5f2fe
@ -0,0 +1,36 @@
|
|||||||
|
### 0.0.2 (03-27-2012)
|
||||||
|
All changes for this release were made in the backend. Do `[sudo] npm -g update instant-markdown-d` to get them.
|
||||||
|
|
||||||
|
- Updated to the latest github styles!
|
||||||
|
- Performance should be slightly better as CSS is no longer generated at every update.
|
||||||
|
|
||||||
|
### 0.0.3 (04-26-2012)
|
||||||
|
Some changes for this release were made in the backend. Do `[sudo] npm -g update instant-markdown-d` to get them.
|
||||||
|
|
||||||
|
- Delay starting the `instant-markdown-d` server. This fixed the plugin for a few people who were getting empty browser windows.
|
||||||
|
- Display a message with configuration instructions when the preview window can't be closed due to Firefox restrictions.
|
||||||
|
|
||||||
|
### 0.0.4 (12-05-2012)
|
||||||
|
All these changes courtesy of @chreekat, THANKS!
|
||||||
|
|
||||||
|
- Is now an `after/ftplugin` plugin. Markdown filetype detection is left to Vim itself, or other plugins.
|
||||||
|
- Behavior when multiple markdown files are open has been improved
|
||||||
|
- No more weird characters taking over the status/command bar while editing
|
||||||
|
- Internals have been completely rewritten and are much more cleaner and adhere to vim script best practices
|
||||||
|
|
||||||
|
### 0.0.5 (12-05-2012)
|
||||||
|
These changes are _also_ courtesy of @chreekat!
|
||||||
|
|
||||||
|
- Plugin no longer breaks vim mouse scrolling
|
||||||
|
- No longer errors upon opening an empty markdown file
|
||||||
|
- `instant_markdown_slow` option to update preview less frequently
|
||||||
|
|
||||||
|
### 0.0.6 (03-02-2013)
|
||||||
|
All changes for this release were made in the backend. Do `[sudo] npm -g update instant-markdown-d` to get them.
|
||||||
|
|
||||||
|
- Fix for systems (such as Ubuntu, Debian) which use the `nodejs` executable instead of `node`.
|
||||||
|
|
||||||
|
### 0.0.7 (10-31-2013)
|
||||||
|
thanks to @terryma!
|
||||||
|
|
||||||
|
- Added option to only start previewing markdown on demand
|
@ -0,0 +1,75 @@
|
|||||||
|
vim-instant-markdown
|
||||||
|
====================
|
||||||
|
Want to instantly preview finnicky markdown files, but don't want to leave your favorite editor, or have to do it in some crappy browser textarea? **vim-instant-markdown** is your friend! When you open a markdown file in vim, a browser window will open which shows the compiled markdown in real-time, and closes once you close the file in vim.
|
||||||
|
|
||||||
|
As a bonus, [github-flavored-markdown][gfm] is supported, and styles used while previewing are the same as those github uses!
|
||||||
|
|
||||||
|
[![Screenshot][ss]][ssbig]
|
||||||
|
|
||||||
|
Installation
|
||||||
|
------------
|
||||||
|
You first need to have Ruby with RubyGems, and node.js with npm installed. (In the future there might be a version which won't require node.js at all, making installation easier)
|
||||||
|
|
||||||
|
- `[sudo] gem install pygments.rb`
|
||||||
|
- If you're using Ruby 1.9.2 or later, `[sudo] gem install redcarpet`. Otherwise, `[sudo] gem install redcarpet -v 2.3.0`
|
||||||
|
- `[sudo] npm -g install instant-markdown-d`
|
||||||
|
- If you're on Linux, the `xdg-utils` package needs to be installed (is installed by default on Ubuntu).
|
||||||
|
- Copy the `after/ftplugin/markdown/instant-markdown.vim` file from this repo into your `~/.vim/after/ftplugin/markdown/` (creating directories as necessary), or use pathogen.
|
||||||
|
- Ensure you have the line `filetype plugin on` in your `.vimrc`
|
||||||
|
- Open a markdown file in vim and enjoy!
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
-------------
|
||||||
|
### g:instant_markdown_slow
|
||||||
|
|
||||||
|
By default, vim-instant-markdown will update the display in realtime. If that taxes your system too much, you can specify
|
||||||
|
|
||||||
|
```
|
||||||
|
let g:instant_markdown_slow = 1
|
||||||
|
```
|
||||||
|
|
||||||
|
before loading the plugin (for example place that in your `~/.vimrc`). This will cause vim-instant-markdown to only refresh on the following events:
|
||||||
|
|
||||||
|
- No keys have been pressed for a while
|
||||||
|
- A while after you leave insert mode
|
||||||
|
- You save the file being edited
|
||||||
|
|
||||||
|
### g:instant_markdown_autostart
|
||||||
|
By default, vim-instant-markdown will automatically launch the preview window when you open a markdown file. If you want to manually control this behavior, you can specify
|
||||||
|
|
||||||
|
```
|
||||||
|
let g:instant_markdown_autostart = 0
|
||||||
|
```
|
||||||
|
|
||||||
|
in your .vimrc. You can then manually trigger preview via the command ```:InstantMarkdownPreview```. This command is only available inside markdown buffers and when the autostart option is turned off.
|
||||||
|
|
||||||
|
Supported Platforms
|
||||||
|
-------------------
|
||||||
|
OSX and Unix/Linuxes*.
|
||||||
|
|
||||||
|
<sub>*: One annoyance in Linux is that there's no way to reliably open a browser page in the background, so you'll likely have to manually refocus your vim session everytime you open a Markdown file. If you have ideas on how to address this I'd love to know!</sub>
|
||||||
|
|
||||||
|
FAQ
|
||||||
|
---
|
||||||
|
> Why don't my `<bla>.md` files trigger this plugin?
|
||||||
|
|
||||||
|
By default, vim (7.3 and above) only recognizes files ending with `.markdown`, `.mdown`, and `README.md` as markdown files. If you want `<anything>.md` to be recognized, I recommend installing one of many markdown plugins available, such as [this one][tpope-markdown].
|
||||||
|
|
||||||
|
> It's not working!
|
||||||
|
|
||||||
|
- Make sure all the dependencies are installed...
|
||||||
|
- Make sure `instant-markdown-d` was installed as a global module (e.g. using `npm -g install`)
|
||||||
|
- Make sure the ruby gems were installed under your default Ruby (i.e. if you're using RVM, use `gem install` and NOT `sudo gem install` as that might cause the gems to be installed under a non-RVM Ruby)
|
||||||
|
- If you're on OSX, and are using zsh and rbenv/rvm...
|
||||||
|
- Make sure that Vim is using the correct version of ruby. From vim, if ```:!which ruby``` returns an unexpected ruby, then see here for a solution: https://github.com/dotphiles/dotzsh#mac-os-x.
|
||||||
|
- Another thing to try would be to add `set shell=bash\ -i` in your `.vimrc` to set interactive bash as the default vim shell. (See [this issue](http://github.com/suan/vim-instant-markdown/issues/41))
|
||||||
|
|
||||||
|
etc.
|
||||||
|
---
|
||||||
|
If you're curious, the code for the mini-server component for this plugin can be found at http://github.com/suan/instant-markdown-d. A plugin can easily be written for any editor to interface with the server to get the same functionality found here.
|
||||||
|
|
||||||
|
|
||||||
|
[ss]: http://dl.dropbox.com/u/28956267/instant-markdown-demo_thumb.gif "Click for bigger preview"
|
||||||
|
[ssbig]: http://dl.dropbox.com/u/28956267/instant-markdown-demo.gif
|
||||||
|
[gfm]: http://github.github.com/github-flavored-markdown/
|
||||||
|
[tpope-markdown]: https://github.com/tpope/vim-markdown
|
@ -0,0 +1,135 @@
|
|||||||
|
" # Configuration
|
||||||
|
if !exists('g:instant_markdown_slow')
|
||||||
|
let g:instant_markdown_slow = 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
if !exists('g:instant_markdown_autostart')
|
||||||
|
let g:instant_markdown_autostart = 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
" # Utility Functions
|
||||||
|
" Simple system wrapper that ignores empty second args
|
||||||
|
function! s:system(cmd, stdin)
|
||||||
|
if strlen(a:stdin) == 0
|
||||||
|
call system(a:cmd)
|
||||||
|
else
|
||||||
|
call system(a:cmd, a:stdin)
|
||||||
|
endif
|
||||||
|
endfu
|
||||||
|
|
||||||
|
function! s:refreshView()
|
||||||
|
let bufnr = expand('<bufnr>')
|
||||||
|
call s:system("curl -X PUT -T - http://localhost:8090/ &>/dev/null &",
|
||||||
|
\ s:bufGetContents(bufnr))
|
||||||
|
endfu
|
||||||
|
|
||||||
|
function! s:startDaemon(initialMD)
|
||||||
|
call s:system("instant-markdown-d &>/dev/null &", a:initialMD)
|
||||||
|
endfu
|
||||||
|
|
||||||
|
function! s:initDict()
|
||||||
|
if !exists('s:buffers')
|
||||||
|
let s:buffers = {}
|
||||||
|
endif
|
||||||
|
endfu
|
||||||
|
|
||||||
|
function! s:pushBuffer(bufnr)
|
||||||
|
call s:initDict()
|
||||||
|
let s:buffers[a:bufnr] = 1
|
||||||
|
endfu
|
||||||
|
|
||||||
|
function! s:popBuffer(bufnr)
|
||||||
|
call s:initDict()
|
||||||
|
call remove(s:buffers, a:bufnr)
|
||||||
|
endfu
|
||||||
|
|
||||||
|
function! s:killDaemon()
|
||||||
|
call system("curl -s -X DELETE http://localhost:8090/ &>/dev/null &")
|
||||||
|
endfu
|
||||||
|
|
||||||
|
function! s:bufGetContents(bufnr)
|
||||||
|
return join(getbufline(a:bufnr, 1, "$"), "\n")
|
||||||
|
endfu
|
||||||
|
|
||||||
|
" I really, really hope there's a better way to do this.
|
||||||
|
fu! s:myBufNr()
|
||||||
|
return str2nr(expand('<abuf>'))
|
||||||
|
endfu
|
||||||
|
|
||||||
|
" # Functions called by autocmds
|
||||||
|
"
|
||||||
|
" ## push a new Markdown buffer into the system.
|
||||||
|
"
|
||||||
|
" 1. Track it so we know when to garbage collect the daemon
|
||||||
|
" 2. Start daemon if we're on the first MD buffer.
|
||||||
|
" 3. Initialize changedtickLast, possibly needlessly(?)
|
||||||
|
fu! s:pushMarkdown()
|
||||||
|
let bufnr = s:myBufNr()
|
||||||
|
call s:initDict()
|
||||||
|
if len(s:buffers) == 0
|
||||||
|
call s:startDaemon(s:bufGetContents(bufnr))
|
||||||
|
endif
|
||||||
|
call s:pushBuffer(bufnr)
|
||||||
|
let b:changedtickLast = b:changedtick
|
||||||
|
endfu
|
||||||
|
|
||||||
|
" ## pop a Markdown buffer
|
||||||
|
"
|
||||||
|
" 1. Pop the buffer reference
|
||||||
|
" 2. Garbage collection
|
||||||
|
" * daemon
|
||||||
|
" * autocmds
|
||||||
|
fu! s:popMarkdown()
|
||||||
|
let bufnr = s:myBufNr()
|
||||||
|
silent au! instant-markdown * <buffer=abuf>
|
||||||
|
call s:popBuffer(bufnr)
|
||||||
|
if len(s:buffers) == 0
|
||||||
|
call s:killDaemon()
|
||||||
|
endif
|
||||||
|
endfu
|
||||||
|
|
||||||
|
" ## Refresh if there's something new worth showing
|
||||||
|
"
|
||||||
|
" 'All things in moderation'
|
||||||
|
fu! s:temperedRefresh()
|
||||||
|
if !exists('b:changedtickLast')
|
||||||
|
let b:changedtickLast = b:changedtick
|
||||||
|
elseif b:changedtickLast != b:changedtick
|
||||||
|
let b:changedtickLast = b:changedtick
|
||||||
|
call s:refreshView()
|
||||||
|
endif
|
||||||
|
endfu
|
||||||
|
|
||||||
|
fu! s:previewMarkdown()
|
||||||
|
call s:startDaemon(join(getline(1, '$'), "\n"))
|
||||||
|
aug instant-markdown
|
||||||
|
if g:instant_markdown_slow
|
||||||
|
au CursorHold,BufWrite,InsertLeave <buffer> call s:temperedRefresh()
|
||||||
|
else
|
||||||
|
au CursorHold,CursorHoldI,CursorMoved,CursorMovedI <buffer> call s:temperedRefresh()
|
||||||
|
endif
|
||||||
|
au BufWinLeave <buffer> call s:cleanUp()
|
||||||
|
aug END
|
||||||
|
endfu
|
||||||
|
|
||||||
|
fu! s:cleanUp()
|
||||||
|
call s:killDaemon()
|
||||||
|
au! instant-markdown * <buffer>
|
||||||
|
endfu
|
||||||
|
|
||||||
|
if g:instant_markdown_autostart
|
||||||
|
" # Define the autocmds "
|
||||||
|
aug instant-markdown
|
||||||
|
au! * <buffer>
|
||||||
|
au BufEnter <buffer> call s:refreshView()
|
||||||
|
if g:instant_markdown_slow
|
||||||
|
au CursorHold,BufWrite,InsertLeave <buffer> call s:temperedRefresh()
|
||||||
|
else
|
||||||
|
au CursorHold,CursorHoldI,CursorMoved,CursorMovedI <buffer> call s:temperedRefresh()
|
||||||
|
endif
|
||||||
|
au BufWinLeave <buffer> call s:popMarkdown()
|
||||||
|
au BufwinEnter <buffer> call s:pushMarkdown()
|
||||||
|
aug END
|
||||||
|
else
|
||||||
|
command! -buffer InstantMarkdownPreview call s:previewMarkdown()
|
||||||
|
endif
|
Loading…
Reference in New Issue