emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Bastien <bzg@altern.org>
To: Jason Dunsmore <jason@dunsmor.com>
Cc: Org-mode mailing list <emacs-orgmode@gnu.org>
Subject: Re: Remove current heading from refile targets?
Date: Thu, 21 Jul 2011 16:52:06 +0200	[thread overview]
Message-ID: <87aac71yax.fsf@gnu.org> (raw)
In-Reply-To: <877h7bhg8n.fsf@riotblast.dunsmor.com> (Jason Dunsmore's message of "Thu, 21 Jul 2011 09:15:36 -0500")

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

Jason Dunsmore <jason@dunsmor.com> 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-org-refile-exclude-current-sub-heading-s-even-if-the.patch --]
[-- Type: text/x-patch, Size: 2270 bytes --]

From 04a43208d096e792aea68efadc5df95fcbb7d94b Mon Sep 17 00:00:00 2001
From: Bastien Guerry <bzg@altern.org>
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


[-- Attachment #3: Type: text/plain, Size: 23 bytes --]


Thanks!

-- 
 Bastien

  reply	other threads:[~2011-07-21 14:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-17 19:28 Remove current heading from refile targets? Jason Dunsmore
2011-07-18 20:58 ` Bastien
2011-07-18 22:27   ` Jason Dunsmore
2011-07-18 22:49     ` Bastien
2011-07-19 14:31       ` Jason Dunsmore
2011-07-21 13:06         ` Bastien
2011-07-21 14:15           ` Jason Dunsmore
2011-07-21 14:52             ` Bastien [this message]
2011-07-21 15:03               ` Jason Dunsmore
2011-07-22  9:22                 ` Bastien

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=87aac71yax.fsf@gnu.org \
    --to=bzg@altern.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=jason@dunsmor.com \
    /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).