diff options
| author | Peter Breton | 2000-10-04 05:43:37 +0000 |
|---|---|---|
| committer | Peter Breton | 2000-10-04 05:43:37 +0000 |
| commit | ddb62bf14ac8d0646c3ba609150e952d85b38ec4 (patch) | |
| tree | ce4881cede9754d96f1eca2da70cc11df8360e93 | |
| parent | 8b7187d81658167e7dd1e4f0a5d85565ca47310b (diff) | |
| download | emacs-ddb62bf14ac8d0646c3ba609150e952d85b38ec4.tar.gz emacs-ddb62bf14ac8d0646c3ba609150e952d85b38ec4.zip | |
* net/net-utils.el (nslookup-font-lock-keywords,
ftp-font-lock-keywords, smbclient-font-lock-keywords):
Only set if window-system is non-nil
(net-utils-run-program): Returns buffer.
(network-connection-reconnect): Added this function.
| -rw-r--r-- | lisp/net/net-utils.el | 237 |
1 files changed, 131 insertions, 106 deletions
diff --git a/lisp/net/net-utils.el b/lisp/net/net-utils.el index 9b3e3ee157b..1f05b3f12bf 100644 --- a/lisp/net/net-utils.el +++ b/lisp/net/net-utils.el | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | ;; Author: Peter Breton <pbreton@cs.umb.edu> | 3 | ;; Author: Peter Breton <pbreton@cs.umb.edu> |
| 4 | ;; Created: Sun Mar 16 1997 | 4 | ;; Created: Sun Mar 16 1997 |
| 5 | ;; Keywords: network communications | 5 | ;; Keywords: network communications |
| 6 | ;; Time-stamp: <1999-11-13 10:19:01 pbreton> | 6 | ;; Time-stamp: <2000-10-04 01:32:16 pbreton> |
| 7 | 7 | ||
| 8 | ;; This file is part of GNU Emacs. | 8 | ;; This file is part of GNU Emacs. |
| 9 | 9 | ||
| @@ -25,13 +25,13 @@ | |||
| 25 | ;;; Commentary: | 25 | ;;; Commentary: |
| 26 | ;; | 26 | ;; |
| 27 | ;; There are three main areas of functionality: | 27 | ;; There are three main areas of functionality: |
| 28 | ;; | 28 | ;; |
| 29 | ;; * Wrap common network utility programs (ping, traceroute, netstat, | 29 | ;; * Wrap common network utility programs (ping, traceroute, netstat, |
| 30 | ;; nslookup, arp, route). Note that these wrappers are of the diagnostic | 30 | ;; nslookup, arp, route). Note that these wrappers are of the diagnostic |
| 31 | ;; functions of these programs only. | 31 | ;; functions of these programs only. |
| 32 | ;; | 32 | ;; |
| 33 | ;; * Implement some very basic protocols in Emacs Lisp (finger and whois) | 33 | ;; * Implement some very basic protocols in Emacs Lisp (finger and whois) |
| 34 | ;; | 34 | ;; |
| 35 | ;; * Support connections to HOST/PORT, generally for debugging and the like. | 35 | ;; * Support connections to HOST/PORT, generally for debugging and the like. |
| 36 | ;; In other words, for doing much the same thing as "telnet HOST PORT", and | 36 | ;; In other words, for doing much the same thing as "telnet HOST PORT", and |
| 37 | ;; then typing commands. | 37 | ;; then typing commands. |
| @@ -39,7 +39,7 @@ | |||
| 39 | ;; PATHS | 39 | ;; PATHS |
| 40 | ;; | 40 | ;; |
| 41 | ;; On some systems, some of these programs are not in normal user path, | 41 | ;; On some systems, some of these programs are not in normal user path, |
| 42 | ;; but rather in /sbin, /usr/sbin, and so on. | 42 | ;; but rather in /sbin, /usr/sbin, and so on. |
| 43 | 43 | ||
| 44 | 44 | ||
| 45 | ;;; Code: | 45 | ;;; Code: |
| @@ -57,15 +57,15 @@ | |||
| 57 | :version "20.3" | 57 | :version "20.3" |
| 58 | ) | 58 | ) |
| 59 | 59 | ||
| 60 | (defcustom net-utils-remove-ctl-m | 60 | (defcustom net-utils-remove-ctl-m |
| 61 | (member system-type (list 'windows-nt 'msdos)) | 61 | (member system-type (list 'windows-nt 'msdos)) |
| 62 | "If non-nil, remove control-Ms from output." | 62 | "If non-nil, remove control-Ms from output." |
| 63 | :group 'net-utils | 63 | :group 'net-utils |
| 64 | :type 'boolean | 64 | :type 'boolean |
| 65 | ) | 65 | ) |
| 66 | 66 | ||
| 67 | (defcustom traceroute-program | 67 | (defcustom traceroute-program |
| 68 | (if (eq system-type 'windows-nt) | 68 | (if (eq system-type 'windows-nt) |
| 69 | "tracert" | 69 | "tracert" |
| 70 | "traceroute") | 70 | "traceroute") |
| 71 | "Program to trace network hops to a destination." | 71 | "Program to trace network hops to a destination." |
| @@ -87,7 +87,7 @@ | |||
| 87 | 87 | ||
| 88 | ;; On Linux and Irix, the system's ping program seems to send packets | 88 | ;; On Linux and Irix, the system's ping program seems to send packets |
| 89 | ;; indefinitely unless told otherwise | 89 | ;; indefinitely unless told otherwise |
| 90 | (defcustom ping-program-options | 90 | (defcustom ping-program-options |
| 91 | (and (memq system-type (list 'linux 'gnu/linux 'irix)) | 91 | (and (memq system-type (list 'linux 'gnu/linux 'irix)) |
| 92 | (list "-c" "4")) | 92 | (list "-c" "4")) |
| 93 | "Options for the ping program. | 93 | "Options for the ping program. |
| @@ -96,7 +96,7 @@ These options can be used to limit how many ICMP packets are emitted." | |||
| 96 | :type '(repeat string) | 96 | :type '(repeat string) |
| 97 | ) | 97 | ) |
| 98 | 98 | ||
| 99 | (defcustom ipconfig-program | 99 | (defcustom ipconfig-program |
| 100 | (if (eq system-type 'windows-nt) | 100 | (if (eq system-type 'windows-nt) |
| 101 | "ipconfig" | 101 | "ipconfig" |
| 102 | "ifconfig") | 102 | "ifconfig") |
| @@ -106,7 +106,7 @@ These options can be used to limit how many ICMP packets are emitted." | |||
| 106 | ) | 106 | ) |
| 107 | 107 | ||
| 108 | (defcustom ipconfig-program-options | 108 | (defcustom ipconfig-program-options |
| 109 | (list | 109 | (list |
| 110 | (if (eq system-type 'windows-nt) | 110 | (if (eq system-type 'windows-nt) |
| 111 | "/all" "-a")) | 111 | "/all" "-a")) |
| 112 | "Options for ipconfig-program." | 112 | "Options for ipconfig-program." |
| @@ -120,7 +120,7 @@ These options can be used to limit how many ICMP packets are emitted." | |||
| 120 | :type 'string | 120 | :type 'string |
| 121 | ) | 121 | ) |
| 122 | 122 | ||
| 123 | (defcustom netstat-program-options | 123 | (defcustom netstat-program-options |
| 124 | (list "-a") | 124 | (list "-a") |
| 125 | "Options for netstat-program." | 125 | "Options for netstat-program." |
| 126 | :group 'net-utils | 126 | :group 'net-utils |
| @@ -133,14 +133,14 @@ These options can be used to limit how many ICMP packets are emitted." | |||
| 133 | :type 'string | 133 | :type 'string |
| 134 | ) | 134 | ) |
| 135 | 135 | ||
| 136 | (defcustom arp-program-options | 136 | (defcustom arp-program-options |
| 137 | (list "-a") | 137 | (list "-a") |
| 138 | "Options for arp-program." | 138 | "Options for arp-program." |
| 139 | :group 'net-utils | 139 | :group 'net-utils |
| 140 | :type '(repeat string) | 140 | :type '(repeat string) |
| 141 | ) | 141 | ) |
| 142 | 142 | ||
| 143 | (defcustom route-program | 143 | (defcustom route-program |
| 144 | (if (eq system-type 'windows-nt) | 144 | (if (eq system-type 'windows-nt) |
| 145 | "route" | 145 | "route" |
| 146 | "netstat") | 146 | "netstat") |
| @@ -149,7 +149,7 @@ These options can be used to limit how many ICMP packets are emitted." | |||
| 149 | :type 'string | 149 | :type 'string |
| 150 | ) | 150 | ) |
| 151 | 151 | ||
| 152 | (defcustom route-program-options | 152 | (defcustom route-program-options |
| 153 | (if (eq system-type 'windows-nt) | 153 | (if (eq system-type 'windows-nt) |
| 154 | (list "print") | 154 | (list "print") |
| 155 | (list "-r")) | 155 | (list "-r")) |
| @@ -227,51 +227,54 @@ These options can be used to limit how many ICMP packets are emitted." | |||
| 227 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 227 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 228 | 228 | ||
| 229 | (defconst nslookup-font-lock-keywords | 229 | (defconst nslookup-font-lock-keywords |
| 230 | (progn | 230 | (and window-system |
| 231 | (require 'font-lock) | 231 | (progn |
| 232 | (list | 232 | (require 'font-lock) |
| 233 | (list nslookup-prompt-regexp 0 font-lock-reference-face) | 233 | (list |
| 234 | (list "^[A-Za-z0-9 _]+:" 0 font-lock-type-face) | 234 | (list nslookup-prompt-regexp 0 font-lock-reference-face) |
| 235 | (list "\\<\\(SOA\\|NS\\|MX\\|A\\|CNAME\\)\\>" | 235 | (list "^[A-Za-z0-9 _]+:" 0 font-lock-type-face) |
| 236 | 1 font-lock-keyword-face) | 236 | (list "\\<\\(SOA\\|NS\\|MX\\|A\\|CNAME\\)\\>" |
| 237 | ;; Dotted quads | 237 | 1 font-lock-keyword-face) |
| 238 | (list | 238 | ;; Dotted quads |
| 239 | (mapconcat 'identity | 239 | (list |
| 240 | (make-list 4 "[0-9]+") | 240 | (mapconcat 'identity |
| 241 | "\\.") | 241 | (make-list 4 "[0-9]+") |
| 242 | 0 font-lock-variable-name-face) | 242 | "\\.") |
| 243 | ;; Host names | 243 | 0 font-lock-variable-name-face) |
| 244 | (list | 244 | ;; Host names |
| 245 | (let ((host-expression "[-A-Za-z0-9]+")) | 245 | (list |
| 246 | (concat | 246 | (let ((host-expression "[-A-Za-z0-9]+")) |
| 247 | (mapconcat 'identity | 247 | (concat |
| 248 | (make-list 2 host-expression) | 248 | (mapconcat 'identity |
| 249 | "\\.") | 249 | (make-list 2 host-expression) |
| 250 | "\\(\\." host-expression "\\)*") | 250 | "\\.") |
| 251 | ) | 251 | "\\(\\." host-expression "\\)*") |
| 252 | 0 font-lock-variable-name-face) | 252 | ) |
| 253 | )) | 253 | 0 font-lock-variable-name-face) |
| 254 | "Expressions to font-lock for nslookup.") | 254 | ))) |
| 255 | "Expressions to font-lock for nslookup.") | ||
| 255 | 256 | ||
| 256 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 257 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 257 | ;; FTP goodies | 258 | ;; FTP goodies |
| 258 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 259 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 259 | 260 | ||
| 260 | (defconst ftp-font-lock-keywords | 261 | (defconst ftp-font-lock-keywords |
| 261 | (progn | 262 | (and window-system |
| 262 | (require 'font-lock) | 263 | (progn |
| 263 | (list | 264 | (require 'font-lock) |
| 264 | (list ftp-prompt-regexp 0 font-lock-reference-face)))) | 265 | (list |
| 266 | (list ftp-prompt-regexp 0 font-lock-reference-face))))) | ||
| 265 | 267 | ||
| 266 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 268 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 267 | ;; smbclient goodies | 269 | ;; smbclient goodies |
| 268 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 270 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 269 | 271 | ||
| 270 | (defconst smbclient-font-lock-keywords | 272 | (defconst smbclient-font-lock-keywords |
| 271 | (progn | 273 | (and window-system |
| 272 | (require 'font-lock) | 274 | (progn |
| 273 | (list | 275 | (require 'font-lock) |
| 274 | (list smbclient-prompt-regexp 0 font-lock-reference-face)))) | 276 | (list |
| 277 | (list smbclient-prompt-regexp 0 font-lock-reference-face))))) | ||
| 275 | 278 | ||
| 276 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 279 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 277 | ;; Utility functions | 280 | ;; Utility functions |
| @@ -311,7 +314,7 @@ These options can be used to limit how many ICMP packets are emitted." | |||
| 311 | (let ((moving)) | 314 | (let ((moving)) |
| 312 | (set-buffer (process-buffer process)) | 315 | (set-buffer (process-buffer process)) |
| 313 | (setq moving (= (point) (process-mark process))) | 316 | (setq moving (= (point) (process-mark process))) |
| 314 | 317 | ||
| 315 | (while (string-match "\r" filtered-string) | 318 | (while (string-match "\r" filtered-string) |
| 316 | (setq filtered-string | 319 | (setq filtered-string |
| 317 | (replace-match "" nil nil filtered-string))) | 320 | (replace-match "" nil nil filtered-string))) |
| @@ -323,17 +326,18 @@ These options can be used to limit how many ICMP packets are emitted." | |||
| 323 | (set-marker (process-mark process) (point))) | 326 | (set-marker (process-mark process) (point))) |
| 324 | (if moving (goto-char (process-mark process)))) | 327 | (if moving (goto-char (process-mark process)))) |
| 325 | (set-buffer old-buffer)))) | 328 | (set-buffer old-buffer)))) |
| 326 | 329 | ||
| 327 | (defmacro net-utils-run-program (name header program &rest args) | 330 | (defmacro net-utils-run-program (name header program &rest args) |
| 328 | "Run a network information program." | 331 | "Run a network information program." |
| 329 | ` (let ((buf (get-buffer-create (concat "*" ,name "*")))) | 332 | ` (let ((buf (get-buffer-create (concat "*" ,name "*")))) |
| 330 | (set-buffer buf) | 333 | (set-buffer buf) |
| 331 | (erase-buffer) | 334 | (erase-buffer) |
| 332 | (insert ,header "\n") | 335 | (insert ,header "\n") |
| 333 | (set-process-filter | 336 | (set-process-filter |
| 334 | (apply 'start-process ,name buf ,program ,@args) | 337 | (apply 'start-process ,name buf ,program ,@args) |
| 335 | 'net-utils-remove-ctrl-m-filter) | 338 | 'net-utils-remove-ctrl-m-filter) |
| 336 | (display-buffer buf))) | 339 | (display-buffer buf) |
| 340 | buf)) | ||
| 337 | 341 | ||
| 338 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 342 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 339 | ;; Wrappers for external network programs | 343 | ;; Wrappers for external network programs |
| @@ -343,7 +347,7 @@ These options can be used to limit how many ICMP packets are emitted." | |||
| 343 | (defun traceroute (target) | 347 | (defun traceroute (target) |
| 344 | "Run traceroute program for TARGET." | 348 | "Run traceroute program for TARGET." |
| 345 | (interactive "sTarget: ") | 349 | (interactive "sTarget: ") |
| 346 | (let ((options | 350 | (let ((options |
| 347 | (if traceroute-program-options | 351 | (if traceroute-program-options |
| 348 | (append traceroute-program-options (list target)) | 352 | (append traceroute-program-options (list target)) |
| 349 | (list target)))) | 353 | (list target)))) |
| @@ -357,11 +361,11 @@ These options can be used to limit how many ICMP packets are emitted." | |||
| 357 | ;;;###autoload | 361 | ;;;###autoload |
| 358 | (defun ping (host) | 362 | (defun ping (host) |
| 359 | "Ping HOST. | 363 | "Ping HOST. |
| 360 | If your system's ping continues until interrupted, you can try setting | 364 | If your system's ping continues until interrupted, you can try setting |
| 361 | `ping-program-options'." | 365 | `ping-program-options'." |
| 362 | (interactive | 366 | (interactive |
| 363 | (list (read-from-minibuffer "Ping host: " (net-utils-machine-at-point)))) | 367 | (list (read-from-minibuffer "Ping host: " (net-utils-machine-at-point)))) |
| 364 | (let ((options | 368 | (let ((options |
| 365 | (if ping-program-options | 369 | (if ping-program-options |
| 366 | (append ping-program-options (list host)) | 370 | (append ping-program-options (list host)) |
| 367 | (list host)))) | 371 | (list host)))) |
| @@ -385,7 +389,7 @@ If your system's ping continues until interrupted, you can try setting | |||
| 385 | 389 | ||
| 386 | ;; This is the normal name on most Unixes. | 390 | ;; This is the normal name on most Unixes. |
| 387 | ;;;###autoload | 391 | ;;;###autoload |
| 388 | (defalias 'ifconfig 'ipconfig) | 392 | (defalias 'ifconfig 'ipconfig) |
| 389 | 393 | ||
| 390 | ;;;###autoload | 394 | ;;;###autoload |
| 391 | (defun netstat () | 395 | (defun netstat () |
| @@ -435,7 +439,7 @@ If your system's ping continues until interrupted, you can try setting | |||
| 435 | "Lookup the DNS information for HOST." | 439 | "Lookup the DNS information for HOST." |
| 436 | (interactive | 440 | (interactive |
| 437 | (list (read-from-minibuffer "Lookup host: " (net-utils-machine-at-point)))) | 441 | (list (read-from-minibuffer "Lookup host: " (net-utils-machine-at-point)))) |
| 438 | (let ((options | 442 | (let ((options |
| 439 | (if nslookup-program-options | 443 | (if nslookup-program-options |
| 440 | (append nslookup-program-options (list host)) | 444 | (append nslookup-program-options (list host)) |
| 441 | (list host)))) | 445 | (list host)))) |
| @@ -462,10 +466,10 @@ If your system's ping continues until interrupted, you can try setting | |||
| 462 | ) | 466 | ) |
| 463 | 467 | ||
| 464 | ;; Using a derived mode gives us keymaps, hooks, etc. | 468 | ;; Using a derived mode gives us keymaps, hooks, etc. |
| 465 | (define-derived-mode | 469 | (define-derived-mode |
| 466 | nslookup-mode comint-mode "Nslookup" | 470 | nslookup-mode comint-mode "Nslookup" |
| 467 | "Major mode for interacting with the nslookup program." | 471 | "Major mode for interacting with the nslookup program." |
| 468 | (set | 472 | (set |
| 469 | (make-local-variable 'font-lock-defaults) | 473 | (make-local-variable 'font-lock-defaults) |
| 470 | '((nslookup-font-lock-keywords))) | 474 | '((nslookup-font-lock-keywords))) |
| 471 | (setq local-abbrev-table nslookup-mode-abbrev-table) | 475 | (setq local-abbrev-table nslookup-mode-abbrev-table) |
| @@ -495,8 +499,8 @@ If your system's ping continues until interrupted, you can try setting | |||
| 495 | (list | 499 | (list |
| 496 | (progn | 500 | (progn |
| 497 | (require 'ffap) | 501 | (require 'ffap) |
| 498 | (read-from-minibuffer | 502 | (read-from-minibuffer |
| 499 | "Lookup host: " | 503 | "Lookup host: " |
| 500 | (or (ffap-string-at-point 'machine) ""))))) | 504 | (or (ffap-string-at-point 'machine) ""))))) |
| 501 | (net-utils-run-program | 505 | (net-utils-run-program |
| 502 | "Dig" | 506 | "Dig" |
| @@ -506,15 +510,15 @@ If your system's ping continues until interrupted, you can try setting | |||
| 506 | " ** ")) | 510 | " ** ")) |
| 507 | dig-program | 511 | dig-program |
| 508 | (list host) | 512 | (list host) |
| 509 | )) | 513 | )) |
| 510 | 514 | ||
| 511 | ;; This is a lot less than ange-ftp, but much simpler. | 515 | ;; This is a lot less than ange-ftp, but much simpler. |
| 512 | ;;;###autoload | 516 | ;;;###autoload |
| 513 | (defun ftp (host) | 517 | (defun ftp (host) |
| 514 | "Run ftp program." | 518 | "Run ftp program." |
| 515 | (interactive | 519 | (interactive |
| 516 | (list | 520 | (list |
| 517 | (read-from-minibuffer | 521 | (read-from-minibuffer |
| 518 | "Ftp to Host: " (net-utils-machine-at-point)))) | 522 | "Ftp to Host: " (net-utils-machine-at-point)))) |
| 519 | (require 'comint) | 523 | (require 'comint) |
| 520 | (let ((buf (get-buffer-create (concat "*ftp [" host "]*")))) | 524 | (let ((buf (get-buffer-create (concat "*ftp [" host "]*")))) |
| @@ -528,24 +532,24 @@ If your system's ping continues until interrupted, you can try setting | |||
| 528 | (switch-to-buffer-other-window buf) | 532 | (switch-to-buffer-other-window buf) |
| 529 | )) | 533 | )) |
| 530 | 534 | ||
| 531 | (define-derived-mode | 535 | (define-derived-mode |
| 532 | ftp-mode comint-mode "FTP" | 536 | ftp-mode comint-mode "FTP" |
| 533 | "Major mode for interacting with the ftp program." | 537 | "Major mode for interacting with the ftp program." |
| 534 | 538 | ||
| 535 | (set | 539 | (set |
| 536 | (make-local-variable 'font-lock-defaults) | 540 | (make-local-variable 'font-lock-defaults) |
| 537 | '((ftp-font-lock-keywords))) | 541 | '((ftp-font-lock-keywords))) |
| 538 | 542 | ||
| 539 | (make-local-variable 'comint-prompt-regexp) | 543 | (make-local-variable 'comint-prompt-regexp) |
| 540 | (setq comint-prompt-regexp ftp-prompt-regexp) | 544 | (setq comint-prompt-regexp ftp-prompt-regexp) |
| 541 | 545 | ||
| 542 | (make-local-variable 'comint-input-autoexpand) | 546 | (make-local-variable 'comint-input-autoexpand) |
| 543 | (setq comint-input-autoexpand t) | 547 | (setq comint-input-autoexpand t) |
| 544 | 548 | ||
| 545 | ;; Already buffer local! | 549 | ;; Already buffer local! |
| 546 | (setq comint-output-filter-functions | 550 | (setq comint-output-filter-functions |
| 547 | (list 'comint-watch-for-password-prompt)) | 551 | (list 'comint-watch-for-password-prompt)) |
| 548 | 552 | ||
| 549 | (setq local-abbrev-table ftp-mode-abbrev-table) | 553 | (setq local-abbrev-table ftp-mode-abbrev-table) |
| 550 | (abbrev-mode t) | 554 | (abbrev-mode t) |
| 551 | ) | 555 | ) |
| @@ -560,9 +564,9 @@ If your system's ping continues until interrupted, you can try setting | |||
| 560 | 564 | ||
| 561 | (defun smbclient (host service) | 565 | (defun smbclient (host service) |
| 562 | "Connect to SERVICE on HOST via SMB." | 566 | "Connect to SERVICE on HOST via SMB." |
| 563 | (interactive | 567 | (interactive |
| 564 | (list | 568 | (list |
| 565 | (read-from-minibuffer | 569 | (read-from-minibuffer |
| 566 | "Connect to Host: " (net-utils-machine-at-point)) | 570 | "Connect to Host: " (net-utils-machine-at-point)) |
| 567 | (read-from-minibuffer "SMB Service: "))) | 571 | (read-from-minibuffer "SMB Service: "))) |
| 568 | (require 'comint) | 572 | (require 'comint) |
| @@ -581,42 +585,42 @@ If your system's ping continues until interrupted, you can try setting | |||
| 581 | 585 | ||
| 582 | (defun smbclient-list-shares (host) | 586 | (defun smbclient-list-shares (host) |
| 583 | "List services on HOST." | 587 | "List services on HOST." |
| 584 | (interactive | 588 | (interactive |
| 585 | (list | 589 | (list |
| 586 | (read-from-minibuffer | 590 | (read-from-minibuffer |
| 587 | "Connect to Host: " (net-utils-machine-at-point)) | 591 | "Connect to Host: " (net-utils-machine-at-point)) |
| 588 | )) | 592 | )) |
| 589 | (let ((buf (get-buffer-create (format "*SMB Shares on %s*" host)))) | 593 | (let ((buf (get-buffer-create (format "*SMB Shares on %s*" host)))) |
| 590 | (set-buffer buf) | 594 | (set-buffer buf) |
| 591 | (comint-mode) | 595 | (comint-mode) |
| 592 | (comint-exec | 596 | (comint-exec |
| 593 | buf | 597 | buf |
| 594 | "smbclient-list-shares" | 598 | "smbclient-list-shares" |
| 595 | smbclient-program | 599 | smbclient-program |
| 596 | nil | 600 | nil |
| 597 | (list "-L" host) | 601 | (list "-L" host) |
| 598 | ) | 602 | ) |
| 599 | (smbclient-mode) | 603 | (smbclient-mode) |
| 600 | (switch-to-buffer-other-window buf))) | 604 | (switch-to-buffer-other-window buf))) |
| 601 | 605 | ||
| 602 | (define-derived-mode | 606 | (define-derived-mode |
| 603 | smbclient-mode comint-mode "smbclient" | 607 | smbclient-mode comint-mode "smbclient" |
| 604 | "Major mode for interacting with the smbclient program." | 608 | "Major mode for interacting with the smbclient program." |
| 605 | 609 | ||
| 606 | (set | 610 | (set |
| 607 | (make-local-variable 'font-lock-defaults) | 611 | (make-local-variable 'font-lock-defaults) |
| 608 | '((smbclient-font-lock-keywords))) | 612 | '((smbclient-font-lock-keywords))) |
| 609 | 613 | ||
| 610 | (make-local-variable 'comint-prompt-regexp) | 614 | (make-local-variable 'comint-prompt-regexp) |
| 611 | (setq comint-prompt-regexp smbclient-prompt-regexp) | 615 | (setq comint-prompt-regexp smbclient-prompt-regexp) |
| 612 | 616 | ||
| 613 | (make-local-variable 'comint-input-autoexpand) | 617 | (make-local-variable 'comint-input-autoexpand) |
| 614 | (setq comint-input-autoexpand t) | 618 | (setq comint-input-autoexpand t) |
| 615 | 619 | ||
| 616 | ;; Already buffer local! | 620 | ;; Already buffer local! |
| 617 | (setq comint-output-filter-functions | 621 | (setq comint-output-filter-functions |
| 618 | (list 'comint-watch-for-password-prompt)) | 622 | (list 'comint-watch-for-password-prompt)) |
| 619 | 623 | ||
| 620 | (setq local-abbrev-table smbclient-mode-abbrev-table) | 624 | (setq local-abbrev-table smbclient-mode-abbrev-table) |
| 621 | (abbrev-mode t) | 625 | (abbrev-mode t) |
| 622 | ) | 626 | ) |
| @@ -630,7 +634,7 @@ If your system's ping continues until interrupted, you can try setting | |||
| 630 | 634 | ||
| 631 | ;; Full list is available at: | 635 | ;; Full list is available at: |
| 632 | ;; ftp://ftp.isi.edu/in-notes/iana/assignments/port-numbers | 636 | ;; ftp://ftp.isi.edu/in-notes/iana/assignments/port-numbers |
| 633 | (defvar network-connection-service-alist | 637 | (defvar network-connection-service-alist |
| 634 | (list | 638 | (list |
| 635 | (cons 'echo 7) | 639 | (cons 'echo 7) |
| 636 | (cons 'active-users 11) | 640 | (cons 'active-users 11) |
| @@ -659,7 +663,7 @@ If your system's ping continues until interrupted, you can try setting | |||
| 659 | This list in not complete.") | 663 | This list in not complete.") |
| 660 | 664 | ||
| 661 | ;; Workhorse macro | 665 | ;; Workhorse macro |
| 662 | (defmacro run-network-program (process-name host port | 666 | (defmacro run-network-program (process-name host port |
| 663 | &optional initial-string) | 667 | &optional initial-string) |
| 664 | ` | 668 | ` |
| 665 | (let ((tcp-connection) | 669 | (let ((tcp-connection) |
| @@ -667,9 +671,9 @@ This list in not complete.") | |||
| 667 | ) | 671 | ) |
| 668 | (setq buf (get-buffer-create (concat "*" ,process-name "*"))) | 672 | (setq buf (get-buffer-create (concat "*" ,process-name "*"))) |
| 669 | (set-buffer buf) | 673 | (set-buffer buf) |
| 670 | (or | 674 | (or |
| 671 | (setq tcp-connection | 675 | (setq tcp-connection |
| 672 | (open-network-stream | 676 | (open-network-stream |
| 673 | ,process-name | 677 | ,process-name |
| 674 | buf | 678 | buf |
| 675 | ,host | 679 | ,host |
| @@ -680,7 +684,7 @@ This list in not complete.") | |||
| 680 | (set-marker (process-mark tcp-connection) (point-min)) | 684 | (set-marker (process-mark tcp-connection) (point-min)) |
| 681 | (set-process-filter tcp-connection 'net-utils-remove-ctrl-m-filter) | 685 | (set-process-filter tcp-connection 'net-utils-remove-ctrl-m-filter) |
| 682 | (and ,initial-string | 686 | (and ,initial-string |
| 683 | (process-send-string tcp-connection | 687 | (process-send-string tcp-connection |
| 684 | (concat ,initial-string "\r\n"))) | 688 | (concat ,initial-string "\r\n"))) |
| 685 | (display-buffer buf))) | 689 | (display-buffer buf))) |
| 686 | 690 | ||
| @@ -723,9 +727,9 @@ queries of the form USER@HOST, and wants a query containing USER only." | |||
| 723 | (setq regexps (cdr regexps))) | 727 | (setq regexps (cdr regexps))) |
| 724 | (when regexps | 728 | (when regexps |
| 725 | (setq user-and-host user)) | 729 | (setq user-and-host user)) |
| 726 | (run-network-program | 730 | (run-network-program |
| 727 | process-name | 731 | process-name |
| 728 | host | 732 | host |
| 729 | (cdr (assoc 'finger network-connection-service-alist)) | 733 | (cdr (assoc 'finger network-connection-service-alist)) |
| 730 | user-and-host))) | 734 | user-and-host))) |
| 731 | 735 | ||
| @@ -804,7 +808,7 @@ from SEARCH-STRING. With argument, prompt for whois server." | |||
| 804 | (completing-read "Whois server name: " | 808 | (completing-read "Whois server name: " |
| 805 | whois-server-list nil nil "whois.") | 809 | whois-server-list nil nil "whois.") |
| 806 | server-name))) | 810 | server-name))) |
| 807 | (run-network-program | 811 | (run-network-program |
| 808 | "Whois" | 812 | "Whois" |
| 809 | host | 813 | host |
| 810 | (cdr (assoc 'whois network-connection-service-alist)) | 814 | (cdr (assoc 'whois network-connection-service-alist)) |
| @@ -828,22 +832,22 @@ from SEARCH-STRING. With argument, prompt for whois server." | |||
| 828 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 832 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 829 | 833 | ||
| 830 | ;; Using a derived mode gives us keymaps, hooks, etc. | 834 | ;; Using a derived mode gives us keymaps, hooks, etc. |
| 831 | (define-derived-mode | 835 | (define-derived-mode |
| 832 | network-connection-mode comint-mode "Network-Connection" | 836 | network-connection-mode comint-mode "Network-Connection" |
| 833 | "Major mode for interacting with the network-connection program." | 837 | "Major mode for interacting with the network-connection program." |
| 834 | ) | 838 | ) |
| 835 | 839 | ||
| 836 | (defun network-connection-mode-setup (host service) | 840 | (defun network-connection-mode-setup (host service) |
| 837 | (let ((network-abbrev-table | 841 | (let ((network-abbrev-table |
| 838 | (or | 842 | (or |
| 839 | (assoc service network-connection-service-abbrev-alist) | 843 | (assoc service network-connection-service-abbrev-alist) |
| 840 | (and (rassoc service network-connection-service-alist) | 844 | (and (rassoc service network-connection-service-alist) |
| 841 | (assoc | 845 | (assoc |
| 842 | (elt (rassoc service network-connection-service-alist) 0) | 846 | (elt (rassoc service network-connection-service-alist) 0) |
| 843 | network-connection-service-abbrev-alist))))) | 847 | network-connection-service-abbrev-alist))))) |
| 844 | (make-local-variable 'network-connection-host) | 848 | (make-local-variable 'network-connection-host) |
| 845 | (setq network-connection-host host) | 849 | (setq network-connection-host host) |
| 846 | (make-local-variable 'network-connection-service) | 850 | (make-local-variable 'network-connection-service) |
| 847 | (setq network-connection-service service) | 851 | (setq network-connection-service service) |
| 848 | (and network-abbrev-table | 852 | (and network-abbrev-table |
| 849 | (setq local-abbrev-table (cdr network-abbrev-table)) | 853 | (setq local-abbrev-table (cdr network-abbrev-table)) |
| @@ -853,17 +857,17 @@ from SEARCH-STRING. With argument, prompt for whois server." | |||
| 853 | ;;;###autoload | 857 | ;;;###autoload |
| 854 | (defun network-connection-to-service (host service) | 858 | (defun network-connection-to-service (host service) |
| 855 | "Open a network connection to SERVICE on HOST." | 859 | "Open a network connection to SERVICE on HOST." |
| 856 | (interactive | 860 | (interactive |
| 857 | (list | 861 | (list |
| 858 | (read-from-minibuffer "Host: " (net-utils-machine-at-point)) | 862 | (read-from-minibuffer "Host: " (net-utils-machine-at-point)) |
| 859 | (completing-read "Service: " | 863 | (completing-read "Service: " |
| 860 | (mapcar | 864 | (mapcar |
| 861 | (function | 865 | (function |
| 862 | (lambda (elt) | 866 | (lambda (elt) |
| 863 | (list (symbol-name (car elt))))) | 867 | (list (symbol-name (car elt))))) |
| 864 | network-connection-service-alist)))) | 868 | network-connection-service-alist)))) |
| 865 | (network-connection | 869 | (network-connection |
| 866 | host | 870 | host |
| 867 | (cdr (assoc (intern service) network-connection-service-alist))) | 871 | (cdr (assoc (intern service) network-connection-service-alist))) |
| 868 | ) | 872 | ) |
| 869 | 873 | ||
| @@ -882,7 +886,7 @@ from SEARCH-STRING. With argument, prompt for whois server." | |||
| 882 | (buf (get-buffer-create (concat "*" process-name "*"))) | 886 | (buf (get-buffer-create (concat "*" process-name "*"))) |
| 883 | ) | 887 | ) |
| 884 | (or (zerop portnum) (setq service portnum)) | 888 | (or (zerop portnum) (setq service portnum)) |
| 885 | (make-comint | 889 | (make-comint |
| 886 | process-name | 890 | process-name |
| 887 | (cons host service)) | 891 | (cons host service)) |
| 888 | (set-buffer buf) | 892 | (set-buffer buf) |
| @@ -891,6 +895,27 @@ from SEARCH-STRING. With argument, prompt for whois server." | |||
| 891 | (pop-to-buffer buf) | 895 | (pop-to-buffer buf) |
| 892 | )) | 896 | )) |
| 893 | 897 | ||
| 898 | (defun network-connection-reconnect () | ||
| 899 | "Reconnect a network connection, preserving the old input ring." | ||
| 900 | (interactive) | ||
| 901 | (let ((proc (get-buffer-process (current-buffer))) | ||
| 902 | (old-comint-input-ring comint-input-ring) | ||
| 903 | (host network-connection-host) | ||
| 904 | (service network-connection-service) | ||
| 905 | ) | ||
| 906 | (if (not (or (not proc) | ||
| 907 | (eq (process-status proc) 'closed))) | ||
| 908 | (message "Still connected") | ||
| 909 | (goto-char (point-max)) | ||
| 910 | (insert (format "Reopening connection to %s\n" host)) | ||
| 911 | (network-connection host | ||
| 912 | (if (numberp service) | ||
| 913 | service | ||
| 914 | (cdr (assoc service network-connection-service-alist)))) | ||
| 915 | (and old-comint-input-ring | ||
| 916 | (setq comint-input-ring old-comint-input-ring)) | ||
| 917 | ))) | ||
| 918 | |||
| 894 | (provide 'net-utils) | 919 | (provide 'net-utils) |
| 895 | 920 | ||
| 896 | ;;; net-utils.el ends here | 921 | ;;; net-utils.el ends here |