From e54b77c8d7f5715fab3424f3332fe1fbe0210577 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Thu, 1 Jun 2023 22:46:52 -0700 Subject: [oni-org] Automatically hide source code blocks marked as hidden Source: https://emacs.stackexchange.com/questions/44914/choose-individual-startup-visibility-of-org-modes-source-blocks --- oni-org/oni-org.el | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'oni-org/oni-org.el') diff --git a/oni-org/oni-org.el b/oni-org/oni-org.el index 55e88c8..f401f60 100644 --- a/oni-org/oni-org.el +++ b/oni-org/oni-org.el @@ -4,7 +4,7 @@ ;; Author: Tom Willemse ;; Keywords: local -;; Version: 2023.0530.174013 +;; Version: 2023.0601.224638 ;; Package-Requires: (oni-yasnippet oni-alert oni-hydra org org-bullets org-edna diminish all-the-icons olivetti form-feed org-pretty-table) ;; This program is free software; you can redistribute it and/or modify @@ -1210,5 +1210,22 @@ otherwise return ‘oni-org-link-nonexistent-file’." (org-link-set-parameters "file" :face #'oni-org-file-face-selector) +;;; Automatically hide code blocks that specify they should be hidden. +;; Inspired by +;; https://emacs.stackexchange.com/questions/44914/choose-individual-startup-visibility-of-org-modes-source-blocks + +(defun oni-org-hide-hidden-code-blocks () + "Hide any code blocks that have been marked as hidden. +This is done by adding a ‘:hidden t’ header argument to the code block." + (interactive) + (org-block-map + (lambda () + (let ((element (org-element-at-point))) + (when (and (equal (org-element-type element) 'src-block) + (map-elt (nth 2 (org-babel-get-src-block-info)) :hidden)) + (org-fold-hide-block-toggle t nil element)))))) + +(add-hook 'org-mode-hook #'oni-org-hide-hidden-code-blocks) + (provide 'oni-org) ;;; oni-org.el ends here -- cgit v1.2.3-54-g00ecf