nvim: Fix scratchpad functionality
`:ScratchPad` command has been fixed and its functionality slightly extended: `:ScratchPad` will replace the current buffer with an empty scratchpad, with the filetype defined in `g:scratchpad_ft` (or the buffer-scope equivalent). `:ScratchPad!` will create a new split and open the empty scratchpad there. Additionally, a single argument can be passed to the command with the name of the filetype that the scratchpad should contain, e.g. `:Scratchpad! golang` Most of the plugin process has been shifted to lua and only a single command mapping remains as vimscript for now.
This commit is contained in:
parent
285e74f1a7
commit
afbe10c0d1
3 changed files with 52 additions and 9 deletions
|
@ -1,11 +1,40 @@
|
||||||
|
--[[
|
||||||
|
creates a 'scratch' buffer which is ephemeral --
|
||||||
|
it will disappear when vim closes, does not save to anything and does not
|
||||||
|
appear in the buffer list. Useful for e.g. jotting down quick notes and thoughts.
|
||||||
|
|
||||||
|
If called with bang, will replace the current buffer with the scratch
|
||||||
|
window, otherwise opens a new split.
|
||||||
|
|
||||||
|
The buffer, by default is set to the pandoc filetype.
|
||||||
|
This can be changed by setting the `g:scratchpad_ft` variable or the `b:scratchpad_ft`
|
||||||
|
variable to the intended filetype.
|
||||||
|
]]--
|
||||||
local api = vim.api
|
local api = vim.api
|
||||||
local M= {}
|
local M= {}
|
||||||
|
|
||||||
function M.makeScratch()
|
local function isempty(s)
|
||||||
api.nvim_command('enew')
|
return s == nil or s == ''
|
||||||
-- vim.bo[0].bufhidden=hide
|
end
|
||||||
vim.bo[0].buftype=nofile
|
|
||||||
vim.bo[0].swapfile=false
|
function M.create(split, ft)
|
||||||
|
-- should we create a new split or switch out the current buffer?
|
||||||
|
if isempty(split) then split = false else split = true end
|
||||||
|
-- which filetype to set for the scratchpad, defaults to pandoc
|
||||||
|
if isempty(ft) then ft = vim.b["scratchpad_ft"] or vim.g["scratchpad_ft"] or "pandoc" end
|
||||||
|
|
||||||
|
local buf = api.nvim_create_buf(false, true)
|
||||||
|
if buf == 0 then
|
||||||
|
print("Error opening scratch buffer.")
|
||||||
|
end
|
||||||
|
api.nvim_buf_set_option(buf, "bufhidden", "hide")
|
||||||
|
api.nvim_buf_set_option(buf, "buftype", "nofile")
|
||||||
|
api.nvim_buf_set_option(buf, "swapfile",false)
|
||||||
|
api.nvim_buf_set_option(buf, "filetype",ft)
|
||||||
|
|
||||||
|
if split then api.nvim_command('vsplit new') end -- i think this is the only way to interact with the buffers creating a new split
|
||||||
|
-- switch to scratchpad
|
||||||
|
api.nvim_win_set_buf(0, buf)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
@ -1,5 +1,15 @@
|
||||||
function s:makeScratch()
|
" --[[ scratchpad.lua
|
||||||
lua require('scratchpad').makeScratch()
|
"
|
||||||
endfunction
|
" creates a 'scratch' buffer which is ephemeral --
|
||||||
|
" it will disappear when vim closes, does not save to anything and does not
|
||||||
|
" appear in the buffer list. Useful for e.g. jotting down quick notes and thoughts.
|
||||||
|
"
|
||||||
|
" If called with bang, will replace the current buffer with the scratch
|
||||||
|
" window, otherwise opens a new split.
|
||||||
|
"
|
||||||
|
" The buffer, by default is set to the pandoc filetype.
|
||||||
|
" This can be changed by setting the `g:scratchpad_ft` variable or the `b:scratchpad_ft`
|
||||||
|
" variable to the intended filetype.
|
||||||
|
" ]]--
|
||||||
|
|
||||||
command! ScratchPad call s:makeScratch()
|
command! -nargs=? -bang ScratchPad :lua require("scratchpad").create("<bang>","<args>")
|
||||||
|
|
|
@ -72,3 +72,7 @@ dialogue
|
||||||
Uber
|
Uber
|
||||||
precarity
|
precarity
|
||||||
financialization
|
financialization
|
||||||
|
Walmart
|
||||||
|
Wrocław
|
||||||
|
Poznań
|
||||||
|
Taylorization
|
||||||
|
|
Loading…
Reference in a new issue