Babble,
, On describing GnoponEmacs nodes
I'd love to be able to just say (describe)
in a node and have it describe it.
I think the closest I'll be able to get (in-text, I can probably shortcode it somehow) is src_elisp((gpe/describe))
, which is… still pretty tight.
But the question is how to get there. I feel like perhaps I can do something like what I've done with my Org-roam capture templates: have functions in files, in a folder, and load that folder into some namespace (probably gpe/node
, now that I think about it.)
So first let me whip up something that describes a node, and I'll put it in describing's file.
Nothing real:
(defun describe ()
"TBD"
"Doesn't work")
But I need some file there to test loading a directory of single-function files into a namespace.
(defun gpe/load-node-acts ()
"Load all node act files and alias their functions under the `gpe/node/` namespace."
(interactive)
(dolist (file (directory-files "~/ems/org/src/gpe/node-acts/"
t "\\.el$"))
(let* ((name (file-name-base file))
(sym (intern name))
(nsym (intern (format "gpe/node/%s" name))))
(load-file file)
(when (fboundp sym)
(defalias nsym sym)))))
With that, I should be able to do src_elisp(gpe/node/describe)
and it parse:
Babble, babble by emsenn
, On describing GnoponEmacs nodes is (a|an|the)Yup!
Great. Next step is rewriting the describe function to actually try and describe the node it's at. I could easily see this getting very complex, but for now I'll (try) and keep it simple.
(defun describe (&optional insert)
"Describes the node"
(let* ((title (or (org-entry-get (point) "name")
(org-collect-keywords '("TITLE"))
'("This")))
(title (if (listp title) (cadr (assoc "TITLE" title))
title))
(form (or (org-entry-get (point) "form" t)
"[[id:cb43263c-7d3d-44df-8236-588b3d9ed55a][undescribed node]]"))
(description (format "%s is (a|an|the) %s" title form)))
(if insert (insert description) description)))
This now lets me do (gpe/node/describe t)
to insert a node's description at point: Babble, , On describing GnoponEmacs nodes is (a|an|the) babble
Or, even easier, C-u M-x gpe/node/describe
Great! Realizing maybe it should include the link to the node, and also let me pick a node beside the one I'm at, so I can use it to create descriptions for other nodes, without it having to be hardcoded into the node like I remember doing in old versions of my Emacs stuff.
But for now this feels like a good amount of improving to have done! I've set a precedent for having acts that nodes can do, to improve themselves, as long as I give them the information.