* Remove current heading from refile targets? @ 2011-07-17 19:28 Jason Dunsmore 2011-07-18 20:58 ` Bastien 0 siblings, 1 reply; 10+ messages in thread From: Jason Dunsmore @ 2011-07-17 19:28 UTC (permalink / raw) To: Org-mode mailing list I noticed that when I go to refile a heading, the heading that I'm refiling is listed in the refile targets. If I choose to refile the heading to itself, the following error is displayed: org-refile: Cannot refile to position inside the tree or region When I'm choosing a refile target, the current heading gets in the way. Would it make sense to remove the current heading from the refile targets? I have org-completion-use-ido set to `t', so I'm using the ido interface to refile. Regards, Jason ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Remove current heading from refile targets? 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 0 siblings, 1 reply; 10+ messages in thread From: Bastien @ 2011-07-18 20:58 UTC (permalink / raw) To: Jason Dunsmore; +Cc: Org-mode mailing list Hi Jason, Jason Dunsmore <emacs-orgmode@dunsmor.com> writes: > I noticed that when I go to refile a heading, the heading that I'm > refiling is listed in the refile targets. If I choose to refile the > heading to itself, the following error is displayed: > > org-refile: Cannot refile to position inside the tree or region > > When I'm choosing a refile target, the current heading gets in the way. > Would it make sense to remove the current heading from the refile > targets? Indeed. I've just pushed a fix for this. > I have org-completion-use-ido set to `t', so I'm using the ido > interface to refile. I don't use `org-completion-use-ido' so I cannot test, but it should work okay -- please let me know if there is any problem. Thanks, -- Bastien ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Remove current heading from refile targets? 2011-07-18 20:58 ` Bastien @ 2011-07-18 22:27 ` Jason Dunsmore 2011-07-18 22:49 ` Bastien 0 siblings, 1 reply; 10+ messages in thread From: Jason Dunsmore @ 2011-07-18 22:27 UTC (permalink / raw) To: Bastien; +Cc: Org-mode mailing list Bastien <bzg@altern.org> writes: > Hi Jason, > > Jason Dunsmore <emacs-orgmode@dunsmor.com> writes: > >> I noticed that when I go to refile a heading, the heading that I'm >> refiling is listed in the refile targets. If I choose to refile the >> heading to itself, the following error is displayed: >> >> org-refile: Cannot refile to position inside the tree or region >> >> When I'm choosing a refile target, the current heading gets in the way. >> Would it make sense to remove the current heading from the refile >> targets? > > Indeed. > > I've just pushed a fix for this. > >> I have org-completion-use-ido set to `t', so I'm using the ido >> interface to refile. > > I don't use `org-completion-use-ido' so I cannot test, but it should > work okay -- please let me know if there is any problem. Hm, I don't see any change with or without org-completion-use-ido set. The current heading still shows up in the refile targets. Here are my org-refile related configs: (setq org-refile-targets '((nil . (:maxlevel . 2)))) (setq org-refile-allow-creating-parent-nodes t) (setq org-refile-use-outline-path t) (setq org-refile-use-cache nil) Regards, Jason ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Remove current heading from refile targets? 2011-07-18 22:27 ` Jason Dunsmore @ 2011-07-18 22:49 ` Bastien 2011-07-19 14:31 ` Jason Dunsmore 0 siblings, 1 reply; 10+ messages in thread From: Bastien @ 2011-07-18 22:49 UTC (permalink / raw) To: Jason Dunsmore; +Cc: Org-mode mailing list Jason Dunsmore <jason@dunsmor.com> writes: > Hm, I don't see any change with or without org-completion-use-ido set. > The current heading still shows up in the refile targets. Weird. I double-check and have the current heading filtered out of the refile targets. Can you check again and/or send a small test file? -- Bastien ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Remove current heading from refile targets? 2011-07-18 22:49 ` Bastien @ 2011-07-19 14:31 ` Jason Dunsmore 2011-07-21 13:06 ` Bastien 0 siblings, 1 reply; 10+ messages in thread From: Jason Dunsmore @ 2011-07-19 14:31 UTC (permalink / raw) To: Bastien; +Cc: Org-mode mailing list Bastien <bzg@altern.org> writes: > Jason Dunsmore <jason@dunsmor.com> writes: > >> Hm, I don't see any change with or without org-completion-use-ido set. >> The current heading still shows up in the refile targets. > > Weird. I double-check and have the current heading filtered out of the > refile targets. Can you check again and/or send a small test file? 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. --8<---------------cut here---------------start------------->8--- * Heading1 ** Subheading1 * Heading2 --8<---------------cut here---------------end--------------->8--- ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Remove current heading from refile targets? 2011-07-19 14:31 ` Jason Dunsmore @ 2011-07-21 13:06 ` Bastien 2011-07-21 14:15 ` Jason Dunsmore 0 siblings, 1 reply; 10+ messages in thread From: Bastien @ 2011-07-21 13:06 UTC (permalink / raw) To: Jason Dunsmore; +Cc: Org-mode mailing list [-- 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 think. [-- 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 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 [-- Attachment #3: Type: text/plain, Size: 14 bytes --] -- Bastien ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: Remove current heading from refile targets? 2011-07-21 13:06 ` Bastien @ 2011-07-21 14:15 ` Jason Dunsmore 2011-07-21 14:52 ` Bastien 0 siblings, 1 reply; 10+ messages in thread From: Jason Dunsmore @ 2011-07-21 14:15 UTC (permalink / raw) To: Bastien; +Cc: Org-mode mailing list Bastien <bzg@altern.org> writes: > 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. Looks good except for one quirk. If the heading has a TODO keyword, it isn't excluded. Example: --8<---------------cut here---------------start------------->8--- * Heading1 ** TODO Subheading1 * Heading2 --8<---------------cut here---------------end--------------->8--- Thanks! ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Remove current heading from refile targets? 2011-07-21 14:15 ` Jason Dunsmore @ 2011-07-21 14:52 ` Bastien 2011-07-21 15:03 ` Jason Dunsmore 0 siblings, 1 reply; 10+ messages in thread From: Bastien @ 2011-07-21 14:52 UTC (permalink / raw) To: Jason Dunsmore; +Cc: Org-mode mailing list [-- 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 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: Remove current heading from refile targets? 2011-07-21 14:52 ` Bastien @ 2011-07-21 15:03 ` Jason Dunsmore 2011-07-22 9:22 ` Bastien 0 siblings, 1 reply; 10+ messages in thread From: Jason Dunsmore @ 2011-07-21 15:03 UTC (permalink / raw) To: Bastien; +Cc: Org-mode mailing list Bastien <bzg@altern.org> writes: > 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. That seems to work perfectly. Thanks again Bastien. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Remove current heading from refile targets? 2011-07-21 15:03 ` Jason Dunsmore @ 2011-07-22 9:22 ` Bastien 0 siblings, 0 replies; 10+ messages in thread From: Bastien @ 2011-07-22 9:22 UTC (permalink / raw) To: Jason Dunsmore; +Cc: Org-mode mailing list Jason Dunsmore <emacs-orgmode@dunsmor.com> writes: >> Please test this second patch over the previous one. > > That seems to work perfectly. Thanks again Bastien. Thanks for confirming. I've now applied the patch. -- Bastien ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2011-07-22 9:21 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 2011-07-21 15:03 ` Jason Dunsmore 2011-07-22 9:22 ` Bastien
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).