all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
To: 13831@debbugs.gnu.org
Subject: bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
Date: Wed, 27 Feb 2013 11:50:42 +0100	[thread overview]
Message-ID: <87d2vmm3nh.fsf@gmail.com> (raw)
In-Reply-To: <87liaam7dh.fsf@gmail.com>

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	other threads:[~2013-02-27 10:50 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-27  9:30 bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function Thierry Volpiatto
2013-02-27  9:48 ` Thierry Volpiatto
2013-02-27 10:11   ` Andreas Schwab
2013-02-27 10:50     ` Thierry Volpiatto [this message]
2013-02-27 11:57       ` Andreas Schwab
2013-02-27 12:03         ` Thierry Volpiatto
2013-02-27 14:08       ` Stefan Monnier
2013-02-27 14:35         ` Thierry Volpiatto
2013-02-27 15:25           ` Stefan Monnier
2013-02-27 16:36             ` Thierry Volpiatto
2013-02-28  4:51               ` Stefan Monnier
2013-02-28  6:18                 ` Thierry Volpiatto
2013-02-28 14:04                   ` Stefan Monnier
2013-02-28 19:45                     ` Thierry Volpiatto
2013-03-01  3:05                       ` Stefan Monnier
2013-03-01  7:02                         ` Thierry Volpiatto
2013-03-01 14:29                           ` Stefan Monnier
2013-03-01 15:22                             ` Thierry Volpiatto
2013-03-01 17:28                               ` Stefan Monnier
2013-03-01 19:07                             ` Thierry Volpiatto
2013-03-11 18:31                               ` Stefan Monnier
2013-03-13 14:43                                 ` Thierry Volpiatto
2013-03-13 17:52                                   ` Stefan Monnier
2013-03-13 20:12                                     ` Thierry Volpiatto
2013-03-03  6:16                             ` Thierry Volpiatto
2013-03-01 14:30                           ` Thierry Volpiatto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d2vmm3nh.fsf@gmail.com \
    --to=thierry.volpiatto@gmail.com \
    --cc=13831@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.