Browse Source

org-agenda.el (org-agenda-format-item): Don't add the 'effort and 'effort-minutes text properties

* org-agenda.el (org-agenda-format-item): Don't add the
'effort and 'effort-minutes text properties as they are
already accessible through the 'txt property of agenda lines.

* org-clock.el (org-clock-in): Refresh both the 'effort and
'effort-minutes text properties.

* org-rmail.el (rmail, rmail-file-name): Silent byte-compiler.

* org.el (org-refresh-properties): Allow to set several text
properties by passing an alist to the TPROP argument.
(org-set-effort, org-property-next-allowed-value): Use 'effort
instead of 'org-effort.
(org-agenda-prepare-buffers): Update both 'effort and
'effort-minutes.
(org-mark-jump-unhide): Move up to silent the byte-compiler.
Bastien Guerry 6 years ago
parent
commit
d978a9e585
4 changed files with 45 additions and 33 deletions
  1. 9 17
      lisp/org-agenda.el
  2. 3 1
      lisp/org-clock.el
  3. 2 0
      lisp/org-rmail.el
  4. 31 15
      lisp/org.el

+ 9 - 17
lisp/org-agenda.el

@@ -6443,9 +6443,10 @@ Any match of REMOVE-RE will be removed from TXT."
 	     (category-icon (if category-icon
 				(propertize " " 'display category-icon)
 			      ""))
+	     (effort (get-text-property 1 'effort txt))
 	     ;; time, tag, effort are needed for the eval of the prefix format
 	     (tag (if tags (nth (1- (length tags)) tags) ""))
-	     time effort neffort
+	     time
 	     (ts (if dotime (concat
 			     (if (stringp dotime) dotime "")
 			     (and org-agenda-search-headline-for-time txt))))
@@ -6502,16 +6503,6 @@ Any match of REMOVE-RE will be removed from TXT."
 		       (concat (make-string (max (- 50 (length txt)) 1) ?\ )
 			       (match-string 2 txt))
 		       t t txt))))
-	(when (derived-mode-p 'org-mode)
-	  (setq effort (ignore-errors (get-text-property 0 'org-effort txt))))
-
-	;; org-agenda-add-time-grid-maybe calls us with *Agenda* as
-	;; current buffer, so move this check outside of above
-	(if effort
-	    (setq neffort (org-duration-string-to-minutes effort)
-		  effort (setq effort (concat "[" effort "]")))
-	  ;; prevent erroring out with %e format when there is no effort
-	  (setq effort ""))
 
 	(when remove-re
 	  (while (string-match remove-re txt)
@@ -6564,8 +6555,6 @@ Any match of REMOVE-RE will be removed from TXT."
 	  'org-lowest-priority org-lowest-priority
 	  'time-of-day time-of-day
 	  'duration duration
-	  'effort effort
-	  'effort-minutes neffort
 	  'breadcrumbs breadcrumbs
 	  'txt txt
 	  'level level
@@ -6701,10 +6690,13 @@ and stored in the variable `org-prefix-format-compiled'."
 	  (setq varform `(format ,f (org-eval ,(read (match-string 4 s)))))
 	(if opt
 	    (setq varform
-		  `(if (equal "" ,var)
+		  `(if (or (equal "" ,var) (equal nil ,var))
 		       ""
-		     (format ,f (if (equal "" ,var) "" (concat ,var ,c)))))
-	  (setq varform `(format ,f (if (equal ,var "") "" (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
+		     (format ,f (concat ,var ,c))))
+	  (setq varform
+		`(format ,f (if (or (equal ,var "")
+				    (equal ,var nil)) ""
+			      (concat ,var ,c (get-text-property 0 'extra-space ,var)))))))
       (setq s (replace-match "%s" t nil s))
       (push varform vars))
     (setq vars (nreverse vars))
@@ -7556,7 +7548,7 @@ E looks like \"+<2:25\"."
 (defun org-agenda-compare-effort (op value)
   "Compare the effort of the current line with VALUE, using OP.
 If the line does not have an effort defined, return nil."
-  (let ((eff (org-get-at-bol 'effort-minutes)))
+  (let ((eff (org-get-at-eol 'effort-minutes 1)))
     (if (equal op ??)
 	(not eff)
       (funcall op (or eff (if org-sort-agenda-noeffort-is-high 32767 0))

+ 3 - 1
lisp/org-clock.el

@@ -1131,7 +1131,9 @@ 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-properties org-effort-property 'org-effort)
+  (org-refresh-properties
+   org-effort-property '((effort . identity)
+			 (effort-minutes . org-duration-string-to-minutes)))
   (catch 'abort
     (let ((interrupting (and (not org-clock-resolving-clocks-due-to-idleness)
 			     (org-clocking-p)))

+ 2 - 0
lisp/org-rmail.el

@@ -36,9 +36,11 @@
 (declare-function rmail-show-message  "rmail" (&optional n no-summary))
 (declare-function rmail-what-message  "rmail" (&optional pos))
 (declare-function rmail-toggle-header "rmail" (&optional arg))
+(declare-function rmail               "rmail" (&optional file-name-arg))
 (declare-function rmail-widen         "rmail" ())
 (defvar rmail-current-message)  ; From rmail.el
 (defvar rmail-header-style)     ; From rmail.el
+(defvar rmail-file-name)        ; From rmail.el
 
 ;; Install the link type
 (org-add-link-type "rmail" 'org-rmail-open)

+ 31 - 15
lisp/org.el

@@ -9443,8 +9443,10 @@ call CMD."
 
 (defun org-refresh-properties (dprop tprop)
   "Refresh buffer text properties.
-DPROP is the drawer property and TPROP is the corresponding text
-property to set."
+DPROP is the drawer property and TPROP is either the
+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)
     (org-with-silent-modifications
@@ -9456,9 +9458,18 @@ property to set."
 	   (setq p (org-match-string-no-properties 1))
 	   (save-excursion
 	     (org-back-to-heading t)
-	     (put-text-property
-	      (point-at-bol) (or (outline-next-heading) (point-max)) tprop p))))))))
-
+	     ;; 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)))))))))
 
 ;;;; Link Stuff
 
@@ -15315,9 +15326,9 @@ When INCREMENT is non-nil, set the property to the next allowed value."
       (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))
+      (put-text-property (point-at-bol) (point-at-eol) 'effort val))
     (when (string= heading org-clock-current-task)
-      (setq org-clock-effort (get-text-property (point-at-bol) 'org-effort))
+      (setq org-clock-effort (get-text-property (point-at-bol) 'effort))
       (org-clock-update-mode-line))
     (message "%s is now %s" prop val)))
 
@@ -16103,7 +16114,9 @@ completion."
     (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))
+	(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)))
       (when (string= org-clock-current-task heading)
 	(setq org-clock-effort nval)
 	(org-clock-update-mode-line)))
@@ -18276,7 +18289,10 @@ When a buffer is unmodified, it is just killed.  When modified, it is saved
 	    (or (memq 'stats org-agenda-ignore-properties)
 		(org-refresh-stats-properties))
 	    (or (memq 'effort org-agenda-ignore-properties)
-		(org-refresh-properties org-effort-property 'org-effort))
+		(org-refresh-properties
+		 org-effort-property
+		 '((effort . identity)
+		   (effort-minutes . org-duration-string-to-minutes))))
 	    (or (memq 'appt org-agenda-ignore-properties)
 		(org-refresh-properties "APPT_WARNTIME" 'org-appt-warntime))
 	    (setq org-todo-keywords-for-agenda
@@ -24544,6 +24560,12 @@ To get rid of the restriction, use \\[org-agenda-remove-restriction-lock]."
 			   (outline-invisible-p)))
        (org-show-context 'bookmark-jump)))
 
+(defun org-mark-jump-unhide ()
+  "Make the point visible with `org-show-context' after jumping to the mark."
+  (when (and (derived-mode-p 'org-mode)
+	     (outline-invisible-p))
+    (org-show-context 'mark-goto)))
+
 (eval-after-load "simple"
   '(defadvice pop-to-mark-command (after org-make-visible activate)
      "Make the point visible with `org-show-context'."
@@ -24559,12 +24581,6 @@ To get rid of the restriction, use \\[org-agenda-remove-restriction-lock]."
      "Make the point visible with `org-show-context'."
      (org-mark-jump-unhide)))
 
-(defun org-mark-jump-unhide ()
-  "Make the point visible with `org-show-context' after jumping to the mark."
-  (when (and (derived-mode-p 'org-mode)
-	     (outline-invisible-p))
-    (org-show-context 'mark-goto)))
-
 ;; Make session.el ignore our circular variable
 (defvar session-globals-exclude)
 (eval-after-load "session"