0

I found this reddit post which has a config to hide the header context of a inline src block. So, using the config, inline source like src_python{return 123}, becomes {return 123}. I customized it so that it automatically toggles the visibility between normal and insert modes in evil mode.

But this is a function which is a toggle for the entire buffer. Can I instead get similar functionality by customizing org-appear to hide & unhide the inline src headers whenever the cursor/point is on it?


(defvar org-inline-src-hidden nil
    "Tracks whether inline source blocks and results are currently hidden.")

(defun org-toggle-inline-src-visibility ()
  "Toggle visibility of inline source blocks and results in the buffer."
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (let ((inhibit-read-only t))
      (if org-inline-src-hidden
          ;; Unhide inline source blocks and results
          (progn
            (remove-overlays (point-min) (point-max))
            (setq org-inline-src-hidden nil)
            (message "Inline source blocks and results are now visible."))
        ;; Hide inline source blocks and results
        ;; (while (re-search-forward "\\(src_[A-z-]+?{\\(.\\|\n\\)*?[^}]}\\)\\ ?\\({{{results(\\(.*\\))}}}\\)?" nil t)
        (while (re-search-forward "\\(src_[A-z-].*\\)\\({\\(.\\|\n\\)*?}\\)" nil t)
          (let ((start (match-beginning 0))
                (end (match-end 0)))
            ;; Debugging: Show what the regex matched
            (message "Hiding: %s" (buffer-substring-no-properties start end))
            ;; Apply overlay
            (let ((ov (make-overlay start end)))
              (overlay-put ov 'display (match-string 2)))
            ))
        (setq org-inline-src-hidden t)
        (message "Inline source blocks and results are now hidden.")))))
1
  • Gemini says that it can be done using (org-appear-set-entities '(emphasis links subscripts (custom-entity . "\\(my-custom-pattern\\)"))). But I can't get it to work. I also don' see this mentioned in the documentation, so i'm assuming this is just AI hallucination. Commented Nov 10 at 7:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.