Jonathan Lam

Core Developer @ Hudson River Trading


Blog

Brain dump 1

On 6/5/2021, 2:20:39 PM

Return to blog


I used to have "brain dump" posts on my old blog, and I figure I'll do it again here. The reasoning behind this is that there are many small fragments of (hopefully interesting) thought that get built up. The process of doing the research necessary to form a blog post into a complete idea is especially prone to spawning these tidbits of unfinished thought.


Actor and Lisper: Shiro Kawai

Some website I looked at recently (probably looking something up about Emacs) using was built in Gauche Scheme, one of the distros I hadn't heard much about. The developer is named Shiro Kawai, which I thought was an interesting name1.

The most interesting fact about him is that he is a professional programmer and actor. I don't really think I've seen many programmers do much else (relevant quote), especially in the arts. What's more, he wrote some papers about how he uses Scheme in movie production. According to his interview on Uses This, he coding preference is Lisp (CL, Clojure, and Gauche of course) and these come up both in hobbyist and professional contexts. And he uses Emacs.

Seems like a really cool guy.


Org mode and project explorer for Emacs

These are two plugins I'd like to try.

Org mode seems impressively popular. It's an Emacs package that provides a notetaking (Org-anization) major mode for Emacs. In the context in which I saw it (coming up later in this brain dump), it was being used to generate a website with its publish feature. It's large enough that they use the term Worg (World of Org). From a quick glance it seems like a plaintext markup language like Markdown, but with Emacs features like embedded code snippet "panes" (I'm not sure what the correct term would be). Seem like a high learning curve though, with the number of features it seems to offer.

Another thing I've been looking at is project-explorer which does exactly what you think it does. I haven't tried this out either, but it looks very appealing as I'm not totally navigating buffers and windows2 in Emacs yet. My mode of navigation mostly comprises C-x o and C-x b, which is really inefficient with more than three buffers (usually I'm cross-referencing many more files than that) or when a term-mode buffer is open (then the C-x prefixes become C-c prefixes].


Vimscript vs. Emacs

When I was writing the two recent posts about Emacs (here, here), comparison to ViM was a frequent topic. I found a lot of good opinions about Emacs and ViM, but this post by Christopher Clark was well put.

Vimscript encapsulates the Vim commands (much like Emacs keyboard macros do) and they have a certain logic to them, as someone recently wrote they are designed to be “composable” their are verbs and nouns and they are generally used as pairs “dh” is delete-backward-character and the order is consistent. This is a really good feature of the Vi command set.

In Emacs lisp (elisp), you need to know the name of the command, it is probably close to delete-backward-character but the details can vary as in is it forward-search or search-forward. Even though I have used elisp for years and use it on an at least weekly if not always daily basis, I still find myself looking up some of the names if I haven’t used them is over a couple of days.

The running joke is that there is an Emacs command that does anything you want, you just have to know the obscure key combination that invokes it. Emacs people call that control-meta-cokebottle. However, that is equally true of elisp. There is probably an elisp package that does what you want, you just have to know which one it is and then what the function name in it is. The names are rarely consistent and many are only composable in the sense that all programming languages are.

However, some of the functions are 100s of lines long. My ask yes-or-no function is an example of that, because it has some “dwim” (do what I mean) aspects. Thus, my version of emacs has tens of thousands of lines of customization to make it work exactly what I want (and I actually have some old code that isn’t even incorporated in my current environment that is better than what I currently use, e.g. code that makes the kill ring indefinitely deep).

The relevant joke is APL is a diamond (bright, shiny, and hard) and it is nearly impossible to extend APL. Lisp is a ball of mud. You can add anything to a ball of mud and it is still a ball of mud. My emacs .init file is roughly proof of that.

As many have said, Emacs is not an editor it is a lisp interpreter (language environment) that just happens to do editing.


Words of Wisdom

Some terminology/techniques I learnt from work. I don't think any of these are proprietary so they can be shared here.

Not from work, but some other terms I've recently acquired.


A very similar website, by Yann Esposito

During one of my searches about Emacs and ViM, I stumbled across "Learn Vim Progressively" by Yann Esposito. I wasn't really looking for that post, but I immediately noticed that the website had a very similar feel to mine. The centered, narrow column of text; the plain text and minimal styling; the consistent simple header and footer across pages -- it felt very similar to this site. Going back to the homepage of the site, there are also posts about how the site was (statically) generated. originally, it was built on the framework called nanoc. The newer edition is based on the Org mode publish tool (this is how I encountered Org mode originally) and uses a Makefile to selectively build pages3.

In the last link, Yann puts forward some of the design guidelines for his website, which are basically a superset of mine. I was mostly focused on performance, readability, and consistency. Yann also proposes respecting privacy (no dependencies on external CSS/JS) and generates RSS (which I haven't done (yet)). He also describes his website as theme-switchable and frugal, and these also apply to my website even if they weren't conscious decisions.

The subject of some of the other blog posts include Haskell, Git, Vim, jQuery, so it seems like we have a lot in common! Like Shiro, it would be really cool to meet Yann.


My .emacs

This is after of using Emacs for the first time, so I can imagine that this'll grow pretty long eventually. It's currently mostly configuring packages, but I expect that there'll be custom keybindings and functions there in due time.

;;; add melpa repo
;;; use "M-x package-refresh-contents" before installing a package
(require 'package)
(add-to-list 'package-archives
	     '("melpa" . "https://melpa.org/packages/"))
(package-initialize)

;;; emacs customize subsystem
(custom-set-variables
 ;; hide initial start screen
 '(inhibit-startup-screen t)
 
 ;; good builtin theme
 '(custom-enabled-themes '(wombat))

 ;; default of 70 for fci is absurd
 '(fill-column 80)

 ;; add column indicator to modeline
 '(mode-line-format
   '("%e" mode-line-front-space mode-line-mule-info mode-line-client
     mode-line-modified mode-line-remote mode-line-frame-identification
     mode-line-buffer-identification "   " mode-line-position
     (vc-mode vc-mode) "  " mode-line-modes mode-line-misc-info
     mode-line-end-spaces "  %l:%c"))

 ;; currently installed packages
 '(package-selected-packages '(magit paredit geiser-chez)))

;;; slime setup
(global-display-line-numbers-mode)
(setq inferior-lisp-program "/usr/bin/sbcl")
(add-to-list 'load-path "/usr/share/emacs/site-lisp/slime/")
(require 'slime)
(slime-setup)

;;; paredit hooks: https://www.emacswiki.org/emacs/ParEdit
(autoload 'enable-paredit-mode "paredit"
  "Turn on pseudo-structural editing of Lisp code." t)
(add-hook 'emacs-lisp-mode-hook       #'enable-paredit-mode)
(add-hook 'eval-expression-minibuffer-setup-hook #'enable-paredit-mode)
(add-hook 'ielm-mode-hook             #'enable-paredit-mode)
(add-hook 'lisp-mode-hook             #'enable-paredit-mode)
(add-hook 'lisp-interaction-mode-hook #'enable-paredit-mode)
(add-hook 'scheme-mode-hook           #'enable-paredit-mode)

;;; paredit w/ slime repl
(add-hook 'slime-repl-mode-hook (lambda () (paredit-mode +1)))
(defun override-slime-repl-bindings-with-paredit ()
  (define-key slime-repl-mode-map
    (read-kbd-macro paredit-backward-delete-key) nil))
(add-hook 'slime-repl-mode-hook
	  'override-slime-repl-bindings-with-paredit)

;;; paredit w/ geiser repl
(add-hook 'geiser-repl-mode-hook #'enable-paredit-mode)

;;; auto-reload files
(global-auto-revert-mode)

;;; show 80-char limit
(global-display-fill-column-indicator-mode)

;;; disable toolbar, menubar, scrollbar -- I don't use my mouse
(tool-bar-mode -1)
(menu-bar-mode -1)
(scroll-bar-mode -1)

;;; display battery % in modeline; actually useful because
;;; I use this in full screen a lot
(display-battery-mode 1)

Another thing I would like to try with Emacs (but not directly related to .emacs) is to use an Emacs server. It seems like you'll be able to have a long-term Emacs session open without needing to keep the application (visibly) open, just like many IDEs do.


Footnotes

1. "shiro" = white and "kawaii" = cute in Japanese, although it's probably something different for a name.

2. What Emacs calls "windows," i.e., the panels that each contain a buffer in the Emacs editor. What I usually think of as a "window" Emacs calls a "frame."

3. In comparison, my very simple static website generator is probably much simpler than Org-publish, and I have yet to see how it would play with Makefiles due to its nested nature. But this is probably coming soon as the number of blog posts increases.


© Copyright 2023 Jonathan Lam