Wednesday, December 31, 2014

Stata Gedit Integration

Integrate Gedit with Stata

1. Go to Edit - Preferences - Plugins and activate "External Tools"
(if you cannot activate any plugins, run gedit as a root with "sudo gedit")
2. Go to Tools - Manage External Tools
3. Click on "+" to add a new tool
4. Name the new tool as you wish, e.g., Stata dolines
5. Copy the body of "Gedit_stata_integration_script.txt" in the command space
6. Choose the keyboard shortcut, e.g. "F9"
7. Choose to send only currently highlighted text from the drop-down menu
do /tmp/stata


PS: You might need to install xdotool if it is not currently installed:
sudo get-apt install xdotool

Stata Syntax Highlighting in Gedit

(All credits go to: http://linuxscrapbook.wordpress.com/2010/12/01/stata-syntax-highlighting-for-gedit/ and
http://forums.debian.net/viewtopic.php?f=8&t=55704)

1. Copy  stata.lang file to /usr/share/gtksourceview-3.0/language-specs (for use by all users on the system, requires superuser privileges)

or to ~/.local/share/gtksourceview-3.0/language-specs (for use with your account only) For the latter option, you may have to create the directory first:

mkdir -p ~/.local/share/gtksourceview-3.0/language-specs

For Windows: copy stata.lang file to ProgramFiles (x86)\gedit\share\gtksourceview-3.0.

2. Restart gedit.

.do files are now recognized automatically. For manual selection of the Stata Highlight Mode, go to View > Highlight Mode > Scientific > stata


Nice color scheme in Gedit:

1. Copy solarized_light.xml or solarized_dark.xml (or both) to /usr/share/gtksourceview-3.0/styles (or respective directory) and choose the one you like the best





Source

#!/bin/sh
#!/bin/bash

# Clear temporary-do file if it already exists

[ -e /tmp/stata.do ] && rm /tmp/stata.do

# Write each highlighted lign in the temporary do-file /tmp/stata.do
# - "OLDLINE" is needed just in case if the last line doesn't end with an EOL symbol (in this case, "read LINE" returns "false" and this line is not written in the temporary do-file

while read LINE; do
  echo $LINE >> /tmp/stata.do
  OLDLINE=$LINE
done
if [ "$LINE" != "$OLDLINE" ] ; then
    echo $LINE >> /tmp/stata.do
fi

# check whether the Stata process is runnung already
# for other stata versions change the window title (you can read it on the top of the open Xstata window)

 STATAID=`xdotool search --name "Stata/SE 12.0" | head -n 1`

# if Stata is already running, activate the window; if not, launch the Stata process, wait until it is running, and then activate the window

 if [ -n "$STATAID" ]; then
     xdotool search --name "Stata/SE 12.0" windowactivate %1
 
   # if runnning 2 Stata windows; choose the necessary window number %1 or %2 (play around to identify which window you need)

   
 else
    /usr/local/stata12/xstata-se  &
    sleep 1
    search --name "Stata/SE 12.0" windowactivate

fi

# In the Stata window, activate the command line with Ctrl+4 ,
# and then type "do /tmp/stata [RETURN]"

xdotool key "ctrl+4" && xdotool type "do /tmp/stata" && xdotool key "Return"




No comments:

Post a Comment