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 15:06:59 +0200 Message-ID: <8739hz4wb0.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> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([140.186.70.92]:42475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qjsxg-0004ZY-ND for emacs-orgmode@gnu.org; Thu, 21 Jul 2011 09:06:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qjsxb-0002xG-TH for emacs-orgmode@gnu.org; Thu, 21 Jul 2011 09:06:44 -0400 Received: from mail-ey0-f174.google.com ([209.85.215.174]:58812) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qjsxb-0002x9-KS for emacs-orgmode@gnu.org; Thu, 21 Jul 2011 09:06:39 -0400 Received: by eyx24 with SMTP id 24so2296570eyx.19 for ; Thu, 21 Jul 2011 06:06:38 -0700 (PDT) In-Reply-To: <878vrue403.fsf@riotblast.dunsmor.com> (Jason Dunsmore's message of "Tue, 19 Jul 2011 09:31:24 -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 Hi Jason, Jason Dunsmore 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 think. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-org-refile-exclude-current-heading-and-subheadings-f.patch >From eeeb24bd41a021708d0d22ae183c8c409fc322a9 Mon Sep 17 00:00:00 2001 From: Bastien Guerry Date: Thu, 21 Jul 2011 15:03:59 +0200 Subject: [PATCH] org-refile: exclude current heading and subheadings from targets * 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." (with-temp-buffer (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 "") (kill-whole-line)) (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:\"." org-refile-cache)))) (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:\"." (save-match-data (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))) " " "")) -- 1.7.5.2 --=-=-= Content-Type: text/plain -- Bastien --=-=-=--