From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sebastian Subject: Re: Re: add a whole directory as one item to refile targets Date: Mon, 12 Oct 2009 18:47:46 +0200 Message-ID: <1255366066.5500.12.camel@beteigeuze> References: <938fae2d0910041530v51cdaac4jb8db88b6cb1a8b56@mail.gmail.com> <938fae2d0910101448j2c39d67aw4950c7899c3307a1@mail.gmail.com> <87ocoeq4xw.fsf@gollum.intra.norang.ca> <938fae2d0910120648t5147b4d9y3339d3f06bc732e7@mail.gmail.com> Reply-To: sebastian_rose@gmx.de Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MxO3y-00023A-Da for emacs-orgmode@gnu.org; Mon, 12 Oct 2009 12:47:58 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MxO3t-00020h-Er for emacs-orgmode@gnu.org; Mon, 12 Oct 2009 12:47:57 -0400 Received: from [199.232.76.173] (port=34381 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MxO3t-00020d-8V for emacs-orgmode@gnu.org; Mon, 12 Oct 2009 12:47:53 -0400 Received: from mail.gmx.net ([213.165.64.20]:42294) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1MxO3s-0003yn-MG for emacs-orgmode@gnu.org; Mon, 12 Oct 2009 12:47:53 -0400 In-Reply-To: <938fae2d0910120648t5147b4d9y3339d3f06bc732e7@mail.gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Eraldo Helal Cc: Bernt Hansen , Org-Mode , Carsten Dominik Am Montag, den 12.10.2009, 15:48 +0200 schrieb Eraldo Helal: > > What is Reference/ supposed to be in this case -- a directory? Refiling > > only works to headings (or top level headings) in files in org-mode IIRC. > Yes it is supposed to be a directory... > > I have org files in many directorys... about like so: > reference/emacs/emacs.org > reference/eros/eros.org > reference/Avalon/Avalon.org > reference/Gimp/Gimp.org > reference/office/office.org > reference/home/home.org > reference/poems/poems.org > ... > > What would be a smart way to get a headline from the file inbox.org > named "* Erich Fried poems" to poems.org? > Considering that poems.org is not part of the agenda nor a refile target. > > What I am doing until now is: > folding the headline (tab) > cutting the headline (C-k) > making a split screen (C-x 2) > changing buffer (C-x o) > opening poems.org (C-x C-f "reference/poems/poems.org") > pasting headline (C-y) > changing buffer (C-x o) > removing split view (C-x 1) > > Poems.org is not part of the agenda because it is reference material > and not an active file. > It is also not a refile target because I would have to make every .org > file in all subdirectories a refile target and sometimes the > appropriate file does not yet exist, in which case I need to create > it. > > Any ideas? > Do I need to further try to make clear what I mean? > > Greetings, > Eraldo > Since having so many targets for refiling slows down refiling a lot, I do this here. I've set `org-refile-targets' like this (custom-set-variables): '(org-refile-targets (quote ((org-agenda-files :maxlevel . 3) (sr-org-refile-targets :maxlevel . 2)))) In addition, I have this here in my setup: (defvar sr-org-refile-targets nil "List of refile targets for Org-remember. See `org-refile-targets'.") (defvar sr-org-refile-dir-excludes "^[#\\.].*$") (defvar sr-org-refile-file-excludes "^[#\\.].*$") (defun sr-find-org-refile-targets (&optional recurse dirs file-excludes dir-excludes) "Fill the variable `sr-org-refile-targets'. Optional parameters: recurse If `t', scan the directory recusively. dirs A list of directories to scan for *.org files. file-excludes Regular expression. If a filename matches this regular expression, do not add it to `sr-org-refile-targets'. dir-excludes Regular expression. If a directory name matches this regular expression, do not add it to `sr-org-refile-targets'." (let ((targets (or dirs (list org-directory))) (fex (or file-excludes "^[#\\.].*$")) (dex (or dir-excludes "^[#\\.].*$")) path) (dolist (dir targets) (if (file-directory-p dir) (let ((all (directory-files dir nil "^[^#\\.].*$"))) (dolist (f all) (setq path (concat (file-name-as-directory dir) f)) (cond ((file-directory-p path) (if (and recurse (not (string-match dex f))) (sr-find-org-refile-targets t (list path) fex dex))) ((and (string-match "^[^#\\.].*\\.org$" f) (not (string-match fex f))) (setq sr-org-refile-targets (append (list path) sr-org-refile-targets)))))) (message "Not a directory: %s" path)) ))) (defun sr-add-to-org-refile-targets ( recurse dirs ) "Add a directory to org-refile targets recursively." (interactive "P\nDdirectory: ") (sr-find-org-refile-targets (if recurse t nil) (list dirs) sr-org-refile-file-excludes sr-org-refile-dir-excludes) (message "org-refile-targets: \n%s" sr-org-refile-targets)) Now I call the function `sr-add-to-org-refile-targets' whenever I need to add all Org-files in a directory recursively. Sebastian