Created
October 9, 2013 22:49
-
-
Save joaotavora/6909878 to your computer and use it in GitHub Desktop.
A script to run emacsclient in two basic cases: (1) with stdin, to open a new buffer with the contents passed in (2) without stdin, to open a file passed as the argument.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# | |
# Based on a similar util by Phil Jackson ([email protected]) | |
use Cwd; | |
use File::Copy; | |
if (-t STDIN ) { | |
# No STDIN was passed | |
# | |
@args = (); | |
} else { | |
# Some STDIN was passed | |
# | |
chomp ($tmp_file = `mktemp /tmp/emacsclient.XXXXX`); | |
$data = do { local $/; <DATA> }; | |
$lisp_to_accept_file = <<END; | |
(progn (unless (functionp 'fake-stdin-slurp) | |
$data) | |
(fake-stdin-slurp \"${\(getcwd)}\" \"$tmp_file\") | |
(select-frame-set-input-focus (window-frame (selected-window)))) | |
END | |
copy(\*STDIN,$tmp_file); | |
@args = ("-a","-emacs", "-e", $lisp_to_accept_file); | |
} | |
push @args, @ARGV; | |
system "emacsclient", @args; | |
if ($? == -1) { | |
if ($tmp_file) { | |
print "some data was saved in $tmp_file"; | |
} | |
} else { | |
unlink($tmp_file) if $tmp_file; | |
# print "just removed $tmp_file"; | |
} | |
__DATA__ | |
(defun fake-stdin-slurp (current-dir filename) | |
"Emulate stdin slurp using emacsclient hack" | |
(switch-to-buffer (generate-new-buffer "*stdin*")) | |
(cd current-dir) | |
(insert-file filename) | |
(end-of-buffer)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment