* improving network utility calls in lisp/net/net-utils.el
@ 2009-04-10 13:18 Yoni Rabkin
2009-04-10 13:25 ` Stefan Monnier
0 siblings, 1 reply; 21+ messages in thread
From: Yoni Rabkin @ 2009-04-10 13:18 UTC (permalink / raw
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 929 bytes --]
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: net-utils-improved-utility-calls.patch --]
[-- Type: text/x-diff, Size: 3913 bytes --]
? 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))
<
[-- Attachment #3: Type: text/plain, Size: 55 bytes --]
--
"Cut your own wood and it will warm you twice"
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: improving network utility calls in lisp/net/net-utils.el
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
0 siblings, 1 reply; 21+ messages in thread
From: Stefan Monnier @ 2009-04-10 13:25 UTC (permalink / raw
To: Yoni Rabkin; +Cc: emacs-devel
> 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'. ]
I think using async processes is preferable, and was done specifically
to avoid holding up Emacs until the process completes.
Stefan
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: improving network utility calls in lisp/net/net-utils.el
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 19:34 ` Dan Nicolaescu
0 siblings, 2 replies; 21+ messages in thread
From: Yoni Rabkin @ 2009-04-10 14:09 UTC (permalink / raw
To: emacs-devel
[-- 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"
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: improving network utility calls in lisp/net/net-utils.el
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 19:34 ` Dan Nicolaescu
1 sibling, 1 reply; 21+ messages in thread
From: David De La Harpe Golden @ 2009-04-10 16:40 UTC (permalink / raw
To: Yoni Rabkin; +Cc: emacs-devel
Yoni Rabkin wrote:
> The attached patch runs netstat asynchronously and all of the
> essentially instantaneous processes synchronously (ifconfig, iwconfig,
> arp and route).
>
Only "near-instant" if your network isn't somehow acting up, sorry,
async is just the Right Thing here.
If you don't suppress dns resolution (-n) during routing table output
for example, you potentially pause for a fair old while if there's
problems with dns lookups (which could be caused by, oh, let's see,
network routes being wrong...). Much the same applies to arp tables
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: improving network utility calls in lisp/net/net-utils.el
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 22:13 ` Stefan Monnier
0 siblings, 2 replies; 21+ messages in thread
From: Yoni Rabkin @ 2009-04-10 17:55 UTC (permalink / raw
To: emacs-devel
David De La Harpe Golden <david@harpegolden.net> writes:
> Yoni Rabkin wrote:
>
>> The attached patch runs netstat asynchronously and all of the
>> essentially instantaneous processes synchronously (ifconfig, iwconfig,
>> arp and route).
>>
>
> Only "near-instant" if your network isn't somehow acting up, sorry,
> async is just the Right Thing here.
As a user of both Dired and Gnus I'm well accustomed to waiting for
Emacs to synchronously go fetch something. I agree to wait because of
the quality of the interface I'll get when the process is done.
I won't argue about the other processes since they aren't important to
me (and I had no idea they could hang that long). Is there any reason to
abandon ifconfig and iwconfig? Don't both always run and exit
exceedingly fast?
As an additional selling point I'll add that this would bring at least
those two to look and behave like conventional Emacs pop-up windows(*).
* I get annoyed whenever I press "q" in a pop-up buffer and instead of
the window going away, the letter "q" appears after point. I think
that pop-ups by definition should be easy to get rid of or shouldn't
be pop-ups in the first place.
--
"Cut your own wood and it will warm you twice"
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: improving network utility calls in lisp/net/net-utils.el
2009-04-10 14:09 ` Yoni Rabkin
2009-04-10 16:40 ` David De La Harpe Golden
@ 2009-04-10 19:34 ` Dan Nicolaescu
2009-04-10 22:14 ` Stefan Monnier
1 sibling, 1 reply; 21+ messages in thread
From: Dan Nicolaescu @ 2009-04-10 19:34 UTC (permalink / raw
To: Yoni Rabkin; +Cc: emacs-devel
Yoni Rabkin <yoni@rabkins.net> writes:
> +(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))
You can derive from `special-mode' here (or just use it), it sets
buffer-read-only, and it has the binding for "q".
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: improving network utility calls in lisp/net/net-utils.el
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-10 22:13 ` Stefan Monnier
1 sibling, 1 reply; 21+ messages in thread
From: David De La Harpe Golden @ 2009-04-10 20:10 UTC (permalink / raw
To: Yoni Rabkin; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1099 bytes --]
Yoni Rabkin wrote:
> As an additional selling point I'll add that this would bring at least
> those two to look and behave like conventional Emacs pop-up windows(*).
>
I'm still not seeing any real connection to sync vs. async though,
beyond it being unworkable to _naively_ leave buffer-read-only set on a
buffer that's being async filled with process output? That's not a
great reason to leap to sync, though.
Assuming that anything in net-utils.el that's just run via
net-utils-run-program rather than using a comint-derived mode like
ftp-mode is effectively a simple one-shot output-only
command where your desired treatment is appropriate, you could do
something like the attached ?
i.r. Means you get a read-only popup output dismissable with "q", even
when the command is dawdling mid-output ?
I'm not sure you wouldn't want separate major mode and font locking
for the separate kinds of even simple network utility. Of course,
the outputs of such utilities can vary platform to platform,
so going much beyond highlighting IP addresses and hostnames
might be on thin ice.
[-- Attachment #2: net-utils-romode-async-suggest.diff --]
[-- Type: text/x-patch, Size: 4018 bytes --]
Index: lisp/net/net-utils.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/net/net-utils.el,v
retrieving revision 1.37
diff -U 8 -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 20:04:52 -0000
@@ -255,16 +255,52 @@
(mapconcat 'identity
(make-list 2 host-expression)
"\\.")
"\\(\\." host-expression "\\)*"))
0 'font-lock-variable-name-face))
"Expressions to font-lock for nslookup.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Miscellaneous one-shot network util output display 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 simple one-shot network utilities.")
+
+(define-derived-mode net-utils-mode special-mode "Network Util"
+ "Major mode for viewing output of simple one-shot network utilities."
+ (set
+ (make-local-variable 'font-lock-defaults)
+ '((net-utils-font-lock-keywords)))
+ (use-local-map net-utils-mode-map))
+
+(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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Simplified versions of some at-point functions from ffap.el.
;; It's not worth loading all of ffap just for these.
(defun net-utils-machine-at-point ()
(let ((pt (point)))
(buffer-substring-no-properties
@@ -291,36 +327,39 @@
(defun net-utils-remove-ctrl-m-filter (process output-string)
"Remove trailing control Ms."
(let ((old-buffer (current-buffer))
(filtered-string output-string))
(unwind-protect
(let ((moving))
(set-buffer (process-buffer process))
- (setq moving (= (point) (process-mark process)))
+ (let ((buffer-read-only nil)) ; allow insertion
+ (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))))
+ (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))))
(defun net-utils-run-program (name header program args)
"Run a network information program."
(let ((buf (get-buffer-create (concat "*" name "*"))))
(set-buffer buf)
- (erase-buffer)
- (insert header "\n")
+ (let ((buffer-read-only nil)) ; allow clear
+ (erase-buffer)
+ (insert header "\n"))
+ (net-utils-mode)
(set-process-filter
(apply 'start-process name buf program args)
'net-utils-remove-ctrl-m-filter)
(display-buffer buf)
buf))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Wrappers for external network programs
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: improving network utility calls in lisp/net/net-utils.el
2009-04-10 20:10 ` David De La Harpe Golden
@ 2009-04-10 21:13 ` Yoni Rabkin
2009-04-11 0:42 ` Chad Brown
0 siblings, 1 reply; 21+ messages in thread
From: Yoni Rabkin @ 2009-04-10 21:13 UTC (permalink / raw
To: emacs-devel
David De La Harpe Golden <david@harpegolden.net> writes:
> Yoni Rabkin wrote:
>
>> As an additional selling point I'll add that this would bring at least
>> those two to look and behave like conventional Emacs pop-up windows(*).
>>
>
> I'm still not seeing any real connection to sync vs. async though,
> beyond it being unworkable to _naively_ leave buffer-read-only set on
> a buffer that's being async filled with process output? That's not a
> great reason to leap to sync, though.
If the only safe assumption is that no "instantaneous" processes exist
and the policy is not to make Emacs wait on processes any more than it
already does then the conclusion is that this patch can't go into
Emacs.
I don't think I'll revisit the issue using a different approach since
what I have works fine for me, which leaves me with no drive to change
it. Finally, when the ratio of the length of the discussion about the
patch on emacs-devel to the length of the patch is far greater than 1,
it is probably time to put the matter to rest.
Thank you David for patiently going over this. I certainly appreciate
it.
--
"Cut your own wood and it will warm you twice"
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: improving network utility calls in lisp/net/net-utils.el
2009-04-10 17:55 ` Yoni Rabkin
2009-04-10 20:10 ` David De La Harpe Golden
@ 2009-04-10 22:13 ` Stefan Monnier
2009-04-11 8:47 ` Yoni Rabkin
1 sibling, 1 reply; 21+ messages in thread
From: Stefan Monnier @ 2009-04-10 22:13 UTC (permalink / raw
To: Yoni Rabkin; +Cc: emacs-devel
> As a user of both Dired and Gnus I'm well accustomed to waiting for
> Emacs to synchronously go fetch something. I agree to wait because of
> the quality of the interface I'll get when the process is done.
There's no connection between the two. I only object to the change to
sync processes. The rest looks like good changes.
Stefan
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: improving network utility calls in lisp/net/net-utils.el
2009-04-10 19:34 ` Dan Nicolaescu
@ 2009-04-10 22:14 ` Stefan Monnier
0 siblings, 0 replies; 21+ messages in thread
From: Stefan Monnier @ 2009-04-10 22:14 UTC (permalink / raw
To: Dan Nicolaescu; +Cc: Yoni Rabkin, emacs-devel
>> +(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))
> You can derive from `special-mode' here (or just use it), it sets
^^^
should
> buffer-read-only, and it has the binding for "q".
Stefan
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: improving network utility calls in lisp/net/net-utils.el
2009-04-10 21:13 ` Yoni Rabkin
@ 2009-04-11 0:42 ` Chad Brown
0 siblings, 0 replies; 21+ messages in thread
From: Chad Brown @ 2009-04-11 0:42 UTC (permalink / raw
To: Yoni Rabkin; +Cc: emacs-devel
I suspect it comes down to usage patterns, but if something is wrong
(network-wise), then the following two things happen:
a) people are more likely to want to use the commands
b) the commands are more likely to hang, be slow, etc.
In particular, it's really not hard to get into a situation where dns
name resolution will fail, but won't give up for a couple minutes.
Nobody wants emacs to hang for two minutes to tell them that
something's broken, especially when they were originally asking
because something looked to be broken.
Back when I had to care about such things professionally, I took to
using a program called mtr to check on such situations. I would have
preferred to use something built into emacs, until the first time it
made emacs hang. Put another way, my former self would have been
quite happy to see your proposal as long as it didn't require
synchronized processes. I imagine that there are still quite a few
people in my former boat, so don't get discouraged. It shouldn't be
hard to made it work with an async process, and afterward you will
have learned (assuming you don't already know) something cool about
emacs.
Regardless, thanks for your efforts to improve emacs.
*chad
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: improving network utility calls in lisp/net/net-utils.el
2009-04-10 22:13 ` Stefan Monnier
@ 2009-04-11 8:47 ` Yoni Rabkin
2009-04-11 9:02 ` Eli Zaretskii
0 siblings, 1 reply; 21+ messages in thread
From: Yoni Rabkin @ 2009-04-11 8:47 UTC (permalink / raw
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 589 bytes --]
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> As a user of both Dired and Gnus I'm well accustomed to waiting for
>> Emacs to synchronously go fetch something. I agree to wait because of
>> the quality of the interface I'll get when the process is done.
>
> There's no connection between the two. I only object to the change to
> sync processes. The rest looks like good changes.
I've attached a patch that calls all of the processes asynchronously,
uses `special-mode' and modifies `net-utils-font-lock-keywords'
conservatively (according to David's multi-platform argument).
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: net-utils-improved-utility-calls-3.patch --]
[-- Type: text/x-diff, Size: 5879 bytes --]
? net-utils-improved-utility-calls-2.patch
? net-utils-improved-utility-calls-3.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 11 Apr 2009 08:33:43 -0000
@@ -260,6 +260,38 @@
"Expressions to font-lock for nslookup.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; General network utilities mode
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defconst 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)))
+ (use-local-map net-utils-mode-map))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Utility functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -288,7 +320,6 @@
(skip-chars-backward ":;.,!?" pt)
(point)))))
-
(defun net-utils-remove-ctrl-m-filter (process output-string)
"Remove trailing control Ms."
(let ((old-buffer (current-buffer))
@@ -296,17 +327,18 @@
(unwind-protect
(let ((moving))
(set-buffer (process-buffer process))
- (setq moving (= (point) (process-mark 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)))
+ (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,6 +355,42 @@
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))
+
+(defmacro net-utils-defutil (fname program-name args)
+ (let ((doc (format "Run %s and display diagnostic output."
+ fname)))
+ `(defun ,fname ()
+ ,doc
+ (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)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Wrappers for external network programs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -357,60 +425,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"
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: improving network utility calls in lisp/net/net-utils.el
2009-04-11 8:47 ` Yoni Rabkin
@ 2009-04-11 9:02 ` Eli Zaretskii
2009-04-11 9:17 ` Yoni Rabkin
0 siblings, 1 reply; 21+ messages in thread
From: Eli Zaretskii @ 2009-04-11 9:02 UTC (permalink / raw
To: Yoni Rabkin; +Cc: emacs-devel
> From: Yoni Rabkin <yoni@rabkins.net>
> Date: Sat, 11 Apr 2009 11:47:23 +0300
>
> I've attached a patch that calls all of the processes asynchronously,
> uses `special-mode' and modifies `net-utils-font-lock-keywords'
> conservatively (according to David's multi-platform argument).
Thanks, but why didn't you define the ipconfig alias as well? The
previous version did support it, and I see no reason for removing it
at this time.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: improving network utility calls in lisp/net/net-utils.el
2009-04-11 9:02 ` Eli Zaretskii
@ 2009-04-11 9:17 ` Yoni Rabkin
2009-04-11 12:39 ` Stefan Monnier
0 siblings, 1 reply; 21+ messages in thread
From: Yoni Rabkin @ 2009-04-11 9:17 UTC (permalink / raw
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 660 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Yoni Rabkin <yoni@rabkins.net>
>> Date: Sat, 11 Apr 2009 11:47:23 +0300
>>
>> I've attached a patch that calls all of the processes asynchronously,
>> uses `special-mode' and modifies `net-utils-font-lock-keywords'
>> conservatively (according to David's multi-platform argument).
>
> Thanks, but why didn't you define the ipconfig alias as well? The
> previous version did support it, and I see no reason for removing it
> at this time.
Oversite on my part. I deleted the old `net-utils-run-program' calls
without being careful. Attached is a patch with the alias definition.
Thank you for pointing it out.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: net-utils-improved-utility-calls-4.patch --]
[-- Type: text/x-diff, Size: 5954 bytes --]
? net-utils-improved-utility-calls-2.patch
? net-utils-improved-utility-calls-3.patch
? net-utils-improved-utility-calls-4.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 11 Apr 2009 09:11:35 -0000
@@ -260,6 +260,38 @@
"Expressions to font-lock for nslookup.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; General network utilities mode
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defconst 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)))
+ (use-local-map net-utils-mode-map))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Utility functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -288,7 +320,6 @@
(skip-chars-backward ":;.,!?" pt)
(point)))))
-
(defun net-utils-remove-ctrl-m-filter (process output-string)
"Remove trailing control Ms."
(let ((old-buffer (current-buffer))
@@ -296,17 +327,18 @@
(unwind-protect
(let ((moving))
(set-buffer (process-buffer process))
- (setq moving (= (point) (process-mark 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)))
+ (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,6 +355,43 @@
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))
+
+(defmacro net-utils-defutil (fname program-name args)
+ (let ((doc (format "Run %s and display diagnostic output."
+ fname)))
+ `(defun ,fname ()
+ ,doc
+ (interactive)
+ (net-utils-run-simple
+ (format "*%s*" ,program-name)
+ ,program-name
+ ,args))))
+
+(net-utils-defutil ifconfig ifconfig-program ifconfig-program-options)
+(defalias 'ipconfig 'ifconfig)
+(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)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Wrappers for external network programs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -357,60 +426,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: 56 bytes --]
--
"Cut your own wood and it will warm you twice"
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: improving network utility calls in lisp/net/net-utils.el
2009-04-11 9:17 ` Yoni Rabkin
@ 2009-04-11 12:39 ` Stefan Monnier
2009-07-16 19:52 ` Yoni Rabkin
0 siblings, 1 reply; 21+ messages in thread
From: Stefan Monnier @ 2009-04-11 12:39 UTC (permalink / raw
To: Yoni Rabkin; +Cc: emacs-devel
>>> I've attached a patch that calls all of the processes asynchronously,
>>> uses `special-mode' and modifies `net-utils-font-lock-keywords'
>>> conservatively (according to David's multi-platform argument).
>> Thanks, but why didn't you define the ipconfig alias as well? The
>> previous version did support it, and I see no reason for removing it
>> at this time.
> Oversite on my part. I deleted the old `net-utils-run-program' calls
> without being careful. Attached is a patch with the alias definition.
Looks good, thank you.
We're in feature freeze (actually in pretest) so we'll install it when
we create the branch for Emacs-23.2.
Stefan
PS: The (use-local-map net-utils-mode-map) is superfluous.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: improving network utility calls in lisp/net/net-utils.el
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
0 siblings, 2 replies; 21+ messages in thread
From: Yoni Rabkin @ 2009-07-16 19:52 UTC (permalink / raw
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 934 bytes --]
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>>>> I've attached a patch that calls all of the processes asynchronously,
>>>> uses `special-mode' and modifies `net-utils-font-lock-keywords'
>>>> conservatively (according to David's multi-platform argument).
>>> Thanks, but why didn't you define the ipconfig alias as well? The
>>> previous version did support it, and I see no reason for removing it
>>> at this time.
>> Oversite on my part. I deleted the old `net-utils-run-program' calls
>> without being careful. Attached is a patch with the alias definition.
>
> Looks good, thank you.
> We're in feature freeze (actually in pretest) so we'll install it when
> we create the branch for Emacs-23.2.
>
>
> Stefan
>
>
> PS: The (use-local-map net-utils-mode-map) is superfluous.
I understand that the emacs 23.2 branch has been created so here is the
patch once more minus the superfluous call to `use-local-map'.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: net-utils-improved-utility-calls-5.patch --]
[-- Type: text/x-diff, Size: 5645 bytes --]
Index: 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
--- net-utils.el 5 Jan 2009 03:22:45 -0000 1.37
+++ net-utils.el 16 Jul 2009 19:40:48 -0000
@@ -260,6 +260,37 @@
"Expressions to font-lock for nslookup.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; General network utilities mode
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defconst 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,7 +319,6 @@
(skip-chars-backward ":;.,!?" pt)
(point)))))
-
(defun net-utils-remove-ctrl-m-filter (process output-string)
"Remove trailing control Ms."
(let ((old-buffer (current-buffer))
@@ -296,17 +326,18 @@
(unwind-protect
(let ((moving))
(set-buffer (process-buffer process))
- (setq moving (= (point) (process-mark 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)))
+ (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,6 +354,43 @@
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))
+
+(defmacro net-utils-defutil (fname program-name args)
+ (let ((doc (format "Run %s and display diagnostic output."
+ fname)))
+ `(defun ,fname ()
+ ,doc
+ (interactive)
+ (net-utils-run-simple
+ (format "*%s*" ,program-name)
+ ,program-name
+ ,args))))
+
+(net-utils-defutil ifconfig ifconfig-program ifconfig-program-options)
+(defalias 'ipconfig 'ifconfig)
+(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)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Wrappers for external network programs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -357,60 +425,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."
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: improving network utility calls in lisp/net/net-utils.el
2009-07-16 19:52 ` Yoni Rabkin
@ 2009-07-26 8:02 ` Yoni Rabkin
2009-08-02 19:21 ` Yoni Rabkin
1 sibling, 0 replies; 21+ messages in thread
From: Yoni Rabkin @ 2009-07-26 8:02 UTC (permalink / raw
To: emacs-devel
It's been 10 days so I'm sending in another reminder. If it would be
better to send this in at another time, please say so.
--
"Cut your own wood and it will warm you twice"
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: improving network utility calls in lisp/net/net-utils.el
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
1 sibling, 1 reply; 21+ messages in thread
From: Yoni Rabkin @ 2009-08-02 19:21 UTC (permalink / raw
To: emacs-devel
Does anyone have time to install this?
--
"Cut your own wood and it will warm you twice"
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: improving network utility calls in lisp/net/net-utils.el
2009-08-02 19:21 ` Yoni Rabkin
@ 2009-08-02 22:34 ` Chong Yidong
2009-08-08 8:05 ` Yoni Rabkin
0 siblings, 1 reply; 21+ messages in thread
From: Chong Yidong @ 2009-08-02 22:34 UTC (permalink / raw
To: Yoni Rabkin; +Cc: emacs-devel
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.
With your change, the ifconfig, iwconfig, netstat, arp, and route
commands are no longer autoloaded. Could you fix this? (And
personally, I'd write out the function definitions manually instead of
using the net-utils-defutil macro, because the macro probably confuses
C-h f. It's not that much more work.)
Also, please make net-utils-font-lock-keywords a defvar, not a defconst
(make nslookup-font-lock-keywords a defvar too, while you're at it).
Once you make these changes, just send me the revised patch with a
ChangeLog entry, and I'll install it. Thanks for your patience.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: improving network utility calls in lisp/net/net-utils.el
2009-08-02 22:34 ` Chong Yidong
@ 2009-08-08 8:05 ` Yoni Rabkin
2009-08-08 18:27 ` Chong Yidong
0 siblings, 1 reply; 21+ messages in thread
From: Yoni Rabkin @ 2009-08-08 8:05 UTC (permalink / raw
To: emacs-devel
[-- 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"
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: improving network utility calls in lisp/net/net-utils.el
2009-08-08 8:05 ` Yoni Rabkin
@ 2009-08-08 18:27 ` Chong Yidong
0 siblings, 0 replies; 21+ messages in thread
From: Chong Yidong @ 2009-08-08 18:27 UTC (permalink / raw
To: Yoni Rabkin; +Cc: emacs-devel
Thanks, I've checked in your patch.
^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2009-08-08 18:27 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2009-08-08 18:27 ` Chong Yidong
2009-04-10 19:34 ` Dan Nicolaescu
2009-04-10 22:14 ` Stefan Monnier
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.