acarril / StataLinux

Sublime Text 3 plugin that adds support for Stata (all versions) in Linux.
MIT License
7 stars 2 forks source link

Implement plugin without bash script #9

Open acarril opened 4 years ago

acarril commented 4 years ago

See here.

acarril commented 4 years ago

Added bonus: do this without using the clipboard, which is annoying.

acarril commented 4 years ago

Working on this in the all-python branch.

avila commented 4 years ago

I see you are trying to to implement an all-python solution, so it might be not relevant, but I was a little annoyed by the extension replacing the contents of my clipboard. The following workaround fixes this issue. The only issue is that the command xdotool type ... simulates someone typing the contents of the string onto the target, so it takes a little longer to "type" and run the script. Other than that, runs fine. xclip would, then, not be a dependency any longer.

but again, if an all-python solution is on the way, this will likely be irrelevant. In any case, i hope it might help another user in the mean time.

#!/bin/bash
# Dependencies: xdotool, xclip

# Copy 'do <filename>' to clipboard
string='do ''"'$1'"'
#echo "${string}" | xclip -selection clipboard # Commented out so that it does not replace clipboard contents

# Get Stata window ID (first window that matches the regex)
winid_stata=$(xdotool search --name --limit 1 "Stata/(IC|SE|MP)? 1[0-9]\.[0-9]")

# Send string to Stata's command pane, selecting previous text and copying on top
# Note: there is an issue with xdotool's clearmodifiers option (see https://github.com/jordansissel/xdotool/issues/43)
# xdotool type --window ${winid_stata} ${string} # xdotool type is slow AF
if [ ! -z "$winid_stata" ]; then
    xdotool key --window ${winid_stata} --delay 50 ctrl+a BackSpace # <<<<------------
    xdotool type --window ${winid_stata} "${string}" # <<<<------------
    xdotool key --window ${winid_stata} Return # <<<<------------
else
    echo "No Stata window open."
    exit 1
fi

BTW. To edit this file adhocly one can press Ctrl+Shift+P and type View Package File and the search for sublime-stata.sh

avila commented 4 years ago

which library do you use to call xdotool from python? this one https://pypi.org/project/python-libxdo/??