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

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

Re: go from *Process List* to each process's buffer easy


From: Kevin Rodgers
Subject: Re: go from *Process List* to each process's buffer easy
Date: Mon, 20 Oct 2003 18:06:19 -0600
User-agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2

Dan Jacobson wrote:

Hitting RET on a line in the *Process List* buffer should take one to
that process's buffer, if any.

One way you could do that would be to temporarily bind temp-buffer-show-hook

in list-processes.  I don't know to do that in C, though, so I experimented
by advising it (which works if you call it via `M-x list-processes').  The
new hook function has to parse the *Process List* buffer, which is kind of
nasty because the Proc and Buffer columns can be arbitrary strings (including
spaces) and may be shifted to the right.  (The *Completions* buffer used to
have the same problem, but now you can use the mouse-face property to find
the individual items.)  Anyway, here's a hack to get you started:
(defadvice list-processes (around make-xrefs activate)
  "Add hyperlinks to select each process buffer."
  (let ((temp-buffer-show-hook 'list-processes-make-xrefs))
    ad-do-it))

(defun list-processes-make-xrefs (&optional buffer)
  "Add bindings to select each process buffer via `local-keymap' overlay 
properties."
  (save-excursion
    (set-buffer (or buffer (current-buffer)))
    (goto-char (point-min))
    ;; See src/process.c:list_processes_1():
    (or (re-search-forward "^-+  +-+  +-+  +-+  +-+$" nil t)
        (error "*Process List* header not found"))
    (forward-line 1)
    (let* ((proc-regexp "\\([a-zA-Z0-9---]+\\)")
           (status-regexp
            "\\(run\\|stop\\|exit\\|signal\\|open\\|closed\\|nil\\)")
           (buffer-regexp "\\([a-zA-Z0-9---<>*()]+ ?[a-zA-Z0-9---<>*()]+\\)")
           (proc-status-buffer-regexp
            (format "\\=%s  +%s  +%s  +"
                    proc-regexp status-regexp buffer-regexp))
           (help-echo
            (substitute-command-keys
             "\\<help-mode-map>\\[help-follow-mouse]: Select this buffer"))
           process-buffer)
      (while (re-search-forward proc-status-buffer-regexp nil t)
        (setq process-buffer (get-buffer (match-string 3)))
        (if process-buffer              ; not "(none)" or "(Killed)"
            (help-xref-button 3 'switch-to-buffer process-buffer help-echo))
        (forward-line 1)))))

reply via email to

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