(define-button-type 'org-clock-in-button
'follow-link t
'face 'custom-button
'mouse-face 'custom-button-mouse
'action (lambda (b) (org-clock-in)))
(define-button-type 'org-clock-out-button
'follow-link t
'face 'custom-button
'mouse-face 'custom-button-mouse
'action (lambda (b) (org-clock-out)))
(defun has-clock-in-button ()
(s-contains? "Clock In" (nth 4 (org-heading-components))))
(defun has-clock-out-button ()
(s-contains? "Clock Out" (nth 4 (org-heading-components))))
(defun pod/add-clock-in-button-to-right-of-heading ()
(unless (has-clock-in-button)
(save-excursion
(org-end-of-line)
(let ((end-of-line-before-insert (point)))
(insert " Clock In")
(let* ((button-start (+ 4 end-of-line-before-insert))
(button-end (+ 8 button-start)))
(make-button button-start button-end :type 'org-clock-in-button))))))
;; (defun remove-clock-in-button ()
;; )
(defun pod/add-clock-out-button-to-right-of-heading ()
(unless (has-clock-out-button)
(outline-up-heading)
;; (remove-clock-in-button)
(save-excursion
(org-end-of-line)
(let ((end-of-line-before-insert (point)))
(insert " Clock Out")
(let* ((button-start (+ 4 end-of-line-before-insert))
(button-end (+ 9 button-start)))
(make-button button-start button-end :type 'org-clock-out-button))))))
(add-hook 'org-after-todo-state-change-hook #'pod/add-clock-in-button-to-right-of-heading)
(add-hook 'org-clock-in-hook #'pod/add-clock-out-button-to-right-of-heading)
(add-hook 'org-clock-out-hook #'pod/add-clock-in-button-to-right-of-heading)