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
Prev Previous commit
Next Next commit
docs: Updated Emacs tips with code review
  • Loading branch information
Mainstay-Noah-Huppert committed Jul 28, 2022
commit c28a743cea659d8c7d9767df791ebd790561ffdd
42 changes: 30 additions & 12 deletions docs/ides/configuring-emacs-tramp.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,42 @@ 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.
In Emacs type `C-x d` and then input: `/-:coder.<name>:` and hit enter. This will open up Dired on the workspace's home directory.

### Using SSH
By default Emacs TRAMP is setup to use SCP to access files on the Coder workspace instance. However you might want to use SSH if you have a jumpbox or some other complex network setup.

To do so set the following in your Emacs `init.el` file:

```lisp
(setq tramp-default-method "ssh")
```

Then when you access the workspace instance via `/-:coder.<name>` Emacs will use SSH. Setting `tramp-default-method` will also tell `ansi-term` mode the correct way to access the remote when directory tracking.

## 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>
1. In your workspace Terraform template be sure to add the following:
```hcl
data "coder_workspace" "me" {
}

resource "coder_agent" "main" {
# ...
env {
name = "CODER_WORKSPACE_NAME"
value = data.coder_workspace.me.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:
2. Next in the shell profile file on the workspace (ex., `~/.bashrc` for Bash and `~/.zshrc` for Zsh) add the following:
```bash
ansi_term_announce_host() {
printf '\033AnSiTh %s\n' "$(hostname)"
printf '\033AnSiTh %s\n' "coder.$CODER_WORKSPACE_NAME"
}

ansi_term_announce_user() {
Expand All @@ -53,4 +68,7 @@ To fix this:

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.
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.

### `eshell`
The `eshell` mode will perform directory tracking by default, no additional configuration is needed.