In org-mode Emacs, how to re-select the selected text under the org heading?

Is there a way in Emacs org-mode to automatically redraw the selected text under the org heading? those. cut out the selected text and automatically paste it under the org heading of my choice?

You can name it org-refile-region. Similarly org-refile, but to recreate not the entire subtree, but only the selected area under any heading of the current document.

UPDATE:

Ideally, this functionality is independent of the org-agenda files used by org-refile to avoid displaying irrelevant headers as possible targets.

Currently, this is doable: 1. select text 2. cut 3. another window 4. Scroll to the desired destination title 5. insert text 6. another window

The proposed new feature will make it much more efficient: 1. select the text 2. org-refile-region 3. select the target

The most useful form of this will allow you to choose a target from any currently open documents. My use case includes selecting text from one buffer and updating it from a list of headers in another buffer, i.e. Moving text from the source document displayed in one window and adding it to the targets in the hierarchy of the target document displayed in another window, for example:

+4
source share
1 answer

If you are using emacs 24.1 or later, you can try

(setq org-refile-active-region-within-subtree t)

, , , ( emacs - " " ) .

, org-mode. , org . :

(defvar org-refile-region-format "\n%s\n")

(defvar org-refile-region-position 'top
  "Where to refile a region. Use 'bottom to refile at the
end of the subtree. ")

(defun org-refile-region (beg end copy)
  "Refile the active region.
If no region is active, refile the current paragraph.
With prefix arg C-u, copy region instad of killing it."
  (interactive "r\nP")
  ;; mark paragraph if no region is set
  (unless (use-region-p)
    (setq beg (save-excursion
                (backward-paragraph)
                (skip-chars-forward "\n\t ")
                (point))
          end (save-excursion
                (forward-paragraph)
                (skip-chars-backward "\n\t ")
                (point))))
  (let* ((target (save-excursion (org-refile-get-location)))
         (file (nth 1 target))
         (pos (nth 3 target))
         (text (buffer-substring-no-properties beg end)))
    (unless copy (kill-region beg end))
    (deactivate-mark)
    (with-current-buffer (find-file-noselect file)
      (save-excursion
        (goto-char pos)
        (if (eql org-refile-region-position 'bottom)
            (org-end-of-subtree)
          (org-end-of-meta-data-and-drawers))
        (insert (format org-refile-region-format text))))))

org-refile-get-location . . .

org-refile-targets , , :

nil  ;; only the current file
'((org-agenda-files :maxlevel . 2)) ;; all agenda files, 1st/2nd level
'((org-files-list :maxlevel . 4)) ;; all agenda and all open files
'((my-org-files-list :maxlevel . 4)) ;; all files returned by `my-org-files-list'

org,

(defun my-org-files-list ()
  (mapcar (lambda (buffer)
            (buffer-file-name buffer))
          (org-buffer-list 'files t)))

(setq org-refile-targets '((my-org-files-list :maxlevel . 4)))

M-x customize-option <ret> org-refile-targets

"" " " my-org-files-list

+2

All Articles