Re: Splitting large org file into smaller ones

2020-05-31 Thread John Kitchin
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  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 
> - 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



Re: Splitting large org file into smaller ones

2020-05-30 Thread Marvin M. Doyley
Thanks Bill

> On May 30, 2020, at 11:36 AM, William Denton  wrote:
> 
> On 30 May 2020, Marvin M. Doyley wrote:
> 
>> How do I export the subtree to separate org files, say
>> 
>> - Candidate-a.org 
>> >  >
>> - Candidate-b.org 
>> >  >
> 
> I'll throw out an uninformed suggestion of a possible direction:  archiving 
> subtrees.  I guess you'd have to keep changing the name of the target archive 
> file, or rename it after you'd moved a tree to it, but at least it's getting 
> a whole tree out of the way at once.
> 
> Bill
> --
> William Denton :: Toronto, Canada   ---   Listening to Art: 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__listeningtoart.org_=DwIBAg=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU=T41F_5QsIVBGYhPPUkgYHUp9iPHgs2rOCjs7rfKaTMU=bIZSMkqv64C1tMXjpulbll5ho0_g78uEvbSGB385-YQ=3SYzbH-wXEZ1etjDC-J5keIPie3ll0ngiWihrTPputs=
>  
> https://urldefense.proofpoint.com/v2/url?u=https-3A__www.miskatonic.org_=DwIBAg=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU=T41F_5QsIVBGYhPPUkgYHUp9iPHgs2rOCjs7rfKaTMU=bIZSMkqv64C1tMXjpulbll5ho0_g78uEvbSGB385-YQ=Eyy6EE7boaclNVgLZFy6YP4RM57VQQMr5pBFDOdY5Zo=
>   ---   GHG.EARTH: 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__ghg.earth_=DwIBAg=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU=T41F_5QsIVBGYhPPUkgYHUp9iPHgs2rOCjs7rfKaTMU=bIZSMkqv64C1tMXjpulbll5ho0_g78uEvbSGB385-YQ=WZpqujYA7GRmIP00WVRuyH4g-hRRFcrNhWV9O27p0F0=
>  Caveat lector.  ---   STAPLR: 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__staplr.org_=DwIBAg=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU=T41F_5QsIVBGYhPPUkgYHUp9iPHgs2rOCjs7rfKaTMU=bIZSMkqv64C1tMXjpulbll5ho0_g78uEvbSGB385-YQ=sKITlXUZ5Q6MQoPb4RFPynZVydyakhlNKabGQieVC7c=
>  




Re: Splitting large org file into smaller ones

2020-05-30 Thread Marvin M. Doyley
Cool! I will try this too

Thanks

Cheers,
M

> On May 30, 2020, at 6:23 PM, Diego Zamboni  wrote:
> 
> Hi Marvin,
> 
> I replied to a similar question some time ago, here's my answer (with
> updated links since the files have changed in the meantime):
> 
> I do something similar in my ox-leanpub-book module [1], which exports
> each top-level heading to a different file. The general idea is to use
> =org-map-entries= to loop over the entire buffer [2]. The function you
> call can then check whether the current entry is a header at the level
> you want [3] and then export it to the corresponding file. The title
> can be used to deduct the filename [4].
> 
> I found that I had to mark the entire subtree before calling the
> export function [5], otherwise the headline was not getting included
> in the export.
> 
> I based my code originally on this blog post, which might be a simpler
> starting point:
> https://urldefense.proofpoint.com/v2/url?u=https-3A__medium.com_-40lakshminp_publishing-2Da-2Dbook-2Dusing-2Dorg-2Dmode-2D9e817a56d144=DwIBaQ=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU=T41F_5QsIVBGYhPPUkgYHUp9iPHgs2rOCjs7rfKaTMU=249GZv4Zgx7zyEm64J3m2eEYuchXSdodRltw_gmrqlg=exfuDxb81D5anZ5KD-hCvUI4PRaQxsb812EaBW3b9p4=
>  
> - this code does not select the entire subtree before exporting, which
> means only the contents of the section is exported, but not the
> headline itself.
> 
> I wrote a simplified function which puts the above ideas together,
> feel free to use it:
> https://urldefense.proofpoint.com/v2/url?u=https-3A__gist.github.com_zzamboni_2e6ac3c4f577249d98efb224d9d34488=DwIBaQ=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU=T41F_5QsIVBGYhPPUkgYHUp9iPHgs2rOCjs7rfKaTMU=249GZv4Zgx7zyEm64J3m2eEYuchXSdodRltw_gmrqlg=ARDFenWJJT9XTsBKAReDC6bDx9VwbP3ADCw3o-_hQbY=
>  
> 
> Hope this helps!
> --Diego
> 
> [1] 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_zzamboni_ox-2Dleanpub_tree_book-2Dand-2Dmarkua=DwIBaQ=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU=T41F_5QsIVBGYhPPUkgYHUp9iPHgs2rOCjs7rfKaTMU=249GZv4Zgx7zyEm64J3m2eEYuchXSdodRltw_gmrqlg=peXBLnzs1ABFnCABzVUsley3-VMFDR0_2oLF3TgiBPM=
>  
> [2] 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_zzamboni_ox-2Dleanpub_blob_f7ae0f86f517a321a5150e1c712554b12acf144b_ox-2Dleanpub-2Dbook.el-23L216-2DL217=DwIBaQ=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU=T41F_5QsIVBGYhPPUkgYHUp9iPHgs2rOCjs7rfKaTMU=249GZv4Zgx7zyEm64J3m2eEYuchXSdodRltw_gmrqlg=3K2q6g7FxxjjxKJZtqdsE5bpMFT6RTf3S4mmyldNdLw=
>  
> [3] 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_zzamboni_ox-2Dleanpub_blob_f7ae0f86f517a321a5150e1c712554b12acf144b_ox-2Dleanpub-2Dbook.el-23L145=DwIBaQ=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU=T41F_5QsIVBGYhPPUkgYHUp9iPHgs2rOCjs7rfKaTMU=249GZv4Zgx7zyEm64J3m2eEYuchXSdodRltw_gmrqlg=QOtk1D413Gju7Agm6zgbAMlIwww6e-UV1SZsjomzuZA=
>  
> [4] 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_zzamboni_ox-2Dleanpub_blob_f7ae0f86f517a321a5150e1c712554b12acf144b_ox-2Dleanpub-2Dbook.el-23L154-2DL158=DwIBaQ=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU=T41F_5QsIVBGYhPPUkgYHUp9iPHgs2rOCjs7rfKaTMU=249GZv4Zgx7zyEm64J3m2eEYuchXSdodRltw_gmrqlg=ynLKEu4CLjIJqR3y3zl2UMEkS_onMBSSb2TDwOaixt4=
>  
> [5] 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_zzamboni_ox-2Dleanpub_blob_f7ae0f86f517a321a5150e1c712554b12acf144b_ox-2Dleanpub-2Dbook.el-23L192=DwIBaQ=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU=T41F_5QsIVBGYhPPUkgYHUp9iPHgs2rOCjs7rfKaTMU=249GZv4Zgx7zyEm64J3m2eEYuchXSdodRltw_gmrqlg=quomDHaK1zPArr8wu5m8uwkgug6NZ6eDChE5VMZwrG4=
>  
> 
> On Sat, May 30, 2020 at 12:08 PM Marvin M. Doyley
>  wrote:
>> 
>> 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
>> - Candidate-b.org
>> 
>> 
>> Thanks
>> 
>> M




Re: Splitting large org file into smaller ones

2020-05-30 Thread Marvin M. Doyley
Hi Marcin,

I appreciate this, I will give it a go.

Thanks,
M

> On May 30, 2020, at 9:13 AM, Marcin Borkowski  wrote:
> 
> 
> On 2020-05-30, at 11:51, Marvin M. Doyley  wrote:
> 
>> Hi there,
>> 
>> Is there an efficient way to split a large org file into smaller ones?
> 
> I do not know about "efficient", but you might find my org-one-to-many
> library useful: 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_mbork_org-2Done-2Dto-2Dmany=DwIBAg=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU=T41F_5QsIVBGYhPPUkgYHUp9iPHgs2rOCjs7rfKaTMU=iHWQZlKMtTtC96Iqx0ymA0VpA5m6A73UehcV_vuh1tM=6rsipfH8vh-XeWLb1NEWAcdpcTFAfyUOLHD5Pkmea2o=
>  
> (Note that I don't wven know if it works with newer versions of Org; if
> not, drop me a line, maybe I'll be able to fix it.)
> 
> Best,
> 
> -- 
> Marcin Borkowski
> https://urldefense.proofpoint.com/v2/url?u=http-3A__mbork.pl=DwIBAg=kbmfwr1Yojg42sGEpaQh5ofMHBeTl9EI2eaqQZhHbOU=T41F_5QsIVBGYhPPUkgYHUp9iPHgs2rOCjs7rfKaTMU=iHWQZlKMtTtC96Iqx0ymA0VpA5m6A73UehcV_vuh1tM=VLUzcQS7YObsdTrrwTldDMYEUZJlqE3mMIxxY8tN9JQ=
>  




Re: Splitting large org file into smaller ones

2020-05-30 Thread Diego Zamboni
Hi Marvin,

I replied to a similar question some time ago, here's my answer (with
updated links since the files have changed in the meantime):

I do something similar in my ox-leanpub-book module [1], which exports
each top-level heading to a different file. The general idea is to use
=org-map-entries= to loop over the entire buffer [2]. The function you
call can then check whether the current entry is a header at the level
you want [3] and then export it to the corresponding file. The title
can be used to deduct the filename [4].

I found that I had to mark the entire subtree before calling the
export function [5], otherwise the headline was not getting included
in the export.

I based my code originally on this blog post, which might be a simpler
starting point:
https://medium.com/@lakshminp/publishing-a-book-using-org-mode-9e817a56d144
- this code does not select the entire subtree before exporting, which
means only the contents of the section is exported, but not the
headline itself.

I wrote a simplified function which puts the above ideas together,
feel free to use it:
https://gist.github.com/zzamboni/2e6ac3c4f577249d98efb224d9d34488

Hope this helps!
--Diego

[1] https://github.com/zzamboni/ox-leanpub/tree/book-and-markua
[2] 
https://github.com/zzamboni/ox-leanpub/blob/f7ae0f86f517a321a5150e1c712554b12acf144b/ox-leanpub-book.el#L216-L217
[3] 
https://github.com/zzamboni/ox-leanpub/blob/f7ae0f86f517a321a5150e1c712554b12acf144b/ox-leanpub-book.el#L145
[4] 
https://github.com/zzamboni/ox-leanpub/blob/f7ae0f86f517a321a5150e1c712554b12acf144b/ox-leanpub-book.el#L154-L158
[5] 
https://github.com/zzamboni/ox-leanpub/blob/f7ae0f86f517a321a5150e1c712554b12acf144b/ox-leanpub-book.el#L192

On Sat, May 30, 2020 at 12:08 PM Marvin M. Doyley
 wrote:
>
> 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
> - Candidate-b.org
>
>
> Thanks
>
> M



Re: Splitting large org file into smaller ones

2020-05-30 Thread Julius Dittmar



Am 30.05.20 um 17:36 schrieb William Denton:
> On 30 May 2020, Marvin M. Doyley wrote:
>
>> How do I export the subtree to separate org files, say
>>
>> - Candidate-a.org 
>> - Candidate-b.org 
>
> I'll throw out an uninformed suggestion of a possible direction: 
> archiving subtrees.  I guess you'd have to keep changing the name of
> the target archive file, or rename it after you'd moved a tree to it,
> but at least it's getting a whole tree out of the way at once.

If you'll end up naming the files yourself, then I suggest killing the
whole subtree by C-c C-x C-w (|org-cut-subtree|) with point in the
heading, opening the new file, then yanking the subtree by C-c C-x C-y
(org-paste-subtree).

You could also use the refile mechanism for that, though I never managed
to wrap my head around that one.

HTH,
Julius



Re: Splitting large org file into smaller ones

2020-05-30 Thread William Denton

On 30 May 2020, Marvin M. Doyley wrote:


How do I export the subtree to separate org files, say

- Candidate-a.org 
- Candidate-b.org 


I'll throw out an uninformed suggestion of a possible direction:  archiving 
subtrees.  I guess you'd have to keep changing the name of the target archive 
file, or rename it after you'd moved a tree to it, but at least it's getting a 
whole tree out of the way at once.


Bill
--
William Denton :: Toronto, Canada   ---   Listening to Art: 
https://listeningtoart.org/
https://www.miskatonic.org/ ---   GHG.EARTH: https://ghg.earth/
Caveat lector.  ---   STAPLR: https://staplr.org/



Re: Splitting large org file into smaller ones

2020-05-30 Thread Tim Visher
On Sat, May 30, 2020 at 6:09 AM Marvin M. Doyley 
wrote:

> 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
> …
> **  Candidate B
> …
>
> How do I export the subtree to separate org files, say
>
> - Candidate-a.org 
> - Candidate-b.org 
>

This seems like it would be fairly trivial with a keyboard macro. Certainly
not the most satisfying solution but if you're not doing this all the time
it might be the closest option.


Re: Splitting large org file into smaller ones

2020-05-30 Thread Marcin Borkowski


On 2020-05-30, at 11:51, Marvin M. Doyley  wrote:

> Hi there,
>
> Is there an efficient way to split a large org file into smaller ones?

I do not know about "efficient", but you might find my org-one-to-many
library useful: https://github.com/mbork/org-one-to-many
(Note that I don't wven know if it works with newer versions of Org; if
not, drop me a line, maybe I'll be able to fix it.)

Best,

-- 
Marcin Borkowski
http://mbork.pl



Splitting large org file into smaller ones

2020-05-30 Thread Marvin M. Doyley
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 
- Candidate-b.org 


Thanks

M