diff options
author | carson fire <carsonfire@gmail.com> | 2012-02-24 00:00:00 +0000 |
---|---|---|
committer | Able Scraper <scraper@vim-scripts.org> | 2012-03-07 01:05:44 -0600 |
commit | 0117a7517a0484a882ab0e983aa3c9bce7b9e287 (patch) | |
tree | 2269c97f0cc77a1b7855bdd1fee7cc598b5e19b3 /plugin | |
parent | bf27f5cfaee4a39574d95ce01632d15c54372f7f (diff) | |
download | fountainwiki.vim-0117a7517a0484a882ab0e983aa3c9bce7b9e287.tar.gz |
Version 1.31.3
* Cleaner innards, better internal notes.
* More concise help file.
* Commands shortened; all begin with 'Fn' for quick access.
* Coordinated with Vimwiki navigation and functions.
* Complimentary navigation scheme for other subordinate files.
* Subordinate files wikified.
* Vimwiki-like header adjustment.
* Intuitive shortcut for ALLCAP LINES carriage return.
* Better title page text block protection (indentation).
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/fountainwiki.vim | 187 |
1 files changed, 147 insertions, 40 deletions
diff --git a/plugin/fountainwiki.vim b/plugin/fountainwiki.vim index 94c1051..498bc12 100644 --- a/plugin/fountainwiki.vim +++ b/plugin/fountainwiki.vim @@ -1,15 +1,13 @@ " Vim plugin for Fountain screenplay files -" Plugin Name: FountainWiki & Indentation -" Version: 1.2 -" Last Change: 2012 Feb 21 +" Plugin Name: Fountainwiki & Indentation +" Version: 1.3 +" Last Change: 2012 Feb 24 " Reference: http://fountain.io/ " Maintainer: Carson Fire <carsonfire@gmail.com> -if exists("g:wiki_1.path") - exe 'command WikiReset let g:wiki_1.path = "'.g:wiki_1.path.'"' -elseif exists("g:wiki.path") - exe 'command WikiReset let g:wiki.path = "'.g:wiki.path.'"' -endif +"{{{ Check user settings, load defaults + +" Indentation settings if !exists('FountainWiki_Auto_Indent') let FountainWiki_Auto_Indent = 1 endif @@ -31,6 +29,10 @@ endif if !exists('FountainWiki_Centered_Indent') let FountainWiki_Centered_Indent = '\t\t\t\t' endif +exe 'au FileType fountain,spmd setlocal tw='.g:FountainWiki_Textwidth +exe 'au FileType fountain,spmd setlocal tabstop='.g:FountainWiki_Tabstop + +" Wiki settings if !exists('FountainWiki_Card_Extension') let FountainWiki_Card_Extension = 'txt' endif @@ -47,52 +49,92 @@ if !exists('FountainWiki_Lowercase_Filename') let FountainWiki_Lowercase_Filename = 1 endif if !exists('FountainWiki_Filename_Token') - let FountainWiki_Filename_Token = '.fnx' + let FountainWiki_Filename_Token = '' endif if !exists('FountainWiki_Card_StayOpen') let FountainWiki_Card_StayOpen = 0 endif +"}}} + +"{{{ Create functions + function FountainWikiIndent() + " When triggered, this function indents an entire Fountain doc. normal mvgg}mt - "'t,$s/^\s*//ge - exe '%s/^\s*\(\L*\)$/'.g:FountainWiki_Character_Indent.'\1/ge' - exe '%s/^\s*\(.*\) TO:$/'.g:FountainWiki_Transition_Indent.'\1 TO:/ge' - exe '%s/^\s*> \(.*\)$/'.g:FountainWiki_Transition_Indent.'> \1/ge' - exe '%s/^\s*>\(.*\)</'.g:FountainWiki_Centered_Indent.'>\1</ge' - exe '%s/^\s*(\(.*\))$/'.g:FountainWiki_Parenthetical_Indent.'(\1)/ge' - 't,$s/^\s*\(\.\|INT\. \|EXT\. \|INT\.\/EXT\. \|INT\/EXT\. \|INT \|EXT \|INT\/EXT \|I\/E \|int\. \|ext\. \|int\.\/ext\. \|int\/ext\. \|int \|ext \|int\/ext \|i\/e \)/\1/ge - 't,$s/^\s*$//ge + let g:Safety = "'t,$" + " We bookmark our current location, then bookmark the first blank + " line. + exe g:Safety.'s/^\s*\(\L*\)$/'.g:FountainWiki_Character_Indent.'\1/ge' + exe g:Safety.'s/^\s*\(.*\) TO:$/'.g:FountainWiki_Transition_Indent.'\1 TO:/ge' + exe g:Safety.'s/^\s*> \(.*\)$/'.g:FountainWiki_Transition_Indent.'> \1/ge' + exe g:Safety.'s/^\s*>\(.*\)</'.g:FountainWiki_Centered_Indent.'>\1</ge' + exe g:Safety.'s/^\s*(\(.*\))$/'.g:FountainWiki_Parenthetical_Indent.'(\1)/ge' + " The range 't,$ protects the Fountain title page block; if there is + " no title page block, the first line will probably be a header that + " doesn't need to be indented anyway. + exe '%s/^\s*\(\.\|INT\.\|EXT\.\|INT \|EXT \|INT\/\|I\/E \)/\1/ge' + " Fix section headers mistaken for character names. + exe '%s/^\s*$//ge' + " Remove accidental tabs/spaces from otherwise blank lines. normal 'v + " We return the user to the spot where he began. +endfunction + +function FountainHeaderDown() + " Move header down (add one #, no more than six) + exe '.s/^\(\s*\)\(#*\)\(\s*\)/\1\2# /ge' + exe '.s/#\{7\}/######/ge' +endfunction + +function FountainHeaderUp() + " Move header up (remove one #) + exe '.s/^\(\s*\)\(#\s*\)/\1/ge' endfunction function FountainWikiCards() + " This opens a FountainWikiWord if there's a match. set noignorecase - if exists("g:wiki_1.path") - let g:wiki_1.path = expand("%:p:h") - elseif exists("g:wiki.path") + " Searches are case-sensitive. + if g:FountainWiki_Card_Extension == "wiki" && exists("g:wiki.path") let g:wiki.path = expand("%:p:h") - else + elseif g:FountainWiki_Card_Extension == "wiki" let wiki = {} let g:wiki.path = expand("%:p:h") endif + " We temporarily hijack Vimwiki's home path, if applicable. if g:FountainWiki_Card_Only < 1 && g:FountainWiki_Card_StayOpen < 1 only endif - lcd %:p:h + " If using the sidebar option, we close all windows but the screenplay + " before opening the sidebar. The use of the word 'card' throughout + " reflects the original idea of making 'index cards' open in the + " sidebar. It soon became clear that following the wiki model makes + " more sense. So 'card' is short for 'wiki reference file'. let g:Text = getline('.') + " We grab the current line and begin evaluating it for the presence of + " a FountainWikiWord. let g:Text = substitute(g:Text,"^\s*","","g") + " We remove spaces, as they have no bearing on identifying + " FountainWikiWord. if g:Text =~ "[[" let g:Comment = substitute(g:Text,".*\\[\\[\\(.*\\)\\]\\].*","\\1","g") let g:Comment = substitute(g:Text,"\\A*","","g") let g:Section = g:Comment let g:Character = g:Comment + " If the string contains [[, good bet it's a comment! else let g:Comment = "" let g:Character = substitute(g:Text,"\\U*","","g") let g:Section = substitute(g:Text,"\\A*","","g") + " Definitely not a comment, but it might be a character name + " or section header. endif if ( g:Character == g:Section || matchstr(g:Text,"^#") == "#" ) && g:Text != "" + " If the string passes the first test, it's a + " FountainWikiWord. If the string fails the first test, but + " begins with a hashmark, it's a section header + " FountainWikiWord. If the string is blank, we toss it out. if g:FountainWiki_Lowercase_Filename > 0 let g:Section = tolower(g:Section) endif @@ -103,30 +145,95 @@ function FountainWikiCards() if g:FountainWiki_Card_Right > 0 wincmd r endif + exe 'vertical resize '.g:FountainWiki_Card_Width + " We open the card/wiki file, in place of the + " screenplay, or as a 'sidebar' window, on the right + " or left, and resize if desired. endif - exe 'vertical resize '.g:FountainWiki_Card_Width endif endfunction function ScreenplayHome() - let g:FountainWiki_Home = expand("%:p") - let g:FountainWiki_Home = substitute(g:FountainWiki_Home," ","\\\\ ","g") + " This is a function for navigation. + let g:FountainWiki_Home = substitute(expand("%:p")," ","\\\\ ","g") + let g:FountainWiki_Path = expand("%:p:h") + " We record the position of the current Fountain doc. exe 'command! FountainWiki e '.g:FountainWiki_Home exe 'command! FW e '.g:FountainWiki_Home - nnoremap <leader>fw <esc>:FountainWiki<cr> - au BufRead *.wiki nmap <backspace> <esc>:FountainWiki<cr> + exe 'command! FnScreenplay e '.g:FountainWiki_Home + " Command(s) for returning to the last screenplay doc, from anywhere. + if g:FountainWiki_Card_Extension != "wiki" && g:FountainWiki_Card_Extension != "viki" && g:FountainWiki_Card_Extension != "fountain" + " We grant Vimwiki-like powers to text files + exe 'au BufRead,BufWrite,BufNewFile '.g:FountainWiki_Path.'/*.'.g:FountainWiki_Card_Extension.' nnoremap <buffer> <backspace> <c-o>' + exe 'au BufRead,BufWrite '.g:FountainWiki_Path.'/*.'.g:FountainWiki_Card_Extension.' map <buffer> <cr> <esc>:call SpecialLink()<cr>' + endif +endfunction + +function SpecialLink() + " Wikifies file links in non-wiki files. + let g:FnCheck = expand("<cfile>") + if g:FnCheck =~ '.'.g:FountainWiki_Card_Extension + e <cfile> + else + echo 'Link must be filetype "'.g:FountainWiki_Card_Extension.'"' + endif endfunction -command FountainWikiCursorJump wincmd w -command FountainWikiDisableAuto au! BufWrite *.fountain,*.spmd -command FountainWikiEnableAuto au BufWrite *.fountain,*.spmd silent call FountainWikiIndent() -command FountainWikiIndent silent call FountainWikiIndent() -au BufWrite *.fountain,*.spmd FountainWikiIndent -au BufWrite *.fountain,*.spmd FountainWikiCursorJump -au BufRead *.fountain,*.spmd nnoremap <buffer> <c-cr> <esc>:FountainWikiIndent<cr> -command FountainWikiCards silent call FountainWikiCards() -au BufRead *.fountain,*.spmd nnoremap <buffer> <cr> <esc>:FountainWikiCards<cr> -exe 'au BufRead *.fountain,*.spmd set tw='.g:FountainWiki_Textwidth -exe 'au BufRead *.fountain,*.spmd set tabstop='.g:FountainWiki_Tabstop -exe 'au BufRead *.fountain,*.spmd,*'.g:FountainWiki_Filename_Token.g:FountainWiki_Card_Extension.' nnoremap <buffer> <tab> <c-w>w' -au BufRead *.fountain,*.spmd call ScreenplayHome() +if g:FountainWiki_Card_Extension == "wiki" + " Special adjustments for Vimwiki integration. + if exists("g:wiki.path") + exe 'command! FnReset let g:wiki.path = "'.g:wiki.path.'"' + else + command! FnReset echo "No wiki reset required." + endif + nnoremap <leader>ww <esc>:FnReset<cr>:VimwikiIndex<cr> + nnoremap <leader>wt <esc>:FnReset<cr>:VimwikiTabIndex<cr> + nnoremap <leader>w<leader>w <esc>:FnReset<cr>:VimwikiMakeDiaryNote<cr> + " This resets Vimwiki home to its original value, so that <leader>ww + " results in the expected behavior. + au FileType fountain,spmd map <buffer> <backspace> <esc>:FnReset<cr>:VimwikiIndex<cr> + " If you press 'backspace' in your Fountain doc, we reset Vimwiki home + " to original value and send you there. +endif + +"}}} + +"{{{ Define commands and do stuff + +" Indentation commands, restricted to Fountain files except where otherwise +" noted. +au BufWrite *.fountain,*.spmd silent call FountainWikiIndent() +" Makes indentation automatic on saving +command FountainDisableAutoIndent au! BufWrite *.fountain,*.spmd +command FnOff au! BufWrite *.fountain,*.spmd +" Turn auto indent off +command FountainEnableAutoIndent au BufWrite *.fountain,*.spmd silent call FountainWikiIndent() +command FnOn au BufWrite *.fountain,*.spmd silent call FountainWikiIndent() +" Turn auto indent back on +au FileType fountain,spmd nnoremap <buffer> <c-cr> <esc>:call FountainWikiIndent()<cr> +" CTRL-ENTER indentation shortcut, indents without saving. +command FountainIndent silent call FountainWikiIndent() +command FnIndent silent call FountainWikiIndent() +" Global-use indentation command + +" Wiki commands +command FnJump wincmd w +command FnLink silent call FountainWikiCards() +command FnSublink e <cfile> +au FileType fountain,spmd nnoremap <buffer> <cr> <esc>:silent call FountainWikiCards()<cr> + +" Vimwiki-like header mapping +au FileType fountain,spmd nnoremap <buffer> = <esc>:call FountainHeaderDown()<cr> +au FileType fountain,spmd nnoremap <buffer> - <esc>:call FountainHeaderUp()<cr> + +" Set the latest opened Fountain screenplay as the 'home' screenplay. +au BufWinEnter *.fountain,*.spmd silent call ScreenplayHome() +" Get navigation help. +exe 'nnoremap <backspace><backspace> <esc>:FnScreenplay<cr>' +" Double-backspace guides you back to last open Fountain doc. + +" Quick uppercase shift +au FileType fountain,spmd inoremap <buffer> <s-cr> <esc>gUU$a<cr> +au FileType fountain,spmd nnoremap <buffer> <s-cr> gUU$ + +"}}} |