add direct range to clock range insertion and add agenda clock range

This commit is contained in:
ndwarshuis 2019-01-21 23:57:53 -05:00
parent e035ff9c64
commit ffddc17483
1 changed files with 30 additions and 10 deletions

View File

@ -929,28 +929,40 @@ and reverts all todo keywords to TODO."
(org-back-to-heading t) (org-back-to-heading t)
(delete-region (point) (+ 1 (save-excursion (org-end-of-subtree))))) (delete-region (point) (+ 1 (save-excursion (org-end-of-subtree)))))
(defun nd/org-clock-range () (defun nd/org-clock-range (&optional arg)
"Add a completed clock entry to the current heading. "Add a completed clock entry to the current heading.
Does not touch the running clock." Does not touch the running clock. When called with one C-u prefix
(interactive) argument, ask for a range in minutes in place of the second date."
(interactive "P")
(let* ((t1 (-> (org-read-date t t) float-time)) (let* ((t1 (-> (org-read-date t t) float-time))
(t2 (-> (org-read-date t t nil nil t1) float-time)) (diff (if (equal arg '(4))
(diff (round (- t2 t1)))) (-some-> (read-string "Length in minutes: ")
(if (< diff 0) (message "Second timestamp earlier than first!") (cl-parse-integer :junk-allowed t)
(* 60))
(-> (org-read-date t t nil nil t1)
float-time
round
(- t1)))))
(cond
((not diff) (message "Invalid range given!"))
((< diff 0) (message "Second timestamp earlier than first!"))
(t
(let* ((h (-> diff (/ 3600) floor)) (let* ((h (-> diff (/ 3600) floor))
(m (-> diff (- (* h 3600)) (/ 60) floor)) (m (-> diff (- (* h 3600)) (/ 60) floor))
(new-clock (new-clock
(concat (concat
org-clock-string " " org-clock-string " "
(format-time-string (org-time-stamp-format t t) t1) "--" (format-time-string (org-time-stamp-format t t) t1)
(format-time-string (org-time-stamp-format t t) t2)" => " "--"
(format-time-string (org-time-stamp-format t t) (+ t1 diff))
" => "
(format "%2d:%02d" h m)))) (format "%2d:%02d" h m))))
(save-excursion (save-excursion
(org-clock-find-position nil) (org-clock-find-position nil)
(insert-before-markers "\n") (insert-before-markers "\n")
(backward-char 1) (backward-char 1)
(org-indent-line) (org-indent-line)
(insert new-clock)))))) (insert new-clock)))))))
#+END_SRC #+END_SRC
*** org agenda *** org agenda
These are executed directly from agenda views and affect their source org buffers. The trick is that all of them must somehow go back to the heading to which they allude, execute, then update the agenda view with whatever changes have been made. These are executed directly from agenda views and affect their source org buffers. The trick is that all of them must somehow go back to the heading to which they allude, execute, then update the agenda view with whatever changes have been made.
@ -1001,6 +1013,13 @@ It will clone the last entry in the selected subtree."
(nd/org-agenda-cmd-wrapper (nd/org-agenda-cmd-wrapper
nil nil
(call-interactively #'nd/org-delete-subtree))) (call-interactively #'nd/org-delete-subtree)))
(defun nd/org-agenda-clock-range ()
"Apply `nd/org-clock-range' to an agenda entry"
(interactive)
(nd/org-agenda-cmd-wrapper
nil
(call-interactively #'nd/org-clock-range)))
#+END_SRC #+END_SRC
** calfw ** calfw
This is a nifty calendar...sometimes way faster than the agenda buffer for looking at long term things. This is a nifty calendar...sometimes way faster than the agenda buffer for looking at long term things.
@ -3662,7 +3681,8 @@ These are for mode-specific bindings that can/should be outside of the evil maps
(lambda () (lambda ()
(local-set-key (kbd "C-c C-c") 'org-agenda-set-tags) (local-set-key (kbd "C-c C-c") 'org-agenda-set-tags)
(local-set-key (kbd "C-c C-x c") 'nd/org-agenda-clone-subtree-with-time-shift) (local-set-key (kbd "C-c C-x c") 'nd/org-agenda-clone-subtree-with-time-shift)
(local-set-key (kbd "C-c C-x C-b") 'nd/org-agenda-toggle-checkbox))) (local-set-key (kbd "C-c C-x C-b") 'nd/org-agenda-toggle-checkbox)
(local-set-key (kbd "C-c C-x C-r") 'nd/org-agenda-clock-range)))
#+END_SRC #+END_SRC
*** mu4e *** mu4e
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp