fix(grfn/emacs): More robust org-element title extraction

It *appears* that the main trigger for the :title of an org element
being a list instead of a string is if it contains rich text properties
as children, eg links, bold text, etc. This defines a function
that *attempts* to turn all of those into a single string, for use in my
i3status bar for the currently clocked-in task.

Change-Id: Ib655595914e54cd0e01f0fee6d1352c98a9f1436
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4364
Reviewed-by: grfn <grfn@gws.fyi>
Autosubmit: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
This commit is contained in:
Griffin Smith 2021-12-16 09:40:25 -05:00 committed by clbot
parent d85c6a1b56
commit 3bf3f95105

View file

@ -4,6 +4,23 @@
(require 'org-agenda)
(require 'inflections)
(defun grfn/org-text-element->string (elt)
(cond
((stringp elt) elt)
((and (consp elt)
(symbolp (car elt)))
(-> elt (caddr) (grfn/org-text-element->string) (s-trim) (concat " ")))))
(defun grfn/org-element-title (elt)
(let ((title (org-element-property :title elt)))
(cond
((stringp title) title)
((listp title)
(->> title
(mapcar #'grfn/org-text-element->string)
(s-join "")
(s-trim))))))
(defun grfn/org-agenda-entry->element (agenda-entry)
;; ???
())
@ -87,8 +104,7 @@
(if (org-clocking-p)
(format "(%s) [%s]"
(->> (grfn/org-element-clocked-in-task)
(org-element-property :title)
(car)
(grfn/org-element-title)
(substring-no-properties)
(s-trim))
(grfn/minutes->hours:minutes