diff options
| author | Chong Yidong | 2009-08-08 18:26:36 +0000 |
|---|---|---|
| committer | Chong Yidong | 2009-08-08 18:26:36 +0000 |
| commit | ce299d55e7cd82a29aaca2c74bc0c19690bf3649 (patch) | |
| tree | b20b70be883df63faa31316a1ac702ef2799ffda /lisp | |
| parent | 9cbac26bbbed088c520c2e9289e3dc8cbde32465 (diff) | |
| download | emacs-ce299d55e7cd82a29aaca2c74bc0c19690bf3649.tar.gz emacs-ce299d55e7cd82a29aaca2c74bc0c19690bf3649.zip | |
* net/net-utils.el (net-utils-font-lock-keywords): New var.
(nslookup-font-lock-keywords): Make it a variable.
(net-utils-mode): New mode for viewing diagnostic network output.
(net-utils-remove-ctrl-m-filter): Set inhibit-read-only.
(net-utils-run-simple): New function.
(ifconfig, iwconfig, netstat, arp, route): Use it.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/net/net-utils.el | 176 |
2 files changed, 118 insertions, 67 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index aba028d6ef0..a1b6dd53926 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2009-08-08 Yoni Rabkin <yoni@rabkins.net> | ||
| 2 | |||
| 3 | * net/net-utils.el (net-utils-font-lock-keywords): New var. | ||
| 4 | (nslookup-font-lock-keywords): Make it a variable. | ||
| 5 | (net-utils-mode): New mode for viewing diagnostic network output. | ||
| 6 | (net-utils-remove-ctrl-m-filter): Set inhibit-read-only. | ||
| 7 | (net-utils-run-simple): New function. | ||
| 8 | (ifconfig, iwconfig, netstat, arp, route): Use it. | ||
| 9 | |||
| 1 | 2009-08-08 Dmitry Dzhus <dima@sphinx.net.ru> | 10 | 2009-08-08 Dmitry Dzhus <dima@sphinx.net.ru> |
| 2 | 11 | ||
| 3 | * progmodes/gdb-mi.el (gdb-read-memory-custom) | 12 | * progmodes/gdb-mi.el (gdb-read-memory-custom) |
diff --git a/lisp/net/net-utils.el b/lisp/net/net-utils.el index 7e7e5cd1bbf..f295803ff50 100644 --- a/lisp/net/net-utils.el +++ b/lisp/net/net-utils.el | |||
| @@ -237,7 +237,7 @@ This variable is only used if the variable | |||
| 237 | ;; Nslookup goodies | 237 | ;; Nslookup goodies |
| 238 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 238 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 239 | 239 | ||
| 240 | (defconst nslookup-font-lock-keywords | 240 | (defvar nslookup-font-lock-keywords |
| 241 | (list | 241 | (list |
| 242 | (list "^[A-Za-z0-9 _]+:" 0 'font-lock-type-face) | 242 | (list "^[A-Za-z0-9 _]+:" 0 'font-lock-type-face) |
| 243 | (list "\\<\\(SOA\\|NS\\|MX\\|A\\|CNAME\\)\\>" | 243 | (list "\\<\\(SOA\\|NS\\|MX\\|A\\|CNAME\\)\\>" |
| @@ -260,6 +260,36 @@ This variable is only used if the variable | |||
| 260 | "Expressions to font-lock for nslookup.") | 260 | "Expressions to font-lock for nslookup.") |
| 261 | 261 | ||
| 262 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 262 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 263 | ;; General network utilities mode | ||
| 264 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 265 | |||
| 266 | (defvar net-utils-font-lock-keywords | ||
| 267 | (list | ||
| 268 | ;; Dotted quads | ||
| 269 | (list | ||
| 270 | (mapconcat 'identity (make-list 4 "[0-9]+") "\\.") | ||
| 271 | 0 'font-lock-variable-name-face) | ||
| 272 | ;; Simple rfc4291 addresses | ||
| 273 | (list (concat | ||
| 274 | "\\( \\([[:xdigit:]]+\\(:\\|::\\)\\)+[[:xdigit:]]+\\)" | ||
| 275 | "\\|" | ||
| 276 | "\\(::[[:xdigit:]]+\\)") | ||
| 277 | 0 'font-lock-variable-name-face) | ||
| 278 | ;; Host names | ||
| 279 | (list | ||
| 280 | (let ((host-expression "[-A-Za-z0-9]+")) | ||
| 281 | (concat | ||
| 282 | (mapconcat 'identity (make-list 2 host-expression) "\\.") | ||
| 283 | "\\(\\." host-expression "\\)*")) | ||
| 284 | 0 'font-lock-variable-name-face)) | ||
| 285 | "Expressions to font-lock for general network utilities.") | ||
| 286 | |||
| 287 | (define-derived-mode net-utils-mode special-mode "NetworkUtil" | ||
| 288 | "Major mode for interacting with an external network utility." | ||
| 289 | (set (make-local-variable 'font-lock-defaults) | ||
| 290 | '((net-utils-font-lock-keywords)))) | ||
| 291 | |||
| 292 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 263 | ;; Utility functions | 293 | ;; Utility functions |
| 264 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 294 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 265 | 295 | ||
| @@ -288,7 +318,6 @@ This variable is only used if the variable | |||
| 288 | (skip-chars-backward ":;.,!?" pt) | 318 | (skip-chars-backward ":;.,!?" pt) |
| 289 | (point))))) | 319 | (point))))) |
| 290 | 320 | ||
| 291 | |||
| 292 | (defun net-utils-remove-ctrl-m-filter (process output-string) | 321 | (defun net-utils-remove-ctrl-m-filter (process output-string) |
| 293 | "Remove trailing control Ms." | 322 | "Remove trailing control Ms." |
| 294 | (let ((old-buffer (current-buffer)) | 323 | (let ((old-buffer (current-buffer)) |
| @@ -296,17 +325,18 @@ This variable is only used if the variable | |||
| 296 | (unwind-protect | 325 | (unwind-protect |
| 297 | (let ((moving)) | 326 | (let ((moving)) |
| 298 | (set-buffer (process-buffer process)) | 327 | (set-buffer (process-buffer process)) |
| 299 | (setq moving (= (point) (process-mark process))) | 328 | (let ((inhibit-read-only t)) |
| 300 | 329 | (setq moving (= (point) (process-mark process))) | |
| 301 | (while (string-match "\r" filtered-string) | 330 | |
| 302 | (setq filtered-string | 331 | (while (string-match "\r" filtered-string) |
| 303 | (replace-match "" nil nil filtered-string))) | 332 | (setq filtered-string |
| 304 | 333 | (replace-match "" nil nil filtered-string))) | |
| 305 | (save-excursion | 334 | |
| 306 | ;; Insert the text, moving the process-marker. | 335 | (save-excursion |
| 307 | (goto-char (process-mark process)) | 336 | ;; Insert the text, moving the process-marker. |
| 308 | (insert filtered-string) | 337 | (goto-char (process-mark process)) |
| 309 | (set-marker (process-mark process) (point))) | 338 | (insert filtered-string) |
| 339 | (set-marker (process-mark process) (point)))) | ||
| 310 | (if moving (goto-char (process-mark process)))) | 340 | (if moving (goto-char (process-mark process)))) |
| 311 | (set-buffer old-buffer)))) | 341 | (set-buffer old-buffer)))) |
| 312 | 342 | ||
| @@ -323,6 +353,72 @@ This variable is only used if the variable | |||
| 323 | buf)) | 353 | buf)) |
| 324 | 354 | ||
| 325 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 355 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 356 | ;; General network utilities (diagnostic) | ||
| 357 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 358 | |||
| 359 | (defun net-utils-run-simple (buffer-name program-name args) | ||
| 360 | "Run a network utility for diagnostic output only." | ||
| 361 | (interactive) | ||
| 362 | (when (get-buffer buffer-name) | ||
| 363 | (kill-buffer buffer-name)) | ||
| 364 | (get-buffer-create buffer-name) | ||
| 365 | (with-current-buffer buffer-name | ||
| 366 | (net-utils-mode) | ||
| 367 | (set-process-filter | ||
| 368 | (apply 'start-process (format "%s" program-name) | ||
| 369 | buffer-name program-name args) | ||
| 370 | 'net-utils-remove-ctrl-m-filter) | ||
| 371 | (goto-char (point-min))) | ||
| 372 | (display-buffer buffer-name)) | ||
| 373 | |||
| 374 | ;;;###autoload | ||
| 375 | (defun ifconfig () | ||
| 376 | "Run ifconfig and display diagnostic output." | ||
| 377 | (interactive) | ||
| 378 | (net-utils-run-simple | ||
| 379 | (format "*%s*" ifconfig-program) | ||
| 380 | ifconfig-program | ||
| 381 | ifconfig-program-options)) | ||
| 382 | |||
| 383 | (defalias 'ipconfig 'ifconfig) | ||
| 384 | |||
| 385 | ;;;###autoload | ||
| 386 | (defun iwconfig () | ||
| 387 | "Run iwconfig and display diagnostic output." | ||
| 388 | (interactive) | ||
| 389 | (net-utils-run-simple | ||
| 390 | (format "*%s*" iwconfig-program) | ||
| 391 | iwconfig-program | ||
| 392 | iwconfig-program-options)) | ||
| 393 | |||
| 394 | ;;;###autoload | ||
| 395 | (defun netstat () | ||
| 396 | "Run netstat and display diagnostic output." | ||
| 397 | (interactive) | ||
| 398 | (net-utils-run-simple | ||
| 399 | (format "*%s*" netstat-program) | ||
| 400 | netstat-program | ||
| 401 | netstat-program-options)) | ||
| 402 | |||
| 403 | ;;;###autoload | ||
| 404 | (defun arp () | ||
| 405 | "Run arp and display diagnostic output." | ||
| 406 | (interactive) | ||
| 407 | (net-utils-run-simple | ||
| 408 | (format "*%s*" arp-program) | ||
| 409 | arp-program | ||
| 410 | arp-program-options)) | ||
| 411 | |||
| 412 | ;;;###autoload | ||
| 413 | (defun route () | ||
| 414 | "Run route and display diagnostic output." | ||
| 415 | (interactive) | ||
| 416 | (net-utils-run-simple | ||
| 417 | (format "*%s*" route-program) | ||
| 418 | route-program | ||
| 419 | route-program-options)) | ||
| 420 | |||
| 421 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
| 326 | ;; Wrappers for external network programs | 422 | ;; Wrappers for external network programs |
| 327 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 423 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 328 | 424 | ||
| @@ -357,60 +453,6 @@ If your system's ping continues until interrupted, you can try setting | |||
| 357 | ping-program | 453 | ping-program |
| 358 | options))) | 454 | options))) |
| 359 | 455 | ||
| 360 | ;;;###autoload | ||
| 361 | (defun ifconfig () | ||
| 362 | "Run ifconfig program." | ||
| 363 | (interactive) | ||
| 364 | (net-utils-run-program | ||
| 365 | "Ifconfig" | ||
| 366 | (concat "** Ifconfig ** " ifconfig-program " ** ") | ||
| 367 | ifconfig-program | ||
| 368 | ifconfig-program-options)) | ||
| 369 | |||
| 370 | ;; Windows uses this name. | ||
| 371 | ;;;###autoload | ||
| 372 | (defalias 'ipconfig 'ifconfig) | ||
| 373 | |||
| 374 | ;;;###autoload | ||
| 375 | (defun iwconfig () | ||
| 376 | "Run iwconfig program." | ||
| 377 | (interactive) | ||
| 378 | (net-utils-run-program | ||
| 379 | "Iwconfig" | ||
| 380 | (concat "** Iwconfig ** " iwconfig-program " ** ") | ||
| 381 | iwconfig-program | ||
| 382 | iwconfig-program-options)) | ||
| 383 | |||
| 384 | ;;;###autoload | ||
| 385 | (defun netstat () | ||
| 386 | "Run netstat program." | ||
| 387 | (interactive) | ||
| 388 | (net-utils-run-program | ||
| 389 | "Netstat" | ||
| 390 | (concat "** Netstat ** " netstat-program " ** ") | ||
| 391 | netstat-program | ||
| 392 | netstat-program-options)) | ||
| 393 | |||
| 394 | ;;;###autoload | ||
| 395 | (defun arp () | ||
| 396 | "Run arp program." | ||
| 397 | (interactive) | ||
| 398 | (net-utils-run-program | ||
| 399 | "Arp" | ||
| 400 | (concat "** Arp ** " arp-program " ** ") | ||
| 401 | arp-program | ||
| 402 | arp-program-options)) | ||
| 403 | |||
| 404 | ;;;###autoload | ||
| 405 | (defun route () | ||
| 406 | "Run route program." | ||
| 407 | (interactive) | ||
| 408 | (net-utils-run-program | ||
| 409 | "Route" | ||
| 410 | (concat "** Route ** " route-program " ** ") | ||
| 411 | route-program | ||
| 412 | route-program-options)) | ||
| 413 | |||
| 414 | ;; FIXME -- Needs to be a process filter | 456 | ;; FIXME -- Needs to be a process filter |
| 415 | ;; (defun netstat-with-filter (filter) | 457 | ;; (defun netstat-with-filter (filter) |
| 416 | ;; "Run netstat program." | 458 | ;; "Run netstat program." |