From: Yoni Rabkin <yoni@rabkins.net>
To: emacs-devel@gnu.org
Subject: Re: improving network utility calls in lisp/net/net-utils.el
Date: Fri, 10 Apr 2009 17:09:47 +0300 [thread overview]
Message-ID: <87y6u8k3bo.fsf@rabkins.net> (raw)
In-Reply-To: <jwv4oww63r6.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Fri, 10 Apr 2009 09:25:49 -0400")
[-- Attachment #1: Type: text/plain, Size: 662 bytes --]
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> 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.
>
> [ Please make (unified) context diffs rather than plain diffs. I.e. pass
> the "-u" arg to `cvs diff'. ]
Fixed. Sorry about that.
> I think using async processes is preferable, and was done specifically
> to avoid holding up Emacs until the process completes.
The attached patch runs netstat asynchronously and all of the
essentially instantaneous processes synchronously (ifconfig, iwconfig,
arp and route).
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: net-utils-improved-utility-calls-2.patch --]
[-- Type: text/x-diff, Size: 4819 bytes --]
? net-utils-improved-utility-calls-2.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 -u -r1.37 net-utils.el
--- lisp/net/net-utils.el 5 Jan 2009 03:22:45 -0000 1.37
+++ lisp/net/net-utils.el 10 Apr 2009 14:01:50 -0000
@@ -260,6 +260,43 @@
"Expressions to font-lock for nslookup.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 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)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Utility functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -323,6 +360,34 @@
buf))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 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 arp arp-program arp-program-options)
+(net-utils-defutil route route-program route-program-options)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Wrappers for external network programs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -341,6 +406,16 @@
options)))
;;;###autoload
+(defun netstat ()
+ "Run netstat program."
+ (interactive)
+ (net-utils-run-program
+ "Netstat"
+ (concat "** Netstat ** " netstat-program " ** ")
+ netstat-program
+ netstat-program-options))
+
+;;;###autoload
(defun ping (host)
"Ping HOST.
If your system's ping continues until interrupted, you can try setting
@@ -357,60 +432,6 @@
ping-program
options)))
-;;;###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))
-
;; FIXME -- Needs to be a process filter
;; (defun netstat-with-filter (filter)
;; "Run netstat program."
[-- Attachment #3: Type: text/plain, Size: 55 bytes --]
--
"Cut your own wood and it will warm you twice"
next prev parent reply other threads:[~2009-04-10 14:09 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-10 13:18 improving network utility calls in lisp/net/net-utils.el Yoni Rabkin
2009-04-10 13:25 ` Stefan Monnier
2009-04-10 14:09 ` Yoni Rabkin [this message]
2009-04-10 16:40 ` David De La Harpe Golden
2009-04-10 17:55 ` Yoni Rabkin
2009-04-10 20:10 ` David De La Harpe Golden
2009-04-10 21:13 ` Yoni Rabkin
2009-04-11 0:42 ` Chad Brown
2009-04-10 22:13 ` Stefan Monnier
2009-04-11 8:47 ` Yoni Rabkin
2009-04-11 9:02 ` Eli Zaretskii
2009-04-11 9:17 ` Yoni Rabkin
2009-04-11 12:39 ` Stefan Monnier
2009-07-16 19:52 ` Yoni Rabkin
2009-07-26 8:02 ` Yoni Rabkin
2009-08-02 19:21 ` Yoni Rabkin
2009-08-02 22:34 ` Chong Yidong
2009-08-08 8:05 ` Yoni Rabkin
2009-08-08 18:27 ` Chong Yidong
2009-04-10 19:34 ` Dan Nicolaescu
2009-04-10 22:14 ` Stefan Monnier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y6u8k3bo.fsf@rabkins.net \
--to=yoni@rabkins.net \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).