Browse Source

New defun `org-refresh-effort-properties'

* org-agenda.el (org-agenda-format-item): Do not use
org-get-effort to get the effort text property.
(org-agenda-get-sexps): Use `org-back-to-heading' when setting
the tags.

* org-clock.el (org-clock-in): Refresh effort properties.

* org.el (org-refresh-effort-properties): New defun.
(org-get-effort): Delete.
(org-set-effort): Set the 'org-effort text property.
(org-property-next-allowed-value): Ditto.
(org-agenda-prepare-buffers): Refresh effort properties.
Bastien Guerry 7 years ago
parent
commit
c4d4bf3833
3 changed files with 33 additions and 17 deletions
  1. 2 8
      lisp/org-agenda.el
  2. 4 2
      lisp/org-clock.el
  3. 27 7
      lisp/org.el

+ 2 - 8
lisp/org-agenda.el

@@ -5470,8 +5470,7 @@ Do we have a reason to ignore this TODO entry because it has a time stamp?
 	  (setq marker (org-agenda-new-marker beg)
 		category (org-get-category beg)
 		category-pos (get-text-property beg 'org-category-position)
-		tags (save-excursion (org-backward-heading-same-level 0)
-				     (org-get-tags-at))
+		tags (save-excursion (org-back-to-heading t) (org-get-tags-at))
 		todo-state (org-get-todo-state)
 		warntime (org-entry-get (point) "APPT_WARNTIME")
 		extra nil)
@@ -6224,12 +6223,7 @@ Any match of REMOVE-RE will be removed from TXT."
 			       (match-string 2 txt))
 		       t t txt))))
 	(when (derived-mode-p 'org-mode)
-	  (setq effort
-		(condition-case nil
-		    (org-get-effort
-		     (or (get-text-property 0 'org-hd-marker txt)
-			 (get-text-property 0 'org-marker txt)))
-		  (error nil)))
+	  (setq effort (ignore-errors (get-text-property 0 'org-effort txt)))
 	  (when effort
 	    (setq neffort (org-duration-string-to-minutes effort)
 		  effort (setq effort (concat "[" effort "]")))))

+ 4 - 2
lisp/org-clock.el

@@ -35,6 +35,7 @@
 (declare-function calendar-absolute-from-iso "cal-iso" (&optional date))
 (declare-function notifications-notify "notifications" (&rest params))
 (declare-function org-pop-to-buffer-same-window "org-compat" (&optional buffer-or-name norecord label))
+(declare-function org-refresh-effort-properties "org" ())
 (defvar org-time-stamp-formats)
 (defvar org-ts-what)
 (defvar org-frame-title-format-backup frame-title-format)
@@ -1081,6 +1082,7 @@ time as the start time \(see `org-clock-continuously' to
 make this the default behavior.)"
   (interactive "P")
   (setq org-clock-notification-was-shown nil)
+  (org-refresh-effort-properties)
   (catch 'abort
     (let ((interrupting (and (not org-clock-resolving-clocks-due-to-idleness)
 			     (org-clocking-p)))
@@ -1202,7 +1204,7 @@ make this the default behavior.)"
 	      (setq org-clock-start-time
 		    (apply 'encode-time
 			   (org-parse-time-string (match-string 1))))
-	      (setq org-clock-effort (org-get-effort))
+	      (setq org-clock-effort (get-text-property (point) 'org-effort))
 	      (setq org-clock-total-time (org-clock-sum-current-item
 					  (org-clock-get-sum-start))))
 	     ((eq org-clock-in-resume 'auto-restart)
@@ -1222,7 +1224,7 @@ make this the default behavior.)"
 		(beginning-of-line 1)
 		(org-indent-line-to (- (org-get-indentation) 2)))
 	      (insert org-clock-string " ")
-	      (setq org-clock-effort (org-get-effort))
+	      (setq org-clock-effort (get-text-property (point) 'org-effort))
 	      (setq org-clock-total-time (org-clock-sum-current-item
 					  (org-clock-get-sum-start)))
 	      (setq org-clock-start-time

+ 27 - 7
lisp/org.el

@@ -8642,6 +8642,23 @@ call CMD."
 	   (put-text-property beg end 'org-category-position beg)
 	   (goto-char pos)))))))
 
+(defun org-refresh-effort-properties ()
+  "Refresh effort text properties in the buffer."
+  (let ((case-fold-search t)
+	(inhibit-read-only t) e)
+    (org-unmodified
+     (save-excursion
+       (save-restriction
+	 (widen)
+	 (goto-char (point-min))
+	 (put-text-property (point) (point-max) 'org-effort-timestamp (current-time))
+	 (while (re-search-forward (concat "^[ \t]*:" org-effort-property
+					   ": +\\(.*\\)[ \t]*$") nil t)
+	   (setq e (org-match-string-no-properties 1))
+	   (save-excursion
+	     (org-back-to-heading t)
+	     (put-text-property
+	      (point-at-bol) (point-at-eol) 'org-effort e))))))))
 
 ;;;; Link Stuff
 
@@ -9949,12 +9966,6 @@ there is one, return it."
   '(add-hook 'org-export-preprocess-before-normalizing-links-hook
 	     'org-remove-file-link-modifiers))
 
-;;;; Time estimates
-
-(defun org-get-effort (&optional pom)
-  "Get the effort estimate for the current entry."
-  (org-entry-get pom org-effort-property))
-
 ;;; File search
 
 (defvar org-create-file-search-functions nil
@@ -14301,6 +14312,9 @@ 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) 'org-effort val))
     (message "%s is now %s" prop val)))
 
 (defun org-at-property-p ()
@@ -15021,7 +15035,8 @@ completion."
   (interactive)
   (unless (org-at-property-p)
     (error "Not at a property"))
-  (let* ((key (match-string 2))
+  (let* ((prop (car (save-match-data (org-split-string (match-string 1) ":"))))
+	 (key (match-string 2))
 	 (value (match-string 3))
 	 (allowed (or (org-property-get-allowed-values (point) key)
 		      (and (member value  '("[ ]" "[-]" "[X]"))
@@ -15040,6 +15055,10 @@ completion."
     (org-indent-line)
     (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) 'org-effort nval)))
     (run-hook-with-args 'org-property-changed-functions key nval)))
 
 (defun org-find-olp (path &optional this-buffer)
@@ -16992,6 +17011,7 @@ When a buffer is unmodified, it is just killed.  When modified, it is saved
 	    (widen)
 	    (setq bmp (buffer-modified-p))
 	    (org-refresh-category-properties)
+	    (org-refresh-effort-properties)
 	    (setq org-todo-keywords-for-agenda
 		  (append org-todo-keywords-for-agenda org-todo-keywords-1))
 	    (setq org-done-keywords-for-agenda