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

From: Thierry Volpiatto <[email-masked]>
Date: Wed, 13 Mar 2013 21:12:54 +0100

Stefan Monnier <[email-masked]> writes:

>> I think actually it is not a problem loading ffap when needed:
>> --8<---------------cut here---------------start------------->8---
>>   (defun net-utils-machine-at-point ()
>>     (require 'ffap)
>>     (ffap-machine-at-point))
>>   (defun net-utils-url-at-point ()
>>     (require 'ffap)
>>     (ffap-url-at-point))
>> --8<---------------cut here---------------end--------------->8---
>> This reduce code and do the right thing.
>
> We can even (require 'ffap) at top-level.  It's not that big of a deal.

Ok.

>> I can send a patch if ok.
>
> Please do,

I didn't use `ffap-machine-at-point' because it is hanging forever when
called on e.g www.google.fr.  Don't know if it is a bug or the expected
behavior (I doubt of this according to its docstring).

--8<---------------cut here---------------start------------->8---
(net-utils-machine-at-point, net-utils-url-at-point): Use `ffap-string-at-point'.
(ping): Use localhost as default input if no machine at point.
Use `net-utils-run-simple'.
(run-dig): Use `net-utils-run-simple'.
--8<---------------cut here---------------end--------------->8---

diff --git a/lisp/net/net-utils.el b/lisp/net/net-utils.el
index 9a6c7b1..6155f5b 100644
--- a/lisp/net/net-utils.el
+++ b/lisp/net/net-utils.el
@@ -44,6 +44,8 @@
 
 ;;; Code:
 
+(require 'ffap)
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Customization Variables
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -287,30 +289,15 @@ This variable is only used if the variable
 ;; Utility functions
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-;; Simplified versions of some at-point functions from ffap.el.
-;; It's not worth loading all of ffap just for these.
 (defun net-utils-machine-at-point ()
-  (let ((pt (point)))
-    (buffer-substring-no-properties
-     (save-excursion
-       (skip-chars-backward "-a-zA-Z0-9.")
-       (point))
-     (save-excursion
-       (skip-chars-forward "-a-zA-Z0-9.")
-       (skip-chars-backward "." pt)
-       (point)))))
+  "Return a string of characters from around point.
+Same as `ffap-string-at-point' called with 'machine as arg."
+  (ffap-string-at-point 'machine))
 
 (defun net-utils-url-at-point ()
-  (let ((pt (point)))
-    (buffer-substring-no-properties
-     (save-excursion
-       (skip-chars-backward "--:=&?$+@-Z_a-z~#,%")
-       (skip-chars-forward "^A-Za-z0-9" pt)
-       (point))
-     (save-excursion
-       (skip-chars-forward "--:=&?$+@-Z_a-z~#,%")
-       (skip-chars-backward ":;.,!?" pt)
-       (point)))))
+    "Return a string of characters from around point.
+Same as `ffap-string-at-point' called with 'url as arg."
+  (ffap-string-at-point 'url))
 
 (defun net-utils-remove-ctrl-m-filter (process output-string)
   "Remove trailing control Ms."
@@ -445,14 +432,14 @@ This variable is only used if the variable
 If your system's ping continues until interrupted, you can try setting
 `ping-program-options'."
   (interactive
-   (list (read-from-minibuffer "Ping host: " (net-utils-machine-at-point))))
+   (list (read-from-minibuffer "Ping host: " (or (net-utils-machine-at-point)
+                                                 "localhost"))))
   (let ((options
-	 (if ping-program-options
-	     (append ping-program-options (list host))
-	   (list host))))
-    (net-utils-run-program
+         (if ping-program-options
+             (append ping-program-options (list host))
+           (list host))))
+    (net-utils-run-simple
      (concat "Ping" " " host)
-     (concat "** Ping ** " ping-program " ** " host)
      ping-program
      options)))
 
@@ -535,13 +522,12 @@ If your system's ping continues until interrupted, you can try setting
   (interactive
    (list
     (read-from-minibuffer "Lookup host: "
-                          (or (ffap-string-at-point 'machine) ""))))
-  (net-utils-run-program
-   "Dig"
+                          (net-utils-machine-at-point))))
+  (net-utils-run-simple
    (concat "** "
-	   (mapconcat 'identity
-		      (list "Dig" host dig-program)
-		      " ** "))
+           (mapconcat 'identity
+                      (list "Dig" host dig-program)
+                      " ** "))
    dig-program
    (list host)))

-- 
Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997