Reputation: 121
I'm looking for a way to (repeatedly) append only the additional content of a log-like file to an Emacs buffer. (The file would be the scrollback buffer of a tmux session that's repeatedly exported).
Even better if the Emacs buffer uses org-mode, and the additional content is added as a new:
#+begin_example
The additional content of the log file
#+end_example
Note: In [1], I asked if there's a way in tmux to edit your scrollback buffer. Initial comment so far indicates it's not possible. That's consistent with what I found when looking at tmux documentation etc.
Here's an attempt at explaining in more details. The lines in the example are unrealistic, they're just there to illustrate the principle.
The first version of the log file contains four lines:
line 1
line 2
line 3
line 4
As nothing from that log file has previsouly been appended to the Emacs buffer, add the entire log file. The buffer contains:
This file contains an annotated log from working with XYZ
line 1
line 2
line 3
line 4
Then I edit that buffer, removing the first two lines and inserting an extra line. It now contains:
This file contains an annotated log from working with XYZ
line 3
inserted line
line 4 -
After more work in tmux and export a new log file, the log file contains say ten lines:
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
line 9
line 10
I would now like to append only the additional parts of that log file, compared to with what I previously appended. In this case the additional lines line 5 - line 10.
After appending the additional content, the Emacs buffer would contain:
This file contains an annotated log from working with XYZ
line 3
inserted line
line 4 -
line 5
line 6
line 7
line 8
line 9
line 10
After some more editing, perhaps there was only very few lines I wanted to keep, the buffer would contain:
This file contains an annotated log from working with XYZ
line 3
inserted line
line 4 -
line 8
If trying to append, but there's nothing new in the log file, no new content should be appended to the Emacs buffer. So it'll remain unchanged.
I work a lot in Bash where I e.g.: execute build commands; use sed/awk/grep and other commands; and connect to target systems over serial port and SSH. As I do this from different machines, it's very convenient to use tmux.
However, in tmux, I miss the Emacs' mode you get via M-x shell
. That mode gives me the ability to not only execute commands and capture output, but also to clean up the history by pruning lines I know won't be interesting later. Or go back up and add comments/notes.
As per [1], it seems there might not be a capability in tmux to do what I want. It's only possible to export the scrollback buffer as a text file.
I'm connecting via SSH, through a VPN, from a Windows machine to a Linux workstation. It's on the workstation where tmux runs, with Emacs inside tmux. From there, inside the VPN, I can connect to other machines.
This makes it impractical to just use multiple 'M-x shell` from an Emacs running on the Windows machine. Also, tmux is in general very nice for what I'm doing.
For simplicity, it'd have been nice to just be able to directly edit the scrollback history in tmux.
Barring that, maybe something like the following is possible:
Setup: Open a buffer 'B' in Emacs. Configure "the system" to monitor a text file 'f' for additional content that's to be (repeatedly) appended to buffer 'B'.
In tmux, export the scrollback history of a pane 'P' to file 'f'
In Emacs, initiate import of additional content
In Emacs, optionally edit the content of buffer 'B'
Go to step 2
Are there some existing solutions to achieve something like this?
In some way it's similar to literal programming in reverse, maybe it should be called 'literal capturing' :-)
A partial implementation could be:
[1] Remove parts of the content of the scrollback buffer
Upvotes: 0
Views: 34