all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yoni Rabkin <yoni@rabkins.net>
To: emacs-devel@gnu.org
Subject: Re: improving network utility calls in lisp/net/net-utils.el
Date: Sat, 08 Aug 2009 11:05:09 +0300	[thread overview]
Message-ID: <87ocqqennu.fsf@rabkins.net> (raw)
In-Reply-To: <874ospsv4z.fsf@cyd.mit.edu> (Chong Yidong's message of "Sun, 02 Aug 2009 18:34:04 -0400")

[-- Attachment #1: Type: text/plain, Size: 1046 bytes --]

Chong Yidong <cyd@stupidchicken.com> writes:

> Yoni Rabkin <yoni@rabkins.net> writes:
>
>> Does anyone have time to install this?
>
> Terribly sorry for the delay, I haven't had time to review your patch
> till just now.

No problem at all. Thank you for maintaining Emacs.

> Once you make these changes, just send me the revised patch with a
> ChangeLog entry, and I'll install it.  Thanks for your patience.

lisp/ChangeLog entry:

2009-08-08 Chong Yidong <cyd@stupidchicken.com>

	* net/net-utils.el: Add a read-only mode for viewing,
        font-locking and burying diagnostic network commands.
        (nslookup-font-lock-keywords): Change to defvar.
        (net-utils-font-lock-keywords): New var.
        (net-utils-mode): New mode for viewing diagnostic networkd
        command output.
        (net-utils-remove-ctrl-m-filter): inhibit-read-only <= t.
        (net-utils-run-simple): New function.
        (ifconfig, iwconfig, netstat, arp, route): Use
        net-utils-run-simple.
        Patch by Yoni Rabkin <yoni@rabkins.net>.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: net-utils patch --]
[-- Type: text/x-diff, Size: 6972 bytes --]

*** net-utils.el.~1.37.~	2009-08-04 18:23:44.000000000 +0300
--- net-utils.el	2009-08-08 10:32:54.000000000 +0300
***************
*** 237,243 ****
  ;; Nslookup goodies
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
! (defconst nslookup-font-lock-keywords
    (list
     (list "^[A-Za-z0-9 _]+:" 0 'font-lock-type-face)
     (list "\\<\\(SOA\\|NS\\|MX\\|A\\|CNAME\\)\\>"
--- 237,243 ----
  ;; Nslookup goodies
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
! (defvar nslookup-font-lock-keywords
    (list
     (list "^[A-Za-z0-9 _]+:" 0 'font-lock-type-face)
     (list "\\<\\(SOA\\|NS\\|MX\\|A\\|CNAME\\)\\>"
***************
*** 260,265 ****
--- 260,296 ----
    "Expressions to font-lock for nslookup.")
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+ ;; General network utilities mode
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+ 
+ (defvar net-utils-font-lock-keywords
+   (list
+    ;; Dotted quads
+    (list
+     (mapconcat 'identity (make-list 4 "[0-9]+") "\\.")
+     0 'font-lock-variable-name-face)
+    ;; Simple rfc4291 addresses
+    (list (concat
+ 	  "\\( \\([[:xdigit:]]+\\(:\\|::\\)\\)+[[:xdigit:]]+\\)"
+ 	  "\\|"
+ 	  "\\(::[[:xdigit:]]+\\)")
+     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 special-mode "NetworkUtil"
+   "Major mode for interacting with an external network utility."
+   (set
+    (make-local-variable 'font-lock-defaults)
+    '((net-utils-font-lock-keywords))))
+ 
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;; Utility functions
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
***************
*** 288,294 ****
         (skip-chars-backward ":;.,!?" pt)
         (point)))))
  
- 
  (defun net-utils-remove-ctrl-m-filter (process output-string)
    "Remove trailing control Ms."
    (let ((old-buffer (current-buffer))
--- 319,324 ----
***************
*** 296,312 ****
      (unwind-protect
  	(let ((moving))
  	  (set-buffer (process-buffer process))
! 	  (setq moving (= (point) (process-mark process)))
  
! 	  (while (string-match "\r" filtered-string)
! 	       (setq filtered-string
! 		     (replace-match "" nil nil filtered-string)))
! 
! 	  (save-excursion
! 	    ;; Insert the text, moving the process-marker.
! 	    (goto-char (process-mark process))
! 	    (insert filtered-string)
! 	    (set-marker (process-mark process) (point)))
  	  (if moving (goto-char (process-mark process))))
        (set-buffer old-buffer))))
  
--- 326,343 ----
      (unwind-protect
  	(let ((moving))
  	  (set-buffer (process-buffer process))
! 	  (let ((inhibit-read-only t))
! 	    (setq moving (= (point) (process-mark process)))
  
! 	    (while (string-match "\r" filtered-string)
! 	      (setq filtered-string
! 		    (replace-match "" nil nil filtered-string)))
! 
! 	    (save-excursion
! 	      ;; Insert the text, moving the process-marker.
! 	      (goto-char (process-mark process))
! 	      (insert filtered-string)
! 	      (set-marker (process-mark process) (point))))
  	  (if moving (goto-char (process-mark process))))
        (set-buffer old-buffer))))
  
***************
*** 323,328 ****
--- 354,425 ----
      buf))
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+ ;; General network utilities (diagnostic)
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+ 
+ (defun net-utils-run-simple (buffer-name program-name args)
+   "Run a network utility for diagnostic output only."
+   (interactive)
+   (when (get-buffer buffer-name)
+     (kill-buffer buffer-name))
+   (get-buffer-create buffer-name)
+   (with-current-buffer buffer-name
+     (net-utils-mode)
+     (set-process-filter
+      (apply 'start-process (format "%s" program-name)
+ 	    buffer-name program-name args)
+      'net-utils-remove-ctrl-m-filter)
+     (goto-char (point-min)))
+   (display-buffer buffer-name))
+ 
+ ;;;###autoload
+ (defun ifconfig () 
+   "Run ifconfig and display diagnostic output." 
+   (interactive) 
+   (net-utils-run-simple 
+    (format "*%s*" ifconfig-program) 
+    ifconfig-program 
+    ifconfig-program-options))
+ 
+ (defalias 'ipconfig 'ifconfig)
+ 
+ ;;;###autoload
+ (defun iwconfig () 
+   "Run iwconfig and display diagnostic output." 
+   (interactive) 
+   (net-utils-run-simple 
+    (format "*%s*" iwconfig-program) 
+    iwconfig-program 
+    iwconfig-program-options))
+ 
+ ;;;###autoload
+ (defun netstat ()
+   "Run netstat and display diagnostic output." 
+   (interactive)
+   (net-utils-run-simple
+    (format "*%s*" netstat-program)
+    netstat-program
+    netstat-program-options))
+ 
+ ;;;###autoload
+ (defun arp ()
+   "Run arp and display diagnostic output." 
+   (interactive)
+   (net-utils-run-simple
+    (format "*%s*" arp-program)
+    arp-program
+    arp-program-options))
+ 
+ ;;;###autoload
+ (defun route ()
+   "Run route and display diagnostic output."
+   (interactive)
+   (net-utils-run-simple
+    (format "*%s*" route-program)
+    route-program
+    route-program-options))
+ 
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;; Wrappers for external network programs
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
***************
*** 357,416 ****
       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."
--- 454,459 ----

[-- Attachment #3: Type: text/plain, Size: 55 bytes --]


-- 
   "Cut your own wood and it will warm you twice"

  reply	other threads:[~2009-08-08  8:05 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
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 [this message]
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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ocqqennu.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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.