August 16, 2020

NOTE: This is a raw, untended note, representing a quick capture for the topic at hand. Hopefully it will soon develop into a draft of something useful!

This is pretty cool! Writing fennel directly into elisp as a quoted s-exp:

(defun fennel-reload-form (module-keyword)
"Return a string of the code to reload the `module-keyword' module."
(format "%s\n" `(let [old (require ,module-keyword)
_ (tset package.loaded ,module-keyword nil)
(ok new) (pcall require ,module-keyword)
;; keep the old module if reload failed
new (if (not ok) (do (print new) old) new)]
;; if the module isn't a table then we can't make
;; changes which affect already-loaded code, but if
;; it is then we should splice new values into the
;; existing table and remove values that are gone.
(when (= (type new) :table)
(each [k v (pairs new)]
(tset old k v))
(each [k (pairs old)]
;; the elisp reader is picky about where . can be
(when (not (,"." new k))
(tset old k nil)))
(tset package.loaded ,module-keyword old)))))

(from fennel-mode.el)

2020-08-17 21:17:04

honestly, just realized i can use my j[tab] snippet outside of my journal.org each file is like a whole new app sometimes

I wanted to share this bit:

(defn parent-needs-child-tag [item]
(when (and
(item/needs-child-tag? item)
(item/has-source-file? item))
{:value "Missing a child tag!"
:actions [{:div
[:div [comp/input
{:type :text
:name :item-name
:class ["px-4" "py-2" "bg-city-aqua-dark-800"]
:placeholder "Add a child-tag on blur"
;; TODO clear input on blur
:on-blur (fn [tag]
(let [tag (item/prep-tag tag)]
(when (seq tag)
{:props {:child-tag tag}}]))))}]
:tags #{:active :warning}}))

I've really like creating action types like these:

(when (item/relevant? item)
{:value "Do something relevant"
:event [::events/something-relevant item context time]})

They're super cheap but they pack alot of punch if you have expressive APIs.

For example, with org-crud, you can completely scope a property-crud feature in a set of actions like these:

;; TODO write good example for crud of a property.
;; priority works, but is already a first class org-item
;; maybe just pull tags-crud and speak to org-tags in general
(defn some-item-actions [item]
[(when (item/needs-date? item)){:}])

At some point I added :icon, which leads to some fun little actions in a list.

todo: Attach screenshot (wish this line could be a real org bullet)

But the first example goes further, adding a straight up :div. Where relevant, this div will be rendered in-place. Hope it doesn't blow up my action-lists!

Would you ever write this in another language? Should you? who knows?

Russell Matney

Russell Matney

Writing, Stories, Software, Indie Games


© 2020