[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
improving network utility calls in lisp/net/net-utils.el
From: |
Yoni Rabkin |
Subject: |
improving network utility calls in lisp/net/net-utils.el |
Date: |
Fri, 10 Apr 2009 16:18:21 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (gnu/linux) |
Hello, I am using GNU Emacs 23.0.92.1 (i686-pc-linux-gnu, GTK+ Version
2.12.9) of 2009-04-10
lisp/net/net-utils.el currently provides the eponymously named
functions: M-x ifconfig, M-x iwconfig, M-x route etc.
These functions display the "diagnostic", that is, non-interactive
outputs of the network utilities with the same name. But net-utils.el
calls those processes asynchronously with `start-process' and displays
the raw result in an editable buffer.
The following patch makes calling the non-interactive diagnostic
network utilities synchronous, and provides a read-only mode for
viewing, font-locking and burying the buffers with `q'.
Caveats: Because the call is now synchronous "netstat" will hold up
Emacs until it competes. Also, font-locking could be better. If this
patch is accepted I'll work on that as well.
Attached is the patch made with:
~/src/emacs$ cvs diff > net-utils-improved-utility-calls.patch
? net-utils-improved-utility-calls.patch
? net-utils.patch
? lisp/mail/subdirs.el
? lisp/nxml/char-name/subdirs.el
Index: lisp/net/net-utils.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/net/net-utils.el,v
retrieving revision 1.37
diff -r1.37 net-utils.el
262a263,299
> ;; General network utilities mode
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> (defconst net-utils-font-lock-keywords
> (list
> (list "^[A-Za-z0-9 _]+:" 0 'font-lock-type-face)
> ;; Dotted quads
> (list
> (mapconcat 'identity (make-list 4 "[0-9]+") "\\.")
> 0 'font-lock-variable-name-face)
> ;; Host names
> (list
> (let ((host-expression "[-A-Za-z0-9]+"))
> (concat
> (mapconcat 'identity (make-list 2 host-expression) "\\.")
> "\\(\\." host-expression "\\)*"))
> 0 'font-lock-variable-name-face))
> "Expressions to font-lock for general network utilities.")
>
> (define-derived-mode net-utils-mode text-mode "NetworkUtil"
> "Major mode for interacting with an external network utility."
> (set
> (make-local-variable 'font-lock-defaults)
> '((net-utils-font-lock-keywords)))
> (use-local-map net-utils-mode-map)
> (setq buffer-read-only t))
>
> (defun net-utils-mode-bury-buffer ()
> "Wrapper around `bury-buffer' for pop-ups."
> (interactive)
> (if (one-window-p)
> (bury-buffer)
> (delete-window)))
>
> (define-key net-utils-mode-map "q" 'net-utils-mode-bury-buffer)
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
325a363,391
> ;; General network utilities (diagnostic)
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> (defun net-utils-run-simple (buffer-name program-name args)
> (interactive)
> (when (get-buffer buffer-name)
> (kill-buffer buffer-name))
> (get-buffer-create buffer-name)
> (with-current-buffer buffer-name
> (apply 'call-process program-name nil t nil args)
> (net-utils-mode)
> (goto-char (point-min)))
> (display-buffer buffer-name))
>
> (defmacro net-utils-defutil (fname program-name args)
> `(defun ,fname ()
> (interactive)
> (net-utils-run-simple
> (format "*%s*" ,program-name)
> ,program-name
> ,args)))
>
> (net-utils-defutil ifconfig ifconfig-program ifconfig-program-options)
> (net-utils-defutil iwconfig iwconfig-program iwconfig-program-options)
> (net-utils-defutil netstat netstat-program netstat-program-options)
> (net-utils-defutil arp arp-program arp-program-options)
> (net-utils-defutil route route-program route-program-options)
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
360,413d425
< ;;;###autoload
< (defun ifconfig ()
< "Run ifconfig program."
< (interactive)
< (net-utils-run-program
< "Ifconfig"
< (concat "** Ifconfig ** " ifconfig-program " ** ")
< ifconfig-program
< ifconfig-program-options))
<
< ;; Windows uses this name.
< ;;;###autoload
< (defalias 'ipconfig 'ifconfig)
<
< ;;;###autoload
< (defun iwconfig ()
< "Run iwconfig program."
< (interactive)
< (net-utils-run-program
< "Iwconfig"
< (concat "** Iwconfig ** " iwconfig-program " ** ")
< iwconfig-program
< iwconfig-program-options))
<
< ;;;###autoload
< (defun netstat ()
< "Run netstat program."
< (interactive)
< (net-utils-run-program
< "Netstat"
< (concat "** Netstat ** " netstat-program " ** ")
< netstat-program
< netstat-program-options))
<
< ;;;###autoload
< (defun arp ()
< "Run arp program."
< (interactive)
< (net-utils-run-program
< "Arp"
< (concat "** Arp ** " arp-program " ** ")
< arp-program
< arp-program-options))
<
< ;;;###autoload
< (defun route ()
< "Run route program."
< (interactive)
< (net-utils-run-program
< "Route"
< (concat "** Route ** " route-program " ** ")
< route-program
< route-program-options))
<
--
"Cut your own wood and it will warm you twice"
- improving network utility calls in lisp/net/net-utils.el,
Yoni Rabkin <=
- Re: improving network utility calls in lisp/net/net-utils.el, Stefan Monnier, 2009/04/10
- Re: improving network utility calls in lisp/net/net-utils.el, Yoni Rabkin, 2009/04/10
- Re: improving network utility calls in lisp/net/net-utils.el, David De La Harpe Golden, 2009/04/10
- Re: improving network utility calls in lisp/net/net-utils.el, Yoni Rabkin, 2009/04/10
- Re: improving network utility calls in lisp/net/net-utils.el, David De La Harpe Golden, 2009/04/10
- Re: improving network utility calls in lisp/net/net-utils.el, Yoni Rabkin, 2009/04/10
- Re: improving network utility calls in lisp/net/net-utils.el, Chad Brown, 2009/04/11
- Re: improving network utility calls in lisp/net/net-utils.el, Stefan Monnier, 2009/04/10
- Re: improving network utility calls in lisp/net/net-utils.el, Yoni Rabkin, 2009/04/11
- Re: improving network utility calls in lisp/net/net-utils.el, Eli Zaretskii, 2009/04/11