admin管理员组文章数量:1202394
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.
Detailed example
Here's an attempt at explaining in more details. The lines in the example are unrealistic, they're just there to illustrate the principle.
Step 1 - First exported log file
The first version of the log file contains four lines:
line 1
line 2
line 3
line 4
Step 2 - First append log file to Emacs buffer
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
Step 3 - Some editing of the buffer
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 -
Step 4 - Next export of log file
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
Step 5 - Appending only the additonal parts
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
Step 6 - More editing
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
Step 7 - Appending again, but nothing new in the log file
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.
Background
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.
Environment / constraint
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.
Possible solution
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' :-)
Idea for partial implemenation
A partial implementation could be:
- Create empty file 'latest-import'
- Export (from tmux) to file 'latest-export'
- When appending to Emacs buffer:
- Copy 'latest-export' to 'in-progress'
- Determine the additional lines at the end of 'in-progress' compared to what's in 'latest-import'
- Append these additional lines
- Move 'in-progress' to 'latest-import'
References
[1] Remove parts of the content of the scrollback buffer
本文标签:
版权声明:本文标题:org mode - How to repeatedly re-import and append only additional content of a (log) file into an Emacs buffer where it can be e 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738645210a2104548.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论