Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 102 lines (95 sloc) 2.916 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
" scratch.vim
" @Author: Thomas Link (micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-07-18.
" @Last Change: 2008-10-03.
" @Revision: 0.0.122

if &cp || exists("loaded_tlib_scratch_autoload")
    finish
endif
let loaded_tlib_scratch_autoload = 1


" :def: function! tlib#scratch#UseScratch(?keyargs={})
" Display a scratch buffer (a buffer with no file). See :TScratch for an
" example.
" Return the scratch's buffer number.
function! tlib#scratch#UseScratch(...) "{{{3
    exec tlib#arg#Let([['keyargs', {}]])
" TLogDBG string(keys(keyargs))
    let id = get(keyargs, 'scratch', '__Scratch__')
" TLogVAR id
" TLogDBG winnr()
" TLogDBG bufnr(id)
" TLogDBG bufwinnr(id)
" TLogDBG bufnr('%')
    if id =~ '^\d\+$' && bufwinnr(id) != -1
        if bufnr('%') != id
            exec 'buffer! '. id
        endif
    else
        let bn = bufnr(id)
        let wpos = g:tlib_scratch_pos
        if get(keyargs, 'scratch_vertical')
            let wpos .= ' vertical'
        endif
" TLogVAR wpos
        if bn != -1
" TLogVAR bn
            let wn = bufwinnr(bn)
            if wn != -1
" TLogVAR wn
                exec wn .'wincmd w'
            else
                let cmd = get(keyargs, 'scratch_split', 1) ? wpos.' sbuffer! ' : 'buffer! '
" TLogVAR cmd
                silent exec cmd . bn
            endif
        else
" TLogVAR id
            let cmd = get(keyargs, 'scratch_split', 1) ? wpos.' split ' : 'edit '
" TLogVAR cmd
            silent exec cmd . escape(id, '%#\ ')
" silent exec 'split '. id
        endif
        let ft = get(keyargs, 'scratch_filetype', '')
" TLogVAR ft
" if !empty(ft)
        let &ft=ft
" end
    endif
    setlocal buftype=nofile
    setlocal bufhidden=hide
    setlocal noswapfile
    setlocal nobuflisted
    setlocal modifiable
    setlocal foldmethod=manual
    setlocal foldcolumn=0
    let keyargs.scratch = bufnr('%')
    return keyargs.scratch
endf


" Close a scratch buffer as defined in keyargs (usually a World).
function! tlib#scratch#CloseScratch(keyargs, ...) "{{{3
    TVarArg ['reset_scratch', 1]
    let scratch = get(a:keyargs, 'scratch', '')
" TLogVAR scratch, reset_scratch
    if !empty(scratch)
        let wn = bufwinnr(scratch)
" TLogVAR wn
        try
            if wn != -1
" TLogDBG winnr()
                let wb = tlib#win#Set(wn)
                wincmd c
" exec wb
" redraw
" TLogDBG winnr()
                return 1
            endif
        finally
            if reset_scratch
                let a:keyargs.scratch = ''
            endif
        endtry
    endif
    return 0
endf

Something went wrong with that request. Please try again.