Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
org-clock-select-task with helm
(advice-add 'org-clock-select-task :override #'aj/helm-org-clock-select-task)
(defun aj/helm-org-clock-select-task (&optional prompt)
"Select a task that was recently associated with clocking."
(interactive)
;; TODO sources for these
;; (when (marker-buffer org-clock-default-task)
;; (insert (org-add-props "Default Task\n" nil 'face 'bold))
;; (setq s (org-clock-insert-selection-line ?d org-clock-default-task))
;; (push s sel-list))
;; (when (marker-buffer org-clock-interrupted-task)
;; (insert (org-add-props "The task interrupted by starting the last one\n" nil 'face 'bold))
;; (setq s (org-clock-insert-selection-line ?i org-clock-interrupted-task))
;; (push s sel-list))
;; (when (org-clocking-p)
;; (insert (org-add-props "Current Clocking Task\n" nil 'face 'bold))
;; (setq s (org-clock-insert-selection-line ?c org-clock-marker))
;; (push s sel-list))
;; (run-hooks 'org-clock-before-select-task-hook)
;; (goto-char (point-min))
(or
(helm :sources (list (aj/helm-org-clock-history) (aj/helm-org-clock-agenda-headings))
:candidate-number-limit 99999
:buffer "*Helm org clock*")
(user-error "No clock in task chosen")))
(defun aj/helm-org-clock-history ()
(let (och)
;; Remove successive dups from the clock history to consider
(mapc (lambda (c) (if (not (equal c (car och))) (push c och)))
org-clock-history)
(setq och (reverse och) chl (length och))
(helm-build-sync-source "Recently clocked"
:candidates (mapcar
(lambda (m)
(when (marker-buffer m)
(aj/helm-org-clock-candidate m)))
och))))
(defun aj/helm-org-clock-candidate (marker)
(with-temp-buffer
(let ((cm (org-clock-insert-selection-line 0 marker)))
(goto-char ())
(cons (buffer-substring 4 (point-at-eol)) (cdr cm)))))
(defun aj/helm-org-clock-agenda-headings ()
(helm-build-sync-source "Org agenda headings"
:candidates (helm-org-get-candidates (org-agenda-files) 1 8)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.