I often have got multiple emacs frame in various desktop, but only two of them are visible.
I often need to jump between those two frames, but since other frames are opened I can't use C-x 5 o
, because it cycle among all of them.
For this purpose I wrote a code, which allows to jumps between two frames.
If in frame1, then pressing C-c C-,
the current line will be highlighted. Then, if in frame2, pressing C-c C-.
, the current line will be highlighted and the cursor will jump the other frame (removing the highlighting of that line).
A working example is portrayed in the gif.
The code is the following. Can you help me to extend the behaviour I got also between windows and positions in the same file, not only frame? Thank you. Moreover I am not expert with lisp and I am sure that the amount of code can be shortened.
(defun my-jumping-bookmark-jump(bookmark-name)
(setq pop-up-frames t)
(bookmark-jump-other-window bookmark-name)
(setq pop-up-frames nil))
(defun my-jumping-bookmark-set() (interactive)
(defvar my-jumping-bookmark-alternator)
(setq my-jumping-bookmark-alternator 0)
(bookmark-delete "my-jumping-bookmark0")
(bookmark-delete "my-jumping-bookmark1")
(bm-remove-all-all-buffers)
(bookmark-set "my-jumping-bookmark0")
(bm-toggle)
(message "set"))
(defun my-jumping-bookmark-switch() (interactive)
(if (= (mod my-jumping-bookmark-alternator 2) 0)
(progn (bookmark-set "my-jumping-bookmark1")
(bm-toggle)
;this does not jump between frames or windows, only between positions in the same buffer
;; (bookmark-jump "my-jumping-bookmark0")
;this does not jump between windows or positions in the same buffer, only between frames
(my-jumping-bookmark-jump "my-jumping-bookmark0")
;I used this in the beginning, instead of bm-remove-all-current-buffer, so to remove the highlighting only in the current line, but there is a bug in bm so if you go to the last position in a buffer, the current line is not influenced by bm-toggle
;; (bm-toggle)
(bm-remove-all-current-buffer)
(bookmark-delete "my-jumping-bookmark0")
(setq my-jumping-bookmark-alternator 1)
(message "switched to 1"))
(progn (bookmark-set "my-jumping-bookmark0")
(bm-toggle)
;; (bookmark-jump "my-jumping-bookmark1")
(my-jumping-bookmark-jump "my-jumping-bookmark1")
;; (bm-toggle)
(bm-remove-all-current-buffer)
(bookmark-delete "my-jumping-bookmark1")
(setq my-jumping-bookmark-alternator 0)
(message "switched to 0"))))
(global-set-key (kbd "C-c C-,") 'my-jumping-bookmark-set)
(global-set-key (kbd "C-c C-.") 'my-jumping-bookmark-switch)
Finally, I want to thank the user who suggested me to use pop-up-frames
, in this question.
my-jumping-bookmark-set
, then, when you callmy-jumping-bookmark-switch
, the focus moves to the previous buffer an so on. If the two buffers are in different frame and visible, my code words fine. But not if they belong to the same frame (in two visible windows). Neither it works if I call the two functions I defined from two locations of the same file.