Previously, I’ve talked about integrating little perl "services" into emacs that read from stdin and write to stdout.

Sometimes the processes that make up your emacs application are running on different servers, picking up various pieces of information and it might be necessary to kill them independently or in groups. By default, comint binds C-c C-c to SIGINT, but if you have a moderately complex application, you don’t want to go through each comint buffer and kill the processes individually.

Each of your perl scripts needs to output the PID and the server it is running on.

use Sys::Hostname ; my $hostname = hostname(); print "Started PID $$ on $hostname

" ;

Then the emacs application code needs to use a filter to read that information into a couple of variables.

( defvar proc-pid nil) ( defvar proc-host nil) ( defconst *re-match-pid-host* "Started PID \\ ( [0-9]+ \\ ) on \\ ( [a-z0-9]+ \\ ) " ) ( defun proc-filter (output) ( when (string-match *re-match-pid-host* output) (setq proc-pid (match-string 1 output)) (setq proc-host (match-string 2 output))) output) (add-hook 'comint-preoutput-filter-functions 'proc-filter)

Running commands remotely is easy with ssh. (Incidentally, how does this work in windows-land?)

( defconst *ssh* "ssh -o StrictHostKeyChecking=no" ) ( defun kill-proc () (interactive) ( let ((cmd (format "%s %s kill %s" *ssh* proc-host proc-pid))) (message cmd) (message (shell-command-to-string cmd))))

I’ve demonstrated the make-comint code previously.

( defun start-proc () ( let ((buffer (get-buffer "*stdin-proc*" ))) ( when buffer (kill-buffer "*stdin-proc*" ))) (apply 'make-comint "stdin-proc" "perl" nil (list "./test-stdin.pl" )))

And the result is as expected.

Started PID 5008 on saturn Process stdin-proc terminated