tecosaur / emacs-config

My configuration for Doom Emacs. Mirror of https://git.tecosaur.net/tec/emacs-config.
MIT License
1.04k stars 118 forks source link

doct + all-the-icons #2

Closed progfolio closed 4 years ago

progfolio commented 4 years ago

I like the idea!

I came across your usage here and pushed a change to doct that will allow more introspection during the doct-after-conversion-functions hook. The upshot is that you could specify a custom :icon keyword and use that to take care of prepending your templates' names during the hook.

The necessary functions are:

(defun +doct-icon-declaration-to-icon (declaration)
  "Convert :icon declaration to icon"
  (let ((name (pop declaration))
        (set  (intern (concat "all-the-icons-" (plist-get declaration :set))))
        (face (intern (concat "all-the-icons-" (plist-get declaration :color))))
        (v-adjust (or (plist-get declaration :v-adjust) 0.01)))
    (apply set `(,name :face ,face :v-adjust ,v-adjust))))

(defun +doct-iconify-capture-templates (groups)
  "Add declaration's :icon to each template group in GROUPS."
  (let ((templates (doct-flatten-lists-in groups)))
    (setq doct-templates (mapcar (lambda (template)
                                   (when-let* ((props (nthcdr 5 template))
                                               (spec (plist-get (plist-get props :doct) :icon)))
                                     (setf (nth 1 template) (concat (+doct-icon-declaration-to-icon spec)
                                                                    "\t"
                                                                    (nth 1 template))))
                                   template)
                                 templates))))

And you'd set doct-after-conversion-functions to:

'(+doct-iconify-capture-templates)

Then on your templates you can specify the icon like so:

("Personal todo" :keys "t"
 :icon ("checklist" :set "octicon" :color "purple")
 :prepend t
 :headline "Inbox"
 :template ("* TODO %?" "%i %a"))

IMHO, this is easier to read.

Just thought I'd point out the possibility. Thanks for using doct! (note this will only work on latest version of doct)

tecosaur commented 4 years ago

That looks really neat! I'll be sure to plop that in my config :grinning: Thanks for letting me know and writing up that example!

tecosaur commented 4 years ago

One caveat, this doesn't seem to work with 'parents' as it is, I had to perform this tweak to props in the when-let*

(props (nthcdr (if (= (length template) 4) 2 5) template))
progfolio commented 4 years ago

Yes, I overlooked that! Sorry!