summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2018-01-02 22:00:35 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2018-01-02 22:00:35 +0100
commitd6369e9ac69ce367e862a9678bb46cdc60b77f1f (patch)
tree883224f59328aef77d19064796233598c0ba6c2f
parentb03047557560787fd91438d3788ee8a5e7dce22b (diff)
downloadorg-mode-d6369e9ac69ce367e862a9678bb46cdc60b77f1f.tar.gz
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
-rw-r--r--contrib/manual.org8
-rw-r--r--etc/ORG-NEWS2
-rw-r--r--lisp/org.el81
3 files changed, 38 insertions, 53 deletions
diff --git a/contrib/manual.org b/contrib/manual.org
index aaffd53..101e0e3 100644
--- a/contrib/manual.org
+++ b/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~) ::
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 9419b45..dfb525c 100644
--- a/etc/ORG-NEWS
+++ b/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
diff --git a/lisp/org.el b/lisp/org.el
index f97967c..3b36ead 100644
--- a/lisp/org.el
+++ b/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.