From 3bf3f9510562e98b51d6f771f2f37dc88f165af2 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Thu, 16 Dec 2021 09:40:25 -0500 Subject: 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 Autosubmit: grfn Tested-by: BuildkiteCI --- users/grfn/emacs.d/org-query.el | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'users/grfn/emacs.d') 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 -- cgit 1.4.1