all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Thierry Volpiatto <thierry.volpiatto@gmail.com>
Cc: 13831@debbugs.gnu.org
Subject: bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
Date: Wed, 27 Feb 2013 23:51:54 -0500	[thread overview]
Message-ID: <jwvvc9dkqk0.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87k3ptbtoj.fsf@gmail.com> (Thierry Volpiatto's message of "Wed,  27 Feb 2013 17:36:12 +0100")

> 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)))
 






  reply	other threads:[~2013-02-28  4:51 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
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 [this message]
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=jwvvc9dkqk0.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=13831@debbugs.gnu.org \
    --cc=thierry.volpiatto@gmail.com \
    /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.