Home ~ Start Here ~ Computers ~ Communication ~ Organization ~ Family Photos

emacs

I use emacs whenever I can.

Basic setup

I have a specific setup that I prefer. Here's a reference screenshot; it's blurry because the text details aren't really relevant:

emacs-screen.png

On the left side of the screen, there's a speedbar window in directory mode, tracking the current working directory of the active buffer:

~/var/www/stormrider.io/
0:<+> css
0:<+> images
0:[?] .htaccess
0:[+] 404.org
0:[+] about-me.org
0:[+] altair.org
0:[+] anatomy-of-my-backpack.org
0:[+] arcana.org
0:[+] bill-pics.org
0:[?] build-gallery
0:[+] chatronyms.org
0:[+] credo.org
0:[?] emacs-dragon.png
0:[+] emacs.org
0:[+] exoself.org
0:[+] for-the-fam.org
0:[+] geekcode.org
0:[+] index.org
0:[+] journal.org
0:[+] linux-kernel.org
0:[+] linux.org
0:[+] maas-cli-1.org
0:[+] maas-cli-2.org
0:[+] maas-cli-3.org
0:[+] maas-cli-4.org
0:[+] maas-cli-5.org
0:[+] maas-cli-6.org
0:[+] maas-cli-7.org
0:[+] maas-cli-8.org
0:[+] maas-image-anatomy.org
0:[+] maas-image-deployment.org
0:[+] maas.org
0:[+] networking.org
0:[+] ninety-pct.org
0:[+] phreaking.org
0:[+] pi4-sdr.org
0:[+] pi4.org
0:[+] sharan-pics.org
0:[+] tech.org
0:[+] warsurfing.org

Across the top is the calendar, in reduced font:

    August 2023           September 2023          October 2023    
Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa   Su Mo Tu We Th Fr Sa 
       1  2  3  4  5                   1  2    1  2  3  4  5  6  7 
 6  7  8  9 10 11 12    3  4  5  6  7  8  9    8  9 10 11 12 13 14 
13 14 15 16 17 18 19   10 11 12 13 14 15 16   15 16 17 18 19 20 21 
20 21 22 23 24 25 26   17 18 19 20 21 22 23   22 23 24 25 26 27 28 
27 28 29 30 31         24 25 26 27 28 29 30   29 30 31

And next to that is my org-agenda, also in reduced font:

...
know  NEXT [#C] learn emacs lisp.
know  NEXT [#C] figure out how to do in-buffer to-do keywords.
know  NEXT [#C] learn french.
know  NEXT [#C] learn the linux command line better.
know  NEXT [#C] learn quilting.
know  NEXT [#C] learn yaesu.
know  NEXT [#C] learn radio electronics better.
know  NEXT [#C] read "linux core kernel".
know  NEXT [#C] read "the linux phrasebook".
know  NEXT [#C] read "lyon's commentary".
know  NEXT [#C] read the advanced unix programming book.
...

Below the calendar, also in a smaller font, is my e-shell. It doesn't do everything well, but it's more effective for most shell needs:

host-info          maasapiserver  maastesting  perftests           
maas-offline-docs  maascli        maasui       provisioningserver  
~/usr/src/maas/src $ cd maasagent
~/usr/src/maas/src/maasagent $ ls
Makefile  cmd  go.mod  go.sum  internal  tools.go
~/usr/src/maas/src/maasagent $ cd cmd
~/usr/src/maas/src/maasagent/cmd $ ls
README.md  maas-agent  maas-netmon
~/usr/src/maas/src/maasagent/cmd $ cd maas-agent
~/usr/src/maas/src/maasagent/cmd/maas-agent $ ls
README.md  main.go
~/usr/src/maas/src/maasagent/cmd/maas-agent $ grep EXAMPLE ~/var/www/stormrider.io/*.org
~/usr/src/maas/src/maasagent/cmd/maas-agent $

Next to the e-shell is my diary file, which still needs some kinks worked out. I generally use it for anything I might want to look back for later:

|                                                      |       |
|------------------------------------------------------+-------|
| about-cloud-networks-5808.md                         |  2821 |
| about-controllers-5072.md                            |  7628 |
| about-creating-custom-images-6099.md                 | 33786 |
| about-customising-machines-5976.md                   | 23733 |
| about-dhcp-5807.md                                   | 19101 |
| about-images-5076.md                                 |  2016 |
| about-maas-5064.md                                   | 11078 |
| about-machines-5080.md                               | 71789 |
| about-networking-5084.md                             | 18845 |
| about-rbac-6131.md                                   | 11517 |

Below this is my main editing window, which rotates between whatever buffer I'm working on at the moment:

reference screenshot; it's blurry because the text details aren't really relevant:

#+attr_html: :width 100%
[[https://stormrider.io/images/emacs-screen.png]] 

On the left side of the screen, there's a speedbar window in directory mode, tracking the current working directory of the active buffer:

~/var/www/stormrider.io/
0:<+> css
0:<+> images
0:[?] .htaccess
0:[+] 404.org
0:[+] about-me.org
0:[+] altair.org
0:[+] anatomy-of-my-backpack.org
0:[+] arcana.org

And completing the set, the window to the right of the editing window is my reference window, which I use to bring up -- for example -- code that I'm documenting or a document I'm copying snippets from:

package workflow

import (
	"net"
	"net/netip"
	"time"

	"go.temporal.io/sdk/workflow"

	"launchpad.net/maas/maas/src/maasagent/internal/netmon"
)

// CheckIPParam is a workflow parameter for the CheckIP workflow
type CheckIPParam struct {
	IPs []netip.Addr
}

// CheckIPResult is a value returned by the CheckIP workflow
type CheckIPResult struct {
	IPs map[netip.Addr]net.HardwareAddr

How I create this dashboard on startup

The relevant parts of the .emacs file look like this:

;;; main display code
(sr-speedbar-open)                ;; open speedbar
(calendar)                        ;; open calendar
(org-agenda-list)                 ;; open org-agenda
;;(w3m-gohome)                    ;; open w3m homepage
(eshell)                          ;; open e-shell, splitting main window
(next-multiframe-window)          ;; move to the speedbar window
(shrink-window-horizontally 5)    ;; narrow the speedbar a bit
(next-multiframe-window)          ;; move to top main window
(split-window)                    ;; split main window top/bottom
(shrink-window 2)                 ;; make top window not as tall
(split-window-horizontally)       ;; split top window left/right
(shrink-window-horizontally 5)    ;; shrink top left window a bit
(next-multiframe-window)          ;; move to middle window
(next-multiframe-window)
(shrink-window 2)                 ;; make middle window not as tall
(split-window-horizontally)       ;; split middle window left/right
(next-multiframe-window)          ;; skip to bottom window
(next-multiframe-window)
(split-window-horizontally)       ;; split bottom window left/right
(next-multiframe-window)          ;; move back to top left window
(next-multiframe-window)
(next-multiframe-window)
;; visit the calendar in this window and make the font smaller
(set-window-buffer (selected-window) (get-buffer "*Calendar*"))
(with-selected-window (selected-window)
  (text-scale-adjust -1))
(go-to-top-of-buffer)             ;; center the calendar in the window
(next-multiframe-window)          ;; move to top right window
;; visit the org-agenda-list in this buffer and make the font smaller 
(set-window-buffer (selected-window) (get-buffer "*Org Agenda*"))
(with-selected-window (selected-window)
  (text-scale-adjust -1))
(next-multiframe-window)          ;; move to middle left window
;; visit e-shell in this buffer and make the font smaller
(set-window-buffer (selected-window) (get-buffer "*eshell*"))
(with-selected-window (selected-window)
  (text-scale-adjust -1))
(next-multiframe-window)          ;; move to middle right window
;; visit the diary in this buffer and make the font smaller
(set-window-buffer (selected-window) (get-buffer "diary"))
(with-selected-window (selected-window)
  (text-scale-adjust -1))
(next-multiframe-window)          ;; move to the main editing window

Making my .emacs new-laptop-proof

From time to time, I may grab up another laptop and need to load it with emacs. Rather than having to remember what all packages to download, I set up my .emacs file to handle that for me, like this:

;; Package management
(require 'package)
(setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
                         ("melpa" . "https://melpa.org/packages/")
			 ("nongnu" . "https://elpa.nongnu.org/nongnu/")))
...
;; pass
(unless (package-installed-p 'pass)
  (package-refresh-contents)
  (package-install 'pass))
;; hackernews
(unless (package-installed-p 'hackernews)
 (package-refresh-contents)
 (package-install 'hackernews))
;; hledger-mode
(unless (package-installed-p 'hledger-mode)
 (package-refresh-contents)
 (package-install 'hledger-mode))
;; ido
(unless (package-installed-p 'ido)
  (package-refresh-contents)
  (package-install 'ido))
;; magit
(unless (package-installed-p 'magit)
  (package-refresh-contents)
  (package-install 'magit))
;; org-journal
(unless (package-installed-p 'org-journal)
  (package-refresh-contents)
  (package-install 'org-journal))
;; ox-gfm
(unless (package-installed-p 'ox-gfm)
  (package-refresh-contents)
  (package-install 'ox-gfm))
;; smex
(unless (package-installed-p 'smex)
  (package-refresh-contents)
  (package-install 'smex))
;; sr-speedbar
(unless (package-installed-p 'sr-speedbar)
  (package-refresh-contents)
  (package-install 'sr-speedbar))
;; ubuntu-theme
(unless (package-installed-p 'ubuntu-theme)
  (package-refresh-contents)
  (package-install 'ubuntu-theme))
;; vterm
;;(unless (package-installed-p 'vterm)
;;  (package-refresh-contents)
;;  (package-install 'vterm))
;; w3m
;;(unless (package-installed-p 'w3m)
;;  (package-refresh-contents)
;;  (package-install 'w3m))
;;; require packages
(require 'hackernews)
(require 'hledger-mode)
(require 'ido)
(require 'magit)
(require 'org-id) 
(require 'org-journal)
(require 'org)
(require 'ox-ascii)
(require 'ox-gfm)
(require 'ox-html)
(require 'ox-latex)
(require 'ox-publish)
(require 'smex)
;;(require 'vterm)
;;(require 'w3m)

This code will load packages unless they're already loaded. It also takes the time to set up my package repos first, and to require the packages that are loaded. At any given time, some of them may be commented out, for whatever reason.

Making completion easy

I use ido and smex to enable completion:

;; ido
(setq org-completion-use-ido t)
(setq ido-everywhere t)
(setq ido-max-directory-size 100000)
(ido-mode (quote both))
(setq ido-default-file-method 'selected-window)
(setq ido-default-buffer-method 'selected-window)
(setq org-indirect-buffer-display 'current-window)
...
;; smex
(smex-initialize)
...
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "C-x x") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands)

It's much easier than trying to remember commands, and it brings up the history anytime you do M-x.

If you're interested, you can find my current emacs configuration file -- (".emacs") -- here. Maybe you'll find something you can use.


Copyright (C) 2020-2023 by Stormrider.
All rights reserved.