Skip to content

Instantly share code, notes, and snippets.

@jayeye
Created December 8, 2016 03:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayeye/827a93f191b2da76aab859fa4c8bef3e to your computer and use it in GitHub Desktop.
Save jayeye/827a93f191b2da76aab859fa4c8bef3e to your computer and use it in GitHub Desktop.
Save buffers of a detached or otherwise inaccessible emacs process.
#include <err.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <termios.h>
const char* const kJesusSaves = "\025\033xsave-buffers-kill-emacs\n";
int main(int argc, char* argv[]) {
int fd = open(argv[1], O_WRONLY);
if (fd < 0) {
err(1, "open");
}
for (const char* c = kJesusSaves; *c; ++c) {
if (ioctl(fd, TIOCSTI, c) < 0) {
err(1, "TIOCSTI");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment