Building on My Project Notes and Dispatch Emacs “Package”

Accretion of Functionality Through Crafting and Extending

In Project Dispatch Menu with Org Mode Metadata, Denote, and Transient I wrote about using my Denote 📖 notes, written in Org-Mode 📖, to house metadata related to my project.

The tools been working quite well. I now have a means of grouping like paths, either Uniform Resource Locators (URLs 📖) or local file paths. And in that grouping file, I can add additional metadata. In essence, I have built up a rich bookmark system that overlays my note taking ecosystem.

The dynamism is useful because I also segment my notes. On my work machine I have one set of notes. On my personal machine I have another. But both machines use the same Emacs 📖 configuration.

, I decided to build on this ecosystem to dynamically populate the magit-repository-directories variable.

The magit-repository-directories Variable

The magit-repository-directories variable provides the list of directories to show in the magit-list-repositories buffer. See the Repository List (Magit User Manual).

In brief, the magit-list-repositories shows an overview of the Git 📖 metadata for each of the repositories in the magit-repository-directories list. The metadata, which is customizable, includes the following:

  • Version (e.g. Secure Hash Algorithm (SHA 📖) or tag)
  • Summary of working directory’s status
  • Current branch
  • Number of commits behind the remote branch
  • Number of commits ahead of the remote branch

From that overview, I can open the magit-status buffer to work on that repository.

What I like about the magit-list-repositories function is that it gives me an overview of what all I might be working on. And a convenient means of quickly moving through those projects.

Dynamically Populating magit-list-repositories

(defvar jf/git-project-paths
  '(("~/git/takeonrules.source/" . 1)
    ("~/git/burning_wheel_lifepaths/" . 1)
    ("~/git/dotzshrc/" .  1)
    ("~/git/dotemacs/" . 1)
    ("~/git/emacs-bookmarks/" . 1)
    ("~/git/org" . 1)
    ("~/git/takeonrules.source/themes/hugo-tufte" . 1))
  "A list of `con' cells where the `car' is the name of a directory
and the `cdr' is a ranking.  I have pre-populated this list with
repositories that are generally available on both machines.")

(defun jf/git-project-paths/dynamic ()
  "Return a list of code repository paths."
  (split-string-and-unquote
   (s-trim-right
    (shell-command-to-string
     (concat
      "rg \"^#\\+PROJECT_PATHS: +[^\\.]+\\. +\\\"(~/git/[^/]+/)\\\"\\)\" "
      "~/git/org --no-ignore-vcs --replace='$1' "
      "--only-matching --no-filename")))
   "\n"))

(dolist (path (jf/git-project-paths/dynamic))
  (add-to-list 'jf/git-project-paths (cons path 1)))

(setq magit-repository-directories jf/git-project-paths)

With the above Emacs Lisp (elisp 📖), I add the repositories that I consider part of my machine’s various project work-spaces. And from there, I can easily get a summary overview of my code.