|
| 1 | +# Configuring Emacs TRAMP |
| 2 | +[Emacs TRAMP](https://www.emacswiki.org/emacs/TrampMode) is a method of running editing operations on a remote server. |
| 3 | + |
| 4 | +## Connecting To A Workspace |
| 5 | +To connect to your workspace first run: |
| 6 | + |
| 7 | +``` |
| 8 | +coder config-ssh |
| 9 | +``` |
| 10 | + |
| 11 | +Then you can connect to your workspace by its name in the format: `coder.<name>`. |
| 12 | + |
| 13 | +In Emacs type `C-x d` and then input: `/ssh:coder.<name>:` and hit enter. This will open up Dired on the workspace's home directory. |
| 14 | + |
| 15 | +## Directory Tracking |
| 16 | +### `ansi-term` |
| 17 | +If you run your terminal in Emacs via `ansi-term` then you might run into a problem where while SSH-ed into a workspace Emacs will not change its `default-directory` to open files in the directory your shell is in. |
| 18 | + |
| 19 | +To fix this: |
| 20 | + |
| 21 | +1. In your Emacs `init.el` file add: |
| 22 | + ```lisp |
| 23 | + (setq tramp-default-method "ssh") |
| 24 | + ``` |
| 25 | +2. Be sure to set the hostname on the workspace to the `coder.<name>` format: |
| 26 | + ```bash |
| 27 | + hostname coder.<name> |
| 28 | + ``` |
| 29 | +3. Next in the shell profile file on the workspace (ex., `~/.bashrc`) add the following: |
| 30 | + ```bash |
| 31 | + ansi_term_announce_host() { |
| 32 | + printf '\033AnSiTh %s\n' "$(hostname)" |
| 33 | + } |
| 34 | + |
| 35 | + ansi_term_announce_user() { |
| 36 | + printf '\033AnSiTu %s\n' "$USER" |
| 37 | + } |
| 38 | + |
| 39 | + ansi_term_announce_pwd() { |
| 40 | + printf '\033AnSiTc %s\n' "$PWD" |
| 41 | + } |
| 42 | + |
| 43 | + ansi_term_announce() { |
| 44 | + ansi_term_announce_host |
| 45 | + ansi_term_announce_user |
| 46 | + ansi_term_announce_pwd |
| 47 | + } |
| 48 | + |
| 49 | + cd() { command cd "$@"; ansi_term_announce_pwd; } |
| 50 | + pushd() { command pushd "$@"; ansi_term_announce_pwd; } |
| 51 | + popd() { command popd "$@"; ansi_term_announce_pwd; } |
| 52 | + |
| 53 | + ansi_term_announce |
| 54 | + ``` |
| 55 | + Ansi Term expects the terminal running inside of it to send escape codes to inform Emacs of the hostname, user, and working directory. The above code sends these escape codes and associated data whenever the terminal logs in and whenever the directory changes. |
0 commit comments