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 15:06:59 +0200	[thread overview]
Message-ID: <8739hz4wb0.fsf@gnu.org> (raw)
In-Reply-To: <878vrue403.fsf@riotblast.dunsmor.com> (Jason Dunsmore's message of "Tue, 19 Jul 2011 09:31:24 -0500")

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

Hi Jason,

Jason Dunsmore <jason@dunsmor.com> writes:

> It looks like it removes top-level headings from the refile targets, but
> nothing below that.  For example, in the org file below, place the
> cursor on Subheading1 and type "M-x org-refile".  The current
> heading will be in the list of refile targets.
> * Heading1
> ** Subheading1
> * Heading2

Okay, I didn't get it first.

Please test this attached patch against latest git.

There are two limitations: 

1. It works only if `org-refile-use-cache' is nil.

2. Targets are not excluded when refiling is done from the agenda
   (see Bernt's bug report about this)

I think those limitations are okay -- but let me know what you 

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-refile-exclude-current-heading-and-subheadings-f.patch --]
[-- Type: text/x-patch, Size: 5912 bytes --]

From eeeb24bd41a021708d0d22ae183c8c409fc322a9 Mon Sep 17 00:00:00 2001
From: Bastien Guerry <bzg@altern.org>
Date: Thu, 21 Jul 2011 15:03:59 +0200
Subject: [PATCH] org-refile: exclude current heading and subheadings from

* org.el (org-refile-get-targets): new optional argument
`excluded-entries' to exclude entries from the targets.
(org-refile-get-location): From an org-mode buffer, exclude
current heading and subheadings from the list of target when
org-refile-use-cache is nil.

Thanks to Jason Dunsmore for this idea.
 lisp/org.el |   37 +++++++++++++++++++++++--------------
 1 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index ac60e4e..51b8615 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -1095,8 +1095,8 @@ for the duration of the command."
 					(plain-list-item . auto))
   "Should `org-insert-heading' leave a blank line before new heading/item?
 The value is an alist, with `heading' and `plain-list-item' as CAR,
-and a boolean flag as CDR.  The cdr may also be the symbol `auto', in 
-which case Org will look at the surrounding headings/items and try to 
+and a boolean flag as CDR.  The cdr may also be the symbol `auto', in
+which case Org will look at the surrounding headings/items and try to
 make an intelligent decision whether to insert a blank line or not.
 For plain lists, if the variable `org-empty-line-terminates-plain-lists' is
@@ -1983,7 +1983,7 @@ Interested libraries should add to this list.")
 (defcustom org-loop-over-siblings-within-active-region-p nil
   "Shall some commands act upon siblings in the active region?
-The list of commands is: 
+The list of commands is:
 - `org-schedule'
 - `org-deadline'
 - `org-archive-subtree'
@@ -4712,7 +4712,7 @@ This variable is set by `org-before-change-function'.
 (defvar org-inhibit-blocking nil)       ; Dynamically-scoped param.
 (defvar org-table-buffer-is-an nil)
-;; org-outline-regexp ought to be a defconst but is let-binding 
+;; org-outline-regexp ought to be a defconst but is let-binding
 ;; in some places -- e.g. see the macro org-with-limited-levels
 (defvar org-outline-regexp "\\*+ ")
 (defconst org-outline-regexp-bol "^\\*+ ")
@@ -7740,12 +7740,12 @@ and still retain the repeater to cover future instances of the task."
       (insert template)
       (goto-char (point-min))
-      (while (re-search-forward 
+      (while (re-search-forward
 	      "^[ \t]*CLOCK:.*$" (save-excursion (org-end-of-subtree t t)) t)
 	(replace-match "")
       (goto-char (point-min))
-      (while (re-search-forward 
+      (while (re-search-forward
 	      (concat "^[ \t]*:" (regexp-opt org-drawers) ":[ \t]*$") nil t)
 	(mapc (lambda(d) (org-remove-empty-drawer-at d (point))) org-drawers))
       (setq template (buffer-substring (point-min) (point-max))))
@@ -10153,7 +10153,7 @@ on the system \"/user@host:\"."
       (and set (org-refile-cache-check-set set) set)))))
-(defun org-refile-get-targets (&optional default-buffer)
+(defun org-refile-get-targets (&optional default-buffer excluded-entries)
   "Produce a table with refile targets."
   (let ((case-fold-search nil)
 	;; otherwise org confuses "TODO" as a kw and "Todo" as a word
@@ -10216,7 +10216,8 @@ on the system \"/user@host:\"."
 			   (or (funcall org-refile-target-verify-function)
 			       (throw 'next t))))
-		       (when (looking-at org-complex-heading-regexp)
+		       (when (and (looking-at org-complex-heading-regexp)
+				  (not (member (match-string 4) excluded-entries)))
 			 (setq level (org-reduced-level
 				      (- (match-end 1) (match-beginning 1)))
 			       txt (org-link-display-format (match-string 4))
@@ -10352,8 +10353,8 @@ the *old* location.")
 The list of target headings is compiled using the information in
 `org-refile-targets', which see.
-At the target location, the entry is filed as a subitem of the target 
-heading.  Depending on `org-reverse-note-order', the new subitem will 
+At the target location, the entry is filed as a subitem of the target
+heading.  Depending on `org-reverse-note-order', the new subitem will
 either be the first or the last subitem.
 If there is an active region, all entries in that region will be moved.
@@ -10374,7 +10375,7 @@ See also `org-refile-use-outline-path' and `org-completion-use-ido'.
 If you are using target caching (see `org-refile-use-cache'),
 You have to clear the target cache in order to find new targets.
-This can be done with a 0 prefix (`C-0 C-c C-w') or a triple 
+This can be done with a 0 prefix (`C-0 C-c C-w') or a triple
 prefix argument (`C-u C-u C-u C-c C-w')."
   (interactive "P")
@@ -10496,8 +10497,16 @@ PROMPT should not be suffixed with a colon and a space, because
 this function appends the default value from
 `org-refile-history' automatically, if that is not empty."
   (let ((org-refile-targets org-refile-targets)
-	(org-refile-use-outline-path org-refile-use-outline-path))
-    (setq org-refile-target-table (org-refile-get-targets default-buffer)))
+	(org-refile-use-outline-path org-refile-use-outline-path)
+	excluded-entries)
+    (when (and (eq major-mode 'org-mode)
+	       (not org-refile-use-cache))
+      (org-map-tree
+       (lambda()
+	 (setq excluded-entries
+	       (append excluded-entries (list (org-get-heading t)))))))
+    (setq org-refile-target-table
+	  (org-refile-get-targets default-buffer excluded-entries)))
   (unless org-refile-target-table
     (error "No refile targets"))
   (let* ((prompt (concat prompt
@@ -11888,7 +11897,7 @@ be removed."
 			    (and (eq what 'closed) org-log-done-with-time))
 			(eq what 'closed)
 			nil nil (list org-end-time-was-given)))
-	      (insert 
+	      (insert
 	       (if (not (or (bolp) (eq (char-before) ?\ )
 			    (memq (char-after) '(32 10))
 			    (eobp))) " " ""))

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


  reply	other threads:[~2011-07-21 13:06 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 [this message]
2011-07-21 14:15           ` Jason Dunsmore
2011-07-21 14:52             ` Bastien
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:

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


* 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


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).