emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Archive subtrees hierarchical (keep the parent structure)
@ 2014-08-04 19:29 Florian Adamsky
  2014-08-05  1:55 ` Eric Abrahamsen
  2014-08-05 12:25 ` Ken Mankoff
  0 siblings, 2 replies; 10+ messages in thread
From: Florian Adamsky @ 2014-08-04 19:29 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1345 bytes --]

Dear all,

some of my org-mode files are getting bigger and bigger. So, I decided
to use the archive feature to remove old stuff. However, I was not happy
with the current archive feature, because it just puts subtrees
unorganized in the archive file.

I was more looking for a way to archive a subtree, but keep the parent
structure. Means, if the point is at the subtree "*** FOO" in the
following example:

* A
** B
*** FOO

then it should copy the heading "* A" and "** B" to the archive file and
then move "*** Foo" to it. The only thing that I found was a feature
request from Florian Lindner [fn:1]. A couple of days I was given it a
shot and tried to implement that myself. Attached you'll find my
attempt.

It is a bit hackish, but it works for me. I think the attached code
misses two features:
  1. it only copies the parent headings with tags, but ignores
  properties and stuff like that

  2. it ignores org-reverse-note-order, but that should not be too hard
  to add.

Before I work on it again, I would like to hear your comments. Have I
implemented functions that are already in org-mode? Is this feature
useful for other people? Does it in more complicated org-mode files?

Best regards

Footnotes:

[fn:1] https://lists.gnu.org/archive/html/emacs-orgmode/2014-05/msg01214.html
--
Florian Adamsky
http://florian.adamsky.it/



[-- Attachment #2: org-archive-subtree-hierarchical.el --]
[-- Type: application/emacs-lisp, Size: 3333 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Archive subtrees hierarchical (keep the parent structure)
  2014-08-04 19:29 Archive subtrees hierarchical (keep the parent structure) Florian Adamsky
@ 2014-08-05  1:55 ` Eric Abrahamsen
  2014-08-05 11:08   ` Florian Adamsky
  2014-08-05 12:25 ` Ken Mankoff
  1 sibling, 1 reply; 10+ messages in thread
From: Eric Abrahamsen @ 2014-08-05  1:55 UTC (permalink / raw)
  To: emacs-orgmode

Florian Adamsky <fa-orgmode@haktar.org> writes:

> Dear all,
>
> some of my org-mode files are getting bigger and bigger. So, I decided
> to use the archive feature to remove old stuff. However, I was not happy
> with the current archive feature, because it just puts subtrees
> unorganized in the archive file.
>
> I was more looking for a way to archive a subtree, but keep the parent
> structure. Means, if the point is at the subtree "*** FOO" in the
> following example:
>
> * A
> ** B
> *** FOO
>
> then it should copy the heading "* A" and "** B" to the archive file and
> then move "*** Foo" to it. The only thing that I found was a feature
> request from Florian Lindner [fn:1]. A couple of days I was given it a
> shot and tried to implement that myself. Attached you'll find my
> attempt.

Thanks for this work -- I think this is a nice feature. One concern
about the above is that, if you're archiving many FOOs, then you'll get
a whole bunch of duplicate A/B parent structures. There are several
places in my agenda files where I have the exact structure in your
example, and a *whole* lot of FOOs going in and getting archived out.
How hard would it be to look for an existing A/B parent structure in the
archive file, and put FOO there if it's found? Not a perfect solution,
since you might have more than one A/B, but seems like it would help in
a majority of cases...

Thanks again,
Eric

> It is a bit hackish, but it works for me. I think the attached code
> misses two features:
>   1. it only copies the parent headings with tags, but ignores
>   properties and stuff like that
>
>   2. it ignores org-reverse-note-order, but that should not be too hard
>   to add.
>
> Before I work on it again, I would like to hear your comments. Have I
> implemented functions that are already in org-mode? Is this feature
> useful for other people? Does it in more complicated org-mode files?
>
> Best regards
>
> Footnotes:
>
> [fn:1] https://lists.gnu.org/archive/html/emacs-orgmode/2014-05/msg01214.html
> --
> Florian Adamsky
> http://florian.adamsky.it/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Archive subtrees hierarchical (keep the parent structure)
  2014-08-05  1:55 ` Eric Abrahamsen
@ 2014-08-05 11:08   ` Florian Adamsky
  2014-08-05 11:23     ` Eric Abrahamsen
  0 siblings, 1 reply; 10+ messages in thread
From: Florian Adamsky @ 2014-08-05 11:08 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Eric Abrahamsen

Dear Eric,

On Tuesday, Aug 05 2014, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:

> Thanks for this work -- I think this is a nice feature. One concern
> about the above is that, if you're archiving many FOOs, then you'll get
> a whole bunch of duplicate A/B parent structures. There are several
> places in my agenda files where I have the exact structure in your
> example, and a *whole* lot of FOOs going in and getting archived out.
> How hard would it be to look for an existing A/B parent structure in the
> archive file, and put FOO there if it's found? Not a perfect solution,
> since you might have more than one A/B, but seems like it would help in
> a majority of cases...

if I understand you correctly, then I have already implemented that. If
I would like to archive "*** Foo", the function (fa/org-struct-subtree)
returns the parent headings as a list, e.g. ("*A " "** B"). Inside the
archive file, I search for "* A" and inside that heading I search for
"** B". If "** B" was not found, it inserts the remaining list that was
not found and does not create a new "* A" again. This means if you have
"*A " and "** B" already in your archive file it will not add a new A/B.

A problem exists if you have the exact same structure twice in one file like
the following example:

* A
** B
*** FOO

* A
** B
*** FOO

If you would archive both *** FOO, then the archive file would look like
this:

* A
** B
*** FOO
*** FOO

In order to fix that problem we need a unique id for every heading. My
current implementation implies that at least the first heading is
unique. Then it should not be a problem.

Best regards
--
Florian Adamsky
http://florian.adamsky.it/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Archive subtrees hierarchical (keep the parent structure)
  2014-08-05 11:08   ` Florian Adamsky
@ 2014-08-05 11:23     ` Eric Abrahamsen
  0 siblings, 0 replies; 10+ messages in thread
From: Eric Abrahamsen @ 2014-08-05 11:23 UTC (permalink / raw)
  To: emacs-orgmode

Florian Adamsky <fa-orgmode@haktar.org> writes:

> Dear Eric,
>
> On Tuesday, Aug 05 2014, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:
>
>> Thanks for this work -- I think this is a nice feature. One concern
>> about the above is that, if you're archiving many FOOs, then you'll get
>> a whole bunch of duplicate A/B parent structures. There are several
>> places in my agenda files where I have the exact structure in your
>> example, and a *whole* lot of FOOs going in and getting archived out.
>> How hard would it be to look for an existing A/B parent structure in the
>> archive file, and put FOO there if it's found? Not a perfect solution,
>> since you might have more than one A/B, but seems like it would help in
>> a majority of cases...
>
> if I understand you correctly, then I have already implemented that. If
> I would like to archive "*** Foo", the function (fa/org-struct-subtree)
> returns the parent headings as a list, e.g. ("*A " "** B"). Inside the
> archive file, I search for "* A" and inside that heading I search for
> "** B". If "** B" was not found, it inserts the remaining list that was
> not found and does not create a new "* A" again. This means if you have
> "*A " and "** B" already in your archive file it will not add a new A/B.

Excellent! That's just what I meant, and it sounds like you've already
taken care of it. Personally I don't mind if items get filed under the
wrong parent structure (in case of duplicate parent structures), but if
you wanted to do the unique id trick, that would be nice too!

Thanks,
Eric

> A problem exists if you have the exact same structure twice in one file like
> the following example:
>
> * A
> ** B
> *** FOO
>
> * A
> ** B
> *** FOO
>
> If you would archive both *** FOO, then the archive file would look like
> this:
>
> * A
> ** B
> *** FOO
> *** FOO
>
> In order to fix that problem we need a unique id for every heading. My
> current implementation implies that at least the first heading is
> unique. Then it should not be a problem.
>
> Best regards
> --
> Florian Adamsky
> http://florian.adamsky.it/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Archive subtrees hierarchical (keep the parent structure)
  2014-08-04 19:29 Archive subtrees hierarchical (keep the parent structure) Florian Adamsky
  2014-08-05  1:55 ` Eric Abrahamsen
@ 2014-08-05 12:25 ` Ken Mankoff
  2014-08-05 15:32   ` Florian Adamsky
  1 sibling, 1 reply; 10+ messages in thread
From: Ken Mankoff @ 2014-08-05 12:25 UTC (permalink / raw)
  To: Florian Adamsky; +Cc: emacs-orgmode

Hi Florian,

This code looks useful and an improvement over the previous setup I was
using. https://lists.gnu.org/archive/html/emacs-orgmode/2014-05/msg01218.html

Can you explain what else is needed for your code to work? Currently I
have

#+BEGIN_SRC emacs-lisp
(setq org-archive-location (concat org-directory "/archive/%s_archive::"))
#+END_SRC

But I don't see things archived as subtrees with just this. Do I need
new/different configuration to work with your code?

Thanks,

  -k.


* On 2014-08-04 at 15:29, Florian Adamsky wrote:
> Dear all,
>
> some of my org-mode files are getting bigger and bigger. So, I decided
> to use the archive feature to remove old stuff. However, I was not happy
> with the current archive feature, because it just puts subtrees
> unorganized in the archive file.
>
> I was more looking for a way to archive a subtree, but keep the parent
> structure. Means, if the point is at the subtree "*** FOO" in the
> following example:
>
> * A
> ** B
> *** FOO
>
> then it should copy the heading "* A" and "** B" to the archive file and
> then move "*** Foo" to it. The only thing that I found was a feature
> request from Florian Lindner [fn:1]. A couple of days I was given it a
> shot and tried to implement that myself. Attached you'll find my
> attempt.
>
> It is a bit hackish, but it works for me. I think the attached code
> misses two features:
>   1. it only copies the parent headings with tags, but ignores
>   properties and stuff like that
>
>   2. it ignores org-reverse-note-order, but that should not be too hard
>   to add.
>
> Before I work on it again, I would like to hear your comments. Have I
> implemented functions that are already in org-mode? Is this feature
> useful for other people? Does it in more complicated org-mode files?
>
> Best regards
>
> Footnotes:
>
> [fn:1] https://lists.gnu.org/archive/html/emacs-orgmode/2014-05/msg01214.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Archive subtrees hierarchical (keep the parent structure)
  2014-08-05 12:25 ` Ken Mankoff
@ 2014-08-05 15:32   ` Florian Adamsky
  2014-08-05 16:39     ` Ken Mankoff
  0 siblings, 1 reply; 10+ messages in thread
From: Florian Adamsky @ 2014-08-05 15:32 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Ken Mankoff

Dear Ken,

On Tuesday, Aug 05 2014, Ken Mankoff wrote:

> This code looks useful and an improvement over the previous setup I was
> using. https://lists.gnu.org/archive/html/emacs-orgmode/2014-05/msg01218.html
>
> Can you explain what else is needed for your code to work? Currently I
> have

at the moment, I just run the function org-archive-subtree-hierarchical
interactively.

> #+BEGIN_SRC emacs-lisp
> (setq org-archive-location (concat org-directory "/archive/%s_archive::"))
> #+END_SRC
>
> But I don't see things archived as subtrees with just this. Do I need
> new/different configuration to work with your code?

No, just run M-x org-archive-subtree-hierarchical. I tried the code with
the latest org-mode version 8.3beta and with emacs -q and in both cases
it works without problems.

However, if you set the following variable to the new function, it
should work with the default keybinding for org-archive:

#+BEGIN_SRC emacs-lisp
(setq org-archive-default-command 'org-archive-subtree-hierarchical)
#+END_SRC

If you have any trouble, please give me a note.

Best
--
Florian Adamsky
http://florian.adamsky.it/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Archive subtrees hierarchical (keep the parent structure)
  2014-08-05 15:32   ` Florian Adamsky
@ 2014-08-05 16:39     ` Ken Mankoff
  2014-08-05 17:46       ` Florian Adamsky
  0 siblings, 1 reply; 10+ messages in thread
From: Ken Mankoff @ 2014-08-05 16:39 UTC (permalink / raw)
  To: Florian Adamsky; +Cc: emacs-orgmode

Hi Florian,

* On 2014-08-05 at 11:32, Florian Adamsky wrote:
>> This code looks useful and an improvement over the previous setup I
>> was
>> using. https://lists.gnu.org/archive/html/emacs-orgmode/2014-05/msg01218.html
>>
>> Can you explain what else is needed for your code to work? Currently I
>> have
>
> No, just run M-x org-archive-subtree-hierarchical. I tried the code
> with the latest org-mode version 8.3beta and with emacs -q and in both
> cases it works without problems.
>
> However, if you set the following variable to the new function, it
> should work with the default keybinding for org-archive:
>
> #+BEGIN_SRC emacs-lisp
> (setq org-archive-default-command 'org-archive-subtree-hierarchical)
> #+END_SRC
>
> If you have any trouble, please give me a note.

You are correct that M-x org-archive-subtree-hierarchical works just
fine. But I can't get it to work with the default keybinding as you show
above. 

C-c C-x C-s is my (the?) default keybinding for archiving
trees/subtrees.  Is this the correct keybinding?

When I describe that with C-h k C-c C-x C-s I see:

> C-c C-x C-s runs the command org-advertized-archive-subtree, which is
> an alias for `org-archive-subtree' in `org.el'.
>
> It is bound to C-c C-x C-s, <menu-bar> <Org> <Archive> <Move Subtree
> to Archive file>.
> 
> (org-advertized-archive-subtree &optional FIND-DONE)

So I have tried mapping all of those to call the new function:

(setq org-archive-default-command 'org-archive-subtree-hierarchical)
(setq org-archive-subtree 'org-archive-subtree-hierarchical)
(setq org-advertized-archive-subtree 'org-archive-subtree-hierarchical)

But it still doesn't work. I can bind org-archive-subtree-hierarchical
directly to C-c C-x C-s, which will work. Is that the correct solution?

Thanks,

  -k.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Archive subtrees hierarchical (keep the parent structure)
  2014-08-05 16:39     ` Ken Mankoff
@ 2014-08-05 17:46       ` Florian Adamsky
  2014-08-05 18:00         ` Ken Mankoff
  0 siblings, 1 reply; 10+ messages in thread
From: Florian Adamsky @ 2014-08-05 17:46 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Ken Mankoff

Dear Ken,

On Tuesday, Aug 05 2014, Ken Mankoff <mankoff@gmail.com> wrote:

> You are correct that M-x org-archive-subtree-hierarchical works just
> fine. But I can't get it to work with the default keybinding as you show
> above.
>
> C-c C-x C-s is my (the?) default keybinding for archiving
> trees/subtrees.  Is this the correct keybinding?

according to the documentation the default keybinding to archive the
current entry is C-c C-x C-a. Could you try that instead?

[...]

Best
--
Florian Adamsky
http://florian.adamsky.it/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Archive subtrees hierarchical (keep the parent structure)
  2014-08-05 17:46       ` Florian Adamsky
@ 2014-08-05 18:00         ` Ken Mankoff
  2014-11-04 17:03           ` Dylan Schwilk
  0 siblings, 1 reply; 10+ messages in thread
From: Ken Mankoff @ 2014-08-05 18:00 UTC (permalink / raw)
  To: Florian Adamsky; +Cc: Org-mode

[-- Attachment #1: Type: text/plain, Size: 740 bytes --]

Yes that works perfectly. Not sure why I had memorized a different
keystroke. Thank you!



On Tue, Aug 5, 2014 at 1:46 PM, Florian Adamsky <fa-orgmode@haktar.org>
wrote:

> Dear Ken,
>
> On Tuesday, Aug 05 2014, Ken Mankoff <mankoff@gmail.com> wrote:
>
> > You are correct that M-x org-archive-subtree-hierarchical works just
> > fine. But I can't get it to work with the default keybinding as you show
> > above.
> >
> > C-c C-x C-s is my (the?) default keybinding for archiving
> > trees/subtrees.  Is this the correct keybinding?
>
> according to the documentation the default keybinding to archive the
> current entry is C-c C-x C-a. Could you try that instead?
>
> [...]
>
> Best
> --
> Florian Adamsky
> http://florian.adamsky.it/
>

[-- Attachment #2: Type: text/html, Size: 1311 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Archive subtrees hierarchical (keep the parent structure)
  2014-08-05 18:00         ` Ken Mankoff
@ 2014-11-04 17:03           ` Dylan Schwilk
  0 siblings, 0 replies; 10+ messages in thread
From: Dylan Schwilk @ 2014-11-04 17:03 UTC (permalink / raw)
  To: Org-mode; +Cc: Florian Adamsky

[-- Attachment #1: Type: text/plain, Size: 1539 bytes --]

Dear Florian,

I just found this code you wrote and it is exactly what I wanted for my
archiving.  But I found one little issue.  I discovered that this interacts
with the setting  org-yank-adjusted-subtrees because it calls org-yank.
With
(setq org-yank-justed-subtrees t), the archived subtree is not pasted in as
a child of the created hierarchy, but ends up as a sibling because org-yank
calls org-paste-subtree.

My current workaround is to set  org-yank-adjusted-subtrees nil, but
perhaps there is a clean way to turn off this setting in org-yank so that
org-paste-subtree is not called in this particular case regardless of the
value of org-yank-adjusted-subtrees?

- Dylan Schwilk

On Tue, Aug 5, 2014 at 1:00 PM, Ken Mankoff <mankoff@gmail.com> wrote:

> Yes that works perfectly. Not sure why I had memorized a different
> keystroke. Thank you!
>
>
>
> On Tue, Aug 5, 2014 at 1:46 PM, Florian Adamsky <fa-orgmode@haktar.org>
> wrote:
>
>> Dear Ken,
>>
>> On Tuesday, Aug 05 2014, Ken Mankoff <mankoff@gmail.com> wrote:
>>
>> > You are correct that M-x org-archive-subtree-hierarchical works just
>> > fine. But I can't get it to work with the default keybinding as you show
>> > above.
>> >
>> > C-c C-x C-s is my (the?) default keybinding for archiving
>> > trees/subtrees.  Is this the correct keybinding?
>>
>> according to the documentation the default keybinding to archive the
>> current entry is C-c C-x C-a. Could you try that instead?
>>
>> [...]
>>
>> Best
>> --
>> Florian Adamsky
>> http://florian.adamsky.it/
>>
>
>

[-- Attachment #2: Type: text/html, Size: 2473 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-11-04 17:03 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-04 19:29 Archive subtrees hierarchical (keep the parent structure) Florian Adamsky
2014-08-05  1:55 ` Eric Abrahamsen
2014-08-05 11:08   ` Florian Adamsky
2014-08-05 11:23     ` Eric Abrahamsen
2014-08-05 12:25 ` Ken Mankoff
2014-08-05 15:32   ` Florian Adamsky
2014-08-05 16:39     ` Ken Mankoff
2014-08-05 17:46       ` Florian Adamsky
2014-08-05 18:00         ` Ken Mankoff
2014-11-04 17:03           ` Dylan Schwilk

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).