From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Leo Newsgroups: gmane.emacs.devel Subject: Re: Why is list-processes implemented in C? Date: Mon, 29 Nov 2010 09:44:11 +0000 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1291023867 1424 80.91.229.12 (29 Nov 2010 09:44:27 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 29 Nov 2010 09:44:27 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Nov 29 10:44:23 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PN0HW-0000Ha-3T for ged-emacs-devel@m.gmane.org; Mon, 29 Nov 2010 10:44:23 +0100 Original-Received: from localhost ([127.0.0.1]:55000 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PN0HV-00078G-Fe for ged-emacs-devel@m.gmane.org; Mon, 29 Nov 2010 04:44:21 -0500 Original-Received: from [140.186.70.92] (port=34656 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PN0HP-00077z-Sg for emacs-devel@gnu.org; Mon, 29 Nov 2010 04:44:16 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PN0HO-0005Ms-Nj for emacs-devel@gnu.org; Mon, 29 Nov 2010 04:44:15 -0500 Original-Received: from ppsw-41.csi.cam.ac.uk ([131.111.8.141]:52173) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PN0HO-0005Mc-Gi for emacs-devel@gnu.org; Mon, 29 Nov 2010 04:44:14 -0500 X-Cam-AntiVirus: no malware found X-Cam-SpamDetails: not scanned X-Cam-ScannerInfo: http://www.cam.ac.uk/cs/email/scanner/ Original-Received: from cpc1-cmbg13-0-0-cust596.5-4.cable.virginmedia.com ([86.9.122.85]:65164 helo=Victoria.local) by ppsw-41.csi.cam.ac.uk (smtp.hermes.cam.ac.uk [131.111.8.156]:587) with esmtpsa (PLAIN:sl392) (TLSv1:DHE-RSA-AES128-SHA:128) id 1PN0HL-00006X-Sg (Exim 4.72) (return-path ); Mon, 29 Nov 2010 09:44:12 +0000 In-Reply-To: (Stefan Monnier's message of "Sun, 28 Nov 2010 14:01:45 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (Mac OS X 10.6.5) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:133227 Archived-At: --=-=-= On 2010-11-28 19:01 +0000, Stefan Monnier wrote: >> It looks like it can be implemented in elisp? Any idea why? > > Probably a historical accident. > > > Stefan Elisp version attempt 1: --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=emacs-process.el Content-Transfer-Encoding: quoted-printable Content-Description: emacs-process.el (eval-when-compile (require 'cl)) (defvar emacs-process-mode-map (let ((m (make-sparse-keymap))) (define-key m "\C-k" 'emacs-process-delete) (define-key m "g" 'emacs-process-list) m)) (defun emacs-process-delete (&optional name) (interactive (list (let ((def (get-text-property (point) 'process-name))) (completing-read (if def (format "Delete process (defaul= t %s): " def) "Delete process: ") (mapcar 'process-name (process-list= )) nil t nil nil def)))) (delete-process (get-process name))) (define-derived-mode emacs-process-mode fundamental-mode "Emacs Processes" (setq buffer-read-only t)) (defun emacs-process-info (&optional query-only) "Return a list of (NAMES STATUSES BUFFERS COMMANDS)." (let (processes statuses buffers commands) (mapc (lambda (p) (when (or (not query-only) (and query-only (process-query-on-exit-flag p))) (push (process-name p) processes) (push (symbol-name (process-status p)) statuses) (push (let ((buf (process-buffer p))) (cond ((null buf) "(none)") ((not (buffer-live-p buf)) "(Killed)") (t (buffer-name buf)))) buffers) (push (case (process-type p) (network (destructuring-bind (&key server type service host &allow-other-keys) (process-contact p t) (format "(network %s %s)" (if type "datagram" "stream") (if server (format "server on %s" service) (format "connection to %s" host)= )))) (serial (destructuring-bind (&key port speed &allow-other-keys) (process-contact p t) (format "(serial port %s%s)" (or port "?") (if speed (format " at %s b/s" speed) "")))) (otherwise (mapconcat 'identity (process-command p) "= "))) commands))) (process-list)) (list processes statuses buffers commands))) (defun emacs-process-list (&optional query-only) (interactive) (let ((buf (get-buffer-create "*Process List2*"))) (with-current-buffer buf (let* ((inhibit-read-only t) (minwidth 9) (info (emacs-process-info query-only)) (colwidth (mapcar (lambda (i) (max minwidth (1+ (apply 'max (mapcar 'length i))))) info))) (erase-buffer) (destructuring-bind (names statuses buffers commands) info (loop for name in (append '("Proc" "----") names) for status in (append '("Status" "------") statuses) for buffer in (append '("Buffer" "------") buffers) for command in (append '("Command" "-------") commands) for index from 0 ;; compute the indentation with (col1 col2 col3) =3D colwidth with ind1 =3D col1 with ind2 =3D (+ ind1 col2) with ind3 =3D (+ ind2 col3) do (insert name) (indent-to ind1) (insert status) (indent-to ind2) (insert buffer) (indent-to ind3) (insert command) (when (> index 1) (put-text-property (line-beginning-position) (line-end-position) 'process-name name)) (insert "\n")))) (set-buffer-modified-p nil) (goto-char (point-min)) (emacs-process-mode)) (display-buffer buf))) ;; (defalias 'list-processes 'emacs-process-list) --=-=-= Leo --=-=-=--