Emacs Config Updates

Highlights of recent config changes to my code editor, my text vehicle, my passion project: emacs.

Emacs to me is the gift that keeps on giving. 🎁 It is an old-school editor first published in 1985. The core is made of C, but most of the functionality is written in lisp. It is not only highly but extremely extensible.

This post is essentially a compilation of such config items written in lisp.

Naturally, there are tons of plugins. Helm, Magit and Org to name the ones at the top. Absolutely unmatched approaches to file browsing, git management and note taking, which perfectly fit with emacs’s approach to editing.

After now maybe 6+ years of using the editor and longer periods of no changes at all, I find my experience with this editor again renewed.

1

A new font: Fantasque sans!

img


(set-frame-font "-*-Fantasque Sans Mono-normal-normal-normal-*-17-*-*-*-m-0-iso10646-1" nil t) ;; current frame and future frames
(add-to-list 'default-frame-alist '(font . "-*-Fantasque Sans Mono-normal-normal-normal-*-17-*-*-*-m-0-iso10646-1" )) ;; default font for new frames
(set-face-attribute 'default t :font "-*-Fantasque Sans Mono-normal-normal-normal-*-17-*-*-*-m-0-iso10646-1" ) ;; default font for new frames

A fun and relaxed font which keeps things interesting. It’s wiggly lines are totally cool.

2

Finally, great AWS CDK editing! This is powered by Tide, which also opened me the door for Typescript development in Emacs in general.

img


(use-package tide
  :ensure t
  :config
  (global-set-key (kbd "TAB") #'company-indent-or-complete-common)
  (global-set-key (kbd "C-x p") #'tide-fix)
  :after (typescript-mode company flycheck)
  :hook ((typescript-mode . tide-setup)
         (typescript-mode . tide-hl-identifier-mode)
         (before-save . tide-format-before-save))
  )

The above is only the basic config. All the details here.

The above really satisfies all my current development needs. It can do:

  • syntax checking
  • auto-completion on tab
  • symbol refactoring
  • auto-formatting
  • quick fixes of problems in code

I had originally refrained from trying to set emacs up as an IDE for Typescript, since I had made some bad experiences trying to do so for Python. Those bad memories had held me back from trying the same for Typescript for almost a year. But this now works great! A quick setup, working defaults and good docs. Good also for editing typescript lambdas and apis.

For the meantime I had used VSCode as my Typescript IDE, and it was good, since it just had everything out of the box. Now though I can confidently switch back to emacs with this setup. The only thing I believe it cannot do is automatically install missing packages, but I’m fine with installing these from the terminal.

3

Next up: Opening a Terminal or File Browser at point. With emacs I frequently browse files at all sorts of different directories. Sometimes it comes in handy to open a shell or a file browser at whatever directory I am currently at.

(define-prefix-command 'fbr/launcher)
(define-key global-map "\C-xl" 'fbr/launcher)
(define-key fbr/launcher "o" 'fbr/open-file-dir)
(define-key fbr/launcher "t" 'fbr/open-terminal-in-working-dir)

(defun fbr/open-terminal-in-working-dir ()
  (if (string-equal system-type "darwin")
      (async-shell-command (concat "open -a iTerm " (file-name-directory (buffer-file-name))))
    ))

(defun fbr/open-file-dir ()
  (if (string-equal system-type "darwin")
      (async-shell-command (concat "open -a Finder " (file-name-directory (buffer-file-name))))
    ))

4

And last but not least I found a great emoji plugin! Run emojify-insert-emoji to insert UTF8 emojis anywhere!

(use-package emojify hello! 👋
  :hook (after-init . global-emojify-mode)
  :config
  (custom-set-variables
   '(emojify-display-style 'image)
   '(emojify-emoji-styles '(unicode)))
  )

I read somewhere that emacs will support emojis natively at one point, but for now I’m more than happy with this handy plugin!

The end

Time and time again I meet colleagues who use git without any shortcuts or tool - or even worse: a sub-par visual editor which abstracts and renames functionality. When I look at that, I am more than happy that I can rely on such a powerful commander over the years.

Just the other week I paired with a colleague who tried to check his aws cli configuration with only the Finder. Seeing him struggle to click through all the different folders for what felt like hours was a pain. Finding the home directory, enabling hidden files, I started to feel bad for even sending him on this quest. Then the opening and closing of one file at a time. I started to think about making coffee until he was done. 💤

Even keyboard navigation shortcuts for the shell (readline commands) seem to be widely unknown. Skipping words or lines, going to the start or end of line, or using the reverse search on the shell - those are the things that the shortcuts are for. As an engineer you shouldn’t really have to press your finger on an arrow key on a minute.

At least for me I’m happy that I got the chance to learn these shortcuts and I want to thank the great bearded man for it! 🙏🏻 For any colleague who would like to learn I will pay this forward. 🙌🏻

comments powered by Disqus