I have two frames opened in emacs (one in each monitor, but this is irrelevant). I would like to have a lisp function to switch the buffer in the other frame (in the other monitor), whose focus is in an arbitrary buffer. The buffer I want to switch to in the other frame has a process (say Python) that is already running. When doing this, I want to keep the final focus in the current frame and buffer I ran the lisp function. Only now the other frame will show the buffer with the process. How could I have a lisp function to do that?
Edited: I ended up doing this, but maybe there is a better way
(defun go-to-python-buffer () "Create or visit a Python buffer." (interactive) (if (null (process-live-p (get-process "Python"))) ; (note that this line is different for python b/c get-process return different types in that case) (progn (split-window-sensibly (selected-window)) (other-window 1) (run-python)) (progn (split-window-sensibly (selected-window)) (switch-to-buffer (process-buffer (get-process "Python"))) (other-window -1)) ) ) (defun go-to-python-frame () "Create or visit a Python buffer in another frame." (interactive) ;; check if there is a python process already open, if not, start one (if (not (stringp (get-process "Python"))) ; (note that this line is different for R b/c get-process return different types in that case) (run-python)) (if (= (list-length (frame-list)) 1) ;; if there is just one frame, create another, put the focus, and show the buffer with the python process (progn (switch-to-buffer-other-frame (process-buffer (get-process "Python"))) (other-window-or-frame -1)) (progn ;; if there is another frame already open, show the python buffer, and keep the focus (select-frame (next-frame)) (switch-to-buffer (process-buffer (get-process "Python")) ) (other-window-or-frame -1))))
(let ((a (make-frame '((name . "TODAY")))) (b (make-frame '((name . "TOMORROW"))))) (message "a: %s | b: %s" a b ))