9 sub check_exit_status
($) {
12 die $cmd . ': terminated with signal ' . ($?
& 127) . "\n";
14 die $cmd . ': returned ' . ($?
>> 8) . "\n";
19 # I’ve been having problems with IPC::Run and couldn’t debug them.
20 # Implementing system run with proper stdin and stdout redirection
21 # turned out to be the fastest solution.
27 open(STDIN
, '<', '/dev/null') or die "/dev/null: $!\n";
30 open(STDOUT
, '>', '/dev/null') or die "/dev/null: $!\n";
32 exec 'emacsclient', @_;
33 die "emacsclient: $!\n";
34 } elsif (waitpid($pid, 0) < 0) {
37 check_exit_status
'emacsclient';
43 defined $ENV{'DISPLAY'};
53 # When showing diffs, git indicates old and new versions of the
54 # file by using ‘a/’ and ‘b/’ prefixes. Detect and strip them.
55 if ($arg =~ m
~^[ab
]/(.+)$~ && -e
$1) {
59 # Lastly, try matching ‘«filename»:«line»:«column»:«text»’. «filename»
60 # and «text» may include colons and «line» and «column» are optional.
61 # This makes the matching a bit tricky so we try various possible file
62 # names if there are multiple colons in $arg.
63 my @parts = split /:/, $arg, -1;
64 for (my $i = @parts; --$i; ) {
65 my $filename = join ':', @parts[0..($i - 1)];
69 my $line = $parts[$i] // '';
70 my $column = $parts[$i + 1] // '';
71 if ($line !~ /^\d+$/) {
73 } elsif ($column =~ /^\d+$/) {
74 return ("+$line:$column", $filename);
76 return ("+$line", $filename);
85 open my $fd, '-|', @_ or die "$cmd : $!\n";
87 while (defined(my $line = <$fd>)) {
92 check_exit_status
($cmd);
94 die "$cmd: exited with an empty result\n";
100 my ($windmove, $stdin) = (0, 0);
103 if (@ARGV && $ARGV[0] eq 'e') {
108 my $arg = shift @ARGV;
111 } elsif ($arg eq '-r') {
113 } elsif ($arg eq '-o') {
115 } elsif ($arg =~ /^-(find|which)$/) {
116 push @args, read_process
$1, @ARGV;
118 } elsif ($arg eq '--') {
121 } elsif ($arg eq '-') {
123 } elsif ($arg =~ /^-./) {
124 die "e: unknown option: $arg\n";
126 push @args, file_argument
($arg);
130 if ($windmove eq 'other') {
134 (error (windmove-left)))
136 } elsif ($windmove) {
137 my $direction = $windmove < 0 ?
'left' : 'right';
140 (dotimes (n (abs $windmove))
141 (windmove-$direction))
149 die "e: reading standard input is supported if there are no other arguments\n";
153 $data = join '', <STDIN
>;
154 $data =~ s/\\/\\\\/g;
157 (let ((buf (generate-new-buffer "*pipe*")))
160 (goto-char (point-min))
162 (switch-to-buffer buf)
165 @args = ('-e', $data);
168 client has_x ?
'-cna' : '-a', '';
174 client
'-q', '-ne', $windmove;
177 my @q = $stdin ?
('-q') : ();
178 client
@q, has_x ?
'-na' : '-ta', '', @args;