unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: David De La Harpe Golden <david@harpegolden.net>
To: Yoni Rabkin <yoni@rabkins.net>
Cc: emacs-devel@gnu.org
Subject: Re: improving network utility calls in lisp/net/net-utils.el
Date: Fri, 10 Apr 2009 21:10:13 +0100	[thread overview]
Message-ID: <49DFA7A5.4090606@harpegolden.net> (raw)
In-Reply-To: <87eiw0v1eq.fsf@rabkins.net>

[-- 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

  reply	other threads:[~2009-04-10 20:10 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 [this message]
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=49DFA7A5.4090606@harpegolden.net \
    --to=david@harpegolden.net \
    --cc=emacs-devel@gnu.org \
    --cc=yoni@rabkins.net \
    /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).