Skip to content

Instantly share code, notes, and snippets.

@nobiot
Created April 25, 2021 21:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nobiot/152a5f0e6f761f5100e6b4e019bf0ccf to your computer and use it in GitHub Desktop.
Save nobiot/152a5f0e6f761f5100e6b4e019bf0ccf to your computer and use it in GitHub Desktop.
POC for "schema" idea to go with denderoam.el
(defvar my/schema '()
"Collection of categories.")
(setq my/schema (list
"philosophy"
"philosophy.analytic"
"philosophy.analytic.Russel"
"philosophy.classic"
"philosophy.classic.Greek"
"philosophy.classic.Greek.Plato"
"philosophy.continental.Foucault"
"linguistics"
"linguistics.phonetics"
"linguisitics.phonology"
"linguisitics.semantics"))
(defvar my/schema-hist '())
(defvar my/title-hist '())
(defun my/header-meta-data (title)
"Taken from USLS by Prot.
https://gitlab.com/protesilaos/usls"
`(concat ":properties:" "\n"
":created: " ,(format-time-string "%Y%m%d" (current-time)) "\n"
":end:" "\n"
"#+title: " ,title "\n"
"\n"))
(defun my/slugify (title)
"Exact copy from Org-roam V2."
(cl-flet* ((nonspacing-mark-p (char)
(memq char org-roam-slug-trim-chars))
(strip-nonspacing-marks (s)
(ucs-normalize-NFC-string
(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 underscores
("^_" . "") ;; remove starting underscore
("_$" . ""))) ;; remove ending underscore
(slug (-reduce-from #'cl-replace (strip-nonspacing-marks title) pairs)))
(downcase slug))))
(defun my/new-note ()
"."
(interactive)
(let* ((subdir org-roam-directory)
(hierarchy (completing-read "Enter dendron: " my/schema nil 'confirm nil 'my/schema-hist))
(title (read-string "Enter title: " nil 'my/title-hist))
(slug (my/slugify title))
(filename
(expand-file-name (concat hierarchy "." slug ".org") org-roam-directory)))
(with-current-buffer (find-file filename)
(insert (eval (my/header-meta-data title)))
(org-id-get-create))
(unless (member hierarchy my/schema)
(add-to-list 'my/schema hierarchy))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment