all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
@ 2013-02-27  9:30 Thierry Volpiatto
  2013-02-27  9:48 ` Thierry Volpiatto
  0 siblings, 1 reply; 26+ messages in thread
From: Thierry Volpiatto @ 2013-02-27  9:30 UTC (permalink / raw)
  To: 13831


Hello,
net-utils-mode have no revert-buffer function.
This patch allow using "g" in e.g "*netstat*" buffer.



In GNU Emacs 24.3.50.1 (x86_64-unknown-linux-gnu, X toolkit)
 of 2013-02-26 on dell-14z
Windowing system distributor `The X.Org Foundation', version 11.0.11103000
System Description:	Ubuntu 12.04.2 LTS

Configured using:
 `configure --with-x-toolkit=lucid --without-toolkit-scroll-bars'

Important settings:
  value of $LANG: fr_FR.UTF-8
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t

Major mode: Emacs-Lisp

Minor modes in effect:
  recentf-mode: t
  TeX-PDF-mode: t
  winner-mode: t
  global-undo-tree-mode: t
  undo-tree-mode: t
  auto-image-file-mode: t
  show-paren-mode: t
  display-time-mode: t
  savehist-mode: t
  minibuffer-depth-indicate-mode: t
  eldoc-mode: t
  diff-auto-refine-mode: t
  helm-mode: t
  shell-dirtrack-mode: t
  helm-adaptative-mode: t
  helm-match-plugin-mode: t
  tooltip-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <up> <up> <up> <up> <up> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<down> <down> <down> <down> <down> <down> <down> <down> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up> 
<up> <up> <up> C-SPC C-n C-n C-n C-n C-n C-n C-n C-n 
C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n 
C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n 
C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n 
C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n 
C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n 
C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n C-n 
C-n C-n M-w q M-x <down> <down> <down> <down> <down> 
<return> C-< g q M-x r e p o <return>

Recent messages:
Wrote /home/thierry/labo/emacs-savanah-git/lisp/net/net-utils.el
Type a prefix key to toggle it. Run 'actions' with their prefixes. '?' for more help.
Finding changes in /home/thierry/labo/emacs-savanah-git/lisp/net/net-utils.el...done
End of buffer [3 times]
Beginning of buffer [7 times]
Mark set
End of buffer [4 times]
Saved text from "diff --git a/lisp/net/net-utils.el b/lis"
Reverting `*netstat*'...
reverting `*netstat*' done

Load-path shadows:
~/elisp/auctex/lpath hides ~/elisp/emacs-wget/lpath
/usr/local/share/emacs/24.3.50/lisp/emacs-lisp/tq hides ~/elisp/emms/lisp/tq

Features:
(shadow gnus-dired nnir mail-extr gnus-msg gnus-art mm-uu mml2015
mm-view mml-smime smime dig gnus-sum nnoo gnus-group gnus-undo nnmail
mail-source gnus-start gnus-spec gnus-int gnus-range gnus-win emacsbug
view woman man helm-man helm-apt vc vc-dispatcher help-mode helm-misc
helm-ring net-utils helm-command recentf ido conf-mode allout tex-info
tex dbus vc-rcs sh-script smie executable jka-compr vc-git
naquadah-theme em-smart em-unix em-script em-prompt em-ls em-hist
em-pred em-glob em-dirs em-cmpl em-basic em-banner em-alias esh-var
esh-io esh-cmd esh-opt esh-ext esh-proc esh-arg esh-groups eshell
esh-module esh-mode esh-util align-let server winner undo-tree diff
slime-xref-browser slime-banner slime-tramp slime-asdf slime-fancy
slime-fontifying-fu slime-package-fu slime-references slime-scratch
slime-presentations slime-fuzzy slime-fancy-inspector slime-c-p-c
slime-editing-commands slime-autodoc slime-parse slime-repl image-file
newsticker newst-treeview tree-widget newst-plainview newst-reader
newst-ticker newst-backend xdvi-search preview-latex pcomplete-extension
em-term term disp-table ehelp electric helm-ipython helm-elisp helm-eval
python rx whitespace paren time avoid savehist smtpmail-async smtpmail
sendmail helm-async boxquote markdown-mode org-google-weather
google-weather url-cache iterator googlecl google-maps
google-maps-static google-maps-geocode google-maps-base json
simple-call-tree el-expectations el-mock iedit-rect rect iedit iedit-lib
zop-to-char smallurl mm-url gnus gnus-ems nnheader rectangle-utils
tv-utils async pcvs pcvs-parse pcvs-info pcvs-defs ewoc mb-depth ioccur
cl-info slime hyperspec slime-autoloads tex-site auto-loads esh-toggle
flymake eldoc-eval eldoc no-word dired-extension emms-mpd-config
emms-playlist-limit emms-volume emms-volume-amixer emms-i18n
emms-history emms-score emms-stream-info emms-metaplaylist-mode
emms-bookmarks emms-cue emms-mode-line-icon emms-browser sort
emms-playlist-sort emms-last-played emms-player-xine emms-player-mpd tq
emms-playing-time emms-lyrics emms-url hl-line emms-tag-editor emms-mark
emms-mode-line emms-cache emms-info-ogginfo emms-info-mp3info
emms-playlist-mode emms-player-vlc emms-player-mplayer emms-info
emms-streams later-do emms-source-playlist emms-source-file
emms-player-simple emms-setup emms emms-compat magit-stgit magit-bisect
magit-key-mode magit diff-mode log-edit pcvs-util add-log htmlize-hack
htmlize muse-colors muse-docbook muse-texinfo texnfo-upd texinfo
muse-latex muse-html muse-xml-common muse-wiki cus-edit cus-start
cus-load muse-publish muse-project muse-protocols muse-regexps wid-edit
muse muse-nested-tags muse-mode muse-autoloads org-config-thierry ob-sh
org-crypt cal-china lunar solar cal-dst cal-bahai cal-islam cal-hebrew
holidays hol-loaddefs vc-hg org-wl org-w3m org-vm org-rmail org-mhe
org-mew org-irc org-jsinfo org-infojs org-html org-exp ob-exp
org-exp-blocks org-info org-gnus org-docview org-bibtex bibtex org-bbdb
org-agenda appt diary-lib diary-loaddefs org-annotation-helper
org-capture org-mks remember org-remember org-datetree
addressbook-bookmark message rfc822 mml mml-sec mm-decode mm-bodies
mm-encode mail-parse rfc2231 rfc2047 rfc2045 ietf-drums mailabbrev
mail-utils gmm-utils mailheader firefox-protocol
bookmark-firefox-handler bookmark-extensions org ob-tangle ob-ref ob-lob
ob-table org-footnote org-src ob-comint ob-keys org-pcomplete org-list
org-faces org-entities noutline outline easy-mmode org-version
ob-emacs-lisp ob org-compat org-macs ob-eval org-loaddefs find-func
cal-menu calendar cal-loaddefs bookmark pp init-helm-thierry helm-mode
helm-imenu imenu helm-ls-git helm-descbinds helm-ls-hg helm-files
image-dired tramp tramp-compat tramp-loaddefs trampver shell pcomplete
format-spec dired-x dired-aux ffap thingatpt helm-buffers helm-elscreen
helm-tags helm-bookmark helm-adaptative helm-info helm-net browse-url
xml url url-proxy url-privacy url-expand url-methods url-history
url-cookie url-domsuf url-util url-parse url-vars mailcap helm-plugin
helm-help helm-match-plugin helm-grep wgrep-helm wgrep helm-regexp grep
helm-external helm-utils warnings dired compile comint ansi-color ring
helm-locate helm advice help-fns helm-config helm-aliases epa-file epa
derived epg epg-config auth-source eieio byte-opt bytecomp byte-compile
cconv gnus-util time-date mm-util mail-prsvr password-cache usage-memo
info easymenu cl-macs gv edmacro kmacro cl nadvice cl-lib tooltip
ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd tool-bar dnd
fontset image regexp-opt fringe tabulated-list newcomment lisp-mode
register page menu-bar rfn-eshadow timer select scroll-bar mouse
jit-lock font-lock syntax facemenu font-core frame cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev
minibuffer loaddefs button faces cus-face macroexp files text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote make-network-process dbusbind inotify
dynamic-setting system-font-setting font-render-setting x-toolkit x
multi-tty emacs)

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





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  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
  0 siblings, 1 reply; 26+ messages in thread
From: Thierry Volpiatto @ 2013-02-27  9:48 UTC (permalink / raw)
  To: 13831

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

> Hello,
> net-utils-mode have no revert-buffer function.
> This patch allow using "g" in e.g "*netstat*" buffer.

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é
 ;;; net-utils.el --- network functions
 
 ;; Copyright (C) 1998-2013 Free Software Foundation, Inc.
@@ -285,7 +287,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 +359,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 +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)
+            (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 






^ permalink raw reply related	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-02-27  9:48 ` Thierry Volpiatto
@ 2013-02-27 10:11   ` Andreas Schwab
  2013-02-27 10:50     ` Thierry Volpiatto
  0 siblings, 1 reply; 26+ messages in thread
From: Andreas Schwab @ 2013-02-27 10:11 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: 13831

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)

> @@ -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.

> +            (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.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-02-27 10:11   ` Andreas Schwab
@ 2013-02-27 10:50     ` Thierry Volpiatto
  2013-02-27 11:57       ` Andreas Schwab
  2013-02-27 14:08       ` Stefan Monnier
  0 siblings, 2 replies; 26+ messages in thread
From: Thierry Volpiatto @ 2013-02-27 10:50 UTC (permalink / raw)
  To: 13831

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 






^ permalink raw reply related	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  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
  1 sibling, 1 reply; 26+ messages in thread
From: Andreas Schwab @ 2013-02-27 11:57 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: 13831

RTFM.

NAME is name for process.  It is modified if necessary to make it unique.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-02-27 11:57       ` Andreas Schwab
@ 2013-02-27 12:03         ` Thierry Volpiatto
  0 siblings, 0 replies; 26+ messages in thread
From: Thierry Volpiatto @ 2013-02-27 12:03 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: 13831

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

> RTFM.
Ok, best is you implement this feature request yourself.
I will not follow up on this.

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





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-02-27 10:50     ` Thierry Volpiatto
  2013-02-27 11:57       ` Andreas Schwab
@ 2013-02-27 14:08       ` Stefan Monnier
  2013-02-27 14:35         ` Thierry Volpiatto
  1 sibling, 1 reply; 26+ messages in thread
From: Stefan Monnier @ 2013-02-27 14:08 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: 13831

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

Using process names (like buffer names, BTW) is often unreliable.
Better use the process object itself.  I.e. rather than (set
(make-local-variable 'net-utils-program-name) program-name) and then
later call start-process (which may choose a different name than
program-name if there's already a process by that name), better just do
(set (make-local-variable 'net-utils-proc) (start-process ...))  so you
can then use net-utils-proc, being absolutely sure this is the process
you started.


        Stefan





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-02-27 14:08       ` Stefan Monnier
@ 2013-02-27 14:35         ` Thierry Volpiatto
  2013-02-27 15:25           ` Stefan Monnier
  0 siblings, 1 reply; 26+ messages in thread
From: Thierry Volpiatto @ 2013-02-27 14:35 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 13831

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>>> 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---
>
> Using process names (like buffer names, BTW) is often unreliable.
> Better use the process object itself.  I.e. rather than (set
> (make-local-variable 'net-utils-program-name) program-name) and then
> later call start-process (which may choose a different name than
> program-name if there's already a process by that name), better just do
> (set (make-local-variable 'net-utils-proc) (start-process ...))  so you
> can then use net-utils-proc, being absolutely sure this is the process
> you started.

Thanks Stefan, it is what I understood and it was fixed.

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





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-02-27 14:35         ` Thierry Volpiatto
@ 2013-02-27 15:25           ` Stefan Monnier
  2013-02-27 16:36             ` Thierry Volpiatto
  0 siblings, 1 reply; 26+ messages in thread
From: Stefan Monnier @ 2013-02-27 15:25 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: 13831

> Thanks Stefan, it is what I understood and it was fixed.

Good.  Do you still need help installing it (if so, please resend the
patch because I haven't seen the updated version)?


        Stefan





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-02-27 15:25           ` Stefan Monnier
@ 2013-02-27 16:36             ` Thierry Volpiatto
  2013-02-28  4:51               ` Stefan Monnier
  0 siblings, 1 reply; 26+ messages in thread
From: Thierry Volpiatto @ 2013-02-27 16:36 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 13831

Stefan Monnier <monnier@IRO.UMontreal.CA> writes:

>> Thanks Stefan, it is what I understood and it was fixed.
>
> Good.  Do you still need help installing it (if so, please resend the
> patch because I haven't seen the updated version)?
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.

You will find a (format "%s" program-name), it was here I don't know
why, I leave it, but it can probably be removed.

Also `net-utils-run-simple' was interactive with no arguments provided
interactively, which was wrong, I removed it.

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.


Thanks.


diff --git a/lisp/net/net-utils.el b/lisp/net/net-utils.el
index 28fd5c6..db5637b 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,21 +357,56 @@ This variable is only used if the variable
 ;; General network utilities (diagnostic)
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
+(defvar net-utils-program-name nil)
+(defvar net-utils-program-args nil)
+(defvar net-utils-mode-process 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-process-filter
-     (apply 'start-process (format "%s" program-name)
-	    buffer-name program-name args)
-     'net-utils-remove-ctrl-m-filter)
+    (set (make-local-variable 'net-utils-program-name) program-name)
+    (set (make-local-variable 'net-utils-program-args) args)
+    (set (make-local-variable 'net-utils-mode-process)
+         (apply 'start-process (format "%s" program-name)
+                buffer-name program-name args))
+    (set-process-filter net-utils-mode-process
+                        'net-utils-remove-ctrl-m-filter)
     (goto-char (point-min)))
   (display-buffer buffer-name))
 
+(defun net-utils-revert-function (&optional ignore-auto noconfirm)
+  (message "Reverting `%s'..." (buffer-name))
+  (when net-utils-mode-process
+    (set-process-filter net-utils-mode-process t)
+    (delete-process net-utils-mode-process))
+  (let ((inhibit-read-only t))
+    (erase-buffer)
+    (setq net-utils-mode-process (apply 'start-process net-utils-program-name
+                                        (buffer-name) net-utils-program-name
+                                        net-utils-program-args))
+    (set-process-filter
+     net-utils-mode-process
+     #'(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
+     net-utils-mode-process
+     #'(lambda (process event)
+         (when (string= event "finished\n")
+           (message "Reverting `%s' done" (process-buffer process))))))))
+
 ;;;###autoload
 (defun ifconfig ()
   "Run ifconfig and display diagnostic output."
@@ -428,9 +466,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 





^ permalink raw reply related	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-02-27 16:36             ` Thierry Volpiatto
@ 2013-02-28  4:51               ` Stefan Monnier
  2013-02-28  6:18                 ` Thierry Volpiatto
  0 siblings, 1 reply; 26+ messages in thread
From: Stefan Monnier @ 2013-02-28  4:51 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: 13831

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






^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-02-28  4:51               ` Stefan Monnier
@ 2013-02-28  6:18                 ` Thierry Volpiatto
  2013-02-28 14:04                   ` Stefan Monnier
  0 siblings, 1 reply; 26+ messages in thread
From: Thierry Volpiatto @ 2013-02-28  6:18 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 13831

Hi Stefan,

Stefan Monnier <monnier@iro.umontreal.ca> writes:

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

It doesn't work:

--8<---------------cut here---------------start------------->8---
Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  start-process(nil "*netstat*" nil)
  apply(start-process nil "*netstat*" nil nil)
  (setq net-utils-mode-process (apply (quote start-process) net-utils-program-name (buffer-name) net-utils-program-name net-utils-program-args))
  (let ((inhibit-read-only t)) (erase-buffer) (setq net-utils-mode-process (apply (quote start-process) net-utils-program-name (buffer-name) net-utils-program-name net-utils-program-args)) (set-process-filter net-utils-mode-process (function (lambda (process output-string) (let ((filtered-string output-string)) (set-buffer (process-buffer process)) (let ((inhibit-read-only t)) (while (string-match "" filtered-string) (setq filtered-string ...)) (save-excursion (goto-char ...) (insert filtered-string) (set-marker ... ...))))))) (set-process-sentinel net-utils-mode-process (function (lambda (process event) (if (string= event "finished\n") (progn (message "Reverting `%s' done" (process-buffer process))))))))
  net-utils-revert-function(t nil)
  revert-buffer(t)
  call-interactively(revert-buffer nil nil)
  command-execute(revert-buffer)
--8<---------------cut here---------------end--------------->8---


I will modify your patch to make it working as soon as possible (not
today).
You can install my patch which is working, and we make changes in one or
two days with your patch modified.(Or just wait)

> 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).
Yes the header is not important (for traceroute unneeded).

Thanks.

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





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-02-28  6:18                 ` Thierry Volpiatto
@ 2013-02-28 14:04                   ` Stefan Monnier
  2013-02-28 19:45                     ` Thierry Volpiatto
  0 siblings, 1 reply; 26+ messages in thread
From: Stefan Monnier @ 2013-02-28 14:04 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: 13831

> It doesn't work:

> --8<---------------cut here---------------start------------->8---
> Debugger entered--Lisp error: (wrong-type-argument stringp nil)
>   start-process(nil "*netstat*" nil)
>   apply(start-process nil "*netstat*" nil nil)
>   (setq net-utils-mode-process (apply (quote start-process)
> net-utils-program-name (buffer-name) net-utils-program-name
> net-utils-program-args))

This backtrace clearly shows you tried this in a session that has
left-overs from your old code: the new code does not mention
net-utils-program-name.


        Stefan





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-02-28 14:04                   ` Stefan Monnier
@ 2013-02-28 19:45                     ` Thierry Volpiatto
  2013-03-01  3:05                       ` Stefan Monnier
  0 siblings, 1 reply; 26+ messages in thread
From: Thierry Volpiatto @ 2013-02-28 19:45 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 13831

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> It doesn't work:
>
>> --8<---------------cut here---------------start------------->8---
>> Debugger entered--Lisp error: (wrong-type-argument stringp nil)
>>   start-process(nil "*netstat*" nil)
>>   apply(start-process nil "*netstat*" nil nil)
>>   (setq net-utils-mode-process (apply (quote start-process)
>> net-utils-program-name (buffer-name) net-utils-program-name
>> net-utils-program-args))
>
> This backtrace clearly shows you tried this in a session that has
> left-overs from your old code: the new code does not mention
> net-utils-program-name.

Indeed yes, tried this very early this morning.
Just tried now and it is working, but point move at eof, it should stay
on top of buffer.

Thanks.

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





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-02-28 19:45                     ` Thierry Volpiatto
@ 2013-03-01  3:05                       ` Stefan Monnier
  2013-03-01  7:02                         ` Thierry Volpiatto
  0 siblings, 1 reply; 26+ messages in thread
From: Stefan Monnier @ 2013-03-01  3:05 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: 13831

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


        Stefan





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-03-01  3:05                       ` Stefan Monnier
@ 2013-03-01  7:02                         ` Thierry Volpiatto
  2013-03-01 14:29                           ` Stefan Monnier
  2013-03-01 14:30                           ` Thierry Volpiatto
  0 siblings, 2 replies; 26+ messages in thread
From: Thierry Volpiatto @ 2013-03-01  7:02 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 13831

Hi Stefan,

Stefan Monnier <monnier@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'.

diff --git a/lisp/net/net-utils.el b/lisp/net/net-utils.el
index 28fd5c6..5fe8d35 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,38 @@ 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)
   "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 +440,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 





^ permalink raw reply related	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-03-01  7:02                         ` Thierry Volpiatto
@ 2013-03-01 14:29                           ` Stefan Monnier
  2013-03-01 15:22                             ` Thierry Volpiatto
                                               ` (2 more replies)
  2013-03-01 14:30                           ` Thierry Volpiatto
  1 sibling, 3 replies; 26+ messages in thread
From: Stefan Monnier @ 2013-03-01 14:29 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: 13831

> Here your patch modified, I have simplified
> `net-utils-remove-ctrl-m-filter'.

Actually, my patch is already in the trunk.  Could you make the patch
relative to trunk's version?

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

This code does not affect the selected-window, so there shouldn't be any
save-selected-window.  Instead it should use with-current-buffer.

BTW, I think the desired behavior is not the same for all net-utils
tools.  E.g. for ping, we'd like point to stay at the end.  So you above
change is good but it should be completed with changes in the relevant
commands to set window-point-insertion-type when necessary.


        Stefan





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-03-01  7:02                         ` Thierry Volpiatto
  2013-03-01 14:29                           ` Stefan Monnier
@ 2013-03-01 14:30                           ` Thierry Volpiatto
  1 sibling, 0 replies; 26+ messages in thread
From: Thierry Volpiatto @ 2013-03-01 14:30 UTC (permalink / raw)
  To: 13831

Hi Stefan,

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

> Hi Stefan,
>
> Stefan Monnier <monnier@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 






^ permalink raw reply related	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  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-03  6:16                             ` Thierry Volpiatto
  2 siblings, 1 reply; 26+ messages in thread
From: Thierry Volpiatto @ 2013-03-01 15:22 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 13831

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Here your patch modified, I have simplified
>> `net-utils-remove-ctrl-m-filter'.
>
> Actually, my patch is already in the trunk.  Could you make the patch
> relative to trunk's version?

Ok, this allow reverting from somewhere else (e.g ibuffer, helm):


diff --git a/lisp/net/net-utils.el b/lisp/net/net-utils.el
index cc28bab..5e27c0e 100644
--- a/lisp/net/net-utils.el
+++ b/lisp/net/net-utils.el
@@ -358,7 +358,7 @@ This variable is only used if the variable
 ;; Todo: This data could be saved in a bookmark.
 (defvar net-utils--revert-cmd nil)
 
-(defun net-utils-run-simple (buffer program-name args)
+(defun net-utils-run-simple (buffer program-name args &optional nodisplay)
   "Run a network utility for diagnostic output only."
   (with-current-buffer (if (stringp buffer) (get-buffer-create buffer) buffer)
     (let ((proc (get-buffer-process (current-buffer))))
@@ -369,13 +369,14 @@ This variable is only used if the variable
       (erase-buffer))
     (net-utils-mode)
     (setq-local net-utils--revert-cmd
-                `(net-utils-run-simple ,(current-buffer) ,program-name ,args))
+                `(net-utils-run-simple ,(current-buffer)
+                                       ,program-name ,args 'nodisplay))
     (set-process-filter
          (apply 'start-process program-name
                 (current-buffer) program-name args)
          'net-utils-remove-ctrl-m-filter)
     (goto-char (point-min))
-    (display-buffer (current-buffer))))
+    (unless nodisplay (display-buffer (current-buffer)))))
 
 (defun net-utils--revert-function (&optional ignore-auto noconfirm)
   (message "Reverting `%s'..." (buffer-name))

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





^ permalink raw reply related	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-03-01 15:22                             ` Thierry Volpiatto
@ 2013-03-01 17:28                               ` Stefan Monnier
  0 siblings, 0 replies; 26+ messages in thread
From: Stefan Monnier @ 2013-03-01 17:28 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: 13831

> Ok, this allow reverting from somewhere else (e.g ibuffer, helm):

Thanks, installed,


        Stefan





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-03-01 14:29                           ` Stefan Monnier
  2013-03-01 15:22                             ` Thierry Volpiatto
@ 2013-03-01 19:07                             ` Thierry Volpiatto
  2013-03-11 18:31                               ` Stefan Monnier
  2013-03-03  6:16                             ` Thierry Volpiatto
  2 siblings, 1 reply; 26+ messages in thread
From: Thierry Volpiatto @ 2013-03-01 19:07 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 13831

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> +  (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))))))
>
> This code does not affect the selected-window, so there shouldn't be any
> save-selected-window.  Instead it should use with-current-buffer.

Ok

> BTW, I think the desired behavior is not the same for all net-utils
> tools.  E.g. for ping, we'd like point to stay at the end.  So you above
> change is good but it should be completed with changes in the relevant
> commands to set window-point-insertion-type when necessary.

Actually, the behavior of net-utils tools is to go back to bob
on initial run, and when reverting going to eob, this is not consistent,
we should do the same when reverting IMO.
I suggest we stay on bob for both by default [1] and specify to go to a
specific place (eob) when needed in some command (like ping as you
suggested).

This is for [1]

diff --git a/lisp/net/net-utils.el b/lisp/net/net-utils.el
index 82c1ce0..e7da1aa 100644
--- a/lisp/net/net-utils.el
+++ b/lisp/net/net-utils.el
@@ -319,25 +319,17 @@ 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))))
+  (with-current-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."
@@ -375,7 +367,6 @@ This variable is only used if the variable
          (apply 'start-process program-name
                 (current-buffer) program-name args)
          'net-utils-remove-ctrl-m-filter)
-    (goto-char (point-min))
     (unless nodisplay (display-buffer (current-buffer)))))
 
 (defun net-utils--revert-function (&optional ignore-auto noconfirm)


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





^ permalink raw reply related	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-03-01 14:29                           ` Stefan Monnier
  2013-03-01 15:22                             ` Thierry Volpiatto
  2013-03-01 19:07                             ` Thierry Volpiatto
@ 2013-03-03  6:16                             ` Thierry Volpiatto
  2 siblings, 0 replies; 26+ messages in thread
From: Thierry Volpiatto @ 2013-03-03  6:16 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 13831


Hi Stefan,

`net-utils-remove-ctl-m' is defined, but never used, probably it is good
to use it (it allow not running the test for control-m char on
non--Windows platforms), otherwise we should remove it.

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





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-03-01 19:07                             ` Thierry Volpiatto
@ 2013-03-11 18:31                               ` Stefan Monnier
  2013-03-13 14:43                                 ` Thierry Volpiatto
  0 siblings, 1 reply; 26+ messages in thread
From: Stefan Monnier @ 2013-03-11 18:31 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: 13831

> Actually, the behavior of net-utils tools is to go back to bob
> on initial run, and when reverting going to eob, this is not consistent,
> we should do the same when reverting IMO.
> I suggest we stay on bob for both by default [1] and specify to go to a
> specific place (eob) when needed in some command (like ping as you
> suggested).

> This is for [1]

> diff --git a/lisp/net/net-utils.el b/lisp/net/net-utils.el

Installed, thank you,


        Stefan





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-03-11 18:31                               ` Stefan Monnier
@ 2013-03-13 14:43                                 ` Thierry Volpiatto
  2013-03-13 17:52                                   ` Stefan Monnier
  0 siblings, 1 reply; 26+ messages in thread
From: Thierry Volpiatto @ 2013-03-13 14:43 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 13831

Hi Stefan,

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Installed, thank you,

Ok thanks.

Also here something wrong also:

--8<---------------cut here---------------start------------->8---
;; 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 ()
--8<---------------cut here---------------end--------------->8---

This function return not only machine but anything at point, which is
annoying.

Thus we find some lines later:

--8<---------------cut here---------------start------------->8---
    (read-from-minibuffer "Lookup host: "
                          (or (ffap-string-at-point 'machine) ""))))
--8<---------------cut here---------------end--------------->8---

And ffap is not required.

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.

I can send a patch if ok.

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





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-03-13 14:43                                 ` Thierry Volpiatto
@ 2013-03-13 17:52                                   ` Stefan Monnier
  2013-03-13 20:12                                     ` Thierry Volpiatto
  0 siblings, 1 reply; 26+ messages in thread
From: Stefan Monnier @ 2013-03-13 17:52 UTC (permalink / raw)
  To: Thierry Volpiatto; +Cc: 13831

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

> I can send a patch if ok.

Please do,


        Stefan





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#13831: 24.3.50; [PATCH] net-utils-mode have no revert-buffer function
  2013-03-13 17:52                                   ` Stefan Monnier
@ 2013-03-13 20:12                                     ` Thierry Volpiatto
  0 siblings, 0 replies; 26+ messages in thread
From: Thierry Volpiatto @ 2013-03-13 20:12 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 13831

Stefan Monnier <monnier@iro.umontreal.ca> 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 





^ permalink raw reply related	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2013-03-13 20:12 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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.