Skip to content

Added Emacs Tips Documentation #3247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Aug 1, 2022
Merged
1 change: 1 addition & 0 deletions docs/ides.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ support should work:
- WebStorm
- Web IDEs (code-server, JupyterLab, Jetbrains Projector)
- Note: These are [configured in the template](./ides/configuring-web-ides.md)
- Emacs (with [TRAMP](./ides/configuring-emacs-tramp.md))

## SSH configuration

Expand Down
56 changes: 56 additions & 0 deletions docs/ides/configuring-emacs-tramp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Configuring Emacs TRAMP
[Emacs TRAMP](https://www.emacswiki.org/emacs/TrampMode) is a method of running editing operations on a remote server.

## Connecting To A Workspace
To connect to your workspace first run:

```
coder config-ssh
```

Then you can connect to your workspace by its name in the format: `coder.<name>`.

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.

## Directory Tracking
### `ansi-term`
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.

To fix this:

1. In your Emacs `init.el` file add:
```lisp
(setq tramp-default-method "ssh")
```
2. Then on your Coder workspace instance be sure to set the hostname to the `coder.<name>` format:
```bash
hostname coder.<name>
```
This can also be done in the workspace Terraform template by setting workspace instance's hostname to the data `coder_workspace.name` attribute. How this is done depends on how the instance is provisioned.
3. Next in the shell profile file on the workspace (ex., `~/.bashrc`) add the following:
```bash
ansi_term_announce_host() {
printf '\033AnSiTh %s\n' "$(hostname)"
}

ansi_term_announce_user() {
printf '\033AnSiTu %s\n' "$USER"
}

ansi_term_announce_pwd() {
printf '\033AnSiTc %s\n' "$PWD"
}

ansi_term_announce() {
ansi_term_announce_host
ansi_term_announce_user
ansi_term_announce_pwd
}

cd() { command cd "$@"; ansi_term_announce_pwd; }
pushd() { command pushd "$@"; ansi_term_announce_pwd; }
popd() { command popd "$@"; ansi_term_announce_pwd; }

ansi_term_announce
```
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. The expression in step 1 lets Emacs know that you are accessing the hostname these escape codes announce via SSH.
7 changes: 6 additions & 1 deletion docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"title": "GitHub OAuth",
"description": "Learn how to set up OAuth using your GitHub organization.",
"path": "./install/oauth.md"
}
}
]
},
{
Expand Down Expand Up @@ -84,6 +84,11 @@
"title": "Configuring Web IDEs",
"description": "Learn how to configure web IDEs in your templates",
"path": "./ides/configuring-web-ides.md"
},
{
"title": "Configuring Emacs (with TRAMP)",
"description": "Learn how to configure Emacs in Coder",
"path": "./ides/configuring-emacs-tramp.md"
}
]
},
Expand Down