       "Send 'show state' to Pig"
       (may-open-pig)
       (interactive)
-      (select-window pig-win)
-      (goto-char (point-max))
-      (insert "show state")
-      (comint-send-input)
-      (select-window code-win)
+      (with-current-buffer "*Pig*"
+	(goto-char (point-max))
+	(insert "show state")
+	(comint-send-input))
       (message "State shown"))
 
 

      (setq line-command (buffer-substring begin end))
      (setq real-line-command (replace-regexp-in-string "--.*\n" "" line-command))
      (setq real-line-command (replace-regexp-in-string "\n" " " real-line-command))
      (select-window pig-win)
      (goto-char (point-max))
      (insert real-line-command)
      (comint-send-input)
      (select-window code-win)
      (message "Line executed"))

(defun send-undo ()
      "Send undo to Pig"
      (may-open-pig)
      (interactive)
      (select-window pig-win)
      (goto-char (point-max))
      (insert "undo")
      (comint-send-input)
      (select-window code-win)
      (forward-line -1)
      (message "Undone"))


;; Command line shortcuts
;; ****************************************************************

;; Window with Pig running
(setq pig-win 'nil)

