Re: [code] ctrl-c frequently doesn't work on Windows.

From: Danny MacMillan <foicica.att.nekulturny.org>
Date: Sun, 22 Oct 2017 18:18:07 -0600

On 2017-10-22 15:38, Robert Gieseke wrote:
> Am 22/10/17 um 23:29 schrieb Danny MacMillan:
>>> There is `timeout` in Textadept
>> Thanks for letting me know about this. I'm not sure how you're
>> proposing
>> I would use that as a delay. It doesn't seem to block at the call
>> site,
>> so it won't delay returning from keys.cc which is I think what is
>> making
>> this work. I think the delay needs to be after the call to
>> buffer.copy(), not before.
>>
>> But maybe I'm just not seeing what you're getting at. I tried changing
>> my sleep function to this, and it definitely isn't working.
>
> You're totally right, sorry! I guess it's time for me to sleep ;-)
> But if you're first hack worked already, that's maybe good to test
> further if it really fixes it.
>
> Another idea, how about skipping GTK completely and piping the current
> selection into `clip.exe`? This might have new issues but maybe it's
> worth a try and not even slower than having a short "lock" after each
> Ctrl-C ...

I tried this. With this code, I can't make it fail, even without the
sleep. I assume this is because spawn is itself introducing a delay. I'm
not holding this code up as a shining example of what to do. It's a
dirty hack from beginning to end.

keys.cc = function()
   -- paste.bat adds an extra unwanted newline
   local paste_should_be = buffer.get_sel_text() .. "\n"
   local paste_output = ''
   local function paste_stdout(chunk)
     paste_output = paste_output .. chunk
   end
   local function tohex(s)
     return (s:gsub('.', function (c)
         return string.format('%02X', string.byte(c))
     end))
   end
   local function removecr(s)
     return (s:gsub("\x0d\x0a", function (c)
         return "\n"
     end))
   end
   local function paste_exit(rc)
     local testval = removecr(paste_output)
     if testval ~= paste_should_be then
       -- converted to hex so I can see differences in whitespace
       ui.print("BAD clipboard: '" .. tohex(testval) .. "'")
       ui.print("BAD selection: '" .. tohex(paste_should_be) .. "'")
       ui.dialogs.msgbox({text="Clipboard problem ..."})
     end
   end
   buffer.copy()
   if WIN32 then
     --sleep(0.1)
     local p = spawn("D:\\paste.bat", nil, paste_stdout, nil, paste_exit)
   end
end

But I think I'm going back to a simple sleep. I'll know soon enough if
it doesn't work.

Thanks for your help.

-- 
Dan
-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Sun 22 Oct 2017 - 20:18:07 EDT

This archive was generated by hypermail 2.2.0 : Mon 23 Oct 2017 - 06:42:31 EDT