[scite] Linux, Lua/Scite, and xclip - hang

71 views
Skip to first unread message

sdaau

unread,
Apr 15, 2010, 7:36:06 PM4/15/10
to scite-interest
Hi all,

I'm trying to use something like the following script:

function SelAppendClipboard()
local sel = editor:GetSelText()
--local f = io.popen("echo $(xclip -out -selection clipboard)") --
runs command
-- os.execute("echo $(xclip -l 1 -o)") -- runs command
os.execute("bash -c 'xclip -o'") -- runs command
-- local clipboardcontent = f:read("*a") -- read output of command
-- local newclip = clipboardcontent .. "\n" .. sel
--print(clipboardcontent)
-- editor:CopyText(newclip)
end

To be able to append to current clipboard. Unfortunately, although
os.execute("xclip -o") seems to work fine in lua shell, whenever I
try to run it in scite, it freezes !!


I tried to run strace scite, this is report right before it freezes:,

rt_sigaction(SIGINT, {SIG_IGN}, {SIG_DFL}, 8) = 0
rt_sigaction(SIGQUIT, {SIG_IGN}, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
clone(child_stack=0, flags=CLONE_PARENT_SETTID|SIGCHLD,
parent_tidptr=0xbfc33824) = 6234
waitpid(6234, ^C <unfinished ...>


And with strace -f scite, this is report right before it freezes:

[pid 5617] read(3, 0xa01c880, 4096) = -1 EAGAIN (Resource
temporarily unavailable)
[pid 5617] poll([{fd=3, events=POLLIN}], 1, -1^C <unfinished ...>
Process 5615 resumed
Process 5616 detached
Process 5617 detached

My scite version is SciTE, Version 1.76, May 9 2008 00:47:16; Ubuntu
9.04 , Linux 2.6.28-18-generic....

Is what I want to do possible at all??

Thanks in advance for any answers,

Cheers!

--
You received this message because you are subscribed to the Google Groups "scite-interest" group.
To post to this group, send email to scite-i...@googlegroups.com.
To unsubscribe from this group, send email to scite-interes...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scite-interest?hl=en.

Jeff Pohlmeyer

unread,
Apr 15, 2010, 7:50:58 PM4/15/10
to scite-i...@googlegroups.com, s...@imi.aau.dk
On Thu, Apr 15, 2010 at 6:36 PM, sdaau wrote:

> Unfortunately, although os.execute("xclip -o")  seems to work
> fine in lua shell, whenever I try to run it in scite, it freezes !!


There is another similar command-line tool here:
http://www.vergenet.net/~conrad/software/xsel/
I can't say if it's better, but It does have a built-in --append option.


- Jeff

sdaau

unread,
Jul 23, 2010, 5:41:35 PM7/23/10
to Jeff Pohlmeyer, scite-i...@googlegroups.com
Hi Jeff,

>
> There is another similar command-line tool here:
>  http://www.vergenet.net/~conrad/software/xsel/
> I can't say if it's better, but It does have a built-in --append option.
>

Thanks a lot for the response! There is 'sudo apt-get install xsel' in
Ubuntu, so I tried that, but it ended up being somewhat complicated.

First of all, xsel persistently failed to do anything while called
directly from Scite/Lua, and finally I realized xsel segfaults if you
try to run 'append' while the clipboard is empty! So that forced me to
make a script like this:

---
sudo cat > /usr/bin/appendclipboard <<EOF

CMD=""
REP=""
#DBG="-vvvv"
DBG=""

# is clipboard not empty?
# check because xsel segfaults for empty clipboard!!
echo "$1"
echo ---
xsel --clipboard -o 2>&1

if [ -n "$(xsel --clipboard -o)" ]
then
REP="Clipboard not empty.. Clipboard added."
CMD="xsel --clipboard -i -a $DBG"
else
REP="Clipboard empty.. Clipboard inited."
CMD="xsel --clipboard -i $DBG"
fi

echo ---
#REZ=$(echo "$1" | $CMD 2>&1)
# when running like this in $(), MUST add -i to xsel
# even if its manpage says its implied!!!
# else nothing is appended!
# same problem when running from Scite, even without $()
REZ=$(eval 'echo "$1" | $CMD 2>&1')
echo "$REZ"
echo ----
echo $REP
echo ---
xsel --clipboard -o
EOF

chmod +x /usr/bin/appendclipboard
----

And then, this being called by Lua as:

----
function SelAppendClipboard()
local selorig = editor:GetSelText()
-- escape bloody quotes
local sel = string.gsub(selorig, '"', '\\"')

local cmd = 'bash -c \'appendclipboard "' .. sel .. '"\''
print(cmd)

--~ local ret = os.execute(cmd)
--~ print(ret)

f = io.popen(cmd) -- runs command
l = f:read("*a") -- read output of command
print(l)
end
---

Now, this works fine, if you initially select, say, a filename of an
icon in Gnome and you copy it - so that is your initial clipboard;
then the script as above appends properly. But, if you afterwords
press Ctrl+C for a text selection in Scite (i.e. you overwrite the
clipboard with text from Scite), and then try to append - Scite
freezes (and so does strace), and can be only killed afterward !

(and don't forget to delete 'rm /tmp/SciTE.11398.in' or whatever file
is the Scite handle - otherwise Scite will silently fail to start, if
you have 'check.if.already.open=1' [# one instance of SciTE only] in
your options.. )

In any case, I didn't it was worth debugging that kind of a freeze
(with no errors whatsoever); so I made this patch:

Patch: Added Lua functions for get/set clipboard - scite-interest |
Google Groups -
http://groups.google.com/group/scite-interest/browse_thread/thread/a3fcc32957b11355

and so far so good :) ...

Thanks again,
Cheers!


Reply all
Reply to author
Forward
0 new messages