diff --git a/modules/writing.org b/modules/writing.org index b880045..821ba33 100644 --- a/modules/writing.org +++ b/modules/writing.org @@ -84,6 +84,34 @@ Configure custom keybindings behind =SPC r=. "rb" '(org-roam-buffer-toggle-display :which-key "Buffer")) #+end_src +** File slugs + +The default behaviour of ~org-roam~ when creating a title slug is to replace any non alpha numerical (whitespace) to ~_~. I wanted to change this to use ~_~ and have done so here in my own definition. The only substantial difference from the original definition is the character used. + ++ Define a new ~title-to-slug~ function ++ Override ~org-roam-title-to-slug-function~ + +#+begin_src emacs-lisp +(with-eval-after-load 'org-roam + (require 'cl-lib) + (defun dotfiles/title-to-slug (title) + "Convert TITLE to a filename-suitable slug." + (cl-flet* ((nonspacing-mark-p (char) + (eq 'Mn (get-char-code-property char 'general-category))) + (strip-nonspacing-marks (s) + (apply #'string (seq-remove #'nonspacing-mark-p + (ucs-normalize-NFD-string s)))) + (cl-replace (title pair) + (replace-regexp-in-string (car pair) (cdr pair) title))) + (let* ((pairs `(("[^[:alnum:][:digit:]]" . "-") ;; Convert anything not alphanumeric. + ("--*" . "-") ;; Remove sequential dashes. + ("^-" . "") ;; Remove starting dashes. + ("-$" . ""))) ;; Remove ending dashes. + (slug (-reduce-from #'cl-replace (strip-nonspacing-marks title) pairs))) + (downcase slug)))) + (setq org-roam-title-to-slug-function #'dotfiles/title-to-slug)) +#+end_src + ** Web visualizer Including the extension *Org roam server*[fn:5] will run a web application that visualizes the *Org roam*[fn:4] database. Available whenever the editor is running at https://localhost:8080. The image at the top of this page is an example of the application running.