Emacs switches to a buffer in another frame

I am currently programming emacs. I have a function defined in my .emacs that saves all my work and the interpreter executes to start my work in the current open shell buffer. Usually I will edit one or more frames and open the shell in a separate frame. The problem is that when I run the save and execute function, everything is saved, but the shell buffer is then displayed in the frame that I am currently editing. Thus, I have two frames showing the shell buffer, and I do not see the source code that I just edited. Quite often, when I program, I would immediately like to compare the output of the code with the code that I just wrote. It is a bit annoying to switch back to my code buffer and then go to the end of another shell buffer to look at the output, referring to the code just written.

(defun execute-script () "Switch to shell buffer and re-execute the last command." (interactive) (save-some-buffers) (switch-to-buffer "*shell*") (end-of-buffer) (comint-previous-input 0) (comint-send-input)) 

As you can see, my function is currently quite primitive, just restarting the latest command in the shell.

I know that Emacs has the functionality to switch to the buffer in another frame, since the ido buffer switch code does this. Does anyone have any guidance on what I need to replace my call with a switch to a buffer in order to get the desired effect?

Regards Giles

+4
source share
2 answers

Exchange

 (switch-to-buffer "*shell*") 

for

 (switch-to-buffer-other-window "*shell*") 

This will ensure that two window layouts are executed with the previous buffer on the left side and the shell buffer on the right side.
Edit: If you use a layout of multiple frames, rather than a layout of multiple windows, you can use

 (switch-to-buffer-other-frame "*shell*") 
+3
source

You can also use pop-to-buffer , which later allows you to fine-tune how it behaves, for example. via display-buffer-reuse-frame or display-buffer-alist , or special-display-regexp .

+1
source

Source: https://habr.com/ru/post/1413703/


All Articles