Commit 2c5342d3 authored by Marco Kellershoff's avatar Marco Kellershoff 🤸

Add Screenshot from range

parent 59923a2c
......@@ -13,6 +13,22 @@ so you'd have to make sure that `scrot` is installed.
The screenshot is placed in `~/Pictures/Screenshot.nvim-YYYYMMDD-HHMMSS.png`.
### Range
The `Screenshot` command can also be used with a range, e.g.:
```
:'<,'>Screenshot
```
This opens up a new buffer and sets the filetype to the ft where the selection
came from and then it waits for 500ms and takes a Screenshot.
Then it waits another 500ms and force closes the buffer (`:bd!`).
**Important: Make sure 'hidden' or 'autowriteall' is set,
otherwise this fails if there are unsaved changes.**
It also takes into account the existence of
[XDG user directories][xdg_user_dirs].
......
......@@ -26,6 +26,21 @@ Screenshot *:Screenshot*
It'll write the Screenshots to this directory
instead of the default `$HOME/Pictures`.
The `Screenshot` command can also be used with a range, e.g.:
`:'<,'>Screenshot`
This opens up a new buffer and sets the 'filetype'
to the 'ft' where the selection
came from and then it waits for 500ms and takes a Screenshot.
Then it waits another 500ms and force closes the buffer (`:bd!`).
IMPORTANT:
Make sure 'hidden' or 'autowriteall' is set,
otherwise this fails if there are unsaved changes.
MAPPINGS *Screenshot-mappings*
There are no mappings registered by the plugin.
......
......@@ -27,6 +27,20 @@ function! Screenshot#Window()
call s:ExecExternalCommand(cmd)
endfunction
function! Screenshot#ForceCloseBuffer()
execute "bd!"
endfunction
function! Screenshot#WindowRange() range
let sel = getline(a:firstline, a:lastline)
let ft = &filetype
execute "enew"
call append(0, sel)
execute "set ft=" . ft
call timer_start(500, { tid -> Screenshot#Window() })
call timer_start(500, { tid -> Screenshot#ForceCloseBuffer() })
endfunction
function! s:OnJobEventHandler(job_id, data, event) dict
if a:event == 'stdout'
let str = self.shell.' stdout: '.join(a:data)
......@@ -55,4 +69,5 @@ function! s:ExecExternalCommand(command)
endfunction
command! Screenshot call Screenshot#Window()
command! -range=% -nargs=0 Screenshot :<line1>,<line2>call Screenshot#WindowRange()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment