annotate lisp/comint/ssh.el @ 153:25f70ba0133c r20-3b3

Import from CVS: tag r20-3b3
author cvs
date Mon, 13 Aug 2007 09:38:25 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
1 ;;; ssh.el --- remote login interface
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
2
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1996, 1997 Noah S. Friedman
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
4
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
5 ;; Author: Noah Friedman <friedman@prep.ai.mit.edu>
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
6 ;; Maintainer: friedman@prep.ai.mit.edu
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
7 ;; Keywords: unix, comm
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
8 ;; Created: 1996-07-03
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
9
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
10 ;; $Id: ssh.el,v 1.1 1997/05/28 16:30:50 steve Exp $
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
11
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
12 ;; This program is free software; you can redistribute it and/or modify
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
15 ;; any later version.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
16 ;;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
17 ;; This program is distributed in the hope that it will be useful,
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
20 ;; GNU General Public License for more details.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
21 ;;
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
23 ;; along with this program; if not, you can either send email to this
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
24 ;; program's maintainer or write to: The Free Software Foundation,
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
25 ;; Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
26
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
27 ;;; Commentary:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
28
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
29 ;; Support for remote logins using `ssh'.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
30 ;; This program is layered on top of shell.el; the code here only accounts
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
31 ;; for the variations needed to handle a remote process, e.g. directory
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
32 ;; tracking and the sending of some special characters.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
33
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
34 ;; If you wish for ssh mode to prompt you in the minibuffer for
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
35 ;; passwords when a password prompt appears, just enter m-x send-invisible
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
36 ;; and type in your line, or add `comint-watch-for-password-prompt' to
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
37 ;; `comint-output-filter-functions'.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
38
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
39 ;;; Code:
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
40
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
41 (require 'comint)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
42 (require 'shell)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
43
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
44 (defgroup ssh nil
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
45 "Secure remote login interface"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
46 :group 'processes
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
47 :group 'unix)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
48
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
49 (defcustom ssh-program "ssh"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
50 "*Name of program to invoke ssh"
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
51 :type 'string
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
52 :group 'ssh)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
53
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
54 (defcustom ssh-explicit-args '()
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
55 "*List of arguments to pass to ssh on the command line."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
56 :type '(repeat (string :tag "Argument"))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
57 :group 'ssh)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
58
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
59 (defcustom ssh-mode-hook nil
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
60 "*Hooks to run after setting current buffer to ssh-mode."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
61 :type 'hook
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
62 :group 'ssh)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
63
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
64 (defcustom ssh-process-connection-type t
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
65 "*If non-`nil', use a pty for the local ssh process.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
66 If `nil', use a pipe (if pipes are supported on the local system).
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
67
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
68 Generally it is better not to waste ptys on systems which have a static
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
69 number of them. However, ssh won't allocate a pty on the remote host
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
70 unless one is used locally as well."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
71 :type '(choice (const :tag "ptys" t)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
72 (const :tag "pipes" nil))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
73 :group 'ssh)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
74
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
75 (defcustom ssh-directory-tracking-mode 'local
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
76 "*Control whether and how to do directory tracking in an ssh buffer.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
77
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
78 nil means don't do directory tracking.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
79
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
80 t means do so using an ftp remote file name.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
81
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
82 Any other value means do directory tracking using local file names.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
83 This works only if the remote machine and the local one
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
84 share the same directories (through NFS). This is the default.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
85
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
86 This variable becomes local to a buffer when set in any fashion for it.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
87
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
88 It is better to use the function of the same name to change the behavior of
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
89 directory tracking in an ssh session once it has begun, rather than
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
90 simply setting this variable, since the function does the necessary
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
91 re-synching of directories."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
92 :type '(choice (const :tag "off" nil)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
93 (const :tag "ftp" t)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
94 (const :tag "local" local))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
95 :group 'ssh)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
96
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
97 (make-variable-buffer-local 'ssh-directory-tracking-mode)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
98
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
99 (defcustom ssh-host nil
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
100 "*The name of the remote host. This variable is buffer-local."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
101 :type '(choice (const nil) string)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
102 :group 'ssh)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
103
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
104 (defcustom ssh-remote-user nil
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
105 "*The username used on the remote host.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
106 This variable is buffer-local and defaults to your local user name.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
107 If ssh is invoked with the `-l' option to specify the remote username,
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
108 this variable is set from that."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
109 :type '(choice (const nil) string)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
110 :group 'ssh)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
111
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
112 ;; Initialize ssh mode map.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
113 (defvar ssh-mode-map '())
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
114 (cond
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
115 ((null ssh-mode-map)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
116 (setq ssh-mode-map (if (consp shell-mode-map)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
117 (cons 'keymap shell-mode-map)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
118 (copy-keymap shell-mode-map)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
119 (define-key ssh-mode-map "\C-c\C-c" 'ssh-send-Ctrl-C)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
120 (define-key ssh-mode-map "\C-c\C-d" 'ssh-send-Ctrl-D)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
121 (define-key ssh-mode-map "\C-c\C-z" 'ssh-send-Ctrl-Z)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
122 (define-key ssh-mode-map "\C-c\C-\\" 'ssh-send-Ctrl-backslash)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
123 (define-key ssh-mode-map "\C-d" 'ssh-delchar-or-send-Ctrl-D)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
124 (define-key ssh-mode-map "\C-i" 'ssh-tab-or-complete)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
125
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
126
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
127 ;;;###autoload (add-hook 'same-window-regexps "^\\*ssh-.*\\*\\(\\|<[0-9]+>\\)")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
128
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
129 (defvar ssh-history nil)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
130
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
131 ;;;###autoload
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
132 (defun ssh (input-args &optional buffer)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
133 "Open a network login connection via `ssh' with args INPUT-ARGS.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
134 INPUT-ARGS should start with a host name; it may also contain
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
135 other arguments for `ssh'.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
136
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
137 Input is sent line-at-a-time to the remote connection.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
138
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
139 Communication with the remote host is recorded in a buffer `*ssh-HOST*'
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
140 \(or `*ssh-USER@HOST*' if the remote username differs\).
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
141 If a prefix argument is given and the buffer `*ssh-HOST*' already exists,
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
142 a new buffer with a different connection will be made.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
143
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
144 When called from a program, if the optional second argument BUFFER is
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
145 a string or buffer, it specifies the buffer to use.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
146
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
147 The variable `ssh-program' contains the name of the actual program to
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
148 run. It can be a relative or absolute path.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
149
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
150 The variable `ssh-explicit-args' is a list of arguments to give to
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
151 the ssh when starting. They are prepended to any arguments given in
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
152 INPUT-ARGS.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
154 If the default value of `ssh-directory-tracking-mode' is t, then the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
155 default directory in that buffer is set to a remote (FTP) file name to
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
156 access your home directory on the remote machine. Occasionally this causes
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
157 an error, if you cannot access the home directory on that machine. This
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
158 error is harmless as long as you don't try to use that default directory.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
159
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
160 If `ssh-directory-tracking-mode' is neither t nor nil, then the default
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
161 directory is initially set up to your (local) home directory.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
162 This is useful if the remote machine and your local machine
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
163 share the same files via NFS. This is the default.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
164
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
165 If you wish to change directory tracking styles during a session, use the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
166 function `ssh-directory-tracking-mode' rather than simply setting the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
167 variable."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
168 (interactive (list
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
169 (read-from-minibuffer "ssh arguments (hostname first): "
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
170 nil nil nil 'ssh-history)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
171 current-prefix-arg))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
172
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
173 (let* ((process-connection-type ssh-process-connection-type)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
174 (args (ssh-parse-words input-args))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
175 (host (car args))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
176 (user (or (car (cdr (member "-l" args)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
177 (user-login-name)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
178 (buffer-name (if (string= user (user-login-name))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
179 (format "*ssh-%s*" host)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
180 (format "*ssh-%s@%s*" user host)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
181 proc)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
182
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
183 (and ssh-explicit-args
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
184 (setq args (append ssh-explicit-args args)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
185
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
186 (cond ((null buffer))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
187 ((stringp buffer)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
188 (setq buffer-name buffer))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
189 ((bufferp buffer)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
190 (setq buffer-name (buffer-name buffer)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
191 ((numberp buffer)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
192 (setq buffer-name (format "%s<%d>" buffer-name buffer)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
193 (t
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
194 (setq buffer-name (generate-new-buffer-name buffer-name))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
195
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
196 (setq buffer (get-buffer-create buffer-name))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
197 (pop-to-buffer buffer-name)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
198
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
199 (cond
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
200 ((comint-check-proc buffer-name))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
201 (t
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
202 (comint-exec buffer buffer-name ssh-program nil args)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
203 (setq proc (get-buffer-process buffer))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
204 ;; Set process-mark to point-max in case there is text in the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
205 ;; buffer from a previous exited process.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
206 (set-marker (process-mark proc) (point-max))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
207
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
208 ;; comint-output-filter-functions is just like a hook, except that the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
209 ;; functions in that list are passed arguments. add-hook serves well
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
210 ;; enough for modifying it.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
211 ;; comint-output-filter-functions should already have a
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
212 ;; permanent-local property, at least in emacs 19.27 or later.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
213 (if (fboundp 'make-local-hook)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
214 (make-local-hook 'comint-output-filter-functions)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
215 (make-local-variable 'comint-output-filter-functions))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
216 (add-hook 'comint-output-filter-functions 'ssh-carriage-filter)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
217
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
218 (ssh-mode)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
219
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
220 (make-local-variable 'ssh-host)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
221 (setq ssh-host host)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
222 (make-local-variable 'ssh-remote-user)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
223 (setq ssh-remote-user user)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
224
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
225 (condition-case ()
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
226 (cond ((eq ssh-directory-tracking-mode t)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
227 ;; Do this here, rather than calling the tracking mode
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
228 ;; function, to avoid a gratuitous resync check; the default
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
229 ;; should be the user's home directory, be it local or remote.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
230 (setq comint-file-name-prefix
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
231 (concat "/" ssh-remote-user "@" ssh-host ":"))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
232 (cd-absolute comint-file-name-prefix))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
233 ((null ssh-directory-tracking-mode))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
234 (t
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
235 (cd-absolute (concat comint-file-name-prefix "~/"))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
236 (error nil))))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
237
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
238 (put 'ssh-mode 'mode-class 'special)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
239
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
240 (defun ssh-mode ()
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
241 "Set major-mode for ssh sessions.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
242 If `ssh-mode-hook' is set, run it."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
243 (interactive)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
244 (kill-all-local-variables)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
245 (shell-mode)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
246 (setq major-mode 'ssh-mode)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
247 (setq mode-name "ssh")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
248 (use-local-map ssh-mode-map)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
249 (setq shell-dirtrackp ssh-directory-tracking-mode)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
250 (make-local-variable 'comint-file-name-prefix)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
251 (run-hooks 'ssh-mode-hook))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
252
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
253 (defun ssh-directory-tracking-mode (&optional prefix)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
254 "Do remote or local directory tracking, or disable entirely.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
255
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
256 If called with no prefix argument or a unspecified prefix argument (just
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
257 ``\\[universal-argument]'' with no number) do remote directory tracking via
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
258 ange-ftp. If called as a function, give it no argument.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
259
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
260 If called with a negative prefix argument, disable directory tracking
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
261 entirely.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
262
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
263 If called with a positive, numeric prefix argument, e.g.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
264 ``\\[universal-argument] 1 M-x ssh-directory-tracking-mode\'',
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
265 then do directory tracking but assume the remote filesystem is the same as
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
266 the local system. This only works in general if the remote machine and the
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
267 local one share the same directories (through NFS)."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
268 (interactive "P")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
269 (cond
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
270 ((or (null prefix)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
271 (consp prefix))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
272 (setq ssh-directory-tracking-mode t)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
273 (setq shell-dirtrackp t)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
274 (setq comint-file-name-prefix
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
275 (concat "/" ssh-remote-user "@" ssh-host ":")))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
276 ((< prefix 0)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
277 (setq ssh-directory-tracking-mode nil)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
278 (setq shell-dirtrackp nil))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
279 (t
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
280 (setq ssh-directory-tracking-mode 'local)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
281 (setq comint-file-name-prefix "")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
282 (setq shell-dirtrackp t)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
283 (cond
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
284 (shell-dirtrackp
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
285 (let* ((proc (get-buffer-process (current-buffer)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
286 (proc-mark (process-mark proc))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
287 (current-input (buffer-substring proc-mark (point-max)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
288 (orig-point (point))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
289 (offset (and (>= orig-point proc-mark)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
290 (- (point-max) orig-point))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
291 (unwind-protect
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
292 (progn
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
293 (delete-region proc-mark (point-max))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
294 (goto-char (point-max))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
295 (shell-resync-dirs))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
296 (goto-char proc-mark)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
297 (insert current-input)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
298 (if offset
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
299 (goto-char (- (point-max) offset))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
300 (goto-char orig-point)))))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
301
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
302
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
303 ;; Parse a line into its constituent parts (words separated by
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
304 ;; whitespace). Return a list of the words.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
305 (defun ssh-parse-words (line)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
306 (let ((list nil)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
307 (posn 0)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
308 (match-data (match-data)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
309 (while (string-match "[^ \t\n]+" line posn)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
310 (setq list (cons (substring line (match-beginning 0) (match-end 0))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
311 list))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
312 (setq posn (match-end 0)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
313 (store-match-data (match-data))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
314 (nreverse list)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
315
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
316 (defun ssh-carriage-filter (string)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
317 (let* ((point-marker (point-marker))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
318 (end (process-mark (get-buffer-process (current-buffer))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
319 (beg (or (and (boundp 'comint-last-output-start)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
320 comint-last-output-start)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
321 (- end (length string)))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
322 (goto-char beg)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
323 (while (search-forward "\C-m" end t)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
324 (delete-char -1))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
325 (goto-char point-marker)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
326
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
327 (defun ssh-send-Ctrl-C ()
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
328 (interactive)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
329 (send-string nil "\C-c"))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
330
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
331 (defun ssh-send-Ctrl-D ()
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
332 (interactive)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
333 (send-string nil "\C-d"))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
334
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
335 (defun ssh-send-Ctrl-Z ()
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
336 (interactive)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
337 (send-string nil "\C-z"))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
338
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
339 (defun ssh-send-Ctrl-backslash ()
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
340 (interactive)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
341 (send-string nil "\C-\\"))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
342
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
343 (defun ssh-delchar-or-send-Ctrl-D (arg)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
344 "\
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
345 Delete ARG characters forward, or send a C-d to process if at end of buffer."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
346 (interactive "p")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
347 (if (eobp)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
348 (ssh-send-Ctrl-D)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
349 (delete-char arg)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
350
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
351 (defun ssh-tab-or-complete ()
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
352 "Complete file name if doing directory tracking, or just insert TAB."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
353 (interactive)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
354 (if ssh-directory-tracking-mode
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
355 (comint-dynamic-complete)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
356 (insert "\C-i")))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
357
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents:
diff changeset
358 ;;; ssh.el ends here