~hristoast/hristoast

hristoast/site/blog/updating-my-custom-emacs-setup-part-one.html -rw-r--r-- 5.6 KiB
81430fb9Hristos N. Triantafillou A tip 15 days ago
                                                                                
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
<h1 id="title">Updating My Custom Emacs Setup - Part One: Upgrading Packages</h1>

<div id="dates">
  <span>Posted: <time id="post-date">2022-04-08</time></span>
</div>

<p id="post-excerpt">
  I've <a href="/blog/my-custom-emacs-setup/">previously written</a> about how it is viable to use a custom Emacs setup, but I didn't go too far into the details about what it's like to actually take that route. In this, the first post in a series on updating my custom Emacs setup, I'll talk about my workflow for upgrading packages to newer versions.
</p>

<div id="toc"></div>

<h3>Why Update?</h3>

<p>
  A wise man once told me, "never update anything". Indeed, why update anything in my Emacs setup at all? If things work just fine as-is, can't I just not update and chug along? Yeah I suppose I definitely could. After I've initially installed something, as long as I never delete it I'll have it on my computer. Every time I start Emacs, it will start the same way and run the same code. No problem, right?
</p>

<p>
  Despite the relative security of never updating, I still feel compelled to grab updates for various packages. I don't do it often, but a recent Flycheck release prompted me to review and update some stuff. So I guess my answer to the "why" is: I want the new goodies, but also if there's a problem I can roll back with relative ease, so why not.
</p>

<h3>Trying Out An Update</h3>

<p>
  So, I've decided I want to update some Emacs packages. What do I do? One of the big reasons I use <a href="https://github.com/raxod502/straight.el">straight.el</a> is for how it leverages version control so that you can have a lockfile for all of your package versions. When you install something, it goes into a specific directory where package source repositories live and the version is registered in a lockfile. On my system, packages live at <code>$HOME/.emacs.d/straight/repos</code>.
</p>

<p>First thing's first: I open up a terminal and <code>cd</code> to that directory, then I see what all is there. Several big name packages stand out, so one at a time I:</p>

<ul>
  <li><code>cd</code> into the repo directory for the package I want to update (e.g. <code>cd ctrlf</code>)</li>
  <li>Do a <code>git pull</code></li>
  <li>Look at <code>git log</code> to try and get an idea of what sort of changes have happened</li>
</ul>

<p>
  Most of the time, I'd be done at this point. There's always the possibility to check out a specific revision, but I usually go with whatever the latest code is.
</p>

<p>
  It's important to note that sometimes non-Elisp changes happen that are outside the control of the Emacs package ecosystem. A good example of this is when python-language-server was deprecated, and python-lsp-server became the new defacto. This is something one could easily miss while doing code pulls on package repos.
</p>

<p>
  With selected packages now updated, I'll then start a new (non-daemon) instance of Emacs and see how things are. At this point I'll try out modes that I know were updated to make sure they work as expected.
</p>

<h4>From Within Emacs</h4>

<p>
  Naturally, there's no need to leave Emacs for this process. One can simply issue <code>M-x straight-pull-package RET</code> (or <code>straight-pull-package-and-deps</code>) and then specify which package should be updated.
</p>

<h3>Saving Updates</h3>

<p>
  If everything looks good, I'll update the lock file with <code>M-x straight-freeze-versions RET</code>. The final step is to review the updated lockfile via Magit and commit if everything is satisfactory. It's not the most interesting diff you'll ever see, various commit shas will have been changed, but it does give you a nice high level overview of what's changed.
</p>

<p>
  Okay, that's it. Expecting more? I was too but that's really the entire workflow for updating.
</p>

<h3>Reverting Updates</h3>

<p>
  If for whatever reason you want to revert a package (and the lockfile hasn't been updated yet), all package versions can be restored to the versions specified in the lockfile with <code>M-x straight-thaw-versions RET</code>. This will revert things back to what you've got in the lockfile.
</p>

<p>
  If your lockfile is updated, you can simply revert whatever changes were made (you are using version control, right?).
</p>

<h3>Manual Intervention</h3>

<p>
  Sometimes you may end up needing to manually intervene when updating a package. In my experience it's pretty rare, but you should be prepared for the possibility. In my case I had to manually intervene when some repo changed their primary branch name, but if you've made local changes to any packages that'd be another instance where you may need to tell straight.el what to do. <span class="footnote"> <a href="https://github.com/raxod502/straight.el/blob/af5437f2afd00936c883124d6d3098721c2d306c/README.md#user-manual">The straight.el user manual</a> goes into great detail on how to do many advanced operations.</span>
</p>

<h3>Conclusion</h3>

<p>
  When I planned this post, I guess I thought there'd be more to talk about but this is really it. When you're using straight.el at least, the process of updating packages is pretty simple and boring. As I mentioned, I usually only think about updates when I see news about something updating, but it's great that I can have a simple, flexible update process along with the power and control I'm afforded by straight.el and <a href="https://github.com/jwiegley/use-package">use-package</a>.
</p>

<p>
  In part two of this series, I'll talk about updating my setup by way of adding something new. Until then, happy Emacsing!
</p>

<h3>Footnotes And References</h3>

<div id="footnotes"></div>