Skip to content

Instantly share code, notes, and snippets.

@whhone
Last active December 4, 2023 08:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whhone/e8960bc2d22c1168499d9393a2d58e7d to your computer and use it in GitHub Desktop.
Save whhone/e8960bc2d22c1168499d9393a2d58e7d to your computer and use it in GitHub Desktop.
Emacs lisp function to jump to random org heading. Useful for getting a random note from a giant org file.
(defun my/org-random-heading ()
"Jump to a random org heading in the current org file."
(interactive)
(goto-char (point-min))
(let ((headings '()))
(while (re-search-forward "^\\*+ " nil t)
(push (point) headings))
(when headings
(goto-char (nth (random (length headings)) headings))
(org-reveal))))
(with-eval-after-load "org"
(define-key org-mode-map (kbd "C-c n R") #'my/org-random-heading))
@unhammer
Copy link

There is also M-x org-random-todo-goto-new from https://github.com/unhammer/org-random-todo :)

@whhone
Copy link
Author

whhone commented Nov 29, 2023

Thanks @unhammer ! Good to know!

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