emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: John Kitchin <jkitchin@andrew.cmu.edu>
To: emacs-orgmode@gnu.org
Subject: Re: Splitting large org file into smaller ones
Date: Sun, 31 May 2020 11:29:29 -0400	[thread overview]
Message-ID: <m2sgfg9l7q.fsf@andrew.cmu.edu> (raw)
In-Reply-To: <64119DDD-42BD-47AC-9EB6-DD25FE58BB37@ur.rochester.edu>

This seems like an important thing to get right, so I would hesitate to
do this very automatically.

I would write a function that does what you want, maybe like this:

#+BEGIN_SRC emacs-lisp
(defun subtree-to-file ()
  (interactive)
  (org-narrow-to-subtree)
  (goto-char (point-min))
  (let* ((heading (fifth (org-heading-components)))
	 (fname (concat (mapconcat 'downcase (split-string heading) "-") ".org")))
    (when
	(y-or-n-p (format "Write subtree to %s" fname))
      (org-cut-subtree)
      (with-temp-file fname
	(org-yank))))
  (widen)
  (when (not (org-at-heading-p))
    (org-next-visible-heading 1)))
#+END_SRC

This will generate filenames based on the heading name, and move the
content to that file if you agree with the filename. It does not check
if the fname exists, which may be a good idea. It does not do anything
fancy like promote the heading, it just moves it.

It is a good idea to do this on a copy of the original file, so that you
have an un-altered version in case it does not go as planned.


Marvin M. Doyley <mdoyley@ur.rochester.edu> writes:

> Hi there,
>
> Is there an efficient way to split a large org file into smaller ones?
>
> Lets say I have a master file with the following
>
>
> * Notes
> **  Candidate A
>  - Strong technical background
>  - High H-factor
>  - good funding
> - More established investigator
> - Huge startup need $$
>
> **  Candidate B
> - lower startup need
> - signal processing
> - young investigator
>
>
> How do I export the subtree to separate org files, say
>
> - Candidate-a.org <http://candidate-a.org/>
> - Candidate-b.org <http://candidate-b.org/>
>
>
> Thanks
>
> M


--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu


      parent reply	other threads:[~2020-05-31 15:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-30  9:51 Splitting large org file into smaller ones Marvin M. Doyley
2020-05-30 13:13 ` Marcin Borkowski
2020-05-31  0:40   ` Marvin M. Doyley
2020-05-30 14:37 ` Tim Visher
2020-05-30 15:36 ` William Denton
2020-05-30 18:18   ` Julius Dittmar
2020-05-31  0:42   ` Marvin M. Doyley
2020-05-30 22:23 ` Diego Zamboni
2020-05-31  0:41   ` Marvin M. Doyley
2020-05-31 15:29 ` John Kitchin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2sgfg9l7q.fsf@andrew.cmu.edu \
    --to=jkitchin@andrew.cmu.edu \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).