Takeshi NISHIDA avatar Takeshi NISHIDA committed 8d52f1e

changed l9#tempbuffer

Comments (0)

Files changed (4)

autoload/l9/tempbuffer.vim

 " a:bufname:
 " a:height: Window height. If 0, default height is used.
 "           If less than 0, the window becomes full-screen. 
-" a:listener:
-"   a:listener.onClose(written)
-"   a:listener.onWrite(lines)
-function l9#tempbuffer#open(bufname, filetype, lines, topleft, vertical, height, writable, listener)
+function l9#tempbuffer#openScratch(bufname, filetype, lines, topleft, vertical, height)
   let openCmdPrefix = (a:topleft ? 'topleft ' : '')
         \           . (a:vertical ? 'vertical ' : '')
         \           . (a:height > 0 ? a:height : '')
     execute openCmdPrefix . 'split'
     execute 'silent ' . s:dataMap[a:bufname].bufNr . 'buffer'
   endif
-  let s:dataMap[a:bufname] = {
-        \   'bufNr': bufnr('%'),
-        \   'written': 0,
-        \   'listener': a:listener,
-        \ }
   if a:height < 0
     only
   endif
-  setlocal buflisted noswapfile bufhidden=delete
+  setlocal buflisted noswapfile bufhidden=delete modifiable noreadonly buftype=nofile
   let &l:filetype = a:filetype
   silent file `=a:bufname`
   call setline(1, a:lines)
-  if a:writable
-    setlocal nomodified   modifiable noreadonly buftype=acwrite
-  else
-    setlocal nomodified nomodifiable   readonly buftype=nofile
-  endif
+  setlocal nomodified
+  let s:dataMap[a:bufname] = {
+        \   'bufNr': bufnr('%'),
+        \ }
+endfunction
+
+" a:bufname:
+" a:height: Window height. If 0, default height is used.
+"           If less than 0, the window becomes full-screen. 
+" a:listener:
+"   a:listener.onClose(written)
+"   a:listener.onWrite(lines)
+function l9#tempbuffer#openReadOnly(bufname, filetype, lines, topleft, vertical, height)
+  call l9#tempbuffer#openScratch(a:bufname, a:filetype, a:lines, a:topleft, a:vertical, a:height)
+  setlocal nomodifiable readonly
+endfunction
+
+" a:listener:
+"   a:listener.onClose(written)
+"   a:listener.onWrite(lines)
+function l9#tempbuffer#openWritable(bufname, filetype, lines, topleft, vertical, height, listener)
+  call l9#tempbuffer#openScratch(a:bufname, a:filetype, a:lines, a:topleft, a:vertical, a:height)
+  setlocal buftype=acwrite
+  let s:dataMap[a:bufname].listener = a:listener
+  let s:dataMap[a:bufname].written = 0
   augroup L9TempBuffer
     autocmd! * <buffer>
     execute printf('autocmd BufDelete   <buffer>        call s:onBufDelete  (%s)', string(a:bufname))
 
 作者:       Takeshi NISHIDA <ns9tks@DELETE-ME.gmail.com>
 ライセンス: MIT Licence
-URL:        http://www.vim.org/scripts/script.php?script_id= [TODO]
+URL:        http://www.vim.org/scripts/script.php?script_id=3252
             http://bitbucket.org/ns9tks/vim-l9/
 
 バグや要望など ~
 
 Author:  Takeshi NISHIDA <ns9tks@DELETE-ME.gmail.com>
 Licence: MIT Licence
-URL:     http://www.vim.org/scripts/script.php?script_id= [TODO]
+URL:     http://www.vim.org/scripts/script.php?script_id=3252
          http://bitbucket.org/ns9tks/vim-l9/
 
 Bugs/Issues/Suggestions/Improvements ~
   function s:timerDump()
     L9TimerStop
     let lines = map(s:timerData, 'v:val.tag . repeat(" ", s:timerTagMaxLen - len(v:val.tag)) . v:val.time')
-    call l9#tempbuffer#open('[l9-timer]', '', lines, 0, 0, 0, 0, {})
+    call l9#tempbuffer#openReadOnly('[l9-timer]', '', lines, 0, 0, 0)
     let s:timerData = []
     let s:timerTagMaxLen = 0
   endfunction
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.