1

For a lecture, I'll have a setup with two frames (one on my notebooks's screen, the other on the projector) showing the same file. When editing the file in the "master" frame I need the "slave" frame to be exactly in sync: both shall show the same position in the file, both shall scroll in sync. If I move the point in the "master" frame it shall move in the "slave" frame accordingly. In short, the "slave" has to be a clone of the "master".

Any ideas?

1 Answer 1

2

Assuming both frames display the same buffer, then all that should be needed is to make sure the window-point and window-start of both frames are in sync.

Sync'ing is easier if it only goes one way, which should be an acceptable restriction in your case. So you could try something like:

;; -*- lexical-binding:t -*-
(defun my-clone-frame ()
  (let* ((src (selected-window))
         (src-point (copy-marker (window-point)))
         (src-start (copy-marker (window-start)))
         (clone (frame-root-window (make-frame))))
    (add-hook 'post-command-hook
              (lambda ()
                (unless (= src-point (window-point src))
                  (move-marker src-point (window-point src))
                  (set-window-point clone src-point))
                (unless (= src-start (window-start src))
                  (move-marker src-start (window-start src))
                  (set-window-start clone src-start))))))
1
  • Stefan, that's exactly what I was looking for. Btw, there is one closing paren missing at the very end.
    – Tom
    Commented Sep 24, 2018 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.