Small refactoring and fix a bug in `org-timer-set-timer'

* org.el (org-refresh-property): New function.
(org-refresh-properties, org-set-effort)
(org-property-next-allowed-value): Use it.

* org-timer.el (org-timer-set-timer): Get the correct number
of minutes from text properties, both in an `org-mode' and
`org-agenda-mode' buffer.
This commit is contained in:
Bastien Guerry 2014-05-28 10:47:05 +02:00
parent 500252abf3
commit 7dceecbb30
2 changed files with 32 additions and 28 deletions

View File

@ -401,10 +401,10 @@ By default, the timer duration will be set to the number of
minutes in the Effort property, if any. You can ignore this by minutes in the Effort property, if any. You can ignore this by
using three `C-u' prefix arguments." using three `C-u' prefix arguments."
(interactive "P") (interactive "P")
(let ((minutes (or (and (not (equal opt '(64))) (let* ((effort-minutes (org-get-at-eol 'effort-minutes 1))
(number-to-string (minutes (or (and (not (equal opt '(64)))
(org-hh:mm-string-to-minutes effort-minutes
(org-entry-get (point) "effort")))) (number-to-string effort-minutes))
(and (numberp opt) (number-to-string opt)) (and (numberp opt) (number-to-string opt))
(and (listp opt) (not (null opt)) (and (listp opt) (not (null opt))
(number-to-string org-timer-default-timer)) (number-to-string org-timer-default-timer))

View File

@ -9450,28 +9450,32 @@ corresponding text property to set, or an alist with each element
being a text property (as a symbol) and a function to apply to being a text property (as a symbol) and a function to apply to
the value of the drawer property." the value of the drawer property."
(let ((case-fold-search t) (let ((case-fold-search t)
(inhibit-read-only t) p) (inhibit-read-only t))
(org-with-silent-modifications (org-with-silent-modifications
(save-excursion (save-excursion
(save-restriction (save-restriction
(widen) (widen)
(goto-char (point-min)) (goto-char (point-min))
(while (re-search-forward (concat "^[ \t]*:" dprop ": +\\(.*\\)[ \t]*$") nil t) (while (re-search-forward (concat "^[ \t]*:" dprop ": +\\(.*\\)[ \t]*$") nil t)
(setq p (org-match-string-no-properties 1)) (org-refresh-property tprop (org-match-string-no-properties 1))))))))
(save-excursion
(org-back-to-heading t) (defun org-refresh-property (tprop p)
;; tprop is a text property symbol "Refresh the buffer text property TPROP from the drawer property P.
(if (symbolp tprop) The refresh happens only for the current tree (not subtree)."
(put-text-property (save-excursion
(point-at-bol) (or (outline-next-heading) (point-max)) tprop p) (org-back-to-heading t)
;; tprop is an alist with (properties . function) elements ;; tprop is a text property symbol
(mapc (lambda(al) (if (symbolp tprop)
(save-excursion (put-text-property
(put-text-property (point) (or (outline-next-heading) (point-max)) tprop p)
(point-at-bol) (or (outline-next-heading) (point-max)) ;; tprop is an alist with (properties . function) elements
(car al) (mapc (lambda(al)
(funcall (cdr al) p)))) (save-excursion
tprop))))))))) (put-text-property
(point-at-bol) (or (outline-next-heading) (point-max))
(car al)
(funcall (cdr al) p))))
tprop))))
;;;; Link Stuff ;;;; Link Stuff
@ -15353,9 +15357,10 @@ When INCREMENT is non-nil, set the property to the next allowed value."
existing nil nil "" nil cur)))))) existing nil nil "" nil cur))))))
(unless (equal (org-entry-get nil prop) val) (unless (equal (org-entry-get nil prop) val)
(org-entry-put nil prop val)) (org-entry-put nil prop val))
(save-excursion (org-refresh-property
(org-back-to-heading t) '((effort . identity)
(put-text-property (point-at-bol) (point-at-eol) 'effort val)) (effort-minutes . org-duration-string-to-minutes))
val)
(when (string= heading org-clock-current-task) (when (string= heading org-clock-current-task)
(setq org-clock-effort (get-text-property (point-at-bol) 'effort)) (setq org-clock-effort (get-text-property (point-at-bol) 'effort))
(org-clock-update-mode-line)) (org-clock-update-mode-line))
@ -16142,11 +16147,10 @@ completion."
(beginning-of-line 1) (beginning-of-line 1)
(skip-chars-forward " \t") (skip-chars-forward " \t")
(when (equal prop org-effort-property) (when (equal prop org-effort-property)
(save-excursion (org-refresh-property
(org-back-to-heading t) '((effort . identity)
(put-text-property (point-at-bol) (point-at-eol) 'effort nval) (effort-minutes . org-duration-string-to-minutes))
(put-text-property (point-at-bol) (point-at-eol) 'effort-minutes nval)
(org-duration-string-to-minutes nval)))
(when (string= org-clock-current-task heading) (when (string= org-clock-current-task heading)
(setq org-clock-effort nval) (setq org-clock-effort nval)
(org-clock-update-mode-line))) (org-clock-update-mode-line)))