about summary refs log tree commit diff
path: root/users/grfn
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2021-12-16T14·40-0500
committerclbot <clbot@tvl.fyi>2021-12-16T14·52+0000
commit3bf3f9510562e98b51d6f771f2f37dc88f165af2 (patch)
tree8742823193168d42d0a9eb58a800a58ec9d72565 /users/grfn
parentd85c6a1b56eae850a972d7c0708525a736d33d01 (diff)
fix(grfn/emacs): More robust org-element title extraction r/3267
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
Diffstat (limited to 'users/grfn')
-rw-r--r--users/grfn/emacs.d/org-query.el20
1 files changed, 18 insertions, 2 deletions
diff --git a/users/grfn/emacs.d/org-query.el b/users/grfn/emacs.d/org-query.el
index 0b987280f2a1..022832c05fac 100644
--- a/users/grfn/emacs.d/org-query.el
+++ b/users/grfn/emacs.d/org-query.el
@@ -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