Devon Ville
Devon Ville

Reputation: 2091

Refile list items in org mode

I've been trying to refine my org-fu, and one of my tasks is refiling list items. I usually prefer using list items for various reasons (mainly being - not littering my CONTENT view, and having a real outline, considering the amount of tasks I have).

But alas, when I try refiling a list item created using the capture system, I get an error - I'm not allowed to do so, because it "doesn't make sense".

Is there a way to override this behavior?

Edit: ATM I only manage to refile entries (i.e. headlines), and then transform them manually into list items. I assume there's a better solution than this...

I found this function in org-capture.el:

(defun org-capture-refile ()
  "Finalize the current capture and then refile the entry.
Refiling is done from the base buffer, because the indirect buffer is then
already gone.  Any prefix argument will be passed to the refile command."
  (interactive)
  (unless (eq (org-capture-get :type 'local) 'entry)
    (error
     "Refiling from a capture buffer makes only sense for `entry'-type templates"))
  (let ((pos (point))
    (base (buffer-base-buffer (current-buffer)))
    (org-refile-for-capture t))
    (org-capture-finalize)
    (save-window-excursion
      (with-current-buffer (or base (current-buffer))
    (save-excursion
      (save-restriction
        (widen)
        (goto-char pos)
        (call-interactively 'org-refile)))))))

How can I remove the part of (unless (eq (org-capture-get :type 'local) 'entry) so it can take effect?

Edit: 23.10.12

So far I managed to get this to work:

(defun narrow-and-reveal ()
    "Narrow and reveal all content"
    (org-narrow-to-subtree)
    (org-show-subtree)
    )
(defun widen-and-outline ()
    "Widen and move to beginning of file"
    (widen)
    (beginning-of-buffer)
    (org-overview)
    (org-content)
    )
(defun org-goto-symbol ()
  "Will navigate to the symbol at the current point of the cursor"
  (widen-and-outline)
  (interactive)
  (let ((current-prefix-arg 4)) ;; emulate C-u
    (call-interactively 'org-refile)) ;; invoke org-refile interactively
  (narrow-and-reveal)
  )
(defun custom-org-prompt-headline ()
  (org-goto-symbol) ;; invoke org-refile interactively
  (end-of-buffer))
(setq org-capture-templates`(
    ("t" "ToDo" item (file+function (concat org-directory "ToDo.org") custom-org-prompt-headline))))

But it prompts me for the section in a file before entering the list item itself, which I find kind of distracting. I would just love to have the option to refile list items. I can't imagine it should be that difficult to achieve..does it?

Upvotes: 5

Views: 2255

Answers (2)

studgeek
studgeek

Reputation: 14920

After digging through the mailing list archives, the best solution I have found for this so far is the org-refile-active-region-within-subtree option. It enables refile to move arbitrary regions of text, but it refile also converts that text to a header (using org-toggle-heading) before it moves it.

So at least the text gets moved, but its probably not 100% what you want (its no longer a list). Its probably a good starting point though to look for an even better solution. Perhaps by running org-toggle-heading after the text is moved.

Here is the inline documentation:

Non-nil means also refile active region within a subtree.

By default `org-refile' doesn't allow refiling regions if they don't contain a set of subtrees, but it might be convenient to do so sometimes: in that case, the first line of the region is converted to a headline before refiling.

And I found it in this thread - http://lists.gnu.org/archive/html/emacs-orgmode/2011-08/msg00535.html

Upvotes: 1

Nikana Reklawyks
Nikana Reklawyks

Reputation: 3404

Indeed, there is a better way: why don't you use capture templates?

Basically, you just have to define the templates you like, say:

(setq org-capture-templates
 '(("t" "something" item (file+olp "~/path/to/you/file.org" "Header" "Subheader")
        "- %?\n  %i")
   ("n" "notes" checkitem (file+olp "~/somewhere/notes.org" "Notes")
        "- [ ] %?\n")))

And then, at use-time, call (M-x) org-capture (bound to C-cc if you follow standard customizations), enter your note in the already a list-item template, C-cC-c, and you're done !

All the details are in the manual (settings syntax, automagically expanding elements…)

Upvotes: 1

Related Questions