New command `org-copy' to copy a subtree/region

* org.el (org-refile-keep): New variable.
(org-copy): New command to copy notes.
(org-refile): New parameter msg to override the "Refile"
string in the default prompt.
(org-mode-map): Bind "C-c M-w" to `org-copy'.

* org.texi (Refile and copy): Document the new command `org-copy'.

* orgguide.texi (Refile and copy): Ditto.

Thanks to Kalev Takkis who triggered this change.
This commit is contained in:
Bastien Guerry 2012-09-23 11:42:41 +02:00
parent 7b7e876319
commit a65b5bd36c
3 changed files with 56 additions and 32 deletions

View File

@ -480,7 +480,7 @@ Capture - Refile - Archive
* Attachments:: Add files to tasks
* RSS Feeds:: Getting input from RSS feeds
* Protocols:: External (e.g.@: Browser) access to Emacs and Org
* Refiling notes:: Moving a tree from one place to another
* Refile and copy:: Moving/copying a tree from one place to another
* Archiving:: What to do with finished projects
Capture
@ -1514,7 +1514,7 @@ to create a number of tasks related to a series of lectures to prepare. For
more details, see the docstring of the command
@code{org-clone-subtree-with-time-shift}.
@orgcmd{C-c C-w,org-refile}
Refile entry or region to a different location. @xref{Refiling notes}.
Refile entry or region to a different location. @xref{Refile and copy}.
@orgcmd{C-c ^,org-sort}
Sort same-level entries. When there is an active region, all entries in the
region will be sorted. Otherwise the children of the current headline are
@ -6504,7 +6504,7 @@ trees to an archive file keeps the system compact and fast.
* Attachments:: Add files to tasks
* RSS Feeds:: Getting input from RSS feeds
* Protocols:: External (e.g.@: Browser) access to Emacs and Org
* Refiling notes:: Moving a tree from one place to another
* Refile and copy:: Moving/copying a tree from one place to another
* Archiving:: What to do with finished projects
@end menu
@ -6571,7 +6571,7 @@ so that you can resume your work without further distraction. When called
with a prefix arg, finalize and then jump to the captured item.
@orgcmd{C-c C-w,org-capture-refile}
Finalize the capture process by refiling (@pxref{Refiling notes}) the note to
Finalize the capture process by refiling (@pxref{Refile and copy}) the note to
a different place. Please realize that this is a normal refiling command
that will be executed---so the cursor position at the moment you run this
command is important. If you have inserted a tree with a parent and
@ -7043,7 +7043,7 @@ list of drawers in that file:
For more information, including how to read atom feeds, see
@file{org-feed.el} and the docstring of @code{org-feed-alist}.
@node Protocols, Refiling notes, RSS Feeds, Capture - Refile - Archive
@node Protocols, Refile and copy, RSS Feeds, Capture - Refile - Archive
@section Protocols for external access
@cindex protocols, for external access
@cindex emacsserver
@ -7057,17 +7057,22 @@ a remote website you are looking at with the browser. See
@uref{http://orgmode.org/worg/org-contrib/org-protocol.php} for detailed
documentation and setup instructions.
@node Refiling notes, Archiving, Protocols, Capture - Refile - Archive
@section Refiling notes
@node Refile and copy, Archiving, Protocols, Capture - Refile - Archive
@section Refile and copy
@cindex refiling notes
@cindex copying notes
When reviewing the captured data, you may want to refile some of the entries
into a different list, for example into a project. Cutting, finding the
right location, and then pasting the note is cumbersome. To simplify this
process, you can use the following special command:
When reviewing the captured data, you may want to refile or to copy some of
the entries into a different list, for example into a project. Cutting,
finding the right location, and then pasting the note is cumbersome. To
simplify this process, you can use the following special command:
@table @kbd
@orgcmd{C-c M-w,org-copy}
@findex org-copy
Copying works like refiling, except that the original note is not deleted.
@orgcmd{C-c C-w,org-refile}
@findex org-refile
@vindex org-reverse-note-order
@vindex org-refile-targets
@vindex org-refile-use-outline-path
@ -7104,7 +7109,7 @@ setting @code{org-refile-use-cache}. To make the command see new possible
targets, you have to clear the cache with this command.
@end table
@node Archiving, , Refiling notes, Capture - Refile - Archive
@node Archiving, , Refile and copy, Capture - Refile - Archive
@section Archiving
@cindex archiving

View File

@ -163,7 +163,7 @@ Dates and Times
Capture - Refile - Archive
* Capture::
* Refiling notes:: Moving a tree from one place to another
* Refile and copy:: Moving a tree from one place to another
* Archiving:: What to do with finished projects
Capture
@ -438,7 +438,7 @@ Promote/demote the current subtree by one level.
Move subtree up/down (swap with previous/next subtree of same
level).
@item C-c C-w
Refile entry or region to a different location. @xref{Refiling notes}.
Refile entry or region to a different location. @xref{Refile and copy}.
@item C-x n s/w
Narrow buffer to current subtree / widen it again
@end table
@ -1530,11 +1530,11 @@ archive file keeps the system compact and fast.
@menu
* Capture::
* Refiling notes:: Moving a tree from one place to another
* Refile and copy:: Moving a tree from one place to another
* Archiving:: What to do with finished projects
@end menu
@node Capture, Refiling notes, Capture - Refile - Archive, Capture - Refile - Archive
@node Capture, Refile and copy, Capture - Refile - Archive, Capture - Refile - Archive
@section Capture
Org's method for capturing new items is heavily inspired by John Wiegley
@ -1574,7 +1574,7 @@ Once you are done entering information into the capture buffer,
@kbd{C-c C-c} will return you to the window configuration before the capture
process, so that you can resume your work without further distraction.
@item C-c C-w
Finalize by moving the entry to a refile location (@pxref{Refiling notes}).
Finalize by moving the entry to a refile location (@pxref{Refile and copy}).
@item C-c C-k
Abort the capture process and return to the previous state.
@end table
@ -1622,15 +1622,18 @@ possibilities, consult the manual for more.
%u, %U @r{like the above, but inactive timestamps}
@end smallexample
@node Refiling notes, Archiving, Capture, Capture - Refile - Archive
@section Refiling notes
@node Refile and copy, Archiving, Capture, Capture - Refile - Archive
@section Refile and copy
When reviewing the captured data, you may want to refile some of the entries
into a different list, for example into a project. Cutting, finding the
right location, and then pasting the note is cumbersome. To simplify this
process, you can use the following special command:
When reviewing the captured data, you may want to refile or copy some of the
entries into a different list, for example into a project. Cutting, finding
the right location, and then pasting the note is cumbersome. To simplify
this process, you can use the following special command:
@table @kbd
@item C-c M-x
Copy the entry or region at point. This command behaves like
@code{org-refile}, except that the original note will not be deleted.
@item C-c C-w
Refile the entry or region at point. This command offers possible locations
for refiling the entry and lets you select one with completion. The item (or
@ -1644,7 +1647,7 @@ Use the refile interface to jump to a heading.
Jump to the location where @code{org-refile} last moved a tree to.
@end table
@node Archiving, , Refiling notes, Capture - Refile - Archive
@node Archiving, , Refile and copy, Capture - Refile - Archive
@section Archiving
When a project represented by a (sub)tree is finished, you may want

View File

@ -10934,7 +10934,16 @@ Note that this is still *before* the stuff will be removed from
the *old* location.")
(defvar org-capture-last-stored-marker)
(defun org-refile (&optional goto default-buffer rfloc)
(defvar org-refile-keep nil
"Non-nil means `org-refile' will copy instead of refile.")
(defun org-copy ()
"Like `org-refile', but copy."
(interactive)
(let ((org-refile-keep t))
(funcall 'org-refile nil nil nil "Copy")))
(defun org-refile (&optional goto default-buffer rfloc msg)
"Move the entry or entries at point to another heading.
The list of target headings is compiled using the information in
`org-refile-targets', which see.
@ -10957,6 +10966,9 @@ With a prefix argument of `2', refile to the running clock.
RFLOC can be a refile location obtained in a different way.
MSG is a string to replace \"Refile\" in the default prompt with
another verb. E.g. `org-copy' sets this parameter to \"Copy\".
See also `org-refile-use-outline-path' and `org-completion-use-ido'.
If you are using target caching (see `org-refile-use-cache'),
@ -10967,7 +10979,8 @@ prefix argument (`C-u C-u C-u C-c C-w')."
(interactive "P")
(if (member goto '(0 (64)))
(org-refile-cache-clear)
(let* ((cbuf (current-buffer))
(let* ((actionmsg (or msg "Refile"))
(cbuf (current-buffer))
(regionp (org-region-active-p))
(region-start (and regionp (region-beginning)))
(region-end (and regionp (region-end)))
@ -11003,10 +11016,11 @@ prefix argument (`C-u C-u C-u C-c C-w')."
(org-back-to-heading t)
(setq heading-text
(nth 4 (org-heading-components))))
(org-refile-get-location
(cond (goto "Goto")
(regionp "Refile region to")
(t (concat "Refile subtree \""
(regionp (concat actionmsg " region to"))
(t (concat actionmsg " subtree \""
heading-text "\" to")))
default-buffer
(and (not (equal '(4) goto))
@ -11078,13 +11092,14 @@ prefix argument (`C-u C-u C-u C-c C-w')."
(move-marker org-capture-last-stored-marker (point)))
(if (fboundp 'deactivate-mark) (deactivate-mark))
(run-hooks 'org-after-refile-insert-hook))))
(if regionp
(delete-region (point) (+ (point) region-length))
(org-cut-subtree))
(unless org-refile-keep
(if regionp
(delete-region (point) (+ (point) region-length))
(org-cut-subtree)))
(when (featurep 'org-inlinetask)
(org-inlinetask-remove-END-maybe))
(setq org-markers-to-move nil)
(message "Refiled to \"%s\" in file %s" (car it) file)))))))
(message (concat actionmsg " to \"%s\" in file %s: done") (car it) file)))))))
(defun org-refile-goto-last-stored ()
"Go to the location where the last refile was stored."
@ -18158,6 +18173,7 @@ BEG and END default to the buffer boundaries."
(org-defkey org-mode-map "\C-c\C-d" 'org-deadline)
(org-defkey org-mode-map "\C-c;" 'org-toggle-comment)
(org-defkey org-mode-map "\C-c\C-w" 'org-refile)
(org-defkey org-mode-map "\C-c\M-w" 'org-copy)
(org-defkey org-mode-map "\C-c/" 'org-sparse-tree) ; Minor-mode reserved
(org-defkey org-mode-map "\C-c\\" 'org-match-sparse-tree) ; Minor-mode res.
(org-defkey org-mode-map "\C-c\C-m" 'org-ctrl-c-ret)