Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Emacs Command in Other Window

Tags:

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.

like image 982
Brent Newey Avatar asked Oct 15 '09 15:10

Brent Newey


People also ask

How do I switch between windows in Emacs?

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 ).

How do I run commands in Emacs?

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.

Can I run Emacs in terminal?

If you are working with a command line interface with no option to start GUI application, start Emacs directly in the terminal with emacs .

How do I switch buffers in 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.


2 Answers

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.

like image 191
Brent Newey Avatar answered Oct 13 '22 01:10

Brent Newey


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' orsql-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 usingdisplay-buffer'.

like image 28
justinhj Avatar answered Oct 13 '22 01:10

justinhj