alexkarle.com

Source for alexkarle.com
git clone git://git.alexkarle.com/alexkarle.com.git
Log | Files | Refs | README | LICENSE

exploring-plan9.txt (9109B) [raw]


      1 # Exploring Acme, Plan 9, and `NO_COLOR`
      2 
      3 _Published: April 19, 2022_
      4 
      5 For the past couple months I've been exploring Plan 9, a distributed
      6 operating system from Bell Labs from the same group that developed
      7 UNIX and C. It's been a pretty deep rabbit hole, so I thought I'd
      8 write about it here.
      9 
     10 ## How it Started
     11 
     12 It all started with an interest in tooling. I'm generally really
     13 interested in human-computer interaction, and Plan 9 presents a
     14 radically different approach to using a computer. I watched Russ
     15 Cox's [Tour of Acme](https://research.swtch.com/acme) (a text editor
     16 that was written for Plan 9) and was blown away by the way the
     17 plumber allowed hyperlinking plain text through a simple rule-based
     18 system. If you haven't seen Acme in use, I'd highly recommend
     19 watching that first.
     20 
     21 After reading everything I could about Acme, I knew I wanted to
     22 give it a try, so I downloaded
     23 [plan9port](https://9fans.github.io/plan9port/) (a userspace port
     24 of many Plan 9 programs) and tried to integrate it into my workflow.
     25 
     26 ## Early Days: Trying out Acme
     27 
     28 Trying to code in Acme was immediately jarring. I had grown fond
     29 of dark themes and syntax highlighting, so the cream colored
     30 background with plain black text seemed washed out.
     31 
     32 After the shock of the colors came the reality check: I'm no good
     33 with a mouse, and Acme requires precise mouse use.  Acme not only
     34 needs a three button mouse (select, execute, and plumb/open), but
     35 common operations like copy/paste use mouse chording (i.e. button 1
     36 and 3 at the same time).
     37 
     38 Now, I've invested countless hours into learning Vim and have years
     39 of muscle memory built up. I've chosen keyboard-driven tools wherever
     40 possible. So to type on something that lacks what would be considered
     41 primitive keyboard motions (up/down scroll, don't move the cursor)
     42 was a huge adjustment.
     43 
     44 Even so, that wasn't the end of my trial. I swapped my trackball
     45 for a real mouse and gave it an earnest shot. I really enjoyed the
     46 right-click to plumb and grew fond of the colors and simple stacking
     47 interface.
     48 
     49 There was also a certain appeal to it's take on extensions--rather
     50 than have an extension language like VimL or Emacs Lisp, Acme
     51 presents it's contents to other processes as files on a filesystem.
     52 The user can write programs in any language to interact with Acme,
     53 which is so cool.
     54 
     55 Unfortunately, I didn't have the time to invest into fully customizing
     56 Acme via scripts. And given the spartan interface, I really did
     57 need to to continue to use it. For example, the TAB key inputs TAB
     58 characters.  To write Python you'd need to use a script to convert
     59 them to spaces.  Ultimately, I chose to crawl back to tools I was
     60 familiar with.
     61 
     62 ## Middle Ground: Bringing Acme to my Tools
     63 
     64 Acme was too hard to transition to, but I was still bent on bringing
     65 the benefits to my existing tools. I focused on two things:
     66 
     67 1. Building a "plumber" (to decide how to open/display things)
     68 2. Trying out the monochrome colors
     69 
     70 ### Building The Plumber
     71 
     72 This turned out to be rather easy. The key realization was that
     73 `tmux(1)` allows external programs to manipulate the session.  So
     74 with `tmux` as my replacement for acme-windows, I was able to write
     75 a [`plumb`](https://git.sr.ht/~akarle/dotfiles/tree/main/item/bin/plumb)
     76 script that takes in text from the `tmux` selection and opens it
     77 in the browser if it's a URL, `vi` in a new split if it's a file,
     78 `man` if it's a man-page, `git show` if it's a SHA, etc.
     79 
     80 To make this useful, I paired it with several hotkeys that use the
     81 `search-backward` `tmux` command to search for all instances of a
     82 `plumb`-able object. For example, `prefix-H` finds URLs in the
     83 scrollback:
     84 
     85 	bind-key H copy-mode \; send-keys -X search-backward "http[^ ]*"
     86 
     87 Then the `'a'` key in `copy-mode` (while searching) sends the URL
     88 to `plumb`:
     89 
     90 	bind-key -T copy-mode-vi a send-keys -X copy-pipe-no-clear "plumb #{pane_current_path}"
     91 
     92 After a couple months of use, I've found that while searching for
     93 man pages and git-sha's are a cool screensharing trick, I only
     94 really use the URL search. For files, it's nifty that I can teach
     95 `tmux` to open the output of `grep -n` to the exact line, but I've
     96 found that I generally don't want that many Vim's kicking around.
     97 
     98 In other words: Acme did it better. `tmux` can create the splits,
     99 but it doesn't feel cohesive since not all splits are editable.
    100 
    101 ### My Life in Monochrome
    102 
    103 This was a fun experiment. Apologies upfront to Cal, my work friend
    104 who had to go through it with me while we paired a feature :)
    105 
    106 Rob Pike (the author of Acme, amongst many other achievements) has
    107 been
    108 [quoted](https://groups.google.com/g/golang-nuts/c/hJHCAaiL0so/m/kG3BHV6QFfIJ)
    109 saying that "syntax highlighting is juvenile". I wanted to know
    110 why. Could monochrome code really make me a better programmer?
    111 
    112 So, one evening I configured all of my tools to disable color using
    113 the `NO_COLOR` environment variable and individual settings as
    114 described at [https://no-color.org]. I updated my terminal to be
    115 Acme-cream colored and wrote a Vim
    116 [colorscheme](https://git.sr.ht/~akarle/dotfiles/tree/main/item/.config/nvim/colors/acme.lua)
    117 to match. I was ready to take the plunge.
    118 
    119 The initial feeling of switching to `syntax off` was that of being
    120 lost.  I had become so used to the same colorscheme that the colors
    121 themselves act as guideposts to navigate the code. Red for
    122 keywords--helps find the `else` block. Green for strings--easy to
    123 see the end of it. And so on.
    124 
    125 When I disabled syntax highlighting and looked at our codebase, it
    126 felt completely overwhelming and unfamiliar. I had lost my ability
    127 to read it efficiently.
    128 
    129 What followed was interesting--I had to read more intently, and
    130 in doing so I understood the code better. It took longer, but
    131 frequently the time was worth it. Over time, I adjusted and started
    132 to rely on different signposts--the structure of the code (whitespace,
    133 newlines, etc) proved much more important. I never got up to my
    134 full skimming speed though, possibly due to code styles that don't
    135 lend themselves to good visual structure (i.e. super long variable
    136 names causing wrapped lines).
    137 
    138 To my surprise, I actually really enjoyed programming without syntax
    139 highlighting.  It made the little bits of color still there really
    140 stick out in a way that would otherwise get lost in the sea of
    141 color.  Color became a much more intentional indicator, and things
    142 like blue for matching parenthesis and pink for compile errors stood
    143 out.  I felt focused and I do think my code might have been slightly
    144 better structured.
    145 
    146 However, after a few weeks like this, I switched back because, as
    147 Cal put it, "we evolved to see color for a reason". I think there's
    148 definitely a scale of "useful color" and less is more in many cases,
    149 but being able to skim code is super powerful when on a timecrunch.
    150 Plus, it involves less explanation when I pop into a pairing session
    151 and share my screen :)
    152 
    153 ## Going All In: Bare Metal Install
    154 
    155 A month or so ago, still interested in the non-tooling bits of Plan 9,
    156 I decided it was time to give it a true install. I found an old
    157 SSD and put [9front](https://9front.org) on my X220 ThinkPad.
    158 
    159 I was greeted by the now familiar face of Acme, but a lot of other
    160 things about the system felt unfamiliar. For example, while in UNIX
    161 the shell has a bunch of complexity to handle line-editing, in Plan 9
    162 this is all built into the windowing system.  The window for the
    163 terminal allows editing any text, and that's the mechanism used to,
    164 say, rerun the previous command with changes.
    165 
    166 Likewise, there was no pager like `less` to capture and scroll in
    167 the terminal. Instead, the terminal doesn't scroll by default, so
    168 `man` just prints the whole manual and lets the user scroll.
    169 
    170 I didn't get to dive too deep into the actual distributed nature,
    171 since this was a single computer install. That said, I was left in
    172 awe by the realization that the original authors of UNIX had
    173 envisioned a different (and better in many ways) future.
    174 
    175 I find this so interesting because I think it's easy to put one's
    176 favorite technologies on a pedestal. But to see the original authors
    177 create something so different and imagine what could have been...
    178 It really drove home that there's a certain network effect for
    179 software. Once it's used it gets stuck. CLI tools for example--
    180 `git` would take years to change `checkout` due to the number of
    181 scripts that use it.
    182 
    183 It made me wonder--what are the quirks of UNIX that we put up with
    184 as "the way things are"? How could it be better?  Plan 9 was the
    185 closest look at the original authors' responses to these questions.
    186 
    187 ## Going Forward
    188 
    189 I'm writing this now on my OpenBSD install. I spent multiple evenings
    190 getting 9front to work and kept a somewhat detailed log that I've
    191 published on my gopherhole:
    192 [gopher://alexkarle.com/0/notes/plan9-journey.txt]
    193 
    194 Installing and perusing Plan 9 has changed the way I think about
    195 UNIX, mouses, and how I've idolized certain software. It's refreshing
    196 to peek into an alternate universe in which all things truly are
    197 files and resources can be distributed seamlessly across machines,
    198 but it's always nice to come home to the familiar.