Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the paste file in conemu for faster turnaround #446

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion autoload/slime/common.vim
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ function! slime#common#write_paste_file(text)
call mkdir(paste_dir, "p")
endif
let lines = split(a:text, "\n", 1)
call writefile(lines, slime#config#resolve("paste_file"), 'b')
let paste_file = slime#config#resolve("paste_file")
let result = writefile(lines, paste_file, 'bS')
if result != 0
echoerr "Couldn't write to slime paste file."
endif
return paste_file
Comment on lines +28 to +33
Copy link
Owner

@jpalardy jpalardy Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my initial reaction was resolve is probably too fast to benchmark (it's not in some inner loop) 🤔

but looking at the call sites, it wouldn't hurt to return paste_file -- so I think I'm OK with that 👍

I like checking for a writefile error, how about avoiding the result var? (it's only used for the if)

Suggested change
let paste_file = slime#config#resolve("paste_file")
let result = writefile(lines, paste_file, 'bS')
if result != 0
echoerr "Couldn't write to slime paste file."
endif
return paste_file
let paste_file = slime#config#resolve("paste_file")
if writefile(lines, paste_file, 'bS') != 0
echoerr "Couldn't write to slime paste file."
endif
return paste_file

endfunction

function! slime#common#capitalize(text)
Expand Down
9 changes: 3 additions & 6 deletions autoload/slime/targets/conemu.vim
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ function! slime#targets#conemu#config() abort
endfunction

function! slime#targets#conemu#send(config, text)
" use the selection register to send text to ConEmu using the windows clipboard (see help gui-clipboard)
" save the current selection to restore it after send
let tmp = @*
let @* = a:text
call slime#common#system("conemuc -guimacro:%s print", [a:config["HWND"]])
let @* = tmp
" Use the selection register to send text to ConEmu using the slime paste file
let paste_file = slime#common#write_paste_file(a:text)
call slime#common#system("conemuc -guimacro:%s pastefile 2 %s", [a:config["HWND"], paste_file])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all in all, I'm surprised that using the pastefile would be faster than the clipboard … 🤔


The paste file has the S flag set, which tells vim not to bother calling fsync() on the file

The file doesn't contain anything that needs to persist across reboots.

That wasn't my understanding of fsync — doesn't that create a race-condition if we

  1. write (but skip flush)
  2. turn around and read the file

?


another concern is that the pastefile sticks around, holding on to your last slime send — I'm not sure everybody feels comfortable with that, so I've been avoiding it when possible (only screen was still using it, because there were no other choice 😮‍💨 )

endfunction