help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: shell-command-on-region with TRAMP - local binary


From: Xah Lee
Subject: Re: shell-command-on-region with TRAMP - local binary
Date: Tue, 20 Jan 2009 09:06:40 -0800 (PST)
User-agent: G2/1.0

On Jan 20, 8:33 am, Terrence Brannon <metap...@gmail.com> wrote:
> How can I run shell-command-on-region on a remote buffer using a local
> binary?
>
> My current solution is to paste the buffer to a local *scratch* buffer
> and run the command there and then paste it back...
>
> sounds like a nice elisp job for a hungry hacker ;-)
>
> code welcome!

very easy. Your code will simply do the following:

• grab the current buffer's content.
• create a new buffer (or temp file locally)
• run tidy on it.

string together the following snippets will do

(defun ()
"run tramp on current buffer"
(interactive)
...
)

(setq mybuffer (current-buffer))
(setq meat (buffer-string))  ; possibly (widen) first
(with-temp-buffer ; creates new buffer that will be gone after running
  (insert meat)
  (shell-command-on-region ...)
)

the important part is that when you create a temp buffer, its file
path must be local. i think by default with-temp-buffer will not do...
so you might use something like temp file with a local path instead,
e.g.

(defun new-temp-file ()
  "Open a new temp file in “~/Document/temp/”"
  (interactive)
  (random t)
  (find-file
   (concat "~/Documents/temp/" "tmp_"
           (number-to-string (random 999)))))

or

(switch-to-buffer "some random name") ; creates new buffer

O, you can probably just use with-temp-buffer and set its current dir
path will do. You'll have to do some doc searching on the var name for
the path.

if the above is not clear, the following will help:

(example of using shell-command-on-region)
• Elisp Wrapper For Perl Scripts
  http://xahlee.org/emacs/elisp_perl_wrapper.html

(example code of dealing with current buffer)
• Elisp Lesson: Execute/Compile Current File
  http://xahlee.org/emacs/elisp_run_current_file.html

  Xah
∑ http://xahlee.org/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]