Commit | Line | Data |
---|---|---|
1556783e SBS |
1 | <!DOCTYPE html> |
2 | <meta charset="utf-8"> | |
3 | ||
4 | # Setup Instructions for `emacs` | |
5 | ||
6 | Created by [Steven Baltakatei Sandoval][bktei_2020_homepage] on 2020-04-16T23:13Z under a [CC BY-SA 4.0][cc_20131125_bysa] license and last updated on 2020-04-17T02:42Z. | |
7 | ||
8 | ## 1. Summary | |
9 | ||
10 | Emacs is a command line editor. This document contains instructions and files required to install and customize Emacs on GNU/Linux Debian 10 machines. | |
11 | ||
12 | ### 1.1. File list | |
13 | ||
14 | ./config-shared/emacs/home/.emacs.d/init.el # enables MELPA repository | |
15 | ./config-shared/emacs/home/.config/systemd/user/emacs.service # required for automatic daemon startup | |
16 | ./config-shared/emacs/home/.bash_aliases.appendme # contains alias for use with emacs daemon | |
17 | ||
18 | ## 2. Instructions | |
19 | ||
20 | ### 2.1. Install `emacs` package | |
21 | ||
22 | #### 2.1.a. Typical Debian install | |
23 | ||
24 | Use `$ sudo apt-get install emacs` to install `emacs`. | |
25 | ||
26 | #### 2.1.b. Headless Debian install (no GUI) | |
27 | ||
28 | Use `$ sudo apt-get install emacs-nox` to install `emacs` without an X window manager. This may be useful if emacs is to be used via command-line only such as a machine without a monitor to which a use connects via `ssh`. | |
29 | ||
30 | ### 2.2. Enable MELPA package repository | |
31 | ||
32 | MELPA is a package repository for packages that add functionality to `emacs`. Detailed instructions for installing it may be found at melpa.org.<sup>[[1]](#melpa_2019_setupinst)</sup> | |
33 | ||
34 | #### 2.2.a. Typical install | |
35 | ||
36 | Create and/or edit the `~/.emacs.d/init.el` file to include the following text elisp code: | |
37 | ||
38 | (require 'package) | |
39 | (let* ((no-ssl (and (memq system-type '(windows-nt ms-dos)) | |
40 | (not (gnutls-available-p)))) | |
41 | (proto (if no-ssl "http" "https"))) | |
42 | (when no-ssl (warn "\ | |
43 | Your version of Emacs does not support SSL connections, | |
44 | which is unsafe because it allows man-in-the-middle attacks. | |
45 | There are two things you can do about this warning: | |
46 | 1. Install an Emacs version that does support SSL and be safe. | |
47 | 2. Remove this warning from your init file so you won't see it again.")) | |
48 | (add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t) | |
49 | ;; Comment/uncomment this line to enable MELPA Stable if desired. See `package-archive-priorities` | |
50 | ;; and `package-pinned-packages`. Most users will not need or want to do this. | |
51 | ;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t) | |
52 | ) | |
53 | (package-initialize) | |
54 | ||
55 | A copy of this text is contained within the `./config-shared/emacs/home/.emacs.d/init.el` file in this repository. A command to copy this code to a completely new system is below. | |
56 | ||
57 | $ mkdir ~/.emacs.d | |
58 | $ cp ./config-shared/emacs/home/.emacs.d/init.el ~/.emacs.d/init.el | |
59 | ||
60 | Run `M-x package-refresh-contents` (can be run from bash via `$ emacs -nw --eval '(progn (package-refresh-contents) (kill-emacs))'`) to download MELPA package list.<sup>[[2]](#se_20161221_emacsclimultieval)</sup> | |
61 | ||
62 | ### 2.3. Configure `emacs` daemon and `emacsclient` | |
63 | ||
64 | A convenient way to share buffers between different shells (ex: across guake and Terminal) is to edit files using multiple instances of `emacsclient`<sup>[[4]](#emacswiki_20200325_emacsclient)</sup> which each communicate with a single instance of `emacs --daemon`<sup>[[3]](#emacswiki_20200408_emacsdaemon)</sup>. An instance of `emacsclient` running in `guake` may crash due to a problem with `guake` but the text buffer being edited by the user will not be lost since it is maintained by `emacs --daemon`. To regain access to the buffer, one must only start another instance of `emacsclient` and switch to the buffer (ex: via `C-x b`). | |
65 | ||
66 | #### 2.3.a. Create `emacs` daemon as a user service. | |
67 | ||
68 | Create the `~/.config/systemd/user/emacs.service` file to be the following text: | |
69 | ||
70 | [Unit] | |
71 | Description=Emacs text editor | |
72 | Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/ | |
73 | ||
74 | [Service] | |
75 | Type=forking | |
76 | ExecStart=/usr/bin/emacs --daemon | |
77 | ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)" | |
78 | Encopy itvironment=SSH_AUTH_SOCK=%t/keyring/ssh | |
79 | Restart=on-failure | |
80 | ||
81 | [Install] | |
82 | WantedBy=default.target | |
83 | ||
84 | This text is contained in this repository directory as `./config-shared/emacs/home/.config/systemd/user/emacs.service`. This file may be installed using the following command. | |
85 | ||
86 | $ cp ./config-shared/emacs/home/.config/systemd/user/emacs.service ~/.config/systemd/user/emacs.service | |
87 | ||
88 | Enable and start this service by running the following commands. | |
89 | ||
90 | systemctl enable --user emacs | |
91 | systemctl start --user emacs | |
92 | ||
93 | Successful running of this command should produce something like the following messages: | |
94 | ||
95 | Created symlink /home/baltakatei/.config/systemd/user/default.target.wants/emacs.service → /home/baltakatei/.config/systemd/user/emacs.service. | |
96 | ||
97 | A new process named `/usr/bin/emacs --daemon` should appear in `$ ps -aux | grep emacs` output. This process should appear automatically upon login. | |
98 | ||
99 | In order to use the daemon to edit a text file in the command line, the following command should be used. | |
100 | ||
101 | $ emacsclient -nw | |
102 | ||
103 | #### 2.3.b. Create `emacsclient` alias. | |
104 | ||
105 | Typing `emacsclient` instead of just `emacs` is inconvenient. Therefore, it's recommended to make an alias. | |
106 | ||
107 | ##### 2.3.b.i. `bash` alias | |
108 | ||
109 | If `bash` is your primary shell, then the alias can be included in the `~/.bash_aliases` file. The alias can be included by appending the `./config-shared/emacs/home/.bash_aliases.appendme` text file in this repository directory to the `~/.bash_aliases` file in the home directory. The following command may be used to to perform this append operation. | |
110 | ||
111 | $ cat ./config-shared/emacs/home/.bash_aliases.appendme >> ~/.bash_aliases | |
112 | ||
113 | The relevant portion of the `./config-shared/emacs/home/.bash_aliases.appendme` file is below. | |
114 | ||
115 | alias emacs='emacsclient -create-frame --alternate-editor=""' | |
116 | ||
117 | ## 3. Conclusion. | |
118 | ||
119 | Emacs should now be configured to run automatically in the background as a daemon upon login. | |
120 | ||
121 | ## 4. References | |
122 | ||
123 | - <a name="melpa_2019_setupinst">1.</a> ["Getting started"][1]. https://melpa.org . Access date: 2020-04-17. [Archive link](https://web.archive.org/web/20200325114522/https://melpa.org/#/getting-started). Archive date: 2020-03-25. | |
124 | - <a name="se_20161221_emacsclimultieval">2.</a> ["emacs --eval of multiple functions on command line"][2]. Stack Exchange. Access date: 2020-04-17. [Archive link](https://web.archive.org/web/20200417002001/https://emacs.stackexchange.com/questions/29465/emacs-eval-of-multiple-functions-on-command-line/29467) | |
125 | - <a name="emacswiki_20200408_emacsdaemon">3.</a> ["Emacs As Daemon"][3]. EmacsWiki. Access date: 2020-04-17. License: GPLv2. [Archive link](https://web.archive.org/web/20200303223315/https://www.emacswiki.org/emacs/EmacsAsDaemon). Archive date: 2020-03-03. | |
126 | - <a name="emacswiki_20200325_emacsclient">4.</a> ["Emacs Client"][4]. EmacsWiki. Access date: 2020-04-17. License: GPLv2. [Archive link](https://web.archive.org/web/20190804144010/https://www.emacswiki.org/emacs/EmacsClient). Archive date: 2019-08-04. | |
127 | ||
128 | ||
129 | [1]: https://melpa.org/#/getting-started | |
130 | [2]: https://emacs.stackexchange.com/a/29467 | |
131 | [3]: https://www.emacswiki.org/emacs/EmacsAsDaemon | |
132 | [4]: https://www.emacswiki.org/emacs/EmacsClient | |
133 | [bktei_2020_homepage]: http://baltakatei.com | |
134 | [cc_20131125_bysa]: http://creativecommons.org/licenses/by-sa/4.0/ | |
135 | ||
136 | ||
137 | <hr> | |
138 | <p xmlns:dct="http://purl.org/dc/terms/" xmlns:cc="http://creativecommons.org/ns#">This work by <a rel="cc:attributionURL" href="http://baltakatei.com"><span rel="cc:attributionName">Steven Baltakatei Sandoval</span></a> is licensed under <a href="https://creativecommons.org/licenses/by-sa/4.0/?ref=ccchooser" target="_blank" rel="license noopener noreferrer" style="display: inline-block;">CC BY-SA 4.0</a><a href="https://creativecommons.org/licenses/by-sa/4.0/?ref=ccchooser"><img style="height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7;" src="https://search.creativecommons.org/static/img/cc_icon.svg" /><img style="height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7;" src="https://search.creativecommons.org/static/img/cc-by_icon.svg" /><img style="height:22px!important;margin-left: 3px;vertical-align:text-bottom;opacity:0.7;" src="https://search.creativecommons.org/static/img/cc-sa_icon.svg" /></a></p> |