2

Many major modes provide a function to switch between editing and preview rendering a file. I am specifically looking at ps-mode but an answer that applies to others would be nice. I can open the same buffer in two windows, but switching between render and edit (C-c C-c in ps-mode) causes both windows to change. I want to see both the text and the rendering in different windows on the same frame at the same time, preferably with real-time updates.

My instinct is to create two buffers backed by the same file, and a hook so that changes to the editing buffer update the text behind the rendering buffer. Maybe even auto-revert-mode but I'm hoping for something slightly more elegant.

1 Answer 1

2

Partial answer: you can have two buffers with the same content but different buffer-specific settings, such as different cursor positions (that aren't forgotten if the buffer isn't displayed in a window), different major modes, etc. This is called indirect buffers. Press C-x 4 c to create an indirect buffer for the current buffer and show it in a window. You can have one of them render the Postscript and the other show the source: C-c C-c only applies to the current buffer.

There are limitations of indirect buffers. For example, they both use the same font-lock settings. As a consequence, C-c C-c in one buffer removes syntax coloring from the other buffer, though you can get it back by turning font-lock mode on and off in the buffer showing the source.

To automatically update the preview buffer, you could set up an idle timer or an after change function in the source buffer that re-renders the preview.

There is no automatic synchronization between the position in the two buffers. When you're viewing a PDF file rendered from a source (e.g. LaTeX), there are ways to embed backreferences so that when you click in the PDF, the editor jumps to the corresponding place in the source. However, I don't know if that's possible with Postscript, and even if it is, it would require the Postscript source to contain those backreferences, which is probably not feasible if you're editing the Postscript manually.

1
  • That's everything I needed. Destroying and re-creating the preview buffer is easy/fast enough to not need the auto-update. Thanks!
    – memtha
    Sep 5, 2021 at 2:52

Your Answer

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

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