Skip to content
  • Protesilaos Stavrou's avatar
    MAJOR BREAKING CHANGE: change category separator · 1e7bbe19
    Protesilaos Stavrou authored
    Before we would separate categories with a "-" (single dash), but that
    could lead to confusion because the field separator is a "--" (double
    dash).  Now the separator is the plus sign.
    
    What follows are instructions to update existing entries.  Apologies for
    the inconvenience, as I am not aware of a better way to handle this
    case.
    
    * * *
    
    Refactor all your USLS files (WARNING---only tested with Emacs 29):
    
    + BACK UP ALL YOUR FILES (unless you are already tracking them with git,
      in which case double-check the following changes before committing).
    
    + Go to the USLS directory (if there are subdirectories, repeat this
      step for each of them).
    
    + Make Dired editable with `C-x C-q`
    
    + Start recording a keyboard macro with `F3`, `C-x (` or `M-x kmacro-start-macro`.
    
    + Type `M-:` and evaluate:
    
      ```elisp
      (progn
        (goto-char (point-min))
        (if-let* ((end (search-forward-regexp "--\\([0-9A-Za-z_-]*-[0-9A-Za-z_-]*\\)--" nil t))
                  (beg (search-backward-regexp "--\\([0-9A-Za-z_-]*-[0-9A-Za-z_-]*\\)--" nil t)))
            (let* ((string (buffer-substring-no-properties beg end))
                   (rep (replace-regexp-in-string "-+?" "+" (string-trim string "--" "--"))))
              (delete-region beg end)
              (insert (concat "--" rep "--")))
          (keyboard-quit)))
      ```
    
    + After evaluating the above, go back to the top of the buffer and close
      the keyboard macro with `F4`, `C-x )` or `M-x kmacro-end-macro`.
    
    + Repeat the keyboard macro with `C-u 0 F4` (`C-u 0` is the same as
      `C-0`).  If `F4` is not available, use `C-u 0 C-x e`.
    
    + Confirm the changes with `C-c C-c`.
    
    * * *
    
    Update all references to the original file paths (requires the `wgrep`
    package):
    
    + Type `M-:` `(lgrep "--\\([0-9A-Za-z_-]*-[0-9A-Za-z_-]*\\)--.*\\(txt\\|org\\|md\\)" "*" default-directory)`
    
    + Instead of `lgrep` you can use `rgrep` if you have subdirectories.
    
    + In the resulting grep buffer, type `C-x C-q` to make it editable.
    
    + Now re-use the keyboard macro that was defined earlier: `C-u 0 F4`.
    
    + Confirm the changes with `C-c C-c`.
    
    Done!
    1e7bbe19