[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Shell command on region and result in other window
From: |
Daniel Boerner |
Subject: |
Shell command on region and result in other window |
Date: |
Tue, 20 May 2014 18:25:08 +0200 |
Hello everybody,
I'm trying to select through a window some text from one buffer, feed the region into a shell command as a parameter, put the result of this processing into another window and return to the first window.
Here some boiled down and functional test code:
(global-set-key [f1] 'test--copy-command-other-window)
(defun test--copy-command-other-window()
"Copy to and command on other window."
(interactive)
(copy-region-as-kill (mark) (point))
(debug)
(select-window (next-window))
(yank)
(exchange-point-and-mark) ;; activate mark
(shell-command-on-region (mark) (point)
(concat (if (executable-find "env") "env " "")
(concat "perl" " -np -e 'use strict; print $_ . qw ( Hello );'"))
(current-buffer) t)
(deactivate-mark)
(newline)
(select-window (next-window)))
Testing procedure:
Evaluate the above two forms (C-x C-e).
Find a (non-existent) File (C-x C-f). Call it test1.
Split the resulting window (C-x 2).
In one of the resulting window, find another (non-existent) File. Call it test2.
Now, put some text into one of the buffer, say test1.
Window test2:
[empty]
Window test1:
some text, and more text, and more and more text
Now, set a region on some text from test1, say "more text"
and execute the function test--copy-command-other-window through key F1.
Expected result:
Window test2:
more textHello
Window test1:
some text, and more text, and more and more text
Obtained result:
Window test2:
more textHellomore text
Window test1:
some text, and more text, and more and more text
From debugging, I get:
* shell-command-on-region(10 1 "env perl -np -e 'use strict; print $_ . qw ( Hello );'" #<buffer test2> t)
* call-process-region(10 1 "/bin/bash" t t nil "-c" "env perl -np -e 'use strict; print $_ . qw ( Hello );'")
So, shell-command-on-region gets the right values for mark, point and buffer.
It seems to me as if shell-command-on-region is ignoring the REPLACE option (fifth parameter). I also wonder about the sixth parameter (DISPLAY) to call-process-region. Maybe its value should be non-nil.
I think that I'm missing something, so any hint appreciated.
Many thanks.
- Shell command on region and result in other window,
Daniel Boerner <=