emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Marc Ihm <marc@ihm.name>
To: emacs-orgmode@gnu.org
Subject: [PATCH] lisp/org-el: Fix explanation, if state change is blocked by contained checkboxes
Date: Fri, 14 Apr 2017 17:49:50 +0200	[thread overview]
Message-ID: <867f2ndm5d.fsf@ihm.name> (raw)

[-- Attachment #1: Type: text/plain, Size: 669 bytes --]


Hi,

The patch below fixes a minor problem:

Consider a node, which contains unchecked checkboxes; if you have set
org-enforce-todo-checkbox-dependencies and try to change the node to
DONE, you will be denied with a message explaining why. However in this
special case the explanation would be wrong in talking of an unrelated
node instead of the checkboxes.

The fix uses the already existing variable org-blocked-by-checkboxes
(which is handled in org-block-todo-from-checkboxes).  Similar code is
already present in org-agenda-dim-blocked-tasks within org-agenda.el.


Please review the patch and let me know, if you have any comments or
questions.

Thanks,
Marc



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-el: Fix explanation, if state change is blocked by contained checkboxes --]
[-- Type: text/x-patch, Size: 2815 bytes --]

From 97311babee20c291aad0f1e6fa0f147c3ed416bf Mon Sep 17 00:00:00 2001
From: "U-IHM-NOTEBOOK\\Olli" <marc@ihm.name>
Date: Fri, 14 Apr 2017 17:14:02 +0200
Subject: [PATCH 1/1] org-el: Fix explanation, if state change is blocked by
 contained checkboxes

---
 lisp/org.el | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 17caa3f..00d3802 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -12369,6 +12369,7 @@ nil or a string to be used for the todo mark." )
 	(replace-match "0" t nil nil 1)))))
 
 (defvar org-state) ;; dynamically scoped into this function
+(defvar org-blocked-by-checkboxes) ; dynamically scoped
 (defun org-todo (&optional arg)
   "Change the TODO state of an item.
 
@@ -12518,20 +12519,24 @@ When called through ELisp, arg is also interpreted in the following way:
 				     :position startpos))
 		 dolog now-done-p)
 	    (when org-blocker-hook
-	      (setq org-last-todo-state-is-todo
-		    (not (member this org-done-keywords)))
-	      (unless (save-excursion
-			(save-match-data
-			  (org-with-wide-buffer
-			   (run-hook-with-args-until-failure
-			    'org-blocker-hook change-plist))))
-		(if (called-interactively-p 'interactive)
-		    (user-error "TODO state change from %s to %s blocked (by \"%s\")"
-				this org-state org-block-entry-blocking)
-		  ;; fail silently
-		  (message "TODO state change from %s to %s blocked (by \"%s\")"
-			   this org-state org-block-entry-blocking)
-		  (throw 'exit nil))))
+	      (let (org-blocked-by-checkboxes block-reason)
+		(setq org-last-todo-state-is-todo
+		      (not (member this org-done-keywords)))
+		(unless (save-excursion
+			  (save-match-data
+			    (org-with-wide-buffer
+			     (run-hook-with-args-until-failure
+			      'org-blocker-hook change-plist))))
+		  (setq block-reason (if org-blocked-by-checkboxes
+					 "contained checkboxes"
+				       (format "\"%s\"" org-block-entry-blocking)))
+		  (if (called-interactively-p 'interactive)
+		      (user-error "TODO state change from %s to %s blocked (by %s)"
+				  this org-state block-reason)
+		    ;; fail silently
+		    (message "TODO state change from %s to %s blocked (by %s)"
+			     this org-state block-reason)
+		    (throw 'exit nil)))))
 	    (store-match-data match-data)
 	    (replace-match next t t)
 	    (cond ((equal this org-state)
@@ -12714,7 +12719,6 @@ See variable `org-track-ordered-property-with-tag'."
 	(and tag (org-toggle-tag tag 'on))
 	(message "Subtasks must be completed in sequence")))))
 
-(defvar org-blocked-by-checkboxes) ; dynamically scoped
 (defun org-block-todo-from-checkboxes (change-plist)
   "Block turning an entry into a TODO, using checkboxes.
 This checks whether the current task should be blocked from state
-- 
2.8.3


             reply	other threads:[~2017-04-14 15:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-14 15:49 Marc Ihm [this message]
2017-04-17  8:39 ` [PATCH] lisp/org-el: Fix explanation, if state change is blocked by contained checkboxes Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=867f2ndm5d.fsf@ihm.name \
    --to=marc@ihm.name \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).