From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David De La Harpe Golden Newsgroups: gmane.emacs.devel Subject: Re: improving network utility calls in lisp/net/net-utils.el Date: Fri, 10 Apr 2009 21:10:13 +0100 Message-ID: <49DFA7A5.4090606@harpegolden.net> References: <87ljq8lk9u.fsf@rabkins.net> <87y6u8k3bo.fsf@rabkins.net> <49DF7679.20700@harpegolden.net> <87eiw0v1eq.fsf@rabkins.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------050204010709080908040508" X-Trace: ger.gmane.org 1239394246 5749 80.91.229.12 (10 Apr 2009 20:10:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 10 Apr 2009 20:10:46 +0000 (UTC) Cc: emacs-devel@gnu.org To: Yoni Rabkin Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Apr 10 22:12:04 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LsN4z-0001rO-JH for ged-emacs-devel@m.gmane.org; Fri, 10 Apr 2009 22:12:02 +0200 Original-Received: from localhost ([127.0.0.1]:47472 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LsN3b-0008OQ-5q for ged-emacs-devel@m.gmane.org; Fri, 10 Apr 2009 16:10:35 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LsN3X-0008OE-6I for emacs-devel@gnu.org; Fri, 10 Apr 2009 16:10:31 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LsN3S-0008Lh-2v for emacs-devel@gnu.org; Fri, 10 Apr 2009 16:10:30 -0400 Original-Received: from [199.232.76.173] (port=35193 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LsN3S-0008Le-0O for emacs-devel@gnu.org; Fri, 10 Apr 2009 16:10:26 -0400 Original-Received: from harpegolden.net ([65.99.215.13]:45159) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LsN3R-0003jc-FY for emacs-devel@gnu.org; Fri, 10 Apr 2009 16:10:25 -0400 Original-Received: from [87.198.47.25] (87-198-47-25.ptr.magnet.ie [87.198.47.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "David De La Harpe Golden", Issuer "David De La Harpe Golden Personal CA rev 3" (verified OK)) by harpegolden.net (Postfix) with ESMTP id EC2E781E2; Fri, 10 Apr 2009 21:10:21 +0100 (IST) User-Agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103) In-Reply-To: <87eiw0v1eq.fsf@rabkins.net> X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:110192 Archived-At: This is a multi-part message in MIME format. --------------050204010709080908040508 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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. --------------050204010709080908040508 Content-Type: text/x-patch; name="net-utils-romode-async-suggest.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="net-utils-romode-async-suggest.diff" 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 --------------050204010709080908040508--