comparison lisp/net/net-utils.el @ 32197:b949d342e936

(nslookup-prompt-regexp, ftp-prompt-regexp) (smbclient-prompt-regexp): Add usage note to doc string. (ftp-font-lock-keywords, smbclient-font-lock-keywords): Removed. (ftp-mode, smbclient-mode): Don't set `font-lock-defaults'. Use add-hook for adding the comint filter function, and only do so if it's not already in the global hook list. (ftp-mode, smbclient-mode, nslookup-mode): Remove redundant calls to `make-local-variable'. (nslookup-font-lock-keywords): Remove prompt entry. (nslookup): Don't set the process-filter. (finger): Exit the loop correctly when the regexps list runs out. (ftp, smbclient, smbclient-list-shares): Set the real major mode immediately, not after execing. Use `pop-to-buffer' instead of `switch-to-buffer-other-window'.
author Miles Bader <miles@gnu.org>
date Fri, 06 Oct 2000 04:56:34 +0000
parents b048135b76bc
children 2a73e688d635
comparison
equal deleted inserted replaced
32196:219a95f2ef05 32197:b949d342e936
169 :group 'net-utils 169 :group 'net-utils
170 :type '(repeat string) 170 :type '(repeat string)
171 ) 171 )
172 172
173 (defcustom nslookup-prompt-regexp "^> " 173 (defcustom nslookup-prompt-regexp "^> "
174 "Regexp to match the nslookup prompt." 174 "Regexp to match the nslookup prompt.
175
176 This variable is only used if the variable
177 `comint-use-prompt-regexp-instead-of-fields' is non-nil."
175 :group 'net-utils 178 :group 'net-utils
176 :type 'regexp 179 :type 'regexp
177 ) 180 )
178 181
179 (defcustom dig-program "dig" 182 (defcustom dig-program "dig"
193 :group 'net-utils 196 :group 'net-utils
194 :type '(repeat string) 197 :type '(repeat string)
195 ) 198 )
196 199
197 (defcustom ftp-prompt-regexp "^ftp>" 200 (defcustom ftp-prompt-regexp "^ftp>"
198 "Regexp which matches the FTP program's prompt." 201 "Regexp which matches the FTP program's prompt.
202
203 This variable is only used if the variable
204 `comint-use-prompt-regexp-instead-of-fields' is non-nil."
199 :group 'net-utils 205 :group 'net-utils
200 :type 'regexp 206 :type 'regexp
201 ) 207 )
202 208
203 (defcustom smbclient-program "smbclient" 209 (defcustom smbclient-program "smbclient"
211 :group 'net-utils 217 :group 'net-utils
212 :type '(repeat string) 218 :type '(repeat string)
213 ) 219 )
214 220
215 (defcustom smbclient-prompt-regexp "^smb: \>" 221 (defcustom smbclient-prompt-regexp "^smb: \>"
216 "Regexp which matches the smbclient program's prompt." 222 "Regexp which matches the smbclient program's prompt.
223
224 This variable is only used if the variable
225 `comint-use-prompt-regexp-instead-of-fields' is non-nil."
217 :group 'net-utils 226 :group 'net-utils
218 :type 'regexp 227 :type 'regexp
219 ) 228 )
220 229
221 ;; Internal variables 230 ;; Internal variables
228 237
229 (defconst nslookup-font-lock-keywords 238 (defconst nslookup-font-lock-keywords
230 (progn 239 (progn
231 (require 'font-lock) 240 (require 'font-lock)
232 (list 241 (list
233 (list nslookup-prompt-regexp 0 font-lock-reference-face)
234 (list "^[A-Za-z0-9 _]+:" 0 font-lock-type-face) 242 (list "^[A-Za-z0-9 _]+:" 0 font-lock-type-face)
235 (list "\\<\\(SOA\\|NS\\|MX\\|A\\|CNAME\\)\\>" 243 (list "\\<\\(SOA\\|NS\\|MX\\|A\\|CNAME\\)\\>"
236 1 font-lock-keyword-face) 244 1 font-lock-keyword-face)
237 ;; Dotted quads 245 ;; Dotted quads
238 (list 246 (list
252 0 font-lock-variable-name-face) 260 0 font-lock-variable-name-face)
253 )) 261 ))
254 "Expressions to font-lock for nslookup.") 262 "Expressions to font-lock for nslookup.")
255 263
256 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 264 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
257 ;; FTP goodies
258 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
259
260 (defconst ftp-font-lock-keywords
261 (progn
262 (require 'font-lock)
263 (list
264 (list ftp-prompt-regexp 0 font-lock-reference-face))))
265
266 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
267 ;; smbclient goodies
268 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
269
270 (defconst smbclient-font-lock-keywords
271 (progn
272 (require 'font-lock)
273 (list
274 (list smbclient-prompt-regexp 0 font-lock-reference-face))))
275
276 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
277 ;; Utility functions 265 ;; Utility functions
278 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 266 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
279 267
280 ;; Simplified versions of some at-point functions from ffap.el. 268 ;; Simplified versions of some at-point functions from ffap.el.
281 ;; It's not worth loading all of ffap just for these. 269 ;; It's not worth loading all of ffap just for these.
455 (defun nslookup () 443 (defun nslookup ()
456 "Run nslookup program." 444 "Run nslookup program."
457 (interactive) 445 (interactive)
458 (require 'comint) 446 (require 'comint)
459 (comint-run nslookup-program) 447 (comint-run nslookup-program)
460 (set-process-filter (get-buffer-process "*nslookup*")
461 'net-utils-remove-ctrl-m-filter)
462 (nslookup-mode) 448 (nslookup-mode)
463 ) 449 )
464 450
465 ;; Using a derived mode gives us keymaps, hooks, etc. 451 ;; Using a derived mode gives us keymaps, hooks, etc.
466 (define-derived-mode 452 (define-derived-mode nslookup-mode comint-mode "Nslookup"
467 nslookup-mode comint-mode "Nslookup"
468 "Major mode for interacting with the nslookup program." 453 "Major mode for interacting with the nslookup program."
469 (set 454 (set
470 (make-local-variable 'font-lock-defaults) 455 (make-local-variable 'font-lock-defaults)
471 '((nslookup-font-lock-keywords))) 456 '((nslookup-font-lock-keywords)))
472 (setq local-abbrev-table nslookup-mode-abbrev-table) 457 (setq local-abbrev-table nslookup-mode-abbrev-table)
473 (abbrev-mode t) 458 (abbrev-mode t)
474 (make-local-variable 'comint-prompt-regexp)
475 (setq comint-prompt-regexp nslookup-prompt-regexp) 459 (setq comint-prompt-regexp nslookup-prompt-regexp)
476 (make-local-variable 'comint-input-autoexpand)
477 (setq comint-input-autoexpand t) 460 (setq comint-input-autoexpand t)
478 ) 461 )
479 462
480 (define-key nslookup-mode-map "\t" 'comint-dynamic-complete) 463 (define-key nslookup-mode-map "\t" 'comint-dynamic-complete)
481 464
518 (read-from-minibuffer 501 (read-from-minibuffer
519 "Ftp to Host: " (net-utils-machine-at-point)))) 502 "Ftp to Host: " (net-utils-machine-at-point))))
520 (require 'comint) 503 (require 'comint)
521 (let ((buf (get-buffer-create (concat "*ftp [" host "]*")))) 504 (let ((buf (get-buffer-create (concat "*ftp [" host "]*"))))
522 (set-buffer buf) 505 (set-buffer buf)
523 (comint-mode) 506 (ftp-mode)
524 (comint-exec buf (concat "ftp-" host) ftp-program nil 507 (comint-exec buf (concat "ftp-" host) ftp-program nil
525 (if ftp-program-options 508 (if ftp-program-options
526 (append (list host) ftp-program-options) 509 (append (list host) ftp-program-options)
527 (list host))) 510 (list host)))
528 (ftp-mode) 511 (pop-to-buffer buf)))
529 (switch-to-buffer-other-window buf) 512
530 )) 513 (define-derived-mode ftp-mode comint-mode "FTP"
531
532 (define-derived-mode
533 ftp-mode comint-mode "FTP"
534 "Major mode for interacting with the ftp program." 514 "Major mode for interacting with the ftp program."
535
536 (set
537 (make-local-variable 'font-lock-defaults)
538 '((ftp-font-lock-keywords)))
539
540 (make-local-variable 'comint-prompt-regexp)
541 (setq comint-prompt-regexp ftp-prompt-regexp) 515 (setq comint-prompt-regexp ftp-prompt-regexp)
542
543 (make-local-variable 'comint-input-autoexpand)
544 (setq comint-input-autoexpand t) 516 (setq comint-input-autoexpand t)
545 517 ;; Only add the password-prompting hook if it's not already in the
546 ;; Already buffer local! 518 ;; global hook list. This stands a small chance of losing, if it's
547 (setq comint-output-filter-functions 519 ;; later removed from the global list (very small, since any
548 (list 'comint-watch-for-password-prompt)) 520 ;; password prompts will probably immediately follow the initial
549 521 ;; connection), but it's better than getting prompted twice for the
522 ;; same password.
523 (unless (memq 'comint-watch-for-password-prompt
524 (default-value 'comint-output-filter-functions))
525 (add-hook 'comint-output-filter-functions 'comint-watch-for-password-prompt
526 nil t))
550 (setq local-abbrev-table ftp-mode-abbrev-table) 527 (setq local-abbrev-table ftp-mode-abbrev-table)
551 (abbrev-mode t) 528 (abbrev-mode t)
552 ) 529 )
553 530
554 (define-abbrev ftp-mode-abbrev-table "q" "quit") 531 (define-abbrev ftp-mode-abbrev-table "q" "quit")
569 (require 'comint) 546 (require 'comint)
570 (let* ((name (format "smbclient [%s\\%s]" host service)) 547 (let* ((name (format "smbclient [%s\\%s]" host service))
571 (buf (get-buffer-create (concat "*" name "*"))) 548 (buf (get-buffer-create (concat "*" name "*")))
572 (service-name (concat "\\\\" host "\\" service))) 549 (service-name (concat "\\\\" host "\\" service)))
573 (set-buffer buf) 550 (set-buffer buf)
574 (comint-mode) 551 (smbclient-mode)
575 (comint-exec buf name smbclient-program nil 552 (comint-exec buf name smbclient-program nil
576 (if smbclient-program-options 553 (if smbclient-program-options
577 (append (list service-name) smbclient-program-options) 554 (append (list service-name) smbclient-program-options)
578 (list service-name))) 555 (list service-name)))
579 (smbclient-mode) 556 (pop-to-buffer buf)))
580 (switch-to-buffer-other-window buf)
581 ))
582 557
583 (defun smbclient-list-shares (host) 558 (defun smbclient-list-shares (host)
584 "List services on HOST." 559 "List services on HOST."
585 (interactive 560 (interactive
586 (list 561 (list
587 (read-from-minibuffer 562 (read-from-minibuffer
588 "Connect to Host: " (net-utils-machine-at-point)) 563 "Connect to Host: " (net-utils-machine-at-point))
589 )) 564 ))
590 (let ((buf (get-buffer-create (format "*SMB Shares on %s*" host)))) 565 (let ((buf (get-buffer-create (format "*SMB Shares on %s*" host))))
591 (set-buffer buf) 566 (set-buffer buf)
592 (comint-mode)
593 (comint-exec
594 buf
595 "smbclient-list-shares"
596 smbclient-program
597 nil
598 (list "-L" host)
599 )
600 (smbclient-mode) 567 (smbclient-mode)
601 (switch-to-buffer-other-window buf))) 568 (comint-exec buf "smbclient-list-shares"
602 569 smbclient-program nil (list "-L" host))
603 (define-derived-mode 570 (pop-to-buffer buf)))
604 smbclient-mode comint-mode "smbclient" 571
572 (define-derived-mode smbclient-mode comint-mode "smbclient"
605 "Major mode for interacting with the smbclient program." 573 "Major mode for interacting with the smbclient program."
606
607 (set
608 (make-local-variable 'font-lock-defaults)
609 '((smbclient-font-lock-keywords)))
610
611 (make-local-variable 'comint-prompt-regexp)
612 (setq comint-prompt-regexp smbclient-prompt-regexp) 574 (setq comint-prompt-regexp smbclient-prompt-regexp)
613
614 (make-local-variable 'comint-input-autoexpand)
615 (setq comint-input-autoexpand t) 575 (setq comint-input-autoexpand t)
616 576 ;; Only add the password-prompting hook if it's not already in the
617 ;; Already buffer local! 577 ;; global hook list. This stands a small chance of losing, if it's
618 (setq comint-output-filter-functions 578 ;; later removed from the global list (very small, since any
619 (list 'comint-watch-for-password-prompt)) 579 ;; password prompts will probably immediately follow the initial
620 580 ;; connection), but it's better than getting prompted twice for the
581 ;; same password.
582 (unless (memq 'comint-watch-for-password-prompt
583 (default-value 'comint-output-filter-functions))
584 (add-hook 'comint-output-filter-functions 'comint-watch-for-password-prompt
585 nil t))
621 (setq local-abbrev-table smbclient-mode-abbrev-table) 586 (setq local-abbrev-table smbclient-mode-abbrev-table)
622 (abbrev-mode t) 587 (abbrev-mode t)
623 ) 588 )
624 589
625 (define-abbrev smbclient-mode-abbrev-table "q" "quit") 590 (define-abbrev smbclient-mode-abbrev-table "q" "quit")
660 This list in not complete.") 625 This list in not complete.")
661 626
662 ;; Workhorse macro 627 ;; Workhorse macro
663 (defmacro run-network-program (process-name host port 628 (defmacro run-network-program (process-name host port
664 &optional initial-string) 629 &optional initial-string)
665 ` 630 `(let ((tcp-connection)
666 (let ((tcp-connection)
667 (buf) 631 (buf)
668 ) 632 )
669 (setq buf (get-buffer-create (concat "*" ,process-name "*"))) 633 (setq buf (get-buffer-create (concat "*" ,process-name "*")))
670 (set-buffer buf) 634 (set-buffer buf)
671 (or 635 (or
718 (net-utils-machine-at-point)))))) 682 (net-utils-machine-at-point))))))
719 (let* ((user-and-host (concat user "@" host)) 683 (let* ((user-and-host (concat user "@" host))
720 (process-name (concat "Finger [" user-and-host "]")) 684 (process-name (concat "Finger [" user-and-host "]"))
721 (regexps finger-X.500-host-regexps) 685 (regexps finger-X.500-host-regexps)
722 found) 686 found)
723 (while (not (string-match (car regexps) host)) 687 (while (and regexps (not (string-match (car regexps) host)))
724 (setq regexps (cdr regexps))) 688 (setq regexps (cdr regexps)))
725 (when regexps 689 (when regexps
726 (setq user-and-host user)) 690 (setq user-and-host user))
727 (run-network-program 691 (run-network-program
728 process-name 692 process-name