'(godlike-solved t) stream editing in Emacs

Forum rules
We don't support installations in VirtualBox, VMWare, qemu or others. We ignore posts about WINE, PlayOnLinux, Steam and Skype. We don't support btrfs, lvm, UEFI, side-by-side installations with GPT or dualboot with anything newer than Windows XP.
Google your problem first. Check the Wiki. Read the existing threads. It's okay to "hijack" an existing thread, yes! If your problem is not yet covered, open a new thread. To get the quickest possible help, mention the exact release codename in your post (uname -a is a good idea, too). Due to the lack of crystal balls, attach the output of lspci -nnk if you encounter hardware problems.
machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

'(godlike-solved t) stream editing in Emacs

Unread post by machinebacon » Sat May 30, 2015 9:28 am

Just out of curiosity if the Emacs Gods here know if this is possible:

1) send a file to Emacs (I rather mean using a pipe than actually 'finding' it)
2) let it perform a couple of operations (e.g. M-x mark-whole-buffer M-x remove-whitespace-rectangle)
3a) save the file in-place and exit (C-x C-s C-x C-c)
3b) directly show to output on the screen (EDIT: I mean outside of Emacs)

I know that this is much easier with sed, but I really just want to verify if
- it's possible
- how the syntax would look like
- Emacs can be a stream editor
- Emacs can work non-interactively

Thanks!
..gnutella..

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: stream editing in Emacs

Unread post by GekkoP » Sat May 30, 2015 9:33 am

I guess it could be possible.
The options "--file" and "--funcall" should be what you are looking for: https://www.gnu.org/software/emacs/manu ... -Arguments
Also, "--kill" will exit Emacs without confirmation.

I'm not sure you can call more than one function, though.

Edit: maybe this? http://emacswiki.org/emacs/EmacsScripts

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: stream editing in Emacs

Unread post by machinebacon » Sat May 30, 2015 9:41 am

^ Thanks Manu,

Code: Select all

emacs -nw --file logbook --funcall 'mark-whole-buffer' --funcall 'delete-whitespace-rectangle' --funcall 'save-buffer' --kill
works great!
..gnutella..

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: '(godlike-solved t) stream editing in Emacs

Unread post by GekkoP » Sat May 30, 2015 9:47 am

^ Wow! That is cool.

Post Reply