changeset 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 219a95f2ef05
children 255bf3146d5e
files lisp/net/net-utils.el
diffstat 1 files changed, 46 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/net/net-utils.el	Fri Oct 06 04:54:57 2000 +0000
+++ b/lisp/net/net-utils.el	Fri Oct 06 04:56:34 2000 +0000
@@ -171,7 +171,10 @@
   )
 
 (defcustom nslookup-prompt-regexp "^> "
-  "Regexp to match the nslookup prompt."
+  "Regexp to match the nslookup prompt.
+
+This variable is only used if the variable
+`comint-use-prompt-regexp-instead-of-fields' is non-nil."
   :group 'net-utils
   :type  'regexp
   )
@@ -195,7 +198,10 @@
   )
 
 (defcustom ftp-prompt-regexp "^ftp>"
-  "Regexp which matches the FTP program's prompt."
+  "Regexp which matches the FTP program's prompt.
+
+This variable is only used if the variable
+`comint-use-prompt-regexp-instead-of-fields' is non-nil."
   :group 'net-utils
   :type  'regexp
   )
@@ -213,7 +219,10 @@
   )
 
 (defcustom smbclient-prompt-regexp "^smb: \>"
-  "Regexp which matches the smbclient program's prompt."
+  "Regexp which matches the smbclient program's prompt.
+
+This variable is only used if the variable
+`comint-use-prompt-regexp-instead-of-fields' is non-nil."
   :group 'net-utils
   :type  'regexp
   )
@@ -230,7 +239,6 @@
   (progn
     (require 'font-lock)
     (list
-     (list nslookup-prompt-regexp 0 font-lock-reference-face)
      (list "^[A-Za-z0-9 _]+:"     0 font-lock-type-face)
      (list "\\<\\(SOA\\|NS\\|MX\\|A\\|CNAME\\)\\>"
 	   1 font-lock-keyword-face)
@@ -254,26 +262,6 @@
   "Expressions to font-lock for nslookup.")
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; FTP goodies
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-(defconst ftp-font-lock-keywords
-  (progn
-    (require 'font-lock)
-    (list
-     (list ftp-prompt-regexp 0 font-lock-reference-face))))
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; smbclient goodies
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-(defconst smbclient-font-lock-keywords
-  (progn
-    (require 'font-lock)
-    (list
-     (list smbclient-prompt-regexp 0 font-lock-reference-face))))
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Utility functions
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
@@ -457,23 +445,18 @@
   (interactive)
   (require 'comint)
   (comint-run nslookup-program)
-  (set-process-filter (get-buffer-process "*nslookup*")
-   'net-utils-remove-ctrl-m-filter)
   (nslookup-mode)
   )
 
 ;; Using a derived mode gives us keymaps, hooks, etc.
-(define-derived-mode
-  nslookup-mode comint-mode "Nslookup"
+(define-derived-mode nslookup-mode comint-mode "Nslookup"
   "Major mode for interacting with the nslookup program."
   (set
    (make-local-variable 'font-lock-defaults)
    '((nslookup-font-lock-keywords)))
   (setq local-abbrev-table nslookup-mode-abbrev-table)
   (abbrev-mode t)
-  (make-local-variable 'comint-prompt-regexp)
   (setq comint-prompt-regexp nslookup-prompt-regexp)
-  (make-local-variable 'comint-input-autoexpand)
   (setq comint-input-autoexpand t)
   )
 
@@ -520,33 +503,27 @@
   (require 'comint)
   (let ((buf (get-buffer-create (concat "*ftp [" host "]*"))))
     (set-buffer buf)
-    (comint-mode)
+    (ftp-mode)
     (comint-exec buf (concat "ftp-" host) ftp-program nil
 		 (if ftp-program-options
 		     (append (list host) ftp-program-options)
 		   (list host)))
-    (ftp-mode)
-    (switch-to-buffer-other-window buf)
-    ))
-
-(define-derived-mode
-  ftp-mode comint-mode "FTP"
-  "Major mode for interacting with the ftp program."
+    (pop-to-buffer buf)))
 
-  (set
-   (make-local-variable 'font-lock-defaults)
-   '((ftp-font-lock-keywords)))
-
-  (make-local-variable 'comint-prompt-regexp)
+(define-derived-mode ftp-mode comint-mode "FTP"
+  "Major mode for interacting with the ftp program."
   (setq comint-prompt-regexp ftp-prompt-regexp)
-
-  (make-local-variable 'comint-input-autoexpand)
   (setq comint-input-autoexpand t)
-
-  ;; Already buffer local!
-  (setq comint-output-filter-functions
-	(list 'comint-watch-for-password-prompt))
-
+  ;; Only add the password-prompting hook if it's not already in the
+  ;; global hook list.  This stands a small chance of losing, if it's
+  ;; later removed from the global list (very small, since any
+  ;; password prompts will probably immediately follow the initial
+  ;; connection), but it's better than getting prompted twice for the
+  ;; same password.
+  (unless (memq 'comint-watch-for-password-prompt
+		(default-value 'comint-output-filter-functions))
+    (add-hook 'comint-output-filter-functions 'comint-watch-for-password-prompt
+	      nil t))
   (setq local-abbrev-table ftp-mode-abbrev-table)
   (abbrev-mode t)
   )
@@ -571,14 +548,12 @@
 	 (buf (get-buffer-create (concat "*" name "*")))
 	 (service-name (concat "\\\\" host "\\" service)))
     (set-buffer buf)
-    (comint-mode)
+    (smbclient-mode)
     (comint-exec buf name smbclient-program nil
 		 (if smbclient-program-options
 		     (append (list service-name) smbclient-program-options)
 		   (list service-name)))
-    (smbclient-mode)
-    (switch-to-buffer-other-window buf)
-    ))
+    (pop-to-buffer buf)))
 
 (defun smbclient-list-shares (host)
   "List services on HOST."
@@ -589,35 +564,25 @@
     ))
   (let ((buf (get-buffer-create (format "*SMB Shares on %s*" host))))
     (set-buffer buf)
-    (comint-mode)
-    (comint-exec
-     buf
-     "smbclient-list-shares"
-     smbclient-program
-     nil
-     (list "-L" host)
-     )
     (smbclient-mode)
-    (switch-to-buffer-other-window buf)))
-
-(define-derived-mode
-  smbclient-mode comint-mode "smbclient"
-  "Major mode for interacting with the smbclient program."
+    (comint-exec buf "smbclient-list-shares"
+		 smbclient-program nil (list "-L" host))
+    (pop-to-buffer buf)))
 
-  (set
-   (make-local-variable 'font-lock-defaults)
-   '((smbclient-font-lock-keywords)))
-
-  (make-local-variable 'comint-prompt-regexp)
+(define-derived-mode smbclient-mode comint-mode "smbclient"
+  "Major mode for interacting with the smbclient program."
   (setq comint-prompt-regexp smbclient-prompt-regexp)
-
-  (make-local-variable 'comint-input-autoexpand)
   (setq comint-input-autoexpand t)
-
-  ;; Already buffer local!
-  (setq comint-output-filter-functions
-	(list 'comint-watch-for-password-prompt))
-
+  ;; Only add the password-prompting hook if it's not already in the
+  ;; global hook list.  This stands a small chance of losing, if it's
+  ;; later removed from the global list (very small, since any
+  ;; password prompts will probably immediately follow the initial
+  ;; connection), but it's better than getting prompted twice for the
+  ;; same password.
+  (unless (memq 'comint-watch-for-password-prompt
+		(default-value 'comint-output-filter-functions))
+    (add-hook 'comint-output-filter-functions 'comint-watch-for-password-prompt
+	      nil t))
   (setq local-abbrev-table smbclient-mode-abbrev-table)
   (abbrev-mode t)
   )
@@ -662,8 +627,7 @@
 ;; Workhorse macro
 (defmacro run-network-program (process-name host port
 					    &optional initial-string)
-  `
-   (let ((tcp-connection)
+  `(let ((tcp-connection)
 	 (buf)
 	 )
     (setq buf (get-buffer-create (concat "*" ,process-name "*")))
@@ -720,7 +684,7 @@
 	 (process-name (concat "Finger [" user-and-host "]"))
 	 (regexps finger-X.500-host-regexps)
 	 found)
-    (while (not (string-match (car regexps) host))
+    (while (and regexps (not (string-match (car regexps) host)))
       (setq regexps (cdr regexps)))
     (when regexps
       (setq user-and-host user))