bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer functio


From: Thierry Volpiatto
Subject: bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
Date: Wed, 27 Feb 2013 11:50:42 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Andreas Schwab <schwab@linux-m68k.org> writes:

> Thierry Volpiatto <thierry.volpiatto@gmail.com> writes:
>
>> diff --git a/lisp/net/net-utils.el b/lisp/net/net-utils.el
>> index 28fd5c6..3a20add 100644
>> --- a/lisp/net/net-utils.el
>> +++ b/lisp/net/net-utils.el
>> @@ -1,3 +1,5 @@
>> +
>> +Process nil processus arrĂȘtĂ©
>
> error: (void-variable Process)
Yes sorry, fixed.

>> @@ -369,6 +377,31 @@ This variable is only used if the variable
>>      (goto-char (point-min)))
>>    (display-buffer buffer-name))
>>  
>> +(defun net-utils-revert-function (&optional ignore-auto noconfirm)
>> +  (message "Reverting `%s'..." (buffer-name))
>> +  (let ((inhibit-read-only t))
>> +    (erase-buffer)
>> +    (set-process-filter
>> +     (apply 'start-process (format "%s" net-utils-program-name)
>                               ^^^^^^^^^^^^
>
> That's a no-op.
Fixed.

>> +            (buffer-name) net-utils-program-name net-utils-program-args)
>> +     #'(lambda (process output-string)
>> +         (let ((filtered-string output-string))
>> +           (set-buffer (process-buffer process))
>> +           (let ((inhibit-read-only t))
>> +             (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)))))))
>> +    (set-process-sentinel
>> +     (get-process net-utils-program-name)
>
> There is no guarantee that a process with this name exists.
Where ? in the sentinel ?

The process take this name in `net-utils-run-simple':

--8<---------------cut here---------------start------------->8---
    (set (make-local-variable 'net-utils-program-name) program-name)
    (set (make-local-variable 'net-utils-program-args) args)
    (set-process-filter
     (apply 'start-process (format "%s" program-name)
--8<---------------cut here---------------end--------------->8---

I have also removed (interactive) in this same function which was wrong
IMO.

Here the corrected patch:
 
diff --git a/lisp/net/net-utils.el b/lisp/net/net-utils.el
index 28fd5c6..83b3268 100644
--- a/lisp/net/net-utils.el
+++ b/lisp/net/net-utils.el
@@ -285,7 +285,10 @@ 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)))
+  (set (make-local-variable 'revert-buffer-function)
+         'net-utils-revert-function)
+  (define-key net-utils-mode-map (kbd "g") 'revert-buffer))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Utility functions
@@ -354,14 +357,17 @@ This variable is only used if the variable
 ;; General network utilities (diagnostic)
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
+(defvar net-utils-program-name nil)
+(defvar net-utils-program-args nil)
 (defun net-utils-run-simple (buffer-name 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
     (net-utils-mode)
+    (set (make-local-variable 'net-utils-program-name) program-name)
+    (set (make-local-variable 'net-utils-program-args) args)
     (set-process-filter
      (apply 'start-process (format "%s" program-name)
            buffer-name program-name args)
@@ -369,6 +375,33 @@ This variable is only used if the variable
     (goto-char (point-min)))
   (display-buffer buffer-name))
 
+(defun net-utils-revert-function (&optional ignore-auto noconfirm)
+  (message "Reverting `%s'..." (buffer-name))
+  (let ((proc (get-process net-utils-program-name))) 
+    (when proc (set-process-filter proc t) (delete-process proc)))
+  (let ((inhibit-read-only t))
+    (erase-buffer)
+    (set-process-filter
+     (apply 'start-process net-utils-program-name
+            (buffer-name) net-utils-program-name net-utils-program-args)
+     #'(lambda (process output-string)
+         (let ((filtered-string output-string))
+           (set-buffer (process-buffer process))
+           (let ((inhibit-read-only t))
+             (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)))))))
+    (set-process-sentinel
+     (get-process net-utils-program-name)
+     #'(lambda (process event)
+         (when (string= event "finished\n")
+           (message "reverting `%s' done" (buffer-name)))))))
+
 ;;;###autoload
 (defun ifconfig ()
   "Run ifconfig and display diagnostic output."
@@ -428,9 +461,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 






reply via email to

[Prev in Thread] Current Thread [Next in Thread]