-
Notifications
You must be signed in to change notification settings - Fork 1
/
tag-emacs.html
356 lines (319 loc) · 14.5 KB
/
tag-emacs.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="alternate"
type="application/rss+xml"
href="https://chenyo.me/rss.xml"
title="RSS feed for https://chenyo.me">
<title>Chenyo's Blog</title>
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'],['\\(','\\)']]}});
</script>
<meta name="author" content="chenyo">
<meta name="referrer" content="no-referrer">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="assets/style.css" type="text/css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"/>
<link rel="favicon" type="image/x-icon" href="favicon.ico">
<script src="assets/search.js"></script></head>
<body>
<div id="preamble" class="status">
<header>
<h1><a href="https://chenyo.me">Chenyo's org-static-blog</a></h1>
<nav>
<a href="https://chenyo.me">Home</a>
<a href="archive.html">Archive</a>
<a href="tags.html">Tags</a>
<div id="search-container">
<input type="text" id="search-input" placeholder="Search anywhere...">
<i class="fas fa-search search-icon"></i>
</div>
</nav>
</header></div>
<div id="content">
<h1 class="title">Posts tagged "emacs":</h1>
<div class="post-date">07 Sep 2024</div><h1 class="post-title"><a href="https://chenyo.me/2024-09-07-install-doom-emacs-with-lisp-native-compiler-in-wsl2.html">Install Doom Emacs with Lisp native compilation in WSL2</a></h1>
<nav id="table-of-contents" role="doc-toc">
<h2>Table of Contents</h2>
<div id="text-table-of-contents" role="doc-toc">
<ul>
<li><a href="#org967b036">1. Assumptions</a></li>
<li><a href="#org9d97c4c">2. Install prerequisite packages</a></li>
<li><a href="#org98ff32c">3. Install Emacs 29.4</a>
<ul>
<li><a href="#org140f84e">3.1. Before building</a></li>
<li><a href="#org702e974">3.2. Build Emacs 29.4 with native-comp</a></li>
</ul>
</li>
<li><a href="#orge6212e6">4. Install <code>ripgrep</code></a></li>
<li><a href="#org5750277">5. Install Doom Emacs</a></li>
<li><a href="#org219c7a4">6. Some issues with running Emacs in WSL2</a></li>
</ul>
</div>
</nav>
<p>
Today I installed Doom Emacs for my husband on his WSL2.
Although the entire process was guided by Claude, there were some back-and-forth during the interaction.
Therefore I would like to record the full commands I have used here in sequence for any potential reference.
</p>
<div id="outline-container-org967b036" class="outline-2">
<h2 id="org967b036"><span class="section-number-2">1.</span> Assumptions</h2>
<div class="outline-text-2" id="text-1">
<p>
This installation guide assumes a fresh installation of WSL2 Ubuntu 22.04 on Windows 11 in 2024 September.
</p>
</div>
</div>
<div id="outline-container-org9d97c4c" class="outline-2">
<h2 id="org9d97c4c"><span class="section-number-2">2.</span> Install prerequisite packages</h2>
<div class="outline-text-2" id="text-2">
<p>
According to the Doom Emacs <a href="https://github.com/doomemacs/doomemacs#prerequisites">documentation</a>, the following packages are recommended:
</p>
<ul class="org-ul">
<li>Git 2.23+: this is already installed by default.</li>
<li>Emacs 29.4 with <a href="https://www.emacswiki.org/emacs/GccEmacs">Lisp native compilation</a>: this is finicky and will be elaborated later.</li>
<li>ripgrep 14.0+: the documentation says 11.0+ suffices, but <code>doom doctor</code> still complains the latest version (13.0) installed from <code>apt</code> is not advanced, so we need to install it from its Github released package later.</li>
<li>GNU find: also installed already.</li>
<li>fd: <code>sudo apt install fd-find</code> suffices.</li>
</ul>
</div>
</div>
<div id="outline-container-org98ff32c" class="outline-2">
<h2 id="org98ff32c"><span class="section-number-2">3.</span> Install Emacs 29.4</h2>
<div class="outline-text-2" id="text-3">
</div>
<div id="outline-container-org140f84e" class="outline-3">
<h3 id="org140f84e"><span class="section-number-3">3.1.</span> Before building</h3>
<div class="outline-text-3" id="text-3-1">
<p>
First, let’s install some build dependencies:
</p>
<div class="org-src-container">
<pre class="src src-bash"><span style="color: #ECBE7B;">sudo</span> apt update
<span style="color: #ECBE7B;">sudo</span> apt upgrade <span style="color: #5B6268;"># </span><span style="color: #5B6268;">update packages</span>
<span style="color: #ECBE7B;">sudo</span> apt install build-essential libjansson4 libjansson-dev <span style="color: #98be65;">\</span>
libgnutls28-dev libtree-sitter-dev libsqlite3-dev
<span style="color: #ECBE7B;">sudo</span> apt install texinfo <span style="color: #5B6268;"># </span><span style="color: #5B6268;">to generate documentation</span>
</pre>
</div>
<p>
<code>build-essnetial</code> should install necessary tools to build C/C++ programs such as gcc, g++, make, gdb and dpkg.
The rest packages install pre-compiled libraries.
</p>
<p>
Besides these packages, there are two important packages to support Lisp native compilation:
</p>
<div class="org-src-container">
<pre class="src src-bash"><span style="color: #ECBE7B;">sudo</span> apt install ibgccjit0 libgccjit-11-dev <span style="color: #5B6268;"># </span><span style="color: #5B6268;">11 is my gcc version</span>
</pre>
</div>
<p>
After installing them, make sure to export the path in the current session, otherwise the compiler will not realize it.
</p>
<div class="org-src-container">
<pre class="src src-bash"><span style="color: #c678dd;">export</span> <span style="color: #dcaeea;">LD_LIBRARY_PATH</span>=/usr/lib/gcc/x86_64-linux-gnu/11:$<span style="color: #dcaeea;">LD_LIBRARY_PATH</span>
</pre>
</div>
<p>
The last thing to do is install a bunch of X and GTK-3 development libraries for Emacs GUI, and another bunch of image processing libraries.
</p>
<div class="org-src-container">
<pre class="src src-bash"><span style="color: #ECBE7B;">sudo</span> apt install libx11-dev libtiff-dev libgtk-3-dev libncurses-dev
<span style="color: #ECBE7B;">sudo</span> apt install libtiff5-dev libgif-dev libjpeg-dev libpng-dev libxpm-dev
</pre>
</div>
<p>
Without the above packages, one may encounter the following error when configuring the Emacs build:
</p>
<blockquote>
<p>
You seem to be running X, but no X development libraries
were found. You should install the relevant development files for X
and for the toolkit you want, such as Gtk+ or Motif. Also make
sure you have development files for image handling, i.e.
tiff, gif, jpeg, png and xpm.
</p>
</blockquote>
</div>
</div>
<div id="outline-container-org702e974" class="outline-3">
<h3 id="org702e974"><span class="section-number-3">3.2.</span> Build Emacs 29.4 with native-comp</h3>
<div class="outline-text-3" id="text-3-2">
<p>
At this moment, we can start to download Emacs source code:
</p>
<div class="org-src-container">
<pre class="src src-bash">wget https://ftp.gnu.org/gnu/emacs/emacs-29.4.tar.xz
tar xvf emacs-29.4.tar.xz
<span style="color: #ECBE7B;">cd</span> emacs-29.4
</pre>
</div>
<p>
Then we can configure the build (i.e., generate Makefile) with the following command.
</p>
<div class="org-src-container">
<pre class="src src-bash">./configure --with-native-compilation --with-x-toolkit=gtk3 --without-pop
</pre>
</div>
<ul class="org-ul">
<li><code>--with-native-compilation</code>: with this flag the Emacs source code is compiled to native machine code to achieve better performance.
<ul class="org-ul">
<li>Otherwise it is compiled to bytecode and then interpreted by Emacs virtual machine during runtime.</li>
</ul></li>
<li><code>--with-x-toolkit=gtk3</code>: this is recommended by Claude.</li>
<li><code>--without-pop</code>: if we are not using Emacs as the email client, we don’t need to bother configure the protocol.</li>
</ul>
<p>
If everything goes well, one should see the following line in the output.
If not, make sure <code>libgccjit</code> has been installed and exported.
</p>
<blockquote>
<p>
Does Emacs have native lisp compiler? yes
</p>
</blockquote>
<p>
Now we can finally start compiling the Emacs:
</p>
<div class="org-src-container">
<pre class="src src-bash"><span style="color: #ECBE7B;">make</span> -j$<span style="color: #51afef;">(</span>nproc<span style="color: #51afef;">)</span>
</pre>
</div>
<p>
If some error occurs, we may want to start again, to do this:
</p>
<div class="org-src-container">
<pre class="src src-bash"><span style="color: #ECBE7B;">sudo</span> apt install autoconf automake
<span style="color: #ECBE7B;">rm</span> -f Makefile
./autogen.sh <span style="color: #5B6268;"># </span><span style="color: #5B6268;">regenerate the configuration file</span>
<span style="color: #5B6268;"># </span><span style="color: #5B6268;">then rebuild</span>
<span style="color: #ECBE7B;">make</span> -j$<span style="color: #51afef;">(</span>nproc<span style="color: #51afef;">)</span>
</pre>
</div>
<p>
Finally, install Emacs globally:
</p>
<div class="org-src-container">
<pre class="src src-bash"><span style="color: #ECBE7B;">sudo</span> <span style="color: #ECBE7B;">make</span> install
</pre>
</div>
<p>
To confirm the Emacs indeed used the native Lisp compiler, one can evaluate inside the vanilla Emacs with <code>M-:</code> (<code>M</code> is <code>Alt</code> in WSL2):
</p>
<div class="org-src-container">
<pre class="src src-lisp">(native-comp-available-p) <span style="color: #5B6268;">;; </span><span style="color: #5B6268;">should return t</span>
</pre>
</div>
<p>
Congratulations! You have now installed the latest and fastest Emacs on WSL2.
</p>
</div>
</div>
</div>
<div id="outline-container-orge6212e6" class="outline-2">
<h2 id="orge6212e6"><span class="section-number-2">4.</span> Install <code>ripgrep</code></h2>
<div class="outline-text-2" id="text-4">
<p>
As mentioned in ripgrep <a href="https://github.com/BurntSushi/ripgrep?tab=readme-ov-file#installation">documentation</a>, for Debian/Ubuntu users, one should
install the latest ripgrep 14.0+ with the following commands.
</p>
<div class="org-src-container">
<pre class="src src-bash"><span style="color: #ECBE7B;">curl</span> -LO https://github.com/BurntSushi/ripgrep/releases/download/14.1.0/ripgrep_14.1.0-1_amd64.deb <span style="color: #5B6268;"># </span><span style="color: #5B6268;">check the latest version on its documentation</span>
<span style="color: #ECBE7B;">sudo</span> dpkg -i ripgrep_14.1.0-1_amd64.deb <span style="color: #5B6268;"># </span><span style="color: #5B6268;">dpkg has been installed before</span>
</pre>
</div>
<p>
Instead, if one installs it with <code>apt</code>, a 13.0+ version is installed and running <code>doom doctor</code> later returns the warning:
</p>
<blockquote>
<p>
The installed ripgrep binary was not built with support for PCRE lookaheads.
</p>
</blockquote>
</div>
</div>
<div id="outline-container-org5750277" class="outline-2">
<h2 id="org5750277"><span class="section-number-2">5.</span> Install Doom Emacs</h2>
<div class="outline-text-2" id="text-5">
<p>
Installing Doom Emacs is straightforward, but before that, one should first remove the default Emacs configuration folder:
</p>
<div class="org-src-container">
<pre class="src src-bash"><span style="color: #ECBE7B;">rm</span> -rf ~/.emacs.d
</pre>
</div>
<p>
Then, clone and install Doom Emacs, it could take a while.
</p>
<div class="org-src-container">
<pre class="src src-bash"><span style="color: #ECBE7B;">git</span> clone --depth <span style="color: #da8548; font-weight: bold;">1</span> https://github.com/doomemacs/doomemacs ~/.config/emacs
~/.config/emacs/bin/doom install
</pre>
</div>
<p>
Don’t forget to export <code>~/.config/emacs/bin</code> to <code>PATH</code>:
</p>
<div class="org-src-container">
<pre class="src src-bash"><span style="color: #ECBE7B;">echo</span> <span style="color: #98be65;">'export PATH="$HOME/.config/emacs/bin:$PATH"'</span> >> ~/.bashrc
<span style="color: #c678dd;">source</span> ~/.bashrc
</pre>
</div>
<p>
Now one can run <code>doom doctor</code> to check any missing dependencies, e.g., <code>shellcheck</code>.
One common issue is the Nerd font is not installed by default so that some icons are not properly displayed.
To fix that, run <code>M-x nerd-icons-install-font</code> inside the Emacs, then update the font cache with:
</p>
<div class="org-src-container">
<pre class="src src-bash">fc-cache -fv
<span style="color: #5B6268;"># </span><span style="color: #5B6268;">fc-list | </span><span style="color: #5B6268;">grep</span><span style="color: #5B6268;"> Nerd # to verify the font is installed</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org219c7a4" class="outline-2">
<h2 id="org219c7a4"><span class="section-number-2">6.</span> Some issues with running Emacs in WSL2</h2>
<div class="outline-text-2" id="text-6">
<ul class="org-ul">
<li><p>
The first thing is I cannot reload the configuration with <code>M-x doom/reload</code> as running this command always gives me the following error message so that I need to restart the Emacs every time the configuration is changed.
</p>
<blockquote>
<p>
%s sync -B -e
/bin/bash: line 1: fg: no job control
</p>
</blockquote></li>
<li>I really dislike the <a href="https://www.reddit.com/r/wsl2/comments/16b4skx/wsl_softwares_with_white_window_borders/">white border</a> that surrounds any application launched by WSL!</li>
</ul>
</div>
</div>
<div class="taglist"><a href="https://chenyo.me/tags.html">Tags</a>: <a href="https://chenyo.me/tag-linux.html">linux</a> <a href="https://chenyo.me/tag-emacs.html">emacs</a> <a href="https://chenyo.me/tag-tool.html">tool</a> </div><div id="archive">
<a href="https://chenyo.me/archive.html">Other posts</a>
</div>
</div>
<div id="postamble" class="status"><div id="search-results"></div>
<footer>
<div class="footer-content">
<div class="footer-left">
<p>© 2024 chenyo. Some rights reserved.</p>
<a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/">
<img alt="Creative Commons License" style="border-width: 0"
src="https://i.creativecommons.org/l/by-nc/4.0/88x31.png"/>
</a>
</div>
<div class="social-links">
<a href="https://t.me/chenyo17" target="_blank" rel="noopener noreferrer">
<i class="fab fa-telegram"></i>
</a>
<a href="https://github.com/chenyo-17" target="_blank" rel="noopener noreferrer">
<i class="fab fa-github"></i>
</a>
</div>
</footer></div>
</body>
</html>