[Top][All Lists]

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

Re: igrep on remote files with tramp?

From: Kevin Rodgers
Subject: Re: igrep on remote files with tramp?
Date: Tue, 02 Aug 2005 14:35:13 -0600
User-agent: Mozilla Thunderbird 0.9 (X11/20041105)

Daniel Berdine wrote:
> On Thu, 28 Jul 2005 15:28:54 -0400, Kevin Rodgers wrote
> (in article <address@hidden>):
> > igrep only supports ange-ftp (and efs) to the extent that the
> > igrep-visited-files and Buffer-menu-igrep commands explicitly ignore
> > remote files.
> >
> > To properly support remote files, igrep would need to invoke the grep
> > command in a remote shell.  I know there has been discussion about
> > whether Emacs should implement process handlers, so that tramp could run
> > programs on a remote host when invoked from a buffer visiting a remote
> > file.  But I don't know what was decided and implemented (if anything).
> Ok, thanks.
> I'm obviously ignorant here, but why is this so different than, say,
> incremental searches across several remote files with tramp?

I'm completely ignorant about tramp.  Do you mean incremental search
across several buffers visiting remote files via tramp?  Or does tramp
provide its own incremental search command?

> Can't a local igrep be run on the local tmp files that get used for so
> many other purposes?

I don't know how tramp works, but ange-ftp evidently does not leave the
local tmp files on disk once their contents have been inserted into the

> In any case, being able to run remote processes with tramp would be great.

It turns out that ange-ftp provides file name handlers for
shell-command, which uses remote-shell-program (e.g.  /bin/remsh) to
execute the command on the other host when visiting a remote file or
directory.  So I would be suprised if tramp does not provide the same
functionality when you use e.g. `! grep foo *.java'.

But igrep and grep are based on compile, which uses start-process
instead of shell-command.  But since tramp provides commands for
compilation of files on remote hosts (see, perhaps tramp-util.el
just needs something like this (cribbed from tramp-compile):

(defun tramp-grep (command)
  "Run grep COMMAND on remote host."
   (list (read-from-minibuffer "Run grep (like this): "
                               (or (car grep-history) grep-command)
                               nil nil 'grep-history)))
  (setq grep-command command)
  (unless (string-match "[ \t]*&[ \t]*\\'" command)
    (setq command (concat command "&")))
  (save-some-buffers (not compilation-ask-about-save) nil)
  (let ((d default-directory))
      (pop-to-buffer (get-buffer-create "*grep*") t)
      (setq default-directory d)))
  (tramp-handle-shell-command command (get-buffer "*grep*"))
  (pop-to-buffer (get-buffer "*grep*"))
  (compilation-minor-mode 1)
  (tramp-minor-mode 1))

(tramp-remap-command 'grep 'tramp-grep)

(when (fboundp 'add-menu-button)
  (funcall 'add-menu-button
   '("Tools" "Grep")
   ["Search Files (Grep)..."
    (command-execute (if tramp-minor-mode 'tramp-grep 'grep))
    :active (fboundp 'grep)]))

> I've frequently wished I could do this with gdb within emacs, for instance.

You are not alone.

Kevin Rodgers

reply via email to

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