Skip to content

Commit 3bddcf2

Browse files
docs: added emacs notes
1 parent b19cf70 commit 3bddcf2

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

docs/ides.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ support should work:
1818
- WebStorm
1919
- Web IDEs (code-server, JupyterLab, Jetbrains Projector)
2020
- Note: These are [configured in the template](./ides/configuring-web-ides.md)
21+
- Emacs (with [TRAMP](./ides/configuring-emacs-tramp.md))
2122

2223
## SSH configuration
2324

docs/ides/configuring-emacs-tramp.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)