From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thierry Volpiatto Newsgroups: gmane.emacs.bugs Subject: bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function Date: Fri, 01 Mar 2013 15:30:16 +0100 Organization: Emacs Helm Message-ID: <87y5e7w5tz.fsf@gmail.com> References: <87liaam7dh.fsf@gmail.com> <87hakym6il.fsf@gmail.com> <87d2vmm3nh.fsf@gmail.com> <871uc1ese2.fsf@gmail.com> <87k3ptbtoj.fsf@gmail.com> <877gltm05y.fsf@gmail.com> <87vc9cgr2i.fsf@gmail.com> <87zjyny54l.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1362148334 27542 80.91.229.3 (1 Mar 2013 14:32:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 1 Mar 2013 14:32:14 +0000 (UTC) To: 13831@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Mar 01 15:32:34 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 1UBR0g-0008Gz-Ai for geb-bug-gnu-emacs@m.gmane.org; Fri, 01 Mar 2013 15:32:30 +0100 Original-Received: from localhost ([::1]:58424 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBR0L-0001p6-7f for geb-bug-gnu-emacs@m.gmane.org; Fri, 01 Mar 2013 09:32:09 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:54485) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBR0H-0001oY-VE for bug-gnu-emacs@gnu.org; Fri, 01 Mar 2013 09:32:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UBR0C-0008Sk-TU for bug-gnu-emacs@gnu.org; Fri, 01 Mar 2013 09:32:05 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:52252) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBR0C-0008Sg-Pa for bug-gnu-emacs@gnu.org; Fri, 01 Mar 2013 09:32:00 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UBR2A-0001d0-Dx for bug-gnu-emacs@gnu.org; Fri, 01 Mar 2013 09:34:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <87liaam7dh.fsf@gmail.com> Resent-From: Thierry Volpiatto Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 01 Mar 2013 14:34:02 +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 X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.13621483836176 (code B ref -1); Fri, 01 Mar 2013 14:34:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 1 Mar 2013 14:33:03 +0000 Original-Received: from localhost ([127.0.0.1]:57716 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UBR1A-0001bP-1E for submit@debbugs.gnu.org; Fri, 01 Mar 2013 09:33:02 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:42771) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UBR15-0001bF-Ui for submit@debbugs.gnu.org; Fri, 01 Mar 2013 09:32:58 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UBQz2-0007x3-HR for submit@debbugs.gnu.org; Fri, 01 Mar 2013 09:30:53 -0500 Original-Received: from lists.gnu.org ([208.118.235.17]:39755) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBQz2-0007ww-Ck for submit@debbugs.gnu.org; Fri, 01 Mar 2013 09:30:48 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:54050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBQyv-0001h8-O9 for bug-gnu-emacs@gnu.org; Fri, 01 Mar 2013 09:30:48 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UBQyt-0007v3-QR for bug-gnu-emacs@gnu.org; Fri, 01 Mar 2013 09:30:41 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:60863) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBQyt-0007uv-G0 for bug-gnu-emacs@gnu.org; Fri, 01 Mar 2013 09:30:39 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UBQz3-0006ia-Hl for bug-gnu-emacs@gnu.org; Fri, 01 Mar 2013 15:30:49 +0100 Original-Received: from lbe83-2-78-243-104-167.fbx.proxad.net ([78.243.104.167]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 01 Mar 2013 15:30:49 +0100 Original-Received: from thierry.volpiatto by lbe83-2-78-243-104-167.fbx.proxad.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 01 Mar 2013 15:30:49 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 148 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: lbe83-2-78-243-104-167.fbx.proxad.net User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) Cancel-Lock: sha1:mvwMUEQee2hOeZGUrxhn82V2qr0= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x 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:71982 Archived-At: Hi Stefan, Thierry Volpiatto writes: > Hi Stefan, > > Stefan Monnier writes: > >>> Indeed yes, tried this very early this morning. >>> Just tried now and it is working, >> >> Thanks. >> >>> but point move at eof, it should stay on top of buffer. >> >> I think the difference between the initial run and the revert is that >> for the initial run, the traceroute buffer is not in the >> selected-window, whereas in the revert case, it is the selected-window. >> >> Apparently the behavior is partly on purpose, since >> net-utils-remove-ctrl-m-filter (which, BTW, should use >> with-current-buffer rather than unwind-protect) explicitly moves point. > > Here your patch modified, I have simplified > `net-utils-remove-ctrl-m-filter'. We forget to handle the case where the buffer is reverted from somewhere else e.g ibuffer, helm etc..., this next patch handle this: (Don't display buffer) diff --git a/lisp/net/net-utils.el b/lisp/net/net-utils.el index 28fd5c6..3498f23 100644 --- a/lisp/net/net-utils.el +++ b/lisp/net/net-utils.el @@ -285,7 +285,8 @@ This variable is only used if the variable (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 @@ -318,25 +319,18 @@ This variable is only used if the variable (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)) - (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)))) + (save-selected-window + (set-buffer (process-buffer process)) + (save-excursion + (let ((inhibit-read-only t) + (filtered-string output-string)) + (while (string-match "\r" filtered-string) + (setq filtered-string + (replace-match "" nil nil filtered-string))) + ;; Insert the text, moving the process-marker. + (goto-char (process-mark process)) + (insert filtered-string) + (set-marker (process-mark process) (point)))))) (defun net-utils-run-program (name header program args) "Run a network information program." @@ -354,20 +348,39 @@ This variable is only used if the variable ;; 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 &optional nodisplay) "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 'nodisplay)) (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)) + (unless nodisplay (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 +441,8 @@ This variable is only used if the variable (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))) -- Thierry Get my Gnupg key: gpg --keyserver pgp.mit.edu --recv-keys 59F29997