From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function Date: Wed, 27 Feb 2013 23:51:54 -0500 Message-ID: References: <87liaam7dh.fsf@gmail.com> <87hakym6il.fsf@gmail.com> <87d2vmm3nh.fsf@gmail.com> <871uc1ese2.fsf@gmail.com> <87k3ptbtoj.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1362027132 29917 80.91.229.3 (28 Feb 2013 04:52:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 28 Feb 2013 04:52:12 +0000 (UTC) Cc: 13831@debbugs.gnu.org To: Thierry Volpiatto Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Feb 28 05:52:36 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UAvTu-0002hu-Qb for geb-bug-gnu-emacs@m.gmane.org; Thu, 28 Feb 2013 05:52:35 +0100 Original-Received: from localhost ([::1]:42049 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAvTZ-0003KX-Rf for geb-bug-gnu-emacs@m.gmane.org; Wed, 27 Feb 2013 23:52:13 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:36920) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAvTW-0003KJ-OU for bug-gnu-emacs@gnu.org; Wed, 27 Feb 2013 23:52:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UAvTU-0001Na-N2 for bug-gnu-emacs@gnu.org; Wed, 27 Feb 2013 23:52:10 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:49278) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAvTU-0001NM-JH for bug-gnu-emacs@gnu.org; Wed, 27 Feb 2013 23:52:08 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UAvVK-0001Ki-4L for bug-gnu-emacs@gnu.org; Wed, 27 Feb 2013 23:54:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 28 Feb 2013 04:54:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13831 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 13831-submit@debbugs.gnu.org id=B13831.13620272355105 (code B ref 13831); Thu, 28 Feb 2013 04:54:01 +0000 Original-Received: (at 13831) by debbugs.gnu.org; 28 Feb 2013 04:53:55 +0000 Original-Received: from localhost ([127.0.0.1]:54742 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UAvVC-0001KI-P0 for submit@debbugs.gnu.org; Wed, 27 Feb 2013 23:53:55 -0500 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.182]:33215) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UAvVA-0001KB-OU for 13831@debbugs.gnu.org; Wed, 27 Feb 2013 23:53:53 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av8EABK/CFFFpaTU/2dsb2JhbABEuzWDWRdzgh4BAQQBViMFCws0EhQYDSSIHgbBLZEKA4hhnBmBXoMV X-IPAS-Result: Av8EABK/CFFFpaTU/2dsb2JhbABEuzWDWRdzgh4BAQQBViMFCws0EhQYDSSIHgbBLZEKA4hhnBmBXoMV X-IronPort-AV: E=Sophos;i="4.84,565,1355115600"; d="scan'208";a="2661339" Original-Received: from 69-165-164-212.dsl.teksavvy.com (HELO pastel.home) ([69.165.164.212]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 27 Feb 2013 23:51:56 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id ED15D6C2AE; Wed, 27 Feb 2013 23:51:54 -0500 (EST) In-Reply-To: <87k3ptbtoj.fsf@gmail.com> (Thierry Volpiatto's message of "Wed, 27 Feb 2013 17:36:12 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:71936 Archived-At: > Yes please, I only have a git repo of Emacs now. > Here the patch modified again, tested with netstat. > Let me know if you find something wrong. Setting the process-filter to t seems odd, so I changed it to nil. Also I renamed the new functions and vars to use a "net-utils--" prefix. And I got rid of net-utils-mode-process. Finally, I removed the `g' binding, since it's already provided by `special-mode-map'. Oh, and now I see that the revert function uses a different code (e.g. different process filter) than the original code. That's weird. Why not call net-utils-run-simple from the revert function? Oh, right because net-utils-run-simple kills its buffer first. OK, can you test the patch below which changes net-utils-run-simple such that it doesn't kill the buffer, thus making the revert function much simpler? > Many functions are actually using `net-utils-run-program' and will not > have `revert-buffer' enabled, I corrected only `trace-route', but others > could be modified, that can be done later, it will be easy. Feel free do those conversions (tho I see that there's a difference in that using net-utils-run-simple means that no header gets inserted; this difference between net-utils-run-simple and net-utils-run-simple should probably be eliminated by always inserting a standard header built from program-name and args). Stefan === modified file 'lisp/net/net-utils.el' --- lisp/net/net-utils.el 2013-01-01 09:11:05 +0000 +++ lisp/net/net-utils.el 2013-02-28 04:45:02 +0000 @@ -285,7 +285,8 @@ (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)))) + '((net-utils-font-lock-keywords))) + (setq-local revert-buffer-function #'net-utils--revert-function)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Utility functions @@ -354,20 +355,38 @@ ;; General network utilities (diagnostic) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defun net-utils-run-simple (buffer-name program-name args) +;; Todo: This data could be saved in a bookmark. +(defvar net-utils--revert-cmd nil) + +(defun net-utils-run-simple (buffer 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 + (with-current-buffer (if (stringp buffer) (get-buffer-create buffer) buffer) + (let ((proc (get-buffer-process (current-buffer)))) + (when proc + (set-process-filter proc nil) + (delete-process proc))) + (let ((inhibit-read-only t)) + (erase-buffer)) (net-utils-mode) + (setq-local net-utils--revert-cmd + `(net-utils-run-simple ,(current-buffer) ,program-name ,args)) (set-process-filter - (apply 'start-process (format "%s" program-name) - buffer-name program-name args) + (apply 'start-process program-name + (current-buffer) program-name args) 'net-utils-remove-ctrl-m-filter) - (goto-char (point-min))) - (display-buffer buffer-name)) + (goto-char (point-min)) + (display-buffer (current-buffer)))) + +(defun net-utils--revert-function (&optional ignore-auto noconfirm) + (message "Reverting `%s'..." (buffer-name)) + (apply (car net-utils--revert-cmd) (cdr net-utils--revert-cmd)) + (let ((proc (get-buffer-process (current-buffer)))) + (when proc + (set-process-sentinel + proc + (lambda (process event) + (when (string= event "finished\n") + (message "Reverting `%s' done" (process-buffer process)))))))) ;;;###autoload (defun ifconfig () @@ -428,9 +447,8 @@ (if traceroute-program-options (append traceroute-program-options (list target)) (list target)))) - (net-utils-run-program + (net-utils-run-simple (concat "Traceroute" " " target) - (concat "** Traceroute ** " traceroute-program " ** " target) traceroute-program options)))