* Shell command on region and result in other window
@ 2014-05-20 16:25 Daniel Boerner
2014-05-23 19:32 ` Fwd: " Daniel Boerner
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Boerner @ 2014-05-20 16:25 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 2203 bytes --]
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.
[-- Attachment #2: Type: text/html, Size: 2696 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Fwd: Shell command on region and result in other window
2014-05-20 16:25 Shell command on region and result in other window Daniel Boerner
@ 2014-05-23 19:32 ` Daniel Boerner
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Boerner @ 2014-05-23 19:32 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 2578 bytes --]
I respond myself: wrong perl switch on shell-command-on-region
Please, ignore my previous message.
Sorry, sorry for polluting this mailing list.
By the way, THANKS to everybody for GNU Emacs.
---------- Forwarded message ----------
From: Daniel Boerner
Date: 2014-05-20 18:25 GMT+02:00
Subject: Shell command on region and result in other window
To: emacs-devel@gnu.org
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.
[-- Attachment #2: Type: text/html, Size: 3379 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-05-23 19:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-20 16:25 Shell command on region and result in other window Daniel Boerner
2014-05-23 19:32 ` Fwd: " Daniel Boerner
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.