tags:

views:

90

answers:

2

I'm looking for a way to send the output of an arbitrary Emacs command (in my case sql-send-region) to another window. I would prefer to maintain focus in the window I am currently in, which would effectively give me one window to edit queries and one window to view the output.

+2  A: 

Have you tried setting this variable to t, it sounds like the behaviour you want.

sql-pop-to-buffer-after-send-region

After a call to sql-send-region' or sql-send-buffer', the window is split and the SQLi buffer is shown. If this variable is not nil, that buffer's window will be selected by calling pop-to-buffer'. If this variable is nil, that buffer is shown using display-buffer'.

justinhj
I agree this seems like the answer, but placing "(custom-set-variables '(sql-pop-to-buffer-after-send-region t))" in my .emacs file doesn't seem to change the behavior in a noticeable way. Perhaps I'm using it incorrectly?
Brent Newey
Hi BrentDid you restart emacs, or do C-e after the expression to evalulate it?You can do C-h v sql-pop-to-buffer-after-send-region to see what it is set to.
justinhj
I did, with no luck. However, your response gave me some new leads to help me solve my problem. See my response, below. Thanks!
Brent Newey
+3  A: 

I was able to write some Emacs Lisp to solve my problem:

(defun sql-send-region-and-return (start end)
  (interactive "r")
  (let ((oldbuf (buffer-name)))
    (sql-send-region start end)
    (switch-to-buffer oldbuf)))

This sends the result of your region to the SQL buffer and returns back to your current buffer, effectively accomplishing the stated objective.

Thanks justinhj for giving me some new leads to solve my problem.

Brent Newey