Skip to content

Instantly share code, notes, and snippets.

@jdtsmith
Last active October 26, 2022 17:50
Show Gist options
  • Save jdtsmith/4b14a6c2c1b06e9089b729afd10a16fd to your computer and use it in GitHub Desktop.
Save jdtsmith/4b14a6c2c1b06e9089b729afd10a16fd to your computer and use it in GitHub Desktop.
org transpose: transpose shared level 1 and level 2 org headlines (i.e. grouping by level 2), and display in a new (read-only) buffer.
(defun my/org-transpose-view ()
(interactive)
(let* ((tree (org-element-parse-buffer 'headline))
(buf (current-buffer))
(tbuf (concat "*" (buffer-name buf) "-transpose*"))
tp)
(org-element-map tree 'headline
(lambda (hl)
(if (eq (org-element-property :level hl) 2) ;only level 2
(let* ((l2 (org-element-property :raw-value hl))
(parent (org-element-property :parent hl)) ; level 1 parent
(l1 (org-element-property :raw-value parent)))
(push (cons l1
(mapcar (lambda (k) (org-element-property k hl))
'(:contents-begin :contents-end)))
(alist-get l2 tp nil nil #'equal))))))
(with-current-buffer-window tbuf nil nil
(mapc (lambda (l2grp)
(insert "* " (car l2grp) ?\n)
(dolist (l1grp (nreverse (cdr l2grp)))
(insert "** " (car l1grp) ?\n
(with-current-buffer buf
(apply #'buffer-substring (cdr l1grp))))))
(nreverse tp))
(org-mode))))

Day 1

Process 1

Something something.

Process 2

Whose it now?

Process 3

In which I know something you don’t.

With several

Don’t you know

Sub-categories

As you do

Process 4

How long will it last?

Day 2

Process 1

I remember yesterday.

Process 2

Getting the hang of this.

Process 4

We forgot process 3.

Day 3

Process 1

It really is the finest of processes. The finest.

Process 2

Suppose

you

have
a
deeplyrecursive and disjointedday

What then?

I’ll tell you what… tomorrow.

Process 3

We really hate this process.

Process 4

When will the clock strike 4?

Day 4

Process 1

The secret to success? Efficiency.

Process 2

Ruthless efficiency.

Process 3

And Snacks.

Process 4

Lots of Snacks.

@jdtsmith
Copy link
Author

jdtsmith commented Oct 26, 2022

Just go to the buffer of the included org file and M-x my/org-transpose-view. Looking like:
image
and presto-chango:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment