From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lars Wessman Newsgroups: gmane.emacs.help Subject: Re: Cocoa Emacs 23 and Tramp problem Date: Fri, 6 Mar 2009 14:57:28 -0800 (PST) Organization: http://groups.google.com Message-ID: <75409bc1-911e-46b6-abc4-5b8f2bf8decb@n33g2000vba.googlegroups.com> References: <86bpse70xj.fsf@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1236405401 5378 80.91.229.12 (7 Mar 2009 05:56:41 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 7 Mar 2009 05:56:41 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Mar 07 06:57:58 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LfpXo-0007nv-TP for geh-help-gnu-emacs@m.gmane.org; Sat, 07 Mar 2009 06:57:57 +0100 Original-Received: from localhost ([127.0.0.1]:44485 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LfpWT-0000by-Iq for geh-help-gnu-emacs@m.gmane.org; Sat, 07 Mar 2009 00:56:33 -0500 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!n33g2000vba.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 181 Original-NNTP-Posting-Host: 213.22.20.228 Original-X-Trace: posting.google.com 1236380248 31982 127.0.0.1 (6 Mar 2009 22:57:28 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Fri, 6 Mar 2009 22:57:28 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: n33g2000vba.googlegroups.com; posting-host=213.22.20.228; posting-account=wG1H1QoAAACHtUFAVnw-84TP3v9hG1d- User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/528.16 (KHTML, like Gecko) Version/4.0 Safari/528.16, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:167409 X-Mailman-Approved-At: Sat, 07 Mar 2009 00:54:55 -0500 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:62715 Archived-At: On Mar 6, 10:15=A0pm, Ted Zlatanov wrote: > On Fri, 6 Mar 2009 13:08:53 -0800 (PST) Lars Wessman wrote: > > LW> On Mar 6, 8:46=A0pm, "dericby...@gmail.com" > > LW> wrote: > >> On Mar 6, 6:35=A0pm, Lars Wessman wrote: > > >> (setq exec-path (cons "C:/path/to/ssh/dir" exec-path)) > > LW> No dice, unfortunately. > > Do you have SSH installed? =A0Where? =A0Use that path, not c:/... as the > example suggested. =A0If you need to install it, use Mac Ports. > > If it still doesn't work, post the result of > > M-: (executable-find "ssh") RET > > For me, it says "/usr/bin/ssh" but on MacOS X it may be elsewhere. > > Ted Yes, that is where ssh is located in OS X. The solution you suggested turned out to be on the right track though. I solved the problem by fishing some functions out of Aquamacs, a distribution which I knew had a functioning Tramp, for setting the path. Dave Reitter, the distribution's maintainer, explains in the comments that getting environment variables from the shell is not straightforward. Here is the code that did the trick, which I loaded from a separate file from .emacs: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defvar environment-temp-file nil) ;; (setq shell-file-name "/bin/bash") ;; (let ((debug-on-error)) (mac-read-environment-vars-from-shell)) ;; Reading the environment variables is complex, primarily due to ;; bugs in OS X. On some systems, starting the login shell and ;; printing all variables takes an hour, so we need to have a ;; timeout. However, starting the process asynchronuously using ;; `start-process' fails as well on some other systems. Hence the ;; need to run it with `call-process' and "&", storing the output in ;; a temporary file. ;; dr. 07/2008 (defun mac-read-environment-vars-from-shell () "Import the environment from the system's default login shell specified in `shell-file-name'." (setq environment-temp-file (make-temp-file "envvar-")) ;; running the shell with -l (to load the environment) (setq default-directory "~/") ; ensure it can be executed (message "Shell: %s" shell-file-name) (let* ((shell (or shell-file-name "/bin/bash")) ;; can shell-file- name be nil? (command (format "printenv >%s.tmp; mv %s.tmp %s" environment-temp-file environment-temp-file environment-temp-file))) (if (string-match ".*/\\(ba\\|z\\)sh" shell) (call-process shell nil 0 nil "-l" "-c" command) (if (or (string-match ".*/\\tcsh" shell) (string-match ".*/ksh" shell)) (call-process shell nil 0 nil ;; we can't start tcsh as a login shell ;; because it doesn't accept -l in combination ;; with a command. ;; call-process-region wouldn't work because it's ;; not interactive. "-c" command) (message "Could not retrieve login shell environment with login shell: %s" shell) ;; won't work for csh, because it doesn't take -l -c ... )))) ;; we call the process asynchronuously ;; using start-process does not work for unknown reasons: ;; sometimes it doesn't get the environment. ;; (mac-read-environment-vars-from-shell) ;; (sit-for 1) ;; (mac-read-environment-vars-from-shell-2) (defun mac-read-environment-vars-from-shell-2 () "Reads temporary file if it exists." (if (file-readable-p environment-temp-file) (prog1 (with-temp-buffer (condition-case nil (progn (insert-file-contents-literally environment-temp-file nil) (delete-file environment-temp-file)) (error nil)) (let ((num 0)) (if (eq (buffer-size) 0) (message "Warning: Login shell did not return environment.") (goto-char (point-min)) (while (re-search-forward "^[A-Za-z_0-9]+=3D()\s*[^\x]*? \s*}\s*$" nil t) (replace-match "..." nil nil)) (goto-char (point-min)) (while (search-forward-regexp "^\\([A-Za-z_0-9]+\\)=3D\\(.*\\)$" nil t) (setq num (1+ num)) (setenv (match-string 1) (if (equal (match-string 1) "PATH") (concat (match-string 2) ":" (getenv "PATH")) (match-string 2))))) (message "%d environment variables imported from login shell (%s)." num shell-file-name) (mac-post-environment-vars-function) num))) nil)) (defun mac-post-environment-vars-function () (mac-add-path-to-exec-path) (mac-add-local-directory-to-exec-path) ;; needed for CocoAspell ;; inferior workaround, until mac.c is fixed not to set INFOPATH any longer (if (equal (concat (mac-resources-path) "info") (getenv "INFOPATH")) (setenv "INFOPATH")) ;; when INFOPATH is set from outside, it will only load INFOPATH (let ((extra-dirs (list "~/Library/Application Support/Emacs/info" "/Library/Application Support/Emacs/info" (concat (mac-resources-path) "site-lisp/edit-modes/info") (concat (mac-resources-path) "info")))) (setq Info-default-directory-list (append extra-dirs Info-default-directory-list )) (when (getenv "INFOPATH") (setenv "INFOPATH" (apply 'concat (getenv "INFOPATH") (mapcar (lambda (x) (concat ":" x)) extra-dirs)))))) (defun mac-add-path-to-exec-path () "Add elements from environment variable `PATH' to `exec-path'." (let ((l (split-string (getenv "PATH") ":"))) (mapc (lambda (p) (unless (member p l) (nconc l (list p)))) exec-path) (setq exec-path l))) (defun mac-add-local-directory-to-exec-path () "Add /usr/locaL/bin to `exec-path'" (add-to-list 'exec-path "/usr/local/bin")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; And then I added this to my .emacs: (Mac-read-environment-vars-from-shell) (sit-for 1) (mac-read-environment-vars-from-shell-2) Three cheers for open source!