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.
To select a different window, click with Mouse-1 on its mode line. With the keyboard, you can switch windows by typing C-x o ( other-window ).
You can run any Emacs command by name using M-x , whether or not any keys are bound to it. If you use M-x to run a command which also has a key binding, it displays a message to tell you about the key binding, before running the command.
If you are working with a command line interface with no option to start GUI application, start Emacs directly in the terminal with emacs .
To move between the buffers, type C-x b. Emacs shows you a default buffer name. Press Enter if that's the buffer you want, or type the first few characters of the correct buffer name and press Tab. Emacs fills in the rest of the name.
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.
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'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With