GNU bug report logs - #13831
24.3.50; [PATCH] net-utils-mode have no revert-buffer function

Previous Next

Package: emacs;

Reported by: Thierry Volpiatto <thierry.volpiatto <at> gmail.com>

Date: Wed, 27 Feb 2013 09:33:02 UTC

Severity: wishlist

Tags: patch

Found in version 24.3.50

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Thierry Volpiatto <thierry.volpiatto <at> gmail.com>
To: 13831 <at> debbugs.gnu.org
Subject: bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
Date: Fri, 01 Mar 2013 15:30:16 +0100
Hi Stefan,

Thierry Volpiatto <thierry.volpiatto <at> gmail.com> writes:

> Hi Stefan,
>
> Stefan Monnier <monnier <at> iro.umontreal.ca> 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 





This bug report was last modified 12 years and 68 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.