Browse Source

Use completion in `org-set-effort'

* contrib/manual.org: Document change.
* lisp/org.el (org-set-effort): Change signature.
(org-inc-effort): Apply signature change.

Fixes: 22776, 22597
Nicolas Goaziou 7 years ago
parent
commit
d6369e9ac6
3 changed files with 38 additions and 53 deletions
  1. 4 4
      contrib/manual.org
  2. 2 0
      etc/ORG-NEWS
  3. 32 49
      lisp/org.el

+ 4 - 4
contrib/manual.org

@@ -6823,10 +6823,10 @@ commands:
 
      #+kindex: C-c C-x e
      #+findex: org-set-effort
-     Set the effort estimate for the current entry.  With a numeric
-     prefix argument, set it to the Nth allowed value (see below).
-     This command is also accessible from the agenda with the
-     {{{kbd(e)}}} key.
+     Set the effort estimate for the current entry.  With a prefix
+     argument, set it to the next allowed value---see below.  This
+     command is also accessible from the agenda with the {{{kbd(e)}}}
+     key.
 
 - {{{kbd(C-c C-x C-e)}}} (~org-clock-modify-effort-estimate~) ::
 

+ 2 - 0
etc/ORG-NEWS

@@ -63,6 +63,8 @@ With the new template expansion mechanism (see
 [[*~org-insert-structure-template~]]), the variable changed its data type.
 See docstring for details.
 
+*** Change ~org-set-effort~ signature
+See docstring for details.
 *** Placeholders in =(eval ...)= macros are always strings
 
 Within =(eval ...)= macros, =$1=-like placeholders are always replaced

+ 32 - 49
lisp/org.el

@@ -14939,61 +14939,44 @@ See `org-property-re' for match data, if applicable."
 (defun org-inc-effort ()
   "Increment the value of the effort property in the current entry."
   (interactive)
-  (org-set-effort nil t))
+  (org-set-effort t))
 
 (defvar org-clock-effort)       ; Defined in org-clock.el.
 (defvar org-clock-current-task) ; Defined in org-clock.el.
-(defun org-set-effort (&optional value increment)
+(defun org-set-effort (&optional increment value)
   "Set the effort property of the current entry.
-With numerical prefix arg, use the nth allowed value, 0 stands for the
-10th allowed value.
-
-When INCREMENT is non-nil, set the property to the next allowed value."
+If INCREMENT is non-nil, set the property to the next allowed
+value.  Otherwise, if optional argument VALUE is provided, use
+it.  Eventually, prompt for the new value if none of the previous
+variables is set."
   (interactive "P")
-  (when (equal value 0) (setq value 10))
-  (let* ((completion-ignore-case t)
-	 (prop org-effort-property)
-	 (cur (org-entry-get nil prop))
-	 (allowed (org-property-get-allowed-values nil prop 'table))
-	 (existing (mapcar 'list (org-property-values prop)))
-	 (heading (nth 4 (org-heading-components)))
-	 rpl
-	 (val (cond
-	       ((stringp value) value)
-	       ((and allowed (integerp value))
-		(or (car (nth (1- value) allowed))
-		    (car (org-last allowed))))
-	       ((and allowed increment)
-		(or (cl-caadr (member (list cur) allowed))
-		    (user-error "Allowed effort values are not set")))
-	       (allowed
-		(message "Select 1-9,0, [RET%s]: %s"
-			 (if cur (concat "=" cur) "")
-			 (mapconcat 'car allowed " "))
-		(setq rpl (read-char-exclusive))
-		(if (equal rpl ?\r)
-		    cur
-		  (setq rpl (- rpl ?0))
-		  (when (equal rpl 0) (setq rpl 10))
-		  (if (and (> rpl 0) (<= rpl (length allowed)))
-		      (car (nth (1- rpl) allowed))
-		    (org-completing-read "Effort: " allowed nil))))
-	       (t
-		(org-completing-read
-		 (concat "Effort" (and cur (string-match "\\S-" cur)
-				       (concat " [" cur "]"))
-			 ": ")
-		 existing nil nil "" nil cur)))))
-    (unless (equal (org-entry-get nil prop) val)
-      (org-entry-put nil prop val))
-    (org-refresh-property
-     '((effort . identity)
-       (effort-minutes . org-duration-to-minutes))
-     val)
-    (when (equal heading (bound-and-true-p org-clock-current-task))
-      (setq org-clock-effort (get-text-property (point-at-bol) 'effort))
+  (let* ((allowed (org-property-get-allowed-values nil org-effort-property t))
+	 (current (org-entry-get nil org-effort-property))
+	 (value
+	  (cond
+	   (increment
+	    (unless allowed (user-error "Allowed effort values are not set"))
+	    (or (cl-caadr (member (list current) allowed))
+		(user-error "Unknown value %S among allowed values" current)))
+	   (value
+	    (if (stringp value) value
+	      (error "Invalid effort value: %S" value)))
+	   (t
+	    (let ((must-match
+		   (and allowed
+			(not (get-text-property 0 'org-unrestricted
+						(caar allowed))))))
+	      (completing-read "Effort: " allowed nil must-match))))))
+    (unless (equal current value)
+      (org-entry-put nil org-effort-property value))
+    (org-refresh-property '((effort . identity)
+			    (effort-minutes . org-duration-to-minutes))
+			  value)
+    (when (equal (org-get-heading t t t t)
+		 (bound-and-true-p org-clock-current-task))
+      (setq org-clock-effort (org-get-at-bol 'effort))
       (org-clock-update-mode-line))
-    (message "%s is now %s" prop val)))
+    (message "%s is now %s" org-effort-property value)))
 
 (defun org-entry-properties (&optional pom which)
   "Get all properties of the current entry.