# Encoding: UTF-8

[{beforeRunningCommand: "nop",
  command: 
   "#!/usr/bin/env ruby\nar = [\"<<>>=\",\n  \"<<echo=true>>=\",\"<<echo=false,results=hide>>=\",\n  \"<<echo=false,results=tex>>=\",\n  \"<<echo=false,results=verbatim>>=\"]\ntext = STDIN.readlines\nif (i = ar.index(text[0].strip))\n  text[0] = ar[(i+1)% 4] + \"\\n\"\nend\nprint text.join\n",
  fallbackInput: "scope",
  input: "selection",
  keyEquivalent: "^<",
  name: "Change Block Parameters",
  output: "replaceSelectedText",
  scope: "text.tex.latex.sweave meta.block",
  uuid: "486047C3-9313-4276-97A7-EEDCF2E2ABB8"},
 {beforeRunningCommand: "nop",
  command: 
   ". \"$TM_SUPPORT_PATH/lib/webpreview.sh\"\n\n\thtml_header \"Sweave Bundle Help\" \"Sweave\"\n\tMarkdown.pl \"$TM_BUNDLE_SUPPORT/help.markdown\"|Smartypants.pl\n\thtml_footer\n",
  input: "none",
  name: "Help",
  output: "showAsHTML",
  scope: "text.sweave",
  uuid: "F05EE36B-139D-41A4-8957-637BE0AAD847"},
 {beforeRunningCommand: "nop",
  command: 
   "M=${TM_SWEAVE_WD:=${TM_DIRECTORY}}\nosascript -e 'tell application \"R\" to activate' -e \"tell application \\\"R\\\" to cmd \\\"setwd('$M')\\nSweave('$TM_FILEPATH')\\ndate()\\\"\"",
  input: "selection",
  name: "SWeave in R",
  output: "discard",
  scope: "text.sweave text.tex.latex, source.r",
  uuid: "09834657-AF82-4CB6-8239-3894E9B7926E"},
 {beforeRunningCommand: "nop",
  command: 
   "# this command requires that TM_SWEAVE_MASTER is set\n\nM=${TM_SWEAVE_WD:=${TM_DIRECTORY}}\nosascript -e 'tell application \"R\" to activate' -e \"tell application \\\"R\\\" to cmd \\\"setwd('$M')\\nSweave('$TM_SWEAVE_MASTER')\\ndate()\\\"\"",
  input: "selection",
  name: "SWeave project in R",
  output: "showAsTooltip",
  scope: "source.r, text.sweave",
  uuid: "778EA411-C3C7-42F0-802B-4DE23326E328"},
 {beforeRunningCommand: "nop",
  command: 
   "# Source some support functions we need.\n. \"${TM_SUPPORT_PATH}/lib/html.sh\"\n. \"${TM_SUPPORT_PATH}/lib/webpreview.sh\"\n\n# Get the viewer program. Any program (that works with open -a <name>) can be used,\n# except 'html' which is reserved to mean the internal HTML window. This is also the\n# default option.\nV=${TM_LATEX_VIEWER:-html}\nEL=${TM_LATEX_ERRLVL:-1}\nM=${TM_LATEX_MASTER:-$TM_FILEPATH}\nDIR=`dirname \"$M\"`\nFILE=`basename \"${M%.*}\".tex`\nPDF=\"${FILE%.*}.pdf\"\nCWD=\"`pwd`/\"\n\n# Set up TeX compiler, fallback to xelatex if document indicates it\nif grep -Esq '\\\\usepackage{.*(xunicode|fontspec)|program=xelatex' \"$M\"\n\tthen DEF_TEX=xelatex\n\telse DEF_TEX=pdflatex\nfi\nTEX=${TM_LATEX_COMPILER:-$DEF_TEX}\n\n# Add our tex directory to the TEXINPUTS variable so e.g. pdfsync is found (even when the user hasn’t installed it)\nexport TEXINPUTS=\"$TM_BUNDLE_SUPPORT/tex//:$(kpsewhich --expand-var '$TEXINPUTS')\"\n\n# Switch to the right directory.\ncd \"$TM_PROJECT_DIRECTORY\"\ncd \"$DIR\"\n\n# Prepare output window.\nhtml_header 'Sweave, Typeset &amp; View' \"$FILE\"\necho '<h2>Sweaving…</h2>'\n\nSW=${TM_SWEAVE_WD:=${TM_DIRECTORY}}\necho -e \"setwd('$SW')\\nSweave('$TM_FILEPATH')\" | R --vanilla --quiet | pre\n\n# Check if we actually have a tex compiler\nrequire_cmd \"$TEX\" \"You can either set the <tt>TM_LATEX_COMPILER</tt> variable to the full path of your LaTeX compiler (e.g. <tt>/opt/local/bin/pdflatex</tt> or set the <tt>PATH</tt> variable to include the path of <tt>pdflatex</tt>.\"\n\n\nrun_tex () {\nif [ \"$TEX\" != latexmk.pl ]\n\tthen \"$TEX\" ${TM_LATEX_OPTIONS:=-interaction=nonstopmode -file-line-error-style} \"$1\"\n\telse \"$TEX\" -f -r \"${TM_BUNDLE_SUPPORT}/latexmkrc\" \"$1\"\nfi\n}\n\n# Compile.\nrun_tex \"$FILE\" 2>&1| latexErrWarnHtml.py -v\nRC=$?\n\n# If there is output and it's newer than the current document, then we go directly to preview or link to it.\nif [ -s \"${PDF}\" -a ! \"$PDF\" -ot \"$FILE\" ]; then\n\tif [[ \"$V\" == html ]]; then\n\t\tWEB_LOC=\"tm-file://${DIR}/${PDF}\"\n\t\tWEB_LOC=\"${WEB_LOC//\\\\#/%23}\"\n\t\tif (($RC > $EL))\n\t\t\tthen link \"${WEB_LOC}\" 'Click Here to Preview'\n\t\t\telse redirect \"${WEB_LOC}\"\n\t\tfi\n\telse\n\t\tV=${V%.app} # strip potential .app extension\n\t\tif find_app >/dev/null \"$V.app\"; then\n\t\t\topen -a \"$V\" \"$PDF\"\n\t\t\tif [[ \"$V\" == TeXniscope && -f \"${PDF}sync\" ]]; then\n\t\t\t\tSCRIPT=$(find_app TeXniscope.app)/Contents/Resources/forward-search.sh\n\t\t\t\t[[ -x \"$SCRIPT\" ]] && \"$SCRIPT\" \"$TM_LINE_NUMBER\" \"$TM_FILEPATH\" \"$PDF\"\n\t\t\tfi\n\t\t\tif (($RC <= $EL)); then exit_discard; fi\n\t\telse\n\t\t\tstrong \"Error locating external viewer: $V\"\n\t\tfi\n\tfi\nelse\n\tstrong \"Error: PDF file not written to disk\"\nfi\nhtml_footer\n",
  input: "none",
  keyEquivalent: "@r",
  name: "Sweave, Typeset & View",
  output: "showAsHTML",
  scope: "text.tex.latex.sweave, text.tex.latex.sweave source.r",
  uuid: "F599ACE4-6B59-4235-A2BF-7BABA5C911B7"},
 {beforeRunningCommand: "saveModifiedFiles",
  command: 
   "#echo $TM_DIRECTORY/${{TM_FILENAME%.*}.tex}\nM=${TM_LATEX_MASTER:=$TM_DIRECTORY/${TM_FILENAME%.*}.tex}\nM=${M%.*}.pdf\n#M=$TM_DIRECTORY/$M\n\necho \"<meta http-equiv=\\\"refresh\\\" content=\\\"0; tm-file://${M}\\\"><title>${M}</title>\"\n\necho \"loading <b>$M</b>\"\n\n# open $M",
  dontFollowNewOutput: 0,
  input: "none",
  keyEquivalent: "@V",
  name: "View (PDF)",
  output: "showAsHTML",
  scope: "text.sweave",
  uuid: "43E6A4DB-1524-4FDD-8BD9-76852A2FA790"},
 {beforeRunningCommand: "nop",
  command: 
   "M=${TM_SWEAVE_WD:=${TM_DIRECTORY}}\nosascript -e 'tell application \"R\" to activate' -e \"tell application \\\"R\\\" to cmd \\\"setwd('$M')\\n\\\"\"",
  input: "selection",
  name: "setwd",
  output: "showAsTooltip",
  scope: "source.r, text.sweave",
  uuid: "6B05627E-6513-4C10-A489-1A09001F8D0D"}]
