From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bastien Subject: Re: Remove current heading from refile targets? Date: Thu, 21 Jul 2011 16:52:06 +0200 Message-ID: <87aac71yax.fsf@gnu.org> References: <878vrwk8pk.fsf@riotblast.dunsmor.com> <87livvxq3x.fsf@gnu.org> <87r55ndy2w.fsf@riotblast.dunsmor.com> <871uxnxkz9.fsf@gnu.org> <878vrue403.fsf@riotblast.dunsmor.com> <8739hz4wb0.fsf@gnu.org> <877h7bhg8n.fsf@riotblast.dunsmor.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([140.186.70.92]:53169) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QjuiQ-0002zm-Be for emacs-orgmode@gnu.org; Thu, 21 Jul 2011 10:59:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QjubK-00074J-Po for emacs-orgmode@gnu.org; Thu, 21 Jul 2011 10:51:50 -0400 Received: from mail-fx0-f52.google.com ([209.85.161.52]:56813) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QjubK-00074A-JU for emacs-orgmode@gnu.org; Thu, 21 Jul 2011 10:51:46 -0400 Received: by fxd18 with SMTP id 18so2945521fxd.39 for ; Thu, 21 Jul 2011 07:51:45 -0700 (PDT) In-Reply-To: <877h7bhg8n.fsf@riotblast.dunsmor.com> (Jason Dunsmore's message of "Thu, 21 Jul 2011 09:15:36 -0500") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Jason Dunsmore Cc: Org-mode mailing list --=-=-= Content-Type: text/plain Jason Dunsmore writes: > Looks good except for one quirk. If the heading has a TODO keyword, it > isn't excluded. Example: > > * Heading1 > ** TODO Subheading1 > * Heading2 Please test this second patch over the previous one. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0002-org-refile-exclude-current-sub-heading-s-even-if-the.patch >From 04a43208d096e792aea68efadc5df95fcbb7d94b Mon Sep 17 00:00:00 2001 From: Bastien Guerry Date: Thu, 21 Jul 2011 16:51:12 +0200 Subject: [PATCH 2/2] org-refile: exclude current (sub)heading(s) even if they start with a TODO keyword. (org-get-heading): New optional argument to return heading with no TODO keyword. (org-refile-get-location): Use this new argument. --- lisp/org.el | 26 ++++++++++++++++++-------- 1 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 51b8615..2ba345b 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -6971,15 +6971,25 @@ This is important for non-interactive uses of the command." (hide-subtree))) (run-hooks 'org-insert-heading-hook))))) -(defun org-get-heading (&optional no-tags) - "Return the heading of the current entry, without the stars." +(defun org-get-heading (&optional no-tags no-todo) + "Return the heading of the current entry, without the stars. +When NO-TAGS is non-nil, don't include tags. +When NO-TODO is non-nil, don't include TODO keywords." (save-excursion (org-back-to-heading t) - (if (looking-at - (if no-tags - (org-re "\\*+[ \t]+\\([^\n\r]*?\\)\\([ \t]+:[[:alnum:]:_@#%]+:[ \t]*\\)?$") - "\\*+[ \t]+\\([^\r\n]*\\)")) - (match-string 1) ""))) + (cond + ((and no-tags no-todo) + (looking-at org-complex-heading-regexp) + (match-string 4)) + (no-tags + (looking-at "\\*+[ \t]+\\([^\n\r]*?\\)\\([ \t]+:[[:alnum:]:_@#%]+:[ \t]*\\)?$") + (match-string 1)) + (no-todo + (looking-at (concat "\\*+[ \t]+" org-todo-regexp " +" + "\\([^\n\r]*?[ \t]+:[[:alnum:]:_@#%]+:[ \t]*\\)?$")) + (match-string 2)) + (t (looking-at "\\*+[ \t]+\\([^\r\n]*\\)") + (match-string 1))))) (defun org-heading-components () "Return the components of the current heading. @@ -10504,7 +10514,7 @@ this function appends the default value from (org-map-tree (lambda() (setq excluded-entries - (append excluded-entries (list (org-get-heading t))))))) + (append excluded-entries (list (org-get-heading t t))))))) (setq org-refile-target-table (org-refile-get-targets default-buffer excluded-entries))) (unless org-refile-target-table -- 1.7.5.2 --=-=-= Content-Type: text/plain Thanks! -- Bastien --=-=-=--