summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Guerry <bzg@altern.org>2014-05-28 10:47:05 +0200
committerBastien Guerry <bzg@altern.org>2014-05-28 10:47:05 +0200
commit7dceecbb30b3c51e487cd6426db53a5c5a4e4694 (patch)
treee1051dd6582e3d467e0417b0df231ca2cb64034d
parent500252abf34d003c020b73348d6ca13da5ce46c5 (diff)
downloadorg-mode-7dceecbb30b3c51e487cd6426db53a5c5a4e4694.tar.gz
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.
-rw-r--r--lisp/org-timer.el8
-rw-r--r--lisp/org.el52
2 files changed, 32 insertions, 28 deletions
diff --git a/lisp/org-timer.el b/lisp/org-timer.el
index a051c71..f44b1cf 100644
--- a/lisp/org-timer.el
+++ b/lisp/org-timer.el
@@ -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
using three `C-u' prefix arguments."
(interactive "P")
- (let ((minutes (or (and (not (equal opt '(64)))
- (number-to-string
- (org-hh:mm-string-to-minutes
- (org-entry-get (point) "effort"))))
+ (let* ((effort-minutes (org-get-at-eol 'effort-minutes 1))
+ (minutes (or (and (not (equal opt '(64)))
+ effort-minutes
+ (number-to-string effort-minutes))
(and (numberp opt) (number-to-string opt))
(and (listp opt) (not (null opt))
(number-to-string org-timer-default-timer))
diff --git a/lisp/org.el b/lisp/org.el
index 64bbae4..e4a1956 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -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
the value of the drawer property."
(let ((case-fold-search t)
- (inhibit-read-only t) p)
+ (inhibit-read-only t))
(org-with-silent-modifications
(save-excursion
(save-restriction
(widen)
(goto-char (point-min))
(while (re-search-forward (concat "^[ \t]*:" dprop ": +\\(.*\\)[ \t]*$") nil t)
- (setq p (org-match-string-no-properties 1))
- (save-excursion
- (org-back-to-heading t)
- ;; tprop is a text property symbol
- (if (symbolp tprop)
- (put-text-property
- (point-at-bol) (or (outline-next-heading) (point-max)) tprop p)
- ;; tprop is an alist with (properties . function) elements
- (mapc (lambda(al)
- (save-excursion
- (put-text-property
- (point-at-bol) (or (outline-next-heading) (point-max))
- (car al)
- (funcall (cdr al) p))))
- tprop)))))))))
+ (org-refresh-property tprop (org-match-string-no-properties 1))))))))
+
+(defun org-refresh-property (tprop p)
+ "Refresh the buffer text property TPROP from the drawer property P.
+The refresh happens only for the current tree (not subtree)."
+ (save-excursion
+ (org-back-to-heading t)
+ ;; tprop is a text property symbol
+ (if (symbolp tprop)
+ (put-text-property
+ (point) (or (outline-next-heading) (point-max)) tprop p)
+ ;; tprop is an alist with (properties . function) elements
+ (mapc (lambda(al)
+ (save-excursion
+ (put-text-property
+ (point-at-bol) (or (outline-next-heading) (point-max))
+ (car al)
+ (funcall (cdr al) p))))
+ tprop))))
;;;; Link Stuff
@@ -15353,9 +15357,10 @@ When INCREMENT is non-nil, set the property to the next allowed value."
existing nil nil "" nil cur))))))
(unless (equal (org-entry-get nil prop) val)
(org-entry-put nil prop val))
- (save-excursion
- (org-back-to-heading t)
- (put-text-property (point-at-bol) (point-at-eol) 'effort val))
+ (org-refresh-property
+ '((effort . identity)
+ (effort-minutes . org-duration-string-to-minutes))
+ val)
(when (string= heading org-clock-current-task)
(setq org-clock-effort (get-text-property (point-at-bol) 'effort))
(org-clock-update-mode-line))
@@ -16142,11 +16147,10 @@ completion."
(beginning-of-line 1)
(skip-chars-forward " \t")
(when (equal prop org-effort-property)
- (save-excursion
- (org-back-to-heading t)
- (put-text-property (point-at-bol) (point-at-eol) 'effort nval)
- (put-text-property (point-at-bol) (point-at-eol) 'effort-minutes
- (org-duration-string-to-minutes nval)))
+ (org-refresh-property
+ '((effort . identity)
+ (effort-minutes . org-duration-string-to-minutes))
+ nval)
(when (string= org-clock-current-task heading)
(setq org-clock-effort nval)
(org-clock-update-mode-line)))