Skip to content

Instantly share code, notes, and snippets.

@ryuheechul
Last active January 27, 2023 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryuheechul/1363eec4e945b6840989d255cdbd09e3 to your computer and use it in GitHub Desktop.
Save ryuheechul/1363eec4e945b6840989d255cdbd09e3 to your computer and use it in GitHub Desktop.
Note about emacs
Context about Emacs and me I used a few text editors (with vim key bindings) lightly for a number of years and I started wanting more.

In 2016, I first stumbled upon Spacemacs and got hooked for a while. That was my first Emacs experience. Spacemacs was so user friendly that I didn't have to learn Emacs at all.

In 2017, I moved on to VSCode (with VSpaceCode) as it got popular. In 2019, I moved to [Neo]vim (with SpaceVim) mainly because of the better performance and it was a natural transition as I also started using Tmux and I started to refuse leaving terminals.

In 2021, I moved from SpaceVim to my own configuration as I continuously being drawn to optimizing performance of my tools and Neovim's potentials just exploded recently (after v0.5), so I took advantage of it. I'm very happy and quite productive with current setups thanks to Neovim and great plugins!

Very recently (April 2022) though, somehow I became curious about Emacs again and I realized I know nothing about it really (I'm still fresh off the boat!). So I opened Spacemacs again and I wasn't really satisfied with the performance and I discovered Doom Emacs - reading docs in Doom Emacs is a joy, I appreciate the transparency and the style - and I could see it fits more of my style than Spacemacs as I became more "advanced" and picky now. After this point, my curious brain had to play with Emacs even though I'm not in a situation that I need a better text editor just yet. I'm just in a mode of needing to know about what Emacs really is and how it survived for so long and how customizable/extensible really is.

So I'm learning and playing with it and customizing it to my liking slowly. I quickly realized I need to write things down as I learn, hence this gist.

By the way I still keep all the configurations of the editors that are mentioned above at my dotfiles (why not!) if you are curious to take a look.

Configurations

Native Compilation

https://www.emacswiki.org/emacs/GccEmacs enables native compliation and Emacs 28.1 brought this to upstream.

Why Would You Want

Are you not a fan of better performance?

Wait, it actually comes with a cost trade-off, too (at least the way I use Emacs now with doom sync) as compile time could be quite long depends on your system spec and the complexity of the pacakges, when you add new ones, as well as resource consumptions.

How It Works?

There is a talk from the developer and the key image to me is below.

Screen Shot 2022-04-22 at 19 00 53

The slide is captured from https://european-lisp-symposium.org/static/2020/corallo-nassi-manca-slides.pdf

How I Install via Nix

https://github.com/ryuheechul/dotfiles/commit/1e38e54f636638bc4630d27e29ce54676edb7c45#diff-ddae50e17a3144858c700034c42ca3daf977b684b39633ac87bc6d8a9d0b0821

((emacsPackagesFor (emacs.override { nativeComp = true; }))
  .emacsWithPackages (epkgs: [ epkgs.vterm ]))

How Is Native Compilation Different From Byte Compiling

Byte compiling for Emacs is explained at https://www.gnu.org/software/emacs/manual/html_node/eintr/Byte-Compiling.html. More generic information is found at https://en.wikipedia.org/wiki/Bytecode.

tl;dr:

NC

Native code refers to the compiled code that is only targeting for a specific architecture (i. e. x86_64, aarch64), once it's compiled, it only runs for that arch so you need to compile for each arch if your computers run on different CPU architectures. This additional step enables running your code close to the metal which enables the highest potential on performances. Can you speak your second language faster than your native tongue? Probably not, same goes for how our programs talk with computer hardwares.

In Emacs' case, the result of this file's extention is eln (el is for human readable Elisp file and native compliation compiles el to eln)

Byte Compiling

While native compilation of Elisp on Emacs is relatively new, byte compiling seems to be a thing that's been around for a while. when you byte compile, the result is elc (from your el). This is not (supposed to be) human readable and has performance adavantage as the purpose of it is to optimize how it runs compare to raw el. However it is still being intepreted at runtime so not as fast as native compilation. But elc is more portable as its compiled code shouldn't be different for different CPU architectures.

As I learned, I needed to make a note here and all these note might make me sounds like I know about what I'm talking about but that might not be the case as I literally just learned these things around the time of writing. So even if this might be helpful for you to orient with these concepts, don't blindly trust what I say as I consider myself a layman on both this subject and Emacs.

Tips

refer to tips.org

tips

emacs

Sandbox

Run emacs in sandbox via Doomemacs (for example, run a vanilla Emacs instance).

It works great to quickly test in different configurations. Just watch out that the new instance seems to open silently (at least on macOS).

Editing gist with (Doom) Emacs

  1. Enable https://github.com/doomemacs/doomemacs/tree/master/modules/tools/gist
  2. Follow (auth) instruction from https://github.com/defunkt/gist.el
  3. <Space> g l g to list gist and go from there

Enter insert mode to use its key bindings in case evil mode

When Emacs is Not Responding

like UI is hanging or frozen

i.e. network call is hung

C-g should work like C-c with shells in the terminal. So it might cancel the activity and give the responsiveness back to you.

evil-mode

(in case using Doomemacs) many keybinding information can be found at https://github.com/emacs-evil/evil-collection

And this is especially useful to navigate info properly https://github.com/emacs-evil/evil-collection/blob/master/modes/info/evil-collection-info.el

gL to list history

org-mode

Snippets

<s <tab> to begin source code block

Inline Images

https://davidbosman.fr/tux/emacs-orgmode-always-display-images/

misc

tramp

https://www.emacswiki.org/emacs/TrampMode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment